Repository navigation
fix(subagent): tell a restart orphan's parent how to resume the run - #13317
Conversation
|
Intent: A sub-agent orphaned by a gateway restart whose conversation still exists on disk is announced with its progress and the |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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: |
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS Verify once against a real restart orphan that [DESIGN-REVIEWED] 2685c6f |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The hint decorates only the no-result orphan; the mid-turn Not justified as shipped
What this change shipsInventory (8 items) — 6 justifiedIntent: FIX — a restart orphan's parent is told "no result" and re-spawns, when the surviving conversation could be resumed with
[FIRST-PRINCIPLES-REVIEWED] 2685c6f |
0aa1955 to
50f4c0a
Compare
|
|
|
Opus 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: |
buluoray
left a comment
There was a problem hiding this comment.
Approving at 50f4c0a.
Verified: SessionMap.get behaves exactly as before (the 10-byte prune is now _RESUMABLE_JSONL_MIN_BYTES through a shared helper), and session_files_resumable applies the same rule per provider. The offered spawn_continue(conversation=<agent_id>) handle resolves, because _continue_prelude_impl seeds subagent:<id> from state.json, and a session that is gone gets a typed conversation_gone rather than a crash. The hint is additive and wrapped in try/except. Removing the resumability gate reddens test_a_lost_orphan_with_a_surviving_conversation_says_how_to_resume. 306 + 40 tests passed.
50f4c0a to
d6f2af0
Compare
|
|
|
d6f2af0 to
e13c47e
Compare
|
buluoray
left a comment
There was a problem hiding this comment.
Approving at e13c47e.
Verified the new handle: subagent_id_from_conversation_key(state["conversation_key"]) or agent_id names the conversation's owner, which is the key _continue_prelude_impl builds (subagent:{conv_id}), so the hint resumes the same session-map key instead of putting a second key on the same sid. Reverting to {agent_id} or setting _RESUMABLE_JSONL_MIN_BYTES to 9 each turns the new test red. 157 passed.
Non-blocking:
- The
partial_result("cut off mid-turn by gateway restart") notice gets no resume hint although its conversation survives the same way; either extend it or say in the body that only the "lost" notice is covered. - The branch conflicts with main in
docs/system-specs/modules/subagent.md, so the rebase will need a fresh approval.
43a74bc
e13c47e to
43a74bc
Compare
43a74bc to
677c555
Compare
|
677c555 to
23b78bc
Compare
|
23b78bc to
be89ffc
Compare
|
After a gateway restart, a run the restart caught before its first
token is reported as "lost to gateway restart -- No result was captured
before the restart." That is true of result.txt and false of the run:
its conversation -- every turn and tool call kiro-cli persisted under
~/.kiro/sessions/cli/{sid}.json -- is a file reconciliation keeps on
purpose, and spawn_continue re-seeds the session map from the run's
state.json to resume it. The notice never said so, and parents
re-spawned from scratch, paying for the same tool calls twice.
The lost notice now carries the run's progress (turns, last tool) and
the spawn_continue handle, offered only when the conversation is
resumable by the bar SessionMap.get applies -- the .json present and
the .jsonl holding a turn -- read through the same directory it
consults, so a pruned, released or never-started conversation is never
advertised.
be89ffc to
2685c6f
Compare
|
Post-merge record. This landed ( What I verifiedThe hoisted rule is behaviour-preserving. The The handle's owner resolution is correct. Redaction order. The test is load-bearing. Four independent mutations, each red on
Follow-up on mainFirst Principles' open CONCERNS (Item 1) is fair and undispositioned at this head: This was never grounds to hold the PR. The branch fixed is the one that actively misinforms — Not verifiedNo |
…irodotdev#13317) After a gateway restart, a run the restart caught before its first token is reported as "lost to gateway restart -- No result was captured before the restart." That is true of result.txt and false of the run: its conversation -- every turn and tool call kiro-cli persisted under ~/.kiro/sessions/cli/{sid}.json -- is a file reconciliation keeps on purpose, and spawn_continue re-seeds the session map from the run's state.json to resume it. The notice never said so, and parents re-spawned from scratch, paying for the same tool calls twice. The lost notice now carries the run's progress (turns, last tool) and the spawn_continue handle, offered only when the conversation is resumable by the bar SessionMap.get applies -- the .json present and the .jsonl holding a turn -- read through the same directory it consults, so a pruned, released or never-started conversation is never advertised. Co-authored-by: w <w@k.local>
Problem / Motivation
After a gateway restart, a sub-agent run the restart caught before its first token is announced to its parent as:
That is true of
result.txtand false of the run. Its conversation — every turn and tool call kiro-cli persisted under~/.kiro/sessions/cli/{sid}.json— is a file reconciliation keeps on purpose (retain-by-default), andspawn_continue(conversation="<id>", …)re-seeds the session map from the run'sstate.jsonand resumes it after a restart. The notice never says so.Why it matters
Three such orphans landed in one digest during the 2026-09-23 memory-crash reports; each had run 20–60 minutes of tool calls. Told "no result", the parent re-spawns from scratch and pays for the same work twice, when one
spawn_continuewould have picked the run up where it stopped.What changed (motivation → approach → change)
❌ lost to gateway restart … No result was captured before the restart.It had completed 6 turn(s); its last tool call was \shell`. Its conversation survived the restart: `spawn_continue(conversation="", task=...)` resumes it …` — only when the conversation is resumableorphan_resume_hint(subagent_manager/monitoring.py) builds the extra line from the orphan'sstate.json(session_id,provider,conversation_key,turns,last_tool). The handle names the conversation's owner — theconversation_key's subagent id when the orphan was itself minted byspawn_continue, else the run's own id — so continuing never seeds a second session-map key onto a sid another run already owns. Whether the handle is offered is decided by the one ruleSessionMap.getalready applies before it hands a sid out, now hoisted intosession_files_resumable(sid, provider)insrc/kiro_crew/session_map.py: for kiro-cli the{sid}.jsonpresent and the{sid}.jsonlholding at least a turn (_RESUMABLE_JSONL_MIN_BYTES, the single definitionget()reads too, replacing its bare literal); for any other backendsession/loaddecides, so the handle is offered andspawn_continuerefuses typed if the session is gone. A pruned, released or never-started kiro-cli conversation is never advertised. The hint never raises; a notice that cannot be decorated is still a notice.subagent.pyimports the helper so the rebound_implresolves it;docs/system-specs/modules/subagent.md,session.mdanddocs/system-specs/common/injected-messages.md(the owning spec of the[Subagent completion event]text) document the hint and the shared rule.Backwards compatibility
Compatible: the notice keeps every existing line and gains one;
SessionMap.getkeeps its exact behaviour (its10-byte JSONL bar is now the named constant it shares with the hint). No field, file or API changes.Tests
test/test_subagent_persistence.py::TestOrphanReconciliation::test_a_lost_orphan_with_a_surviving_conversation_says_how_to_resume: no session file → no hint;.jsonwith a nine-byte.jsonl→ no hint (one under the barSessionMap.getprunes at); a.jsonlwith a turn → the hint with turns, last tool and the run id; a non-kiroprovider→ the hint without a file check, asSessionMap.getbehaves; aconversation_keyofsubagent:orig0001→ the handle namesorig0001, not the orphan's own id. Removing themsg += resumeline turns it red.Manual verification
N/A — unit coverage drives
_notify_orphanend to end with the real session-map directory seam; the live gateway on this host must not be restarted to stage an orphan.Screenshots / video
N/A — the change is one line of an injected completion notice; no frontend surface.
Issue link
No linked issue: surfaced while investigating the 2026-09-23 sub-agent death reports (ticket P519578361, internal); companion to #13301, which fixes the stop attribution on the same notices.
Pattern harvest
Not generalizable: the defect is a notice that reports one artifact's absence (
result.txt) as the absence of the work, when a second artifact (the conversation) still carries it. Review-prompt candidate: when a terminal notice says "nothing was captured", check every artifact the run leaves behind, not the one the notice was written around.