Skip to content

#904 Session Chat: background work pill for subagents - #917

Merged
ivanfenenko merged 4 commits into
mainfrom
feature/904-background-work-pill
Nov 1, 2026
Merged

ivanfenenko merged 4 commits into
mainfrom
feature/904-background-work-pill

Conversation

@ivanfenenko

@ivanfenenko ivanfenenko commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #904

What

  • Pure model, both platforms (SessionChatBackgroundWork): lists the subagents the open session started, from its task (v1) / subagent (v2) tool parts, linked to child sessions like the timeline (metadata.sessionId / sessionID, plus the existing linker fallback).
    • One row per child session. A resumed subagent adds a new tool part for the same child (v1 task_id, or a resume the linker maps through input.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.
    • running: the tool part is pending/running, or the child session is busy in the live activity store. That store already follows v1 session.status and v2 session.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.
    • waiting for input: the child, or any session under it (walked by 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).
    • failed / stopped: the tool part errored, or was interrupted by an abort or a decline. These are not counted as running.
    • done: everything else.
    • Finished rows freeze at a server time. Tool parts now carry timeEndEpochMs behind the adapters: v1 state.time.end; v2 REST content time.completed; v2 SSE the settled tool event's time.
      • Background calls settle at spawn, so they use the child session's time.updated instead.
      • A local stamp is the last resort. It is only used when the app watched the finish live, during the same live connection.
      • A finish found by a reconnect refresh shows no time rather than one that includes the time away.
    • Agent name comes from the tool input (agent / subagent_type), then the v2 session agent field or the v1 title suffix, like the Session Chat: name the asking subagent and page requests in permission and question panels #901 request panels.
  • Pill (on the shared OpenCodeFloatingPill counter layout):
    • "3 subagents" with a spinner.
    • Amber "general needs input · 2 running" with a pulsing dot. With several waiting it says "2 subagents need input · 1 running".
    • Hidden when nothing is running or waiting. Spoken as "general needs input, 2 subagents running".
  • Subagents panel: a bottom sheet with one child session row per subagent: agent, task, status and a live timer. Waiting rows come first, then running, then done. Tapping a row with a known session opens that subagent's session.
  • Design system: OpenCodeChildSessionRow gains 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.
  • Mounted in the Session Chat: corner slots for floating pills #903 bottom-left activity slot as a subagents activity item, on both platforms:
    • Priority is running work, or needs input while a subagent waits. Needs input uses the amber counter with the pulsing dot and stays full size with the keyboard up.
    • It shows under any composer, so a waiting subagent stays visible next to an open permission or question panel.
    • Tapping it opens the Subagents panel.
  • Analytics ids for opening and dismissing the panel.

Shells are out of scope (#907).

Checks

  • iOS:
    • SessionChatBackgroundWorkTests (24): counting, labels, priority, nested waiting, resumed subagents, server and local finish times, failed/stopped.
    • Adapter tests for the tool end time (v1, v2 REST, v2 event).
    • A view model test: the pill from three running subagents and one subagent permission.
    • SessionChatBackgroundWorkTests, SessionChatViewModelTests, MessageDomainAdapterTests, EventDomainAdapterTests, SessionMessageEngineTests: 444 passed.
  • Android:
    • SessionChatBackgroundWorkTest (24), plus the matching adapter and view model tests.
    • ui.sessionchat.*, ui.components.*, domain.message.*, domain.event.* and domain.sessioncache.*: 1549 passed.
  • Slot tests on both platforms: the subagents item's priority (running / needs input), staying full size with the keyboard up, the counter layout with the pulsing dot, and the spoken label. On Android, a test that it shows under the child-session lockout.
  • Real apps against the scenario harness on v2, after mounting: subagent-open-after-spawn and Session Chat: name the asking subagent and page requests in permission and question panels #901's permission-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's permission-in-parallel-subagents and question-in-parallel-subagents. Screenshots are in the comment below.

Risks / Follow-ups

  • Not checked against a v1 server: no v1 binary on this machine. The v1 paths (metadata.sessionId, session.status, title-suffix names) are covered by unit tests only.
  • A live "general needs input · 2 running" mix did not come up in the harness runs: the scenarios' subagents all wait at once, or finish quickly once allowed. The real-app runs showed "1 subagent", "2 subagents need input" and "general needs input". The mixed label is covered by unit tests and the gallery.
  • The child session time.updated fallback 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.
  • Background shells (Session Chat: shells in the background work pill #907).

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Real-app check: scenario harness, v2 server

The pill is mounted temporarily (uncommitted) in the row above the composer. Its final place is the #903 bottom-left slot.

Step iOS Android
1. subagent-open-after-spawn: "1 subagent" with spinner ios 1 android 1
2. Subagents panel: live timer on the running row, frozen time on rows seen finishing ios 2 android 2
3. Tapping the running row opens the subagent's session ios 3 android 3
4. permission-in-parallel-subagents: amber "2 subagents need input" ios 4 android 4
5. Explore's permission answered by another client: "general needs input" ios 5 (same state, panel below)
6. Panel with a subagent waiting for input (iOS: question-in-parallel-subagents) ios 6 android 6

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 ivanfenenko left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of PR #917 at dd9a59a5 (everything except the deliberately missing mount).

Verified fine:

  • v1 sessionId / v2 sessionID discovery 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, Android produceState, 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 subagent SessionChatViewModelTest cases (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 {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b13af47: rows are now one per child session.

  • subagents keeps only the latest subagent tool part per child session id, whether the id comes from metadata.sessionId (v1 task_id resume) or the linker's input.sessionID mapping.
  • 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 share ses-a and 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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.end through the adapter (ToolPart only has timeStartEpochMs today), or use the child session's time.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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b13af47: a finished row now freezes at a server time.

  • ToolPart carries timeEndEpochMs behind the adapters:
    • v1: state.time.end (REST and SSE).
    • v2 REST: content time.completed.
    • v2 SSE: the created time of tool.success / tool.failed.
    • The message store merges and the session cache keep it.
  • finishTime order:
    1. The tool end time. Background calls skip it, because they settle at spawn while the child keeps working.
    2. The child session's time.updated.
    3. A local stamp, the last resort.
    • Times before the start are ignored.
  • finishTimes now stamps locally only for rows with no server time, and only when seenLive is 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.

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 v2 time.completed projection, and parseEvent_settledToolStampsItsEventTimeAsTheEnd.

if (row.isActive) {
next.remove(row.id)
} else if (row.id !in next && row.id in wasActive) {
next[row.id] = nowMs

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b13af47, same as iOS.

  • MessagePart.Tool.timeEndEpochMs comes from v1 state.time.end, v2 time.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, MessageDomainAdapterTest and EventDomainAdapterTest.

|| childID.map(busySessionIDs.contains) == true {
.running
} else {
.done

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b13af47 on both platforms.

  • A subagent part in error becomes failed, or stopped when the call was interrupted (user abort or declined).
  • OpenCodeChildSessionRow gets matching failed (error token) and stopped (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.

@ivanfenenko
ivanfenenko changed the base branch from main to feature/903-pill-corner-slots November 1, 2026 00:32
@ivanfenenko
ivanfenenko force-pushed the feature/904-background-work-pill branch from b13af47 to 6ccc9e9 Compare November 1, 2026 00:32
@ivanfenenko

Copy link
Copy Markdown
Collaborator Author

Real-app check after mounting: scenario harness, v2 server

The pill is in the #903 bottom-left activity slot, stacked on #918.

Step iOS Android
1. subagent-open-after-spawn: "1 subagent" in the activity slot ios 1 android 1
2. Subagents panel: live timer on the running row; finished rows freeze at the server run time (0:03, 0:27, …), including on Android, which never saw those runs live ios 2 android 2
3. Tapping the running row opens the subagent's session ios 3 android 3
4. permission-in-parallel-subagents: amber "2 subagents need input" with the pulsing dot, beside the open permission panel ios 4 android 4
5. Explore's permission allowed by another client: "general needs input" ios 5 android 5
6. The panel lists the waiting subagent first ios 6 android 6

Once every permission is answered the pill leaves the slot on both apps.

@ivanfenenko
ivanfenenko marked this pull request as ready for review November 1, 2026 00:57

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review: no finding that 2+ of 1 passes agreed on.

opencode pr-review · passes: muse-spark-1.3-contributor, glm-5.3-flash, deepseek-v4.1-flash · $0.154 · 2 pass(es) failed

Base automatically changed from feature/903-pill-corner-slots to main November 1, 2026 10:19
ivanfenenko and others added 4 commits November 1, 2026 11:27
- 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]>
@ivanfenenko
ivanfenenko force-pushed the feature/904-background-work-pill branch from 19334f1 to aedbc02 Compare November 1, 2026 10:27
@ivanfenenko
ivanfenenko merged commit ba5e5c9 into main Nov 1, 2026
@ivanfenenko
ivanfenenko deleted the feature/904-background-work-pill branch November 1, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session Chat: background work pill for subagents

1 participant