Skip to content

fix: say a stopped sub-agent was stopped in the spawn read tools - #47837

Open
winnythedev wants to merge 2 commits into
mainfrom
fix/47792-spawn-read-tools-stopped-run
Open

winnythedev wants to merge 2 commits into
mainfrom
fix/47792-spawn-read-tools-stopped-run

Conversation

@winnythedev

@winnythedev winnythedev commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A parent reading a stopped sub-agent through spawn_list, spawn_status or spawn_sub_agents is 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_list shows [done];
  • spawn_status returns the partial output with no header;
  • spawn_sub_agents returns "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

  • Changing the status or list routes (dashboard/messaging_api/run_views.py), the completion event (slack/gateway_runtime/subagent_report.py) or the stop path itself.
  • Naming who stopped the run: the routes do not send the stop's origin, so the read tools say "Stopped" without it.
  • The wave's audit tallies (SEL metadata), which still count a stopped child under completed.

What changed (motivation → approach → change)

Symptom: the three read tools show a stopped run as finished.

Root cause: a stop leaves a run's error unset on purpose, and the routes say it was stopped in their own stopped field (stopped: true, outcome: "stopped"). The three tools branched only on done and error, so a stopped run fell into the finished branch. The completion event reads user_stopped and 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_list lists a stopped run as [stopped] ([stopped as it finished its answer] for that case); spawn_status puts a [STOPPED · <note>] header over the output it kept.
  • spawn_parts/wave.py: spawn_sub_agents writes "status": "stopped" with the note in a note field for a stopped child.
  • A Stop can land just as the child finishes its whole answer (_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 of GET /api/spawn carry one more read-only field, answer_finished (dashboard/messaging_api/run_views.py, the completion event's own test: _answer_finished, a result, not partial). 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.
  • An error still wins over a stop in all three tools: [ENDED WITH ERROR · <reason>], the error record, and [done] error: ... in the list, exactly as today.
  • mcp_tools/spawn.py, dashboard/handlers/messaging.py and mcp_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: the spawn_sub_agents status list, the spawn_status section and the status route's done fields say what a stopped run reads as and what answer_finished means.

Overlap: open PRs #46706, #46419, #46326 and #24710 add lines near the same spots in listing.py, and #46419 and #46326 in wave.py's collect step; #46306 touches the spawn.py facade; #40545, #46270, #46712, #47719 and #47739 edit other parts of subagent.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 completed status 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 real SubagentManager and reads it through the real api_spawn_status / api_spawn_list routes and the real tool handlers.
    • spawn_status carries the [STOPPED · ...] header over the partial output;
    • spawn_list shows [stopped], not [done];
    • spawn_sub_agents writes "status": "stopped" with the note, keeping the partial text;
    • a stop that landed as the answer finished: both routes send answer_finished: true, and spawn_status and spawn_sub_agents carry the "as it finished its answer" note over the whole answer;
    • an error wins over a stop on all three tools;
    • control: a finished run keeps [done], its bare result and completed.
  • The completion event and the read tools read one copy of each wording (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.

  • Acted on: a CI review lane blocked on a Stop that lands as the child's answer finishes (the whole answer read as unfinished); the routes now send answer_finished and the tools use the completion event's wording for it. The new test built SubagentManagers 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.
  • Second commit: independent reviewers on the new hunks found no defect; the completion event's text is byte-identical, and the new route field is a boolean derived from a run the caller can already read. The last re-check noted that spawn_list showed [stopped] for both stop kinds; it now reads the list row's answer_finished and says [stopped as it finished its answer], pinned by the new test.
  • Dismissed: the wave's audit tallies still count a stopped child under completed (out of scope, see Not a goal).

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.py and test_facade_mirror_guards.py all pass. local-gate.py --tree-scans ran 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-only test_spawn_tools_without_manager.py below. 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 load libffi.so.6): test_kiro_prerequisite_login_probe.py (unprivileged user namespaces refused), test_crew_log_previous_latch.py restart 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' -- src and the readers of the status/list routes' done/error fields
Sibling: 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 outcome and prints a stopped run as stopped
Sibling: src/kiro_crew/slack/gateway_runtime/subagent_report.py -- not affected -- the completion event already reads user_stopped

Pattern harvest

Rule candidate: review-prompt
Pattern: a reader of a sub-agent run that branches on error alone, where a stop leaves error empty; read outcome or stopped instead

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@winnythedev
winnythedev requested review from a team and KiroCrewCaptain as code owners December 5, 2026 16:01
@winnythedev
winnythedev requested a review from buluoray December 5, 2026 16:01
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 0c5f3ea720fdc7ceca1a7be57185eed1d217651d touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 0c5f3ea720fdc7ceca1a7be57185eed1d217651d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • A run read back from disk carries no answer_finished. A stop that landed as such a run finished its answer therefore reads as "before completing", and the parent may redo work that was already whole. The spec documents this; it errs toward caution and can be reversed later.

[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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 0c5f3ea720fdc7ceca1a7be57185eed1d217651d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 0c5f3ea

Verdict parsed from the review's SHA-scoped output markers for commit 0c5f3ea720fdc7ceca1a7be57185eed1d217651d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 0c5f3ea720fdc7ceca1a7be57185eed1d217651d false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 0c5f3ea720fdc7ceca1a7be57185eed1d217651d — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

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

  • Item 5 — duplicate of src/kiro_crew/slack/gateway_runtime/subagent_report.py:157: the new _answer_finished (run_views.py:68) re-spells the event's inline getattr(info, "_answer_finished", False) and info.result and not info.partial. Grepped _answer_finished\|_finished_answer in src/kiro_crew: 2 copies of the predicate. Only the wording was consolidated. Subtraction: delete the inline condition at subagent_report.py:157 and call the one predicate.

What this change ships

Inventory (7 items) — 6 justified

Intent: a parent agent reading a sub-agent that was stopped is told it was stopped, not handed partial output as a finished result. FIX.

  1. spawn_list shows a stopped run as [stopped] instead of [done] — justified
  2. spawn_list shows [stopped as it finished its answer] when the stop landed as the answer completed — justified
  3. spawn_status puts a [STOPPED · …] header over the output the run kept — justified
  4. spawn_sub_agents reports "status": "stopped" with a note, not completed — justified
  5. GET /api/spawn/{id} and each done row of GET /api/spawn gain an answer_finished boolean — duplicate of the inline test in subagent_report.py:157
  6. Both stop wordings move to subagent_ending.py, and the completion event reads them with byte-identical output — justified
  7. An error still wins over a stop in all three tools — justified

[FIRST-PRINCIPLES-REVIEWED] 0c5f3ea

Description read

[DESCRIPTION-READ] 8574d718b4c9ab2cb9c4a005959c28a282e6180c341c3f13ceddb4ac6867a34f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 0c5f3ea720fdc7ceca1a7be57185eed1d217651d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 0c5f3ea

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 0c5f3ea720fdc7ceca1a7be57185eed1d217651d false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 5, 2026
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
@bolichen97
bolichen97 force-pushed the fix/47792-spawn-read-tools-stopped-run branch from 8d3d6f4 to 328cbd2 Compare December 5, 2026 17:41
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 5, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 5, 2026
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
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 5, 2026
@winnythedev

Copy link
Copy Markdown
Contributor Author
  • A stop that landed as the answer finished read as unfinished span=55383da41251

fixed in 0c5f3ea: GET /api/spawn/{id} and each done row of GET /api/spawn now send answer_finished, the completion event's own test (_answer_finished, a result, not partial).
spawn_sub_agents (wave.py), spawn_status and spawn_list then use the completion event's "Stopped as it finished its answer. Do NOT retry it unprompted." wording, read from one copy in subagent_ending.py.
Pinned by test_a_stop_that_landed_as_the_answer_finished_says_so (both routes, all three tools).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: checking Automated validation is still running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

spawn_status, spawn_list and spawn_sub_agents show a stopped sub-agent as finished

1 participant