Repository navigation
fix: say a stopped sub-agent was stopped in the spawn read tools - #47837
winnythedev wants to merge 2 commits into
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change gives a stopped run its own status in all three read tools, reusing the completion event's exact wording, so the two cannot drift apart. Notes
[DESIGN-REVIEWED] 0c5f3ea Description read[DESCRIPTION-READ] 690cd5ab0409640f6d6954c410ef0df7204552ed7e0f3c78a01be2b5acc790d7 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The one note is that the "answer finished" test now exists twice, while the description claims the event and the tools "cannot drift apart". Notes
What this change shipsInventory (7 items) — 6 justifiedIntent: a parent agent reading a sub-agent that was stopped is told it was stopped, not handed partial output as a finished result. FIX.
[FIRST-PRINCIPLES-REVIEWED] 0c5f3ea Description read[DESCRIPTION-READ] 8574d718b4c9ab2cb9c4a005959c28a282e6180c341c3f13ceddb4ac6867a34f That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
A stop leaves a run's error unset, and the status and list routes say it was stopped in their own stopped field. spawn_list, spawn_status and spawn_sub_agents branched only on done and error, so a stopped run read as finished: [done], a bare partial result, and a "completed" record that also marks the child collected, which keeps the completion event (the one message that says it was stopped) from reaching the parent. The three tools now read the stopped field. spawn_list shows [stopped], spawn_status puts a [STOPPED · ...] header over the kept output, and spawn_sub_agents writes "status": "stopped" with a note, all in the completion event's words. A run that also has an error keeps today's error answer. Fixes #47792
8d3d6f4 to
328cbd2
Compare
A Stop can land just as a sub-agent finishes its whole answer. The completion event then says "Stopped ... as it finished its answer", but the status and list routes did not send that fact, so the three read tools called the whole answer unfinished, and spawn_sub_agents marks the child collected so the event never reaches the parent. The status and list routes now send answer_finished, the completion event's own test, and the read tools use the event's wording for it. Both wordings now live once, in subagent_ending, and the completion event reads them from there. Refs #47792
|
Problem / Motivation
Goal: A parent reading a stopped sub-agent through
spawn_list,spawn_statusorspawn_sub_agentsis told it was stopped, not handed its partial output as a finished result.A sub-agent stopped by Stop on its card, by Stop all or by its parent's end reads as finished to its parent:
spawn_listshows[done];spawn_statusreturns the partial output with no header;spawn_sub_agentsreturns"status": "completed"and marks the child collected, so the completion event, the one message that says "Stopped ... Do NOT treat this as a finished result", never arrives.The parent then tells its person the work is done when it was cut off part-way.
Why it matters
Every Stop of a sub-agent that its parent then reads meets this. The parent reports cut-off work (in the repro, an audit that looked at 3 of 40 modules) as finished, and nothing tells it otherwise.
Not a goal
dashboard/messaging_api/run_views.py), the completion event (slack/gateway_runtime/subagent_report.py) or the stop path itself.What changed (motivation → approach → change)
Symptom: the three read tools show a stopped run as finished.
Root cause: a stop leaves a run's
errorunset on purpose, and the routes say it was stopped in their ownstoppedfield (stopped: true,outcome: "stopped"). The three tools branched only ondoneanderror, so a stopped run fell into the finished branch. The completion event readsuser_stoppedand gets it right; the earlier notes it carries (#25496, #46384) reached these readers, the stop did not.Change:
spawn_parts/listing.py:stopped_run_note(record)gives the completion event's words.spawn_listlists a stopped run as[stopped]([stopped as it finished its answer]for that case);spawn_statusputs a[STOPPED · <note>]header over the output it kept.spawn_parts/wave.py:spawn_sub_agentswrites"status": "stopped"with the note in anotefield for a stopped child._answer_finished,subagent_manager/run_turn.py). The completion event then says "Stopped ... as it finished its answer. Do NOT retry it unprompted.", and the read tools now say the same:GET /api/spawn/{id}and each done row ofGET /api/spawncarry one more read-only field,answer_finished(dashboard/messaging_api/run_views.py, the completion event's own test:_answer_finished, a result, notpartial). No route, auth, admission or stop-path change. This answers the review lane's block on that race; the routes otherwise stay as they were.subagent_ending.py: both stop wordings live there once (STOPPED_BEFORE_COMPLETING,STOPPED_AS_IT_FINISHED); the completion event (slack/gateway_runtime/subagent_report.py) reads them, with byte-identical output, and so do the read tools.[ENDED WITH ERROR · <reason>], theerrorrecord, and[done] error: ...in the list, exactly as today.mcp_tools/spawn.py,dashboard/handlers/messaging.pyandmcp_listing_relay.py: the facades and the listing relay's import list name the new helpers and module (the facade mirror guard, the spawn-parts contract, the messaging composition and the listing code stamp require it).docs/system-specs/modules/subagent.md: thespawn_sub_agentsstatus list, thespawn_statussection and the status route's done fields say what a stopped run reads as and whatanswer_finishedmeans.Overlap: open PRs #46706, #46419, #46326 and #24710 add lines near the same spots in
listing.py, and #46419 and #46326 inwave.py's collect step; #46306 touches thespawn.pyfacade; #40545, #46270, #46712, #47719 and #47739 edit other parts ofsubagent.md. None of them changes the done/error branches this PR edits; whichever lands second rebases.Backwards compatibility
Compatible: a finished run and a run that ended with an error read exactly as before; only a stopped run, which had no stopped reading at all, now reads as stopped. No tool description or schema changed, only reply text. The routes gain one boolean field; no reader rejects unknown fields.
Removes nothing: the
completedstatus and the[done]tag still mean what they did for every run that was not stopped; a stopped run gets its own value instead.Tests
test/test_spawn_read_tools_stopped_run.py(new): builds a stopped run the way a Stop records it (user_stopped,_stop_origin) on a realSubagentManagerand reads it through the realapi_spawn_status/api_spawn_listroutes and the real tool handlers.spawn_statuscarries the[STOPPED · ...]header over the partial output;spawn_listshows[stopped], not[done];spawn_sub_agentswrites"status": "stopped"with the note, keeping the partial text;answer_finished: true, andspawn_statusandspawn_sub_agentscarry the "as it finished its answer" note over the whole answer;[done], its bare result andcompleted.subagent_ending.py), so they cannot drift apart.Proof: not provable -- other: the tests import the new STOPPED_RUN_NOTE constant, so reverting the production hunks fails them at collection; the before run below was taken with literal assertions instead
Before the fix (base beb6b70, same test with literal assertions): 3 failed, 3 passed (the three stopped-run cases fail; the error-wins and finished-run controls pass). After (head): 7 passed, the answer-finished case included.
Review (multi-model interrogate)
Independent reviewers on three model families read the full diff against the CI lane contracts, then one re-check covered the revised hunks.
answer_finishedand the tools use the completion event's wording for it. The new test builtSubagentManagers without binding the repo's autouse cleanup fixture (_close_subagent_managers), leaving their database handles open; it now binds it. Assertions now use the constant instead of literal slices. The facade manifest entry came from the tree-scan facade guard.spawn_listshowed[stopped]for both stop kinds; it now reads the list row'sanswer_finishedand says[stopped as it finished its answer], pinned by the new test.Gates run locally (Linux x86_64)
black (touched files),
check_black_formatting.py,check_subprocess_encoding.py, isort, flake8,check_comment_history.py,check_brand_name.py,check_agent_sdk_boundary.py,check_file_line_cap.py,check_harness_parity.py, docs-lint, semgrep 1.78.0 with the base as baseline,test_flake_pattern_ratchet.py,test_wait_discipline_ratchet.py,test_spawn_parts_contract.pyandtest_facade_mirror_guards.pyall pass.local-gate.py --tree-scansran the related set on the first commit: 66,567 passed; for the second commit the 114 test files that name the routes, the read tools or the completion event ran, and all pass except the host-onlytest_spawn_tools_without_manager.pybelow. Its whole-tree scan shards did not finish locally (11% after 20 minutes) and are left to CI; the facade mirror guard scan ran inside the related set and passes. The failures it reported also fail on clean main on this host, or fail on the host's child-process setup (a scrubbed-env child Python that cannot loadlibffi.so.6):test_kiro_prerequisite_login_probe.py(unprivileged user namespaces refused),test_crew_log_previous_latch.pyrestart probes,test_mcp_listing_import_budget.py,test_mcp_listing_relay.py,test_spawn_tools_without_manager.py. mypy reports six errors in untouched files (metrics/,tracing/,wecom/) from this host's installed stubs and aiohttp. The tool-byte ceiling test was not run: no tool description or schema changed.Manual verification
N/A -- unit coverage drives the real routes and the real
SubagentManager; no live gateway or dashboard run was done.Real-machine verification
Machine: a Linux x86_64 developer host.
Before (main beb6b70):
python -m pytest -n0 test/test_spawn_read_tools_stopped_run.py-> 3 failed, 3 passed ([done], a bare partial result,"status": "completed"for a stopped run).After (head): the same command -> 7 passed.
Cleanup: own computer; no gateway was started and no machine was created.
Related Issues
Fixes #47792
Sibling sweep
Swept:
git grep -ln '/api/spawn' -- srcand the readers of the status/list routes'done/errorfieldsSibling: src/kiro_crew/mcp_tools/spawn_parts/listing.py -- changed here
Sibling: src/kiro_crew/mcp_tools/spawn_parts/wave.py -- changed here
Sibling: src/kiro_crew/cli_commands_gateway_api.py -- not affected -- the CLI waiter already reads
outcomeand prints a stopped run as stoppedSibling: src/kiro_crew/slack/gateway_runtime/subagent_report.py -- not affected -- the completion event already reads
user_stoppedPattern harvest
Rule candidate: review-prompt
Pattern: a reader of a sub-agent run that branches on
erroralone, where a stop leaveserrorempty; readoutcomeorstoppedinsteadChecklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commitsContribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.