Repository navigation
#904 Session Chat: background work pill for subagents - #917
Conversation
Real-app check: scenario harness, v2 serverThe pill is mounted temporarily (uncommitted) in the row above the composer. Its final place is the #903 bottom-left slot. On Android the temporary mount sits in the prompt composer row, so step 4 collapses the permission panel first. The #903 slot decides the real placement. |
ivanfenenko
left a comment
There was a problem hiding this comment.
Review of PR #917 at dd9a59a5 (everything except the deliberately missing mount).
Verified fine:
- v1
sessionId/ v2sessionIDdiscovery goes through the existing linker on both platforms. - Nested waiting walks
parentID, and requests from the parent itself or from other trees are not attributed. - Busy child sessions use the same seeded-or-cached rule on both platforms.
- Panel order and the singular/plural labels are right, and the spoken label is used.
- Reduce Motion is handled by the shared
OpenCodeFloatingPill. - The per-second timer lives inside the sheet only (iOS
TimelineView, AndroidproduceState, which also stops when nothing is active). The pill and the chat do not tick. - Finish times are keyed by part id and pruned to the current rows, so nothing leaks across sessions or grows beyond the loaded messages.
- The status variant on the row uses tokens only.
- No private data in the code, tests or evidence comment.
Tests run locally:
- iOS
SessionChatBackgroundWorkTests: 15 passed. - Android
SessionChatBackgroundWorkTest(15) and the subagentSessionChatViewModelTestcases (6): passed.
Findings: two should-fix, the same issue on both platforms (resumed subagent double count, frozen time after background), and one nit (error shown as done). Inline below.
| if let childID, waitingChildIDs.contains(childID) { | ||
| .waitingForInput | ||
| } else if tool.status == .running || tool.status == .pending | ||
| || childID.map(busySessionIDs.contains) == true { |
There was a problem hiding this comment.
should-fix: a resumed subagent is counted twice (or more)
Rows are keyed by tool part, and status comes from the child session. A task the parent resumes gets a second tool part linked to the same child session: v1 task with task_id reuses the session and writes the same metadata.sessionId, and SessionChatChildSessionLinker already maps a resume's input.sessionID onto the earlier child. While that child runs, every part for it passes busySessionIDs.contains(childID) (and waitingChildIDs the same way). The old completed part flips back to running.
Failure scenario: the parent runs general once, it finishes, and later resumes it. During the resume the pill says "2 subagents" and the panel shows two running rows with different timers, one counting from the first spawn. If the resumed child asks for permission, the pill says "2 subagents need input" for one asker.
Fix: apply child-session state (busy / waiting) only to the latest part per childSessionID. Earlier parts for the same child keep their own tool status, so they show as done. Alternatively, collapse the rows to one per child. Add a test with two parts sharing a sessionID and a busy child: expect one running row and the pill "1 subagent". The Android model (same logic) needs the same change.
There was a problem hiding this comment.
Fixed in b13af47: rows are now one per child session.
subagentskeeps only the latest subagent tool part per child session id, whether the id comes frommetadata.sessionId(v1task_idresume) or the linker'sinput.sessionIDmapping.- The row takes its id, title, start time and status from that part, so the timer counts from the resume.
- Earlier parts for the same child are dropped instead of shown as done. A resume is the same subagent, and a second "done" row for it would read as a separate subagent.
- Parts with no child id yet keep their own rows.
Tests (SessionChatBackgroundWorkTests):
subagents_resumedChildKeepsOneRowFromTheLatestPart: two parts shareses-aand the child is busy. Expect one running row with the resume's start, and the pill says "1 subagent".subagents_resumedChildWaitingCountsOnce: the pill says "general needs input".subagents_partsWithoutChildStaySeparate.
| childId != null && childId in waitingChildIds -> SessionChatSubagentStatus.WaitingForInput | ||
| tool.status == ToolStatus.Running || | ||
| tool.status == ToolStatus.Pending || | ||
| (childId != null && childId in busySessionIds) -> SessionChatSubagentStatus.Running |
There was a problem hiding this comment.
should-fix: same double count as the iOS comment on SessionChatBackgroundWork.swift. A resumed task's earlier part shares the child sessionId, so it shows running or waiting again. Use child state only for the latest part per child.
There was a problem hiding this comment.
Fixed in b13af47, same as iOS: one row per child session from its latest part. Same three tests in SessionChatBackgroundWorkTest.
| if row.isActive { | ||
| next[row.id] = nil | ||
| } else if next[row.id] == nil, wasActive.contains(row.id) { | ||
| next[row.id] = nowMs |
There was a problem hiding this comment.
should-fix: the frozen run time includes time the app was in the background
finishTimes stamps clock.nowMs() the first time the view model sees a row go from active to done. While the app is in the background there is no SSE. The transition is only seen after foregrounding, when the REST refresh on reconnect runs, so the stamp is the foreground time and not the finish time.
Failure scenario: a subagent starts at 12:00:00. The user backgrounds the app at 12:00:30, and the subagent finishes at 12:00:45. The user returns at 12:10:00. The panel shows the row as done with a frozen 10:00 instead of about 0:45. The same happens after any SSE drop longer than the subagent's remaining time.
Fix, in order of preference:
- Freeze from server time: carry the tool part's
state.time.endthrough the adapter (ToolPartonly hastimeStartEpochMstoday), or use the child session'stime.updated. - Or stamp a finish time only for transitions delivered by live SSE. A transition found by the reconnect or REST refresh shows no time, like rows that finished before the chat opened.
Add a test that goes from running to a long gap to done after a refresh. The Android finishTimes has the same issue.
There was a problem hiding this comment.
Fixed in b13af47: a finished row now freezes at a server time.
ToolPartcarriestimeEndEpochMsbehind the adapters:- v1:
state.time.end(REST and SSE). - v2 REST: content
time.completed. - v2 SSE: the
createdtime oftool.success/tool.failed. - The message store merges and the session cache keep it.
- v1:
finishTimeorder:- The tool end time. Background calls skip it, because they settle at spawn while the child keeps working.
- The child session's
time.updated. - A local stamp, the last resort.
- Times before the start are ignored.
finishTimesnow stamps locally only for rows with no server time, and only whenseenLiveis true: the previous rows were computed during the current live connection.- The view model resets its live-since mark whenever the connection leaves
live. - So a finish found by the reconnect refresh, after backgrounding or an SSE drop, gets no time, like rows that finished before the chat opened.
- The view model resets its live-since mark whenever the connection leaves
Tests:
finishTime_usesTheToolEndFromTheServer: start 12:00:00, end +45s, session updated +10 min. Expect 0:45.finishTime_backgroundCallUsesTheChildSessionUpdate.finishTime_serverTimeWinsOverALocalStampAndIgnoresTimesBeforeStart.finishTimes_findingAFinishAfterAGapStampsNothing: running, then a 10-minute gap, then done after the refresh. Nothing is stamped and the row shows no time.finishTimes_skipsRowsWithAServerFinish.- Adapter tests:
messagePart_completedMapsTimeEnd, the v2time.completedprojection, andparseEvent_settledToolStampsItsEventTimeAsTheEnd.
| if (row.isActive) { | ||
| next.remove(row.id) | ||
| } else if (row.id !in next && row.id in wasActive) { | ||
| next[row.id] = nowMs |
There was a problem hiding this comment.
should-fix: same as the iOS comment. nowMs() here is when the VM first sees the row done. After background or reconnect, that is the foreground time, so the frozen run time includes the time away. Prefer the server end time (state.time.end, or the child session's time.updated).
There was a problem hiding this comment.
Fixed in b13af47, same as iOS.
MessagePart.Tool.timeEndEpochMscomes from v1state.time.end, v2time.completed, and the v2 settled event time.- Fallback is the child session's
updatedAtEpochMs. - The local stamp happens only when the finish is seen live with no server time.
- Same tests in
SessionChatBackgroundWorkTest,MessageDomainAdapterTestandEventDomainAdapterTest.
| || childID.map(busySessionIDs.contains) == true { | ||
| .running | ||
| } else { | ||
| .done |
There was a problem hiding this comment.
nit: errored and aborted subagents read as "done"
A task/subagent part in error state lands here: the subagent threw, or the parent was aborted while children ran. The panel row then says "done" in weak text with a frozen time. Nothing tells the user it failed. Consider a failed status (row label "failed" or "stopped" on the error token), or at least leave "done" off error parts. If done is intentional for now, a test that pins the error-to-done mapping would help.
There was a problem hiding this comment.
Fixed in b13af47 on both platforms.
- A subagent part in
errorbecomesfailed, orstoppedwhen the call was interrupted (user abort or declined). OpenCodeChildSessionRowgets matchingfailed(error token) andstopped(weak text) status variants.- Neither counts as running or waiting, so the pill ignores them. Their rows keep a frozen time like done.
- The Component Gallery shows both, in the Background Work Pill panel and the Child Session Row status control.
- Test:
subagents_errorIsFailedAndInterruptedIsStopped_neitherCounts, with busy children, so the error wins over the child's busy state.
b13af47 to
6ccc9e9
Compare
Real-app check after mounting: scenario harness, v2 serverThe pill is in the #903 bottom-left activity slot, stacked on #918. Once every permission is answered the pill leaves the slot on both apps. |
- Pure SessionChatBackgroundWork on both platforms lists the subagents the open session started: running while the task/subagent tool runs or the child session is busy (v1 session.status, v2 session.execution / active), waiting for input when the child or a session under it has a pending permission or question, otherwise done. Done rows keep the run time the app saw. Agent names come from the tool input, then the v2 session agent or the v1 title suffix, like the request panels. - The pill says "3 subagents" with a spinner, or the amber "general needs input · 2 running" with a pulsing dot, on the shared floating pill counter layout; it hides when nothing works or waits. - Subagents panel: one child session row per subagent with its status and a live timer; the child session row gains a status variant. - Component Gallery: Background Work Pill entry and the row status control. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The status and timer column no longer compresses, so "waiting for input" stays readable and the subtitle truncates first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…opped rows - A resumed subagent (v1 task_id, or a resume the linker maps through input.sessionID) adds a tool part for the same child session. The panel now keeps one row per child session, from its latest part, so the child's live state no longer makes the earlier, finished call count as running or waiting again. - Tool parts carry the server end time behind the adapters: v1 state.time.end, v2 content time.completed, and the v2 settled tool event time. A finished row freezes at that time. Background calls (which settle at spawn) use the child session's last update instead. Only rows with no server time get a local stamp, and only when the app watched the finish live; a finish found by the reconnect refresh shows no time. - Errored subagents show "failed" on the error token, stopped ones "stopped"; neither counts as running. The child session row gains both status variants and the gallery shows them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- New Subagents activity item on both platforms: running work, or needs input (amber, pulsing dot, stays full with the keyboard up) while a subagent waits on a permission or question. It shows under any composer, so a waiting subagent stays visible next to an open request panel. - Tapping it opens the Subagents panel; a row opens that subagent's session. - Slot tests cover its priority, look and spoken label. Co-Authored-By: Claude Opus 5.5 <[email protected]>
19334f1 to
aedbc02
Compare























Fixes #904
What
SessionChatBackgroundWork): lists the subagents the open session started, from itstask(v1) /subagent(v2) tool parts, linked to child sessions like the timeline (metadata.sessionId/sessionID, plus the existing linker fallback).task_id, or a resume the linker maps throughinput.sessionID). Only the latest part counts: the row takes its title, start time and status from it, and earlier parts for that child are dropped. A resume is the same subagent, so two rows (one "done", one running) would read as two subagents. Applying the child's live state to every part would count it twice.session.statusand v2session.execution.*/GET /api/session/active, and refreshes over REST on reconnect. So a v1 background task whose tool call has already completed stays running while its child works.parentID), has a pending permission or question. This reuses the requests the inbox already collects for the session tree (Session Chat: name the asking subagent and page requests in permission and question panels #901).timeEndEpochMsbehind the adapters: v1state.time.end; v2 REST contenttime.completed; v2 SSE the settled tool event's time.time.updatedinstead.agent/subagent_type), then the v2 sessionagentfield or the v1 title suffix, like the Session Chat: name the asking subagent and page requests in permission and question panels #901 request panels.OpenCodeFloatingPillcounter layout):OpenCodeChildSessionRowgains an optional status variant: running, waiting for input (amber), done, failed (error token) and stopped. The Component Gallery gets a Background Work Pill entry (pill + panel, needs-input and compact toggles) and a Status control on Child Session Row.subagentsactivity item, on both platforms:Shells are out of scope (#907).
Checks
SessionChatBackgroundWorkTests(24): counting, labels, priority, nested waiting, resumed subagents, server and local finish times, failed/stopped.SessionChatBackgroundWorkTests,SessionChatViewModelTests,MessageDomainAdapterTests,EventDomainAdapterTests,SessionMessageEngineTests: 444 passed.SessionChatBackgroundWorkTest(24), plus the matching adapter and view model tests.ui.sessionchat.*,ui.components.*,domain.message.*,domain.event.*anddomain.sessioncache.*: 1549 passed.subagent-open-after-spawnand Session Chat: name the asking subagent and page requests in permission and question panels #901'spermission-in-parallel-subagents. Screenshots are in the latest evidence comment.sendPrompt_postSendReloadMatchingUser_dropsOptimistic(iOS) is a timing flake already on #903 Session Chat: corner slots for floating pills #918's branch: it also failed 5 of 6 runs on the base under load. Scenarios:subagent-open-after-spawn, Session Chat: name the asking subagent and page requests in permission and question panels #901'spermission-in-parallel-subagentsandquestion-in-parallel-subagents. Screenshots are in the comment below.Risks / Follow-ups
metadata.sessionId,session.status, title-suffix names) are covered by unit tests only.time.updatedfallback only has data when the session tree has been fetched, which today happens for a subagent's permission or question. Otherwise a v1 background subagent gets its time only from a live finish.🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmith-botwith what you need.