Repository navigation
fix(subagents): report a run orphaned by a restart as interrupted - #990
Merged
Merged
Conversation
A background run writes a "running" status entry when it starts and a
result entry when it ends. If the pi-web process stops in between, the
child session is left with "running" as its last lifecycle entry and no
result. After a restart get() read that entry verbatim, so the run
reported "running" forever and get_subagent_result({ wait: true }) never
returned, leaving the parent stuck.
A run stays in the in-memory run table from dispatch until its result
entry is written, so a persisted running or queued status that reaches
get() without a table entry and without a running wrapper can never
finish. Report it as interrupted, the status the tool already renders
("was interrupted before completion"), so the wait returns and the run
can be resumed.
Owner
|
Reviewed. The bug is real: after a restart, a background child whose last lifecycle entry is What I checked:
The two Generated by Claude Code |
This was referenced Oct 29, 2026
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 6, 2026
…egr#990) A background run writes a "running" status entry when it starts and a result entry when it ends. If the pi-web process stops in between, the child session is left with "running" as its last lifecycle entry and no result. After a restart get() read that entry verbatim, so the run reported "running" forever and get_subagent_result({ wait: true }) never returned, leaving the parent stuck. A run stays in the in-memory run table from dispatch until its result entry is written, so a persisted running or queued status that reaches get() without a table entry and without a running wrapper can never finish. Report it as interrupted, the status the tool already renders ("was interrupted before completion"), so the wait returns and the run can be resumed. Co-authored-by: CLAY777 <[email protected]>
windli2018
pushed a commit
to aiti-ai/aiti-ai
that referenced
this pull request
Nov 8, 2026
…egr#990) A background run writes a "running" status entry when it starts and a result entry when it ends. If the pi-web process stops in between, the child session is left with "running" as its last lifecycle entry and no result. After a restart get() read that entry verbatim, so the run reported "running" forever and get_subagent_result({ wait: true }) never returned, leaving the parent stuck. A run stays in the in-memory run table from dispatch until its result entry is written, so a persisted running or queued status that reaches get() without a table entry and without a running wrapper can never finish. Report it as interrupted, the status the tool already renders ("was interrupted before completion"), so the wait returns and the run can be resumed. Co-authored-by: CLAY777 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while reviewing the background-notification path for #987; it is a separate bug with a separate fix.
Problem
A background run appends a
pi-web:subagent-statusrunningentry when it starts and api-web:subagent-resultentry when it ends. If the pi-web process stops in between (restart, crash,pi-webupgrade), the child session is left withrunningas its last lifecycle entry and no result.After the restart,
get()returns that entry verbatim, so:get_subagent_result({ wait: true })polls forever, and the parent turn never ends;Change
lib/subagent-runtime.ts: a run stays ingetSubagentRuns()from dispatch until its result entry is written, on every path (completed, failed, aborted, queued-abort). So whenget()reads a persistedrunning/queuedstatus without a table entry and without a running wrapper, the run can never finish.get()now reports it asinterrupted, a statussubagentFinalTextalready renders ("was interrupted before completion"). The wait loop returns, and the parent canresumethe child.Only
get()changes. The session list andreadSubagentRunare untouched, so nothing is written to the session file and no notification or turn is triggered.Tests
runningorqueuedstatus and no active run →interrupted.running..jsonlafter a simulated restart →interrupted.The two
interruptedcases fail onmainand pass with the change.tscand lint are clean.npm test: the only failures are the existing Windows-host ones, and they fail onmaintoo.