Repository navigation
fix(subagent): hint before re-spawning every child whose state was unread - #19004
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that a gateway 404 for an unknown child id, which also has no [DESIGN-REVIEWED] d22c614 Description read[DESCRIPTION-READ] 4d5cd0d09194d3c99bd5a65126046599b307b318a0e363403ecfad42b4ee7a18 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 |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Before merge, check that the gateway never returns a no- What this change shipsInventory (2 items) — 2 justifiedIntent: stop an agent from re-spawning a started sub-agent that may still be running just because its final status read failed. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] d22c614 Description read[DESCRIPTION-READ] c22c396566380c1ac99c9131d57ed7b9f9fa5a84291911e779a27b0442e2782c That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
c421a33 to
654a647
Compare
654a647 to
ee2059d
Compare
|
Rebased onto The new test still fails on |
ee2059d to
e940182
Compare
…read When spawn_sub_agents could not read a child at the end of its wait (the gateway did not answer, so the read returned an error with no done), it kept the error entry but added the hint to check spawn_status before re-spawning only for a child the gate had deferred. A child that had started got a bare error, so a caller could dispatch the same work again while the first run kept going. The hint now goes on any error entry whose answer carries no done at all, as well as on a deferred child that is not done. The status, the error text, the settle and collect behaviour and the record shape are unchanged.
e940182 to
d22c614
Compare
iamwhatever
left a comment
There was a problem hiding this comment.
This PR makes spawn_sub_agents put the existing "check spawn_status before re-spawning" hint on any error entry whose status read came back with no done key, not only on gate-deferred children, which fixes the root cause: the hint was gated on sa_deferred alone, so a started child whose final read hit a dead gateway got a bare error that invites a double dispatch. I read the whole condition in _SubAgentsStep._collect (src/kiro_crew/mcp_tools/spawn.py:1979-1983) at head d22c614, and traced mcp_core._get/_send: transport failures and HTTPError bodies both come back as {"error": ...} with no done, so those are exactly the rows that now get the hint, while a finished-with-error row (done: True) and a done: False + error row keep their old keys. The status, counts and settled set are unchanged, so nothing new is collected or skipped. The one edge the design lanes raised, a 404 for an id the gateway forgot, also gets the hint, and that is harmless because the hint only tells the caller to look before re-spawning and spawn_status will report the id as unknown. The new test fails on main with KeyError 'hint' and passes here, and the control test pins the finished-error path. Base is main, it is mergeable, checks and all AI lanes are green on the current head, and there is no open change request. — crew-pr-reviewer (deep re-check)
Problem / Motivation
Goal: when
spawn_sub_agentscannot read a child's state at the end of its wait, the caller is told to checkspawn_statusbefore re-spawning, for a started child as well as a gate-deferred one.spawn_sub_agentsinsrc/kiro_crew/mcp_tools/spawn.pyreads each child once more after its wait. When the gateway does not answer,mcp_core._getreturns{"error": …}with nodone. The collect loop reports that as anerrorentry, and adds the hint "accepted at spawn time; its state couldn't be read now; check spawn_status before re-spawning" onlyif aid in sa_deferred(mcp_tools/spawn.py:1606at faa0b5b, current main), the children the gate answered withstatus: "queued". A child that started normally gets a bare error, though the loop's own comment says such a read "could be a transport failure … the agent may still be running".Why it matters
The tool's own rule, above its queued record: "a caller that sees an error for accepted work dispatches it again, and then it runs twice." A bare error for a started child that is still running invites that second dispatch.
Not a goal
error; the settle, count and collect behaviour and the record's keys are unchanged. A gateway-unreachable entry is documented as an error intest_spawn_queued_reason.py(test_a_transport_failure_is_still_an_error), and this change keeps that.done: Falsewith anerrorkeeps its exact keys, astest_failed_poll_of_an_unfinished_child_carries_no_textpins ("its block keeps its keys"); the hint keys ondonebeing absent, which is when no row was read.spawn_sub_agents(it moves the collect loop into a helper that takessa_deferred) and conflicts with this one inspawn.py; whichever lands second needs a rebase.What changed (motivation → approach → change)
sa_deferred.mcp_tools/spawn.py:1979-1983, +5 −1): the hint goes on an error entry when the child is not done and either it was deferred (as before) or the answer carries nodoneat all.self.sa_deferredis still read, so it stays. Since fix(mcp): park waiting tools off the worker so a wait stalls nobody #18841 the collect loop is_SubAgentsStep._collect, and the condition sits there.test/test_spawn_queued_reason.py, classTestSpawnSubAgentsHintsEveryUnreadChild, through the realspawn_sub_agents(driven to its reply by the file's_settle, as the sibling classes are) with the gateway client stubbed:test_a_started_child_the_gateway_did_not_answer_for_gets_the_hint, and the controltest_a_child_that_finished_with_an_error_gets_its_text_and_no_hint. Every existing test passes unchanged, including the deferred-child tests and the two above.Backwards compatibility
Compatible: the status values, the counts, the collected set and the record keys are unchanged. Only an error entry with no
donein its answer gains the existinghintkey.Removes nothing.
Tests
Red on unchanged
origin/main0a47021 (this test file copied into a detached checkout of it),pytest test/test_spawn_queued_reason.py -p no:cacheprovider -q -n 0, RC=1 in 3 of 3 runs:The 19 passed include the control and the deferred-child tests. Green on this branch, rebased onto 0a47021, the same command, RC=0 in 3 of 3 runs:
The 41 test files that import or name the
mcp_tools.spawnmodule,spawn_sub_agentsor_SubAgentsStep: 2790 passed, 4 skipped. mypy onspawn.py, flake8, isort and black on the changed files,scripts/check_black_formatting.py,scripts/docs-lint.sh,scripts/check_harness_parity.pyandCOMMENT_HISTORY_BASE_REF=origin/main scripts/check_comment_history.pyexit 0.Manual verification
None beyond the tests.
Related Issues
None found. Open #17684, #10175, #10171 and #12821 conflict in
mcp_tools/spawn.py, but they conflict there withorigin/mainalready:git merge-treeagainst this head lists the same conflicting files as againstorigin/main(#17684 is the one named in Not a goal). #18905 and #19274 have no conflict inmcp_tools/spawn.py.Pattern harvest
Rule candidate: a reply that cannot say whether accepted work is still running tells the caller how to check before dispatching it again.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)