Skip to content

fix(agents): subagents no longer stay Running after they finish - #206

Merged
badcuban merged 2 commits into
mainfrom
worktree-fix-stale-subagent-rows
Sep 3, 2026
Merged

fix(agents): subagents no longer stay Running after they finish#206
badcuban merged 2 commits into
mainfrom
worktree-fix-stale-subagent-rows

Conversation

@badcuban

@badcuban badcuban commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

The Agents panel and the "Agents working" row kept listing subagents as Running long after they had finished. On a live thread two ghost rows sat next to the one real agent: a background shell command that the harness had moved to the background, and an agent resumed with SendMessage after a provider restart. Both rows had no model and no token count, and nothing could ever settle them.

What went wrong:

  • The Claude adapter reported the SDK's "backgrounded" flag for any task, and both the server roster and the web fold created a subagent row from that flag alone. A shell command is not an agent, and the row had no status to match a stop against.
  • After a provider restart the adapter only knew a background agent by the SDK's "no completion record" notice. When the model resumed it with SendMessage, the SDK started the same task again under the resume call. The adapter's single-completion guard swallowed the new run, but the spawn-depth side effect still created an orphan row keyed by the resume call.

What changed:

  • A metadata patch that states no lifecycle status can only update a known row, never create one. Server projection and web fold agree.
  • The adapter reports the backgrounded flag only for agent tasks and promoted codex runs. A settled task that starts again under a different call is a resumed run and reports start, progress, and completion again. Spawn flags go out only on a task's first sighting.
  • When a turn completes on its own, its still-running foreground agents are settled with the turn. Background agents keep running: they legitimately outlive the turn that spawned them. Interrupted turns still sweep every agent of the turn, as before.
  • The web fold re-opens a settled record when its task reports work again, attaches the task stream's counters to roster-seeded records, and files a resumed agent's replayed final report on the agent's own row by task id, so a resume is one row rather than two.

Tests: projection (flag-only patch creates no row; replayed report lands on the row by task id), ingestion (foreground agent settles on turn complete, background one keeps running), adapter (restart then resume emits a run of its own with no orphan metadata; backgrounded shell command gets no row), web session logic (backgrounded shell command is not an agent; a resume after restart stays one row through progress, completion, and the final report).

Two ghost rows kept showing as running in the Agents panel and the agents-working row. A background shell command the harness moved to the background got a subagent row from its background flag alone. An agent resumed with SendMessage after a provider restart got an orphan row keyed by the resume call, while the adapter's single-completion guard swallowed its new run.

A metadata patch with no lifecycle status now only updates a known row, on both the server roster and the web fold. The Claude adapter reports the background flag only for agent tasks, treats a settled task starting again under a different call as a resumed run, and restates spawn flags only on first sighting. When a turn completes on its own, its still-running foreground agents are settled with it; background agents keep running. The web fold re-opens a settled record from the task stream and files a resumed agent's replayed final report on its own row by task id, mirroring the server.
@vercel

vercel Bot commented Sep 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
threadlines Ready Ready Preview Sep 3, 2026 5:31am UTC

Request Review

@github-actions github-actions Bot added size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels Sep 2, 2026
@badcuban
badcuban merged commit 7489fc0 into main Sep 3, 2026
16 checks passed
@badcuban
badcuban deleted the worktree-fix-stale-subagent-rows branch September 3, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant