Skip to content

fix: inherit per-chat trust to subagents at every spawn depth - #13109

Closed
billygerhard wants to merge 2 commits into
kirodotdev:mainfrom
billygerhard:fix/nested-subagent-trust
Closed

billygerhard wants to merge 2 commits into
kirodotdev:mainfrom
billygerhard:fix/nested-subagent-trust

Conversation

@billygerhard

@billygerhard billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Closes #14110.

Goal: A chat's trust reaches every subagent in its spawn tree, so a trusted fan-out runs to completion without a prompt nobody can see -- and a chat that continues a conversation another chat started does not lend that conversation its trust, so every request such a continuation raises is asked of a person.

You trust a chat. Its subagents run without asking. But when one of those subagents spawns its own subagent, the grandchild stops and waits for permission. Nobody sees the prompt. It sits until the approval timeout, and the whole nested run hangs.

The decision behind the second half of the Goal -- a continuation from another chat no longer borrows that chat's trust -- is recorded as an RFC in #15457 (docs/request-for-change/rfc-conversation-trust-follows-founder.md), merged to main in beea9eac0f and on this branch's base.

Why it matters

Anyone who trusts a chat and walks away from the keyboard expects the whole spawn tree to keep working. Today only the first level does. Any fan-out that goes two levels deep (a coordinator subagent that delegates) stalls for the full approval window and then dies, with no visible prompt to answer.

Not a goal

Backwards compatibility

Compatible: a non-subagent parent key is still one direct store read and its root_session_key equals its parent, an untrusted root still prompts at every depth, and every grant that is not chat-level trust (explicit approval_mode, YOLO and --approval, the parentless agent.approval_mode fallback, auto_approve_sources, the auto_approve_subagent_* hooks) keeps its order and answers a contested run's prompts exactly as it would any other run's, as the RFC decides. What a contested marker withholds is chat-level trust alone: root_approval_policy refuses it without a store read, the spawn gate's parent_trusted and the run loop's chat-trust rung read "" for it, and the interactive approver's slot trust does not answer a prompt keyed by it (the marker resolves to no slot, and a resolver that names a trusted slot is not consulted for it) -- pinned by test_the_contested_refusal_outlives_the_records_that_established_it and test_slot_trust_still_prompts. A run with no parent (a cron's or the CLI's spawn) is not a contested root: it founds its conversation in its own name, and a parentless continuation of it (the CLI's or a script's continue, with no chat behind it) inherits that founding root rather than contesting it, since no chat's trust is gained -- a parentless continuation of a CHAT-founded conversation is contested. The has_session(parent_session_key) liveness probe in the global-config fallback still reads the literal parent key. A record without a stamp (built outside admission) resolves its parent exactly as before. spawn gains private _root_session_key / _conversation_root_session_key kwargs that only the queue drain passes.

Behavior changes, for the release notes. Two things tighten, both deliberately and both permanent until #13244 ships a clearing affordance; two more are visible without trust being involved at all:

  • Continuing another chat's conversation (a trusted chat picking up a task another chat -- or a cron, or the CLI -- started) no longer inherits either chat's trust. The conversation is marked contested, durably on the founder's record; its spawns and tool calls prompt on the global approvals feed, and every later request asks again. The prompt says so and names the way out (start the task again from a single chat).
  • Pre-upgrade nested conversations. A conversation whose founder was a nested run recorded before this change (a state.json with no conversation_root and a subagent: parent) has no readable founding root, so its first continuation after upgrade is contested and stays so; the depth-one case is spared (a pre-upgrade depth-one founder's chat parent is the root admission would have stamped). Start such a task again from one chat rather than continuing the old conversation. Recorded on dashboard: surface a contested subagent conversation instead of a bare global-feed prompt #13244 alongside the clearing affordance.
  • Nested runs' cards move into the root chat's tab. A nested run's card, its live frames, the sidebar badge and the reconnect replay are all addressed to the root chat's tab (the one that would answer its prompts) instead of to a parent key no tab reads, where the card was previously drawn in no tab. Depth-aware rendering of those cards is Nested subagents' WS frames carry a slot no tab reads (Subagents panel is not tree-aware) #13116. One known misroute remains: after a contested continuation finishes, a child it spawned can have its later frames routed to a chat that continues the conversation afterwards (A later contested continuation moves an existing nested run's card to the newer chat's tab #22827).
  • Two continuations of one conversation are never both admitted, trust or no trust. The spawn gate re-checks conversation_busy at its commit point and refuses the rival; a continuation's start also claims its conversation for the length of its awaits (_claimed), so a second continue arriving meanwhile is refused at its prelude rather than admitted and raced. Both refusals are typed conversation_busy and retryable.

What changed (motivation → approach → change)

Trust is stored as approval_policy="auto" on the chat's own session key. A subagent's key is subagent:<id>. On the shared-runtime path that key is never put in the session store, so three places that look up trust by the immediate parent key got "" for a grandchild: the spawn gate in src/kiro_crew/subagent_manager/admission/gate.py, the tool-permission branch in src/kiro_crew/subagent_manager/run.py, and the interactive approver in src/kiro_crew/slack/gateway.py. The approver also could not map subagent:<id> to a dashboard tab, so the prompt went only to the global feed.

Every run now carries two keys stamped once, when it is admitted: SubagentInfo.root_session_key, the chat, cron or channel key at the root of its spawn tree, and SubagentInfo.conversation_root_session_key, the root that governs every request keyed by its conversation. SubagentManager.root_session_key in src/kiro_crew/subagent.py follows parent_session_key links to the root, stopping at a non-subagent key, an unknown id, an empty parent, or a key already seen. A subagent:<id> key names a conversation shared by the original run and each continuation, and a request under it cannot say which one sent it, so the answer never depends on which run is live (a continue handed a CONTINUATION's id is resolved to the founder first -- from the retained record, or from that run's own state.json -- by founder_conversation_id, so the busy check, the root comparison and the contest write address one conversation rather than a second one keyed on the continuation over the same native session): the run that founds a conversation fixes its root, a continuation from the same root inherits it, and a continuation from a different root marks the conversation contested, after which it resolves to its own key. A contested conversation resolves to contested:<key>, a marker that is no session key: the trust lookup (SubagentManager.root_approval_policy, used by the spawn gate and the run loop) refuses it outright and no tab shows it, and because runs admitted beneath the conversation carry the marker in their own stamps, the refusal outlives the records that established it. That marker is read as a TRUST stamp only (trust_root_for); for the TAB, a run below a contest belongs where its parent conversation's LIVE card is, so root_session_key_for climbs the retained ancestry to the first real key, consulting the newest active record under each conversation first (the founder's record, listed first, would otherwise own the card until it was evicted and then hand it to another tab mid-run, leaving the first tab a running card no frame clears), and answers "", the feed, when none is left, and its frames, the rooted listing behind the sidebar's count and the reconnect replay never key on a marker no tab reads. The founding root outlives them too: admission persists it in the run's state.json (conversation_root, written by create_agent_folder), a contested continuation writes the contest onto the founder's record before its turn runs (_write_state_off_loop, given the founder's id, through update_state(durable=True), so a founder held live-only at that moment -- tightened into memory by an incognito or temporary continuation, where a plain merge reports success without touching the file -- still has its state.json stamped, and its in-memory record takes the marker only after the file holds it, so a failed write never leaves memory claiming a contest that a restart would undo; the switch is closed to the one provenance field, conversation_root, and refuses any other field on a live-only record, so no later caller can carry a turn's body to disk on it; the write is the contest's only durable carrier, so a skipped write -- the founder's record unreadable -- is retried once and then refuses the run rather than let a turn through whose contest a restart would forget; the retained founder record in memory takes the marker too), and a continuation that arrives when no in-memory record of the conversation remains (a gateway restart, or the founder evicted) compares against the founder's record -- read off the event loop by spawn_async (_durable_conversation_root, via asyncio.to_thread) and handed to the gate as a value, the gate's resolver itself reading nothing and failing closed without one; a captured contest outranks every retained record, since the record that contested the conversation may be evicted while the founder's is still retained with its founding root -- instead of founding the conversation in its own name -- a matching root is inherited; a different root, a persisted contest, or no readable root at all (folder gone, or a nested record written before the stamp existed) leaves the conversation contested; a depth-one record written before the stamp existed still names its chat parent, which is the root admission would have stamped, so a same-chat continuation of a pre-upgrade run is spared a one-time lockout while a cross-chat one is contested as it would be with the stamp. A run with no parent (a cron's or the CLI's spawn) founds its conversation in its own name and resolves to its own key: nothing contests it, so its registered policy is read as before, and a chat that continues it contests the conversation rather than founding it. The gate captures both keys on the spawn's first entry and carries them in the queued parameters, so a member drained later keeps what it was requested with; the dashboard's retry of a failed run (api_spawn_retry in src/kiro_crew/dashboard/handlers/messaging.py) passes the failed run's stamped root the same way, so a retry is governed by the trust its original ran under rather than by a re-walk of a parent conversation that may since have been continued from a trusted chat. A durable queued row written before the stamp existed is the one re-entry with no captured root: it outlives a restart, its subagent: caller is not rehydrated on boot, and a re-walk at refill would find whichever chat has since continued the caller's conversation. It is covered by the same rule, since every window entry re-enters through the drains with _from_queue=True, so the store's read side (_window_entry in subagent_manager/admission/taskq_bridge.py) hands the row through as written rather than keeping a second copy of the rule. The two stamps part ways on that read side, though: the trust root stays on the row (a re-walk could only widen it), while the conversation root a row was written under is stripped (a replay could only widen it; a CONTESTED stamp is the one value kept, since it is a refusal rather than a grant and the dashboard retry of a failed contested continuation carries the marker as its only tie to the contest, with no conversation key to re-resolve it from) -- a store-only row is not in the in-memory queue, so it does not hold its conversation busy, and a continuation from another chat admitted while it waited on disk writes a contest onto the founder's record that the row's stamp predates; replayed, the stamp would run the refilled continuation, and every tool call in it, on the founding chat's auto-approval. A refilled row re-resolves at re-entry instead, and the pump (_dispatch_async_impl in pump.py) reads the founder's durable record off the loop first, the way spawn_async does for a first entry, since the in-memory record that contested the conversation may be gone while the founder's is still retained with its founding root. The gate enforces one structural rule for every resumed admission (_from_queue, _store_accepted): a nested caller arriving without the stamp resolves to a contested root there, so a future re-entry path that forgets the parameter costs an interactive prompt, never an escalation. The gate reads the root's trust, and the run loop reads its own stamp and hands the root key to the interactive approver, so a prompt that still needs a human lands in the root chat's tab. The run loop reads that stamp through SubagentManager.trust_root_for, which has one exception: a continuation admitted into a contested conversation reads the conversation's marker rather than the chat that continued it, because the turn it runs was authored under the founding chat's key and the continuing chat's trust must not approve what that turn asks for -- its card still belongs to the continuing chat's tab, and its prompts reach the global feed labeled like every other contested prompt; a same-root continuation inherits normally. The spawn gate's trust check, the spawn prompt's address (pump.py) and the gateway's _spawn_approval_slot read the same trust root, so a run admitted into a contested conversation is interactive at admission as well as mid-run, and the dashboard retry of a failed contested continuation passes the marker as _conversation_root_session_key so the retry is governed by it rather than founding a fresh conversation at the chat whose tab held its card (any other stamp is re-derived by the gate). The spawn gate (subagent_manager/admission/pump.py) raises its prompt under the root chat's key rather than the literal subagent:<id> parent, so channel delivery, the tab and a Trust press all address the key the gate reads back. The gateway resolves a spawn approval's tab through _spawn_approval_slot, and a nested run's file card in src/kiro_crew/dashboard/handlers/files.py routes to the same root tab instead of being suppressed, through the same tab accessor (root_session_key_for), so a run below a contested conversation lands its card in the ancestor's tab rather than being dropped on a marker while file_send reports success. Depth is unbounded. docs/system-specs/modules/subagent.md describes the root resolution, the conversation root and the admission stamps.

flowchart LR
  subgraph Before
    C1[chat: trusted]:::ctx --> A1[subagent A]:::ctx
    A1 --> B1[subagent B]:::ctx
    B1 -. "lookup subagent:A → ''" .-> P1[prompt to no tab, times out]:::removed
  end
  subgraph After
    C2[chat: trusted]:::ctx --> A2[subagent A]:::ctx
    A2 --> B2["subagent B<br/>root_session_key = chat"]:::changed
    B2 -- "read root's trust → auto" --> OK[auto-approved]:::added
  end
  classDef added fill:#DCFCE7,stroke:#16A34A
  classDef changed fill:#FEF3C7,stroke:#D97706
  classDef removed fill:#FEE2E2,stroke:#DC2626,stroke-dasharray:4 3
  classDef ctx fill:#E0F2FE,stroke:#0284C7
  linkStyle 2 stroke:#DC2626,stroke-dasharray:4 3
  linkStyle 5 stroke:#16A34A,stroke-width:2px
Loading

🟩 added · 🟨 changed · 🟥 removed · 🟦 unchanged

A nested subagent now carries the key of the chat that started its tree, so it reads that chat's trust and runs unattended instead of hanging.

A nested run's per-run WS frames (subagent_spawn / tool / chunk / done / snapshot from _subagent_event in src/kiro_crew/slack/gateway.py) now carry the root chat's slot too, so the pending card the spawn prompt planted in that tab advances instead of sitting on "Starting" forever; the chip's 30-second reconcile (website/src/pages/chat/SubagentProgressBar.tsx) now matches live rows by run id alone (#20987 on main), so it neither evicts the nested card the frames just painted nor fails a live card in a cron- or channel-born tab, and this PR no longer touches it. The list-carrying subagent_status frame (_broadcast_subagent_status) addresses the same root tab and lists the tree rooted there (SubagentManager.running_agents_rooted_at): its agents payload replaces a slot's whole list and a running of 0 evicts the slot's cards, so a parent-keyed frame would have wiped a live nested card the moment its coordinator finished; the done path hands the frame only a resolved injection slot, not the raw parent key. The reconnect replay (subagent_replay_slot in src/kiro_crew/dashboard/ws.py) names the same tab from the run's stamp, so a reconnect redraws the nested card where the live frames put it. running_agents_for stays parent-keyed: it answers the parent's own wave, the orchestration question. Depth-aware rendering of those cards is tracked in #13116. A contested conversation's prompts reach only the global approvals feed (_spawn_approval_slot answers "" for its marker rather than a phantom slot); its spawn prompts keep the ask as their title (spawn_run(...), as on every sibling card) and carry a second line written in the words of what the user did rather than the system's model -- the state first, so the card's two lines say what this prompt is, then the remedy, whose closing clause says an approval is not a fix (the contest is durable, so every later request asks again), then the why last, whole in Review -- a why that states only what every case the marker covers established (the chat that started the task was not confirmed as the one continuing it: two chats, an unreadable or pre-stamp founder, a resumed admission without its stamp, a cron's or the CLI's run a chat picked up), since the marker does not record which case minted it and the reader may be the very chat that started the task; in active voice with the product as the actor that failed to confirm, so the reader sees at a glance whether they caused the contest (This run has no single owning chat. Start this task again from a single chat, or approve this request (each request will ask again). Kiro Crew could not confirm that the chat continuing this task is the one that started it.; CONTESTED_PROMPT_STATE / CONTESTED_PROMPT_WHY / CONTESTED_PROMPT_REMEDY in subagent.py, assembled by contested_spawn_note) -- which the gateway's spawn approver (_spawn_approve) hands over as the prompt's tool_purpose: the feed card shows the ask in its title and the state and remedy in its body, and the Review panel shows everything; the remedy names no button, since the card offers Review and the panel Approve. A one-line description is unchanged. The run loop leads the purpose of every tool prompt a contested run raises with the same state and a one-clause why, a period before the tool's own purpose so the purpose does not read as a remedy clause (contested_tool_note, via _label_contested_prompt), and the why and remedy last -- after the tool's purpose, so the card's two lines carry the state and what the tool is for (a spawn prompt, which has no purpose to show, puts the remedy second so its card's excerpt reaches the safe verb before it is cut, and the why last), while a user who meets only tool prompts still reads the why and the way out in Review; the three are separate paragraphs and the run's own claim is set as a quote, which the Review panel renders as a distinct muted block, and attributed in words too (CONTESTED_RUN_ATTRIBUTION, "The run says:"), because the card's plain two-line excerpt strips the quote marker and that card is what a habituated approver reads -- so on the one surface that exists because the run is not trusted, its claim never reads with the authority of the system's sentences around it -- so a mid-run shell(...) on the feed says why it has no chat too; naming the asking run on nested prompts, a badge in the Subagents panel, and a clearing affordance for a contested conversation (the contest is durable and otherwise permanent; re-founding it under one chat is a human action for #13244 to design, including rewriting the founder record's conversation_root) are tracked in #13244.

Tests

test/test_subagent_nested_trust.py:

  • three-link chain resolves to the root's "auto"; a cycle terminates and trusts nothing; an unknown id stops the walk without inventing a grant
  • admission stamps root_session_key on a depth-two run; a stamped run keeps its root after its parent is popped from the registry; an unstamped run under a missing parent stays interactive (documented fallback)
  • a continuation of an evicted original reads the founder's durable record: it inherits a matching founding root, is contested for a different one, and is contested when no root can be read (folder gone, or a nested pre-stamp record), while a depth-one pre-stamp record's chat parent is used as the founding root (same-chat inherits, cross-chat contested); a parentless (cron/CLI) run's conversation continued from a chat is contested too, and the one state sentence the prompts carry is true for every such case; a run's own automatic follow-up (spawn_steer mode="follow_up") carries the stamp the run was admitted with (its chat root, or for a cron's or the CLI's run the conversation root it founded in its own name), so it inherits its root even after its parent has been evicted, or when it never had one, where a re-walk of the parent key would have falsely contested the run's own conversation and persisted that contest onto its founder (test_a_runs_own_follow_up_keeps_its_stamp_after_its_parent_is_evicted), and the gate's parent_trusted decides on that resolved root rather than the literal parent_session_key, so a parentless run's follow-up (empty parent, founding stamp presented) is admitted under the policy registered on the run's own key -- the same trust its children already resolve to, and the policy the run loop already runs that turn under -- instead of raising a prompt on the global feed that no chat's trust could answer, while the parentless original resolves to no root and a chat continuing its conversation is contested, neither auto-approved (test_a_parentless_runs_own_follow_up_is_admitted_under_its_registered_trust); two continuations of one conversation can never both be admitted -- the gate re-checks _conversation_busy at its commit point, with no await before the write to _agents, and refuses the rival conversation_busy, since a same-root one registered first would otherwise run its whole turn under the founding root while a cross-root one registered second contested a conversation the first never re-reads (test_two_continuations_of_one_conversation_cannot_both_be_admitted, driven with asyncio.gather); a continuation's start also claims its conversation for the length of its awaits (_continuations_starting, keyed on the conversation rather than flagged on the founder's record, which may be evicted), and _conversation_busy answers the claim under the id the start will run as, so a rival continuation arriving while the start awaits is refused at its prelude rather than admitted -- without it a rival could contest the conversation, finish and be evicted before the start committed, leaving the commit-point check, which adopts a contest from retained records, nothing to adopt, and the founding root the start read before its awaits to grant a chat trust another chat had written past (test_a_continuation_start_holds_its_conversation_through_its_awaits, the start parked inside its durable-root read while the rival is answered, then released and admitted under its own root, the claim gone with it), and the refused rival's committed store row gets taskq_fail's failed write in the same step, as every other refusal of a persisted row does, so a restart does not requeue work the caller was told was refused (test_the_refused_rivals_store_row_is_settled_failed, against the real store). Making that write's durability a precondition of publishing the refusal -- a settle retried until the row reads terminal, with the run's tombstone written first -- is a pre-existing refusal-durability gap shared by every taskq_fail caller, not this change's, and is tracked in taskq_fail publishes a refusal before its failed write lands; a lost write leaves a claimed row for the boot reconcile to requeue #17397; a persisted contest survives a restart (the founding chat cannot reclaim the conversation) and outranks a retained founder whose contesting continuation was evicted (and, without the durable trace, the retained founder alone would have granted it), and a contested continuation's run writes the contest onto the founder's record before its turn runs and stamps the retained founder record in memory with the marker, while a same-root continuation leaves both in place; a same-root continuation inherits the founding root; a cross-root continuation marks the conversation contested (resolves to the contested: marker, order-independent, and stays contested); an untrusted run's spawn admitted after a trusted chat continued its conversation is never auto-approved; the continuation's own tool prompts are likewise interactive and addressed to the contested marker rather than auto-approved on the continuing chat's trust (a same-root continuation still inherits), and a continuation whose contest write is skipped does not run (the writer is retried once, then the run is refused before any turn); the contest reaches the founder's durable file even when the founder is held live-only at that moment (a tightened, incognito-style record, where a plain merge would report success without touching the file), pinned by test_a_contest_reaches_a_live_only_founders_durable_record and by update_state(durable=True)'s own unit tests, which also pin that the live record is published only after the file write succeeds -- a skipped or failed write leaves memory on the old root (test_a_failed_durable_write_publishes_nothing_to_memory); a retry carrying the contested marker at a trusted routing root is interactive at the gate and its run's trust root is the marker; spawn_async reads the founder's record on a worker thread (never the loop thread) and the resolver fails closed rather than read when handed no value; a contested continuation's own spawn prompt names no slot even though its card's tab is the trusted chat, and api_spawn_retry passes the marker for a failed contested continuation and "" otherwise; a contested conversation stays untrusted at the gate and in the run loop even when the store holds "auto" under its key, and a child admitted beneath it stays untrusted after the founder and the continuation are evicted, while a parentless run's own key still reads its registered policy and a trusted chat's continuation of a parentless original contests it instead of founding it (its in-flight spawn stays interactive); two independent founders with different roots (concurrent continuations after eviction) leave the conversation contested; hand-built unstamped records still terminate on a cycle
  • a queued member's parameters carry the captured root, and a drained member keeps the root of the chat that requested it even after the requester's conversation was continued from a trusted chat (still prompts); a dashboard retry passes the failed run's stamped root, the store-accepted re-entry's parameters carry both stamps (so every structural re-entry does), and the gate honours a carried root over a re-walk that would now find a trusted chat (still prompts); a /api/spawn entry names the root chat beside the literal parent
  • a depth-two spawn under a trusted chat is auto-approved (callback never awaited); the run loop hands approval_policy="auto" to the grandchild's session
  • the run loop passes the root key, not subagent:<id>, to the interactive approver on both the ordinary and the low-fidelity-child paths, with the ancestor already gone
  • preservation: depth-one spawn still auto-approves; depth-two under an untrusted root still prompts once, and the prompt is handed off under the root chat's key rather than subagent:<id> and unlabeled, while a contested conversation's spawn prompt carries the contested label; a cron/chat key reads the store directly
  • gateway: _spawn_approval_slot resolves a nested spawn's card to the root chat's tab (and "" for an unknown run, no manager, or a contested root -- never a phantom slot); a prompt addressed to the root chat is approved by that slot's trust; a nested run's subagent_spawn frame carries the root tab's slot; a nested run's file card resolves to the root tab, an unstamped record to its parent; a contested prompt goes to the dashboard feed alone, not the owner's Slack DM (the marker names no channel, and the DM card's Trust button would record the marker as a trusted session)

The module is pinned with healthy_host_memory as the spawn-host ratchet requires. The exploration tests failed on unfixed code and pass after the fix; the preservation tests passed before and after. test_spawn_prompt_first_line_is_the_title_and_the_rest_its_purpose drives the real _spawn_approve closure (captured through _init_subagents) with a two-line and a one-line description. test_status_frame_for_a_nested_run_refreshes_the_root_tabs_list drives the real on_done for a coordinator that finishes before its nested run (the root tab keeps running: 1 and the nested row) and then for the nested run; test_reconnect_replay_slots_a_nested_run_to_the_root_tab, test_a_retried_terminal_report_keeps_the_root_stamp (ancestor evicted before the retry; the snapshot still finds the root tab) and the rooted-vs-wave list test pin the replay slot, the retry stamp and running_agents_rooted_at; the chip's reconcile is pinned by main's own vitest cases for #20987 (a nested or channel-rooted run is kept by id). test_a_resumed_admission_without_its_stamp_fails_closed_in_the_gate pins the gate's structural rule (a _from_queue nested caller without the stamp is contested even when the walk now finds a trusted chat; stamped and parentless re-entries unchanged) and test_a_contested_runs_tool_prompt_says_why_it_has_no_chat pins the tool-prompt label through the real run loop (title intact, purpose = state (why) — the tool's own purpose, no remedy; a chat-rooted run's prompt is untouched). TestRecoveredRowsFailClosed pins the legacy-row path end to end: the read side hands a pre-stamp subagent:-keyed row through unstamped, and re-entering that entry the way the drains do (_from_queue=True) leaves the recovered run interactive even when a re-walk now finds a trusted chat; test_the_read_side_strips_the_conversation_root_a_row_was_written_under pins that the conversation-root stamp is stripped beside the two process-local grants while the trust-root stamp stays, and test_a_refilled_continuation_reads_a_contest_written_while_it_waited drives the dispatcher against the real store with a row stamped under the founding chat, the founder retained in memory with its founding root, and a contest on the founder's durable record: the admitted continuation resolves to the marker and no chat's trust, where either the stamp replayed or the pump skipping the durable read hands it the founding chat's auto-approval. prove.py --per-hunk reverts every behavior hunk and a named test fails for each; the two hunks it reports uncaught are a comment-only edit and the one-line closure that delegates to _spawn_approval_slot. website/scripts/capture-nested-subagent-trust.mjs asserts the dashboard scenes shown under Manual verification (including the contested entry in both themes and the tool card leading with its state) against the built SPA (tsc, eslint and the chip's vitest file pass); approvalNotificationBody.test.tsx pins the purpose-first body for a chat-less prompt and the unchanged default order. test/test_queue_during_subagents.py follows the sidebar badge's move from the tab's own wave (running_agents_for) to the rooted tree: serialize_slots resolves every live run's tab root ONCE per slots push (SubagentManager.live_root_session_keys, a set) and tests each tab for membership, rather than asking running_agents_rooted_at per tab, which would resolve every run once per tab and build a redacted summary list for a boolean; its doubles expose the set accessor, a new case pins that a live grandchild keeps the badge lit after the coordinator that spawned it finishes, and the true-flag case pins one resolution per push across two tabs; editing the file meant formatting it, so it comes off .github/black-baseline.txt (the baseline gate asks for exactly that when a listed file becomes clean).

Manual verification

Captured against the built SPA by website/scripts/capture-nested-subagent-trust.mjs (scripted Playwright; it drives website/dist with the gateway's own WS frames and exits non-zero unless every scene asserts). The depth-one run c0ffee01 is the coordinator; deadbe02 is its child, whose literal parent is subagent:c0ffee01.

The grandchild's spawn prompt, addressed to the root chat's tab, parks in the composer chip beside the running coordinator:

Composer chip in the root chat: 1 running, 1 awaiting; the nested run's row reads "Waiting for your approval to start"

After approval the nested run's frames advance its row, and it is still there 33 seconds later, past the chip's 30-second reconcile whose /api/spawn entry names parent: subagent:c0ffee01 but root: dashboard:<slot>:

Root chat tab with two running rows in the chip, the nested run at 33s and 3 tools, after a reconcile tick

While it runs, a file_send from the nested run raises its card in the same root tab (_subagent_parent_session_key resolves the stamped root; before, the run's literal parent subagent:c0ffee01 named no tab and the card was suppressed):

Root chat tab showing the nested run's file card, "migration-dry-run.log — Dry-run output against the staging schema, 20.5kB, Save", beneath the coordinator's running card, with both runs in the composer chip

A tool call the nested run makes mid-run raises its permission prompt in the same tab (run.py hands the run's stamped root key to _on_tool_approval); the root chat is untrusted here, so the prompt is interactive:

Root chat tab with an inline permission card reading "[subagent] shell(psql -h staging-db -f migrations/0042_pin_schema..." with Allow once and Reject controls, above the composer, with both runs in the chip

Its subagent_done frame then finishes the row, leaving the coordinator alone in the chip:

Composer chip after the nested run's done frame: 1 running

A contested conversation's spawn prompt carries no slot and lands on the global feed. Its title is the ask, as on every sibling card, and its body is written in the words of what the user did -- the state first, so the card's two lines say what this prompt is, its why in a clause, then the remedy (whole in Review, where the decision is made):

Notification feed entry titled "Tool approval: spawn_run(grandc..." whose body reads "Source: subagent · This run has no single owning chat. Start this task..." with a Review button

Review opens the entry where the user decides, with the copy whole and Approve / Reject. The capture below shows it:

Notification detail panel titled "Tool approval: spawn_run(grandchild task)" with the body "Source: subagent. This run has no single owning chat. Start this task again from a single chat, or approve this request (each request will ask again). Kiro Crew could not confirm that the chat continuing this task is the one that started it." and Approve beside Reject

The same entry and panel in the light theme:

The same notification feed entry in the light theme, body "Source: subagent · This run has no single owning chat. Start this task..."

The same detail panel in the light theme with the copy whole, Approve beside Reject

A tool prompt the contested run raises mid-run reaches the same feed with the tool as its title; _label_contested_prompt leads its purpose with the state and a one-clause why, a period separating them from the tool's own purpose, and closes with the remedy -- last, so the card's two lines stay the state and what the tool is for while the Review panel, where the user decides, still names the way out for someone who only ever meets tool prompts. A contested prompt is exactly this case, and the approval record says so explicitly (contested, set by the gateway from the trust root the callback is handed -- _interactive_approval in gateway.py, carried on the record by interaction_coordinator.py and its approval frame), so the feed card's body puts the purpose ahead of the command for it (approvalNotificationBody(..., { purposeFirst })); the reader never infers the case from an empty slot, since a subagent rooted in a cron, the CLI or a channel has no tab either and its purpose is the run's own words, which must not be promoted above the fenced command -- every other prompt keeps the command first. The card says why it has no chat before it is opened, and the whole label reads in Review:

Notification feed entry titled "Tool approval: shell(psql -h stagin..." whose body reads "Source: subagent · This run has no single owning chat. · The run says: Dry..." with a Review button

Notification detail panel for the tool prompt: "This run has no single owning chat.", then the run's own purpose as a muted quoted block "The run says: Dry-run the pinned schema migration against staging before applying it.", then "Kiro Crew could not confirm that the chat continuing this task is the one that started it. Start this task again from a single chat, or approve this request (each request will ask again).", then the psql command in an approval-command block, with Approve beside Reject

The same tool prompt's panel in the light theme, the run's claim set apart as a quote with a purple bar and muted italic:

The tool prompt's detail panel in the light theme: "This run has no single owning chat.", the quoted "The run says: Dry-run the pinned schema migration against staging before applying it." with a purple left bar, then the why and remedy, the psql command block, and Approve beside Reject

Related Issues

Linked issue for the contested-conversation part: #14110 (a continuation from a second chat runs under that chat's Trust on main; base-runnable probe attached there). No issue was filed upstream for nested-depth trust inheritance itself (#4751 is about routing subagent prompts interactively, not inheritance). Follow-ups: the tree-aware Subagents panel, #13116; re-founding or clearing a contested conversation, #13244; the card misroute after a later contested continuation, #22827; folding the three marker-to-slot guards (ws.py, subagent_wiring.py, turn_approvals.py) into one resolver, #22946.

Pattern harvest

Rule candidate: review-prompt
Pattern: "policy or ownership looked up by the immediate parent key when the caller can itself be a child (subagent:) — resolve through the root of the tree, captured once at request time, never re-derived at a later stage"

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • 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

@billygerhard
billygerhard requested review from a team and patrigao September 23, 2026 15:23
@billygerhard

Copy link
Copy Markdown
Contributor Author

Intent: A chat's per-slot trust applies to every subagent in its spawn tree, at any depth, so nested subagents run unattended and any prompt that still needs a human lands in the root chat's tab.
Not a goal: Registering shared-session children in the session store, changing how trust is granted or revoked, or changing the low-fidelity child grant-eligibility gate.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of c5d25fc5e7646dcef8d67740d0099bc90b020382 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. Stamping the root key at admission fixes the cause, the contest rules follow the merged RFC (#15457), the description lists the tightened behaviour as breaking, and 12 rendered images cover the card change.

Notes

  • The contest machinery is large for one case: a cross-chat continuation. It spans the founder's durable record, _continuation_starts claims, the commit-point conversation_busy re-check and retained-claim retries. Each piece adds a state that must stay consistent across eviction and restart, and the spec only holds it together as one ~150-line paragraph. Splitting that spec text into numbered rules would keep later changes reviewable.
  • Chained continues now key on the founder (subagent:<original.id>) instead of subagent:<target.id>. The tests changed to match, but the description never states this as a behaviour change. Pre-upgrade A3→A2 chains rely on both keys resuming the same native session. Say so in the description.

[DESIGN-REVIEWED] c5d25fc

Description read

[DESCRIPTION-READ] 84f4bf8fb2b69040948ac65e1aaeb23040e503fe57b390f938fe8c9d2134a9bb

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 Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — 🔴 changes requested (blocking)

Reviewed c5d25fc5e7646dcef8d67740d0099bc90b020382 via the fork AI-review pipeline; updated in place on each push.

Adjudication upheld 2 of 2 blocking finding(s); those must be resolved before merging.

BLOCKING -- src/kiro_crew/subagent_manager/admission/pump.py:788 -- A terminal memory record does not prove the refusal committed

if start_taken and not registered and not self._ended_record(point.agent_id):
Trigger: A store-only queued continuation refills while another continuation is running; _dispatch_async_impl claims its row, the spawn gate refuses it as conversation_busy, and the posted TaskStore.finish fails under database lock contention.
Outcome: The caller receives a terminal refusal, but the durable row remains STARTING without a runtime. _ended_record suppresses claim retention, and taskq_fail only logs the write failure, leaving the refusal unsettled.
Anchor: persist-before-you-publish
Fix: Await and verify terminal settlement; retain failed settlements for retry without requeueing or executing refused work.

BLOCKING -- src/kiro_crew/subagent_parts/admission_surface.py:1133 -- Descendants ignore their parent's captured tab root

root = top.root_session_key
Trigger: Chat 2's contested continuation spawns C and finishes; Chat 3 continues the ancestor conversation while C remains running. When C spawns G, admission calls _tab_root_below_contest, which ignores C's captured tab_root_session_key and climbs into Chat 3's continuation.
Outcome: C remains in Chat 2, but G's lifecycle frames and file cards appear in Chat 3, which did not request G.
Anchor: defect
Fix: Honor the selected ancestor's captured tab_root_session_key before following its parent conversation.

[BLOCK-MERGE] c5d25fc
[GPT-REVIEWED] c5d25fc

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

Both findings keep blocking the merge.

F1 (src/kiro_crew/subagent_manager/admission/pump.py:788): this finding is anchored to persist-before-you-publish, and that rule carries blocking: true in .review-base-rules/AUTOSDE.yaml:982-983, so I don't weigh it. The harm is also real on its own terms. taskq_fail (taskq_bridge.py:458-467) sends the failed write through _post_store_write, which only logs when the write fails (taskq_bridge.py:379-380, 384-386, 394-395). Even so, _ended_record (patch at 1344-1348, 1375) skips the give-back of the taken start. The row stays STARTING, and the gate's own docstring (patch 948-950) says the next restart requeues that row and runs it. So work the caller was told was refused runs anyway, and nothing shows it.
F2 (src/kiro_crew/subagent_parts/admission_surface.py:1133): MEDIUM. The climb in _tab_root_below_contest (patch 2678-2692) reads only top.root_session_key and never the captured top.tab_root_session_key. That field exists to stop exactly this misrouting (patch 2647-2650, 2654). The result is that a grandchild's frames and file cards appear in a different chat's tab, on the ordinary path of continuing a conversation from another chat. The real fix is a single check of tab_root_session_key at each hop, with no new state, so the harm clearly justifies it.

[ADJUDICATION] c5d25fc5e7646dcef8d67740d0099bc90b020382 total=2 uphold=2 downgrade=0
UPHOLD F1 src/kiro_crew/subagent_manager/admission/pump.py:788 reason=autosde-blocking-rule
UPHOLD F2 src/kiro_crew/subagent_parts/admission_surface.py:1133 reason=harm-warrants-remedy
[GPT-ADJUDICATED] c5d25fc5e7646dcef8d67740d0099bc90b020382

@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of c5d25fc5e7646dcef8d67740d0099bc90b020382 via the fork AI-review pipeline — 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

Every item traces to the depth-trust defect (#14110) or to the founder rule in the base RFC rfc-conversation-trust-follows-founder (in-progress). Each new manager accessor has at least one non-test consumer.

What this change ships

Inventory (10 items) — 9 justified

Intent: let a trusted chat's whole spawn tree run without prompts nobody can see, and stop a chat from lending its trust to another chat's conversation. A FIX, plus a recorded trust-narrowing decision.

  1. Grandchild spawns and tool calls under a trusted chat auto-approve at every depth — justified
  2. A continuation from a different chat, cron or CLI marks the conversation contested, durably, and every request prompts — justified
  3. Pre-upgrade nested conversations are contested on their first continuation — justified
  4. Contested prompts skip slot trust and the Slack DM and go only to the global feed — justified
  5. A contested feed card leads with the copy explaining why — justified
  6. A nested run's prompt, card, frames, sidebar badge and reconnect replay go to the root chat's tab, not to no tab — justified
  7. A second concurrent continuation of one conversation is refused conversation_busy at the prelude and at the commit point — justified
  8. Retrying a failed run keeps the original run's root and contested stamps — undeclared (the description says only the queue drain passes the private kwargs)
  9. A spawn description's first line becomes the title and the remaining lines the purpose — justified
  10. New screenshot capture script for nested-trust routing — justified

[FIRST-PRINCIPLES-REVIEWED] c5d25fc

Description read

[DESCRIPTION-READ] 5b334aad03c324c6e4b92b1ddafe098403af0fc26dd744c49681c90f9621d6f0

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 added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed c5d25fc5e7646dcef8d67740d0099bc90b020382 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] c5d25fc

@billygerhard

billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author
span=35f75f1f3c22

mechanism: SubagentInfo.root_session_key stamped at admission; run loop reads the stamp, not a check-time walk

  • Trust resolution depended on ancestor _agents records staying live

fixed in 94708dd. gate.py stamps info.root_session_key = root_session_key(parent_session_key) before registering the record, while the calling parent is live.
run.py reads root_session_key_for(info) (the stamp) for parent_policy AND passes that root key to both interactive approver paths, so a deleted/cancelled ancestor no longer reverts a nested run to the no-tab prompt.
Revocation semantics preserved: the store is still read per check; only the KEY is captured, never the policy.
Pinned: test_stamped_root_survives_a_deleted_ancestor, test_run_loop_hands_the_root_key_to_the_interactive_approver (ancestor popped before the first prompt), and the unstamped-record fallback test_unstamped_run_under_a_deleted_ancestor_is_the_documented_fallback.

@billygerhard

billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author
span=0d281b7e51fe
  • Capture root_session_key at admission; collapse the call-site walks

fixed in 94708dd. The gateway's getattr-guarded module helper is removed; _interactive_approval reads dashboard_slot_key(parent_session_key) directly again because run.py now hands it the root key, and _spawn_slot_resolver reads the stamp via root_session_key_for(info).
The walk survives only inside SubagentManager.root_session_key as the admission-time resolver and the fallback for a record built outside admission.

@billygerhard

billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author
span=caea88dffaf6
  • Item 3 — sibling no-tab lookups at files.py:528 and ws.py:117/887

accepted-and-deferred (partially fixed). files.py:528 is fixed in 94708dd: _subagent_parent_session_key returns the stamped root, so a nested run's file card lands in the root tab (TestNestedFileCardRoutesToRoot).
The ws.py pair is deferred to #13116 (Due 2026-10-23): re-slotting nested frames alone is unsafe because sseSubagentStatus REPLACES a slot's agent list with running_agents_for(parent_key) and evicts the panel at running <= 0, so a nested wave ending would wipe the root panel while depth-one runs are live. That needs a tree-aware running_agents_for/reducer, which is a panel design change, not this defect.
The issue could not carry the deferred-finding label or an assignee: the author is a fork contributor without triage rights; the Due line is in the body.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 23, 2026
@billygerhard
billygerhard force-pushed the fix/nested-subagent-trust branch from 94708dd to cb5583c Compare September 23, 2026 17:29
@billygerhard

billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author
span=6a3a78cb8f4d

self-added: yes
mechanism: root_session_key walk matches a live continuation by conversation_key when the direct record is absent or finished

  • Evicted original record: the live continuation is missed, nested spawn loses root trust

fixed in cb5583c. root_session_key falls back to the newest ACTIVE record whose conversation_key == key (same newest-active ranking files.py uses for one key carried by several records) when _agents.get(id) misses or the record is done.
Pinned: continuation after eviction resolves to ROOT; original done + continuation live resolves to ROOT; a cycle through a continuation still terminates (test_subagent_nested_trust.py).
Separately, admission now captures the root ONCE on first entry and carries it in the queued params, so a drained member never re-walks a key whose continuation may since have moved to another chat (pinned by test_drained_member_keeps_the_root_captured_when_it_was_requested).

@billygerhard

billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author
span=b17d2b91698e
  • subagent.md still describes the immediate-parent lookup

fixed in cb5583c. docs/system-specs/modules/subagent.md: the "Parent trusted" rung names root-of-tree resolution via resolve_approval_policy, and the parent_policy chain step 1 names the admission-stamped root_session_key, the stamp-not-walk rule, the root key handed to the approver, and that the liveness probe still reads the literal parent key. docs_lint.py clean.

@billygerhard

billygerhard commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor Author
span=ebc85bc0077e

self-added: yes
mechanism: _spawn_slot_resolver closure delegates to a GatewayOrchestrator._spawn_approval_slot method

  • _spawn_slot_resolver wiring unobserved by any test

fixed in cb5583c. The slot resolution is hoisted out of the _init_subagents closure into GatewayOrchestrator._spawn_approval_slot(request_id); the closure is a one-line delegate.
Pinned by test_spawn_approval_slot_is_the_root_chat_tab: a depth-two spawn (ancestor already popped) resolves to chat-1, an unknown run and a missing manager resolve to "". prove.py --per-hunk now catches the method hunk; the remaining uncaught hunk is the delegate line itself.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 23, 2026
@billygerhard

Copy link
Copy Markdown
Contributor Author

d17643a965 -> 616a4ec474: rebased onto main d9b2e9ddf7 after #21464 split test_slack_gateway.py into topic files. The contested=False kwarg on _interactive_approval's prompt assertion stays in test_slack_gateway.py; the root_session_key_for mock on TestRetriggerRecovery._setup and test_a_nested_parents_queue_depth_never_overwrites_the_root_tabs_count moved with their class to test_slack_gateway_subagents.py. No code change. 8744 tests (full B gate list), mypy, static gates, tsc green.

@billygerhard

Copy link
Copy Markdown
Contributor Author

616a4ec474 -> b7155e4829: rebased onto main 4fe2494b7d. Four conflicts, all whole-block moves on main with this PR's edits inside them, ported into the new owners with no behaviour change: #21647 (DashboardState -> state_parts): the live_roots badge test moved to slots_frame.py, the contested= pass-through to dashboard_services.request_approval; #22019 (run coordinator owners): the _ApprovalPrompt root key + contested label, running_agents_rooted_at_impl/_running_summaries and the ladder's root_session_key stay in run.py; the record_id/durable state-writer plumbing moved to run_records.py; the founder contest write + root_approval_policy read moved to run_turn.py (its Reads: list gains root_approval_policy, trust_root_for); #21992/#22003 test splits: the fake manager's live_root_session_keys stub to test_session_control_stop.py, the spawn-approver stub to test_subagent_turn_resilience_context_overflow.py. Main's new signature inventories (test_run_bindings.py, test_state_parts_dashboard_state.py) updated for the re-signed members. Stripped diff vs main otherwise identical to the previous head; the maintainer commit is kept as its own commit. Local: 7,762 backend tests across the subagent/gateway/dashboard-state/queue/session-control suites + bindings suites green, mypy (changed files + subagent_parts + subagent_manager), black gate, isort, flake8, docs/feature-map/comment-history/line-cap, static-ratchet gate, tsc all green.

@billygerhard

Copy link
Copy Markdown
Contributor Author

b7155e4829 -> 33f9b26571: rebased onto main b72606cb4b. One conflict, in the SubagentManager member inventory (test_subagent_parts_composition_contract.py): main added a label kwarg to spawn on the same row this PR extends with its three _root... kwargs; the row now carries both, regenerated from the merged class with the test's own _member_kind. No source change. Full nested-trust/routing/wiring/bindings suites + 7,788 broad backend tests, mypy, black gate, isort, flake8, docs/feature-map/comment-history/line-cap, static ratchets all green locally.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Rebased onto 0836784eef (#22087 split subagent_persistence.py). No behaviour change: the conversation_root field on create_agent_folder and the durable= write-through on update_state now live in subagent_persistence_state.py, where those two functions moved; the facade keeps re-exporting them. Both commits kept as before. Local: nested-trust/persistence/facade/composition suites 673 passed; broad subagent/gateway/dashboard glob 11216 passed; mypy, black, isort, flake8, tsc --noEmit clean. The only local errors were the test_dashboard_gallery_* suites, which error identically on a clean origin/main checkout here (host platform profile), untouched by this PR.

@billygerhard

Copy link
Copy Markdown
Contributor Author

GPT F1 (continuation.py -- a legacy alias could release a running canonical conversation): fixed in 9cd068880f, folded into the first commit.

A release now resolves its id to the founder first (_release_founder, the same walk continue uses; off the loop on the async entry), and _release_prefix is keyed on that founder: the busy check reads the founder's conversation, so spawn_release on a pre-upgrade subagent:A2 alias while A's continuation runs answers conversation_busy, and the TTL sweep's expiry of that alias takes the same path. The alias pointer is retired either way (its SessionMap entry and TTL registry entry forgotten, no file touched); the session files go only with the founder's own mapping, and only once the founder's conversation is free -- releasing through the alias id then releases the conversation itself.

Pin: test_releasing_a_legacy_alias_is_keyed_on_the_founders_conversation (A2 -> A on disk, subagent:A2 and subagent:A both mapped to the native sid, a live run registered under subagent:A): pre-fix the alias release answered released and unlinked the native session; post-fix it refuses, retires only the alias, and the later free release deletes the files once and demotes the founder. Release/sweep/continuation suites 743 passed, broad glob 11235 passed, mypy clean.

F2 (tab routing after a later contested continuation) was downgraded by adjudication as disproportionate; the behaviour is unchanged in this push.

@iamwhatever

Copy link
Copy Markdown
Contributor

Holding for human review. This PR changes which chat's approval policy a nested subagent inherits: runs at any depth under a trusted chat are approved automatically, and a conversation continued from another chat becomes contested and prompts every time. It also changes how continuations are released, which deletes session files. Under the review policy, a change to who is trusted and what an approval policy allows is reserved for a maintainer. Every lane is PASS and every check is green at 9cd068880fcd9f5bfa82b1b9f347d20be4a1674a.

Open points on this head for the human reviewer:

Reviewed head: 9cd068880fcd9f5bfa82b1b9f347d20be4a1674a.

— crew-pr-reviewer (r117)

@billygerhard

Copy link
Copy Markdown
Contributor Author

Answering the r117 open points and the advisory notes on 9cd068880f. Description edits only; no push.

GPT F1 (taskq_fail durability, #17397). The fix is #18165, which is green on every review lane and waiting on the same human review. Either order works for me: land #18165 first and this PR inherits the settle, or record an override here and #18165 closes the gap behind it. Your call.

GPT F2 (card misroute after a later contested continuation). Opened #22827 with the trigger, outcome and the reason it was not fixed here (a third routing root on every record for a cosmetic misroute). Linked from the description's release notes and Related Issues.

Design. Note 1: agreed, the conversation_root field and the contested:<key> marker spelling are frozen until #13244 ships; noted on #13244 is where the clearing affordance lives. Note 2: the commit-point conversation_busy re-check and the _claimed start hold now have their own release-notes bullet in Backwards compatibility, inside the capture window. Note 3: folding the three marker-to-slot guards into one resolver is reasonable; it is a refactor of code this PR only threads through, so I have left it for a follow-up rather than widen this diff.

First Principles item 6. Declared: a release-notes bullet in Backwards compatibility now says that a nested run's card, frames, sidebar badge and reconnect replay move into the root chat's tab (previously drawn in no tab), with #13116 for depth-aware rendering and #22827 for the known misroute.

UX. The two orders are deliberate and documented in What changed: the spawn feed card has no tool purpose, so it puts the remedy second so the excerpt reaches the safe verb before the cut; a tool prompt leads with the state, then the tool's own purpose, with the why and remedy whole in Review. "This run has no single owning chat" is the one sentence that is true for every case the marker covers (two chats, an unreadable or pre-stamp founder, a resumed admission without its stamp, a cron's or CLI's run a chat picked up), which is why it does not name "a different chat". If the maintainer would rather lead with the cause on the spawn card and accept the excerpt cut, say so and I will change the strings in a follow-up push.

Closes line. Added Closes #14110 at the top of the description.

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES -- reviewed 9cd0688 (same head as our r117 review).

Thanks for the replies. #22827 covers the card misroute, Closes #14110 is in the description, and the card move and the conversation_busy / _claimed refusals are now named in the release notes. The UX wording rationale holds.

One item is still untracked: you agreed with the Design note about folding the separate marker-to-slot guards (turn_approvals.py, subagent_wiring.py, ws.py) into one resolver and left it for a follow-up. Please open an issue for it and link it in the description, or say it is not planned.

After that, the PR still needs a maintainer. It changes which chat's Trust a nested subagent inherits, makes a conversation continued from another chat prompt every time, and changes a release path that deletes session files. The maintainer also picks the order with #18165 for the taskq_fail durability gap (#17397).

— crew-pr-reviewer (r118)

@billygerhard

Copy link
Copy Markdown
Contributor Author

r118: the guard consolidation is now tracked as #22946 (one resolver for trust-root -> slot, replacing the separate checks in ws.py, subagent_wiring.py and turn_approvals.py; behaviour-neutral refactor) and linked under Related Issues. Nothing else changed; head is still 9cd068880f. The remaining items -- maintainer sign-off on the trust-policy change and the ordering with #18165 for #17397 -- are the maintainer's.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Housekeeping, no code change: readiness flipped to action required at 23:17Z because the disposition gate started admitting my 143 older <!-- ai-review-disposition … --> comments (my permission on the repo changed) and every one carried span= inside the marker, which the grammar rejects. I edited them in place rather than deleting: the 91 that name a span=<12-hex> finding id now read <!-- ai-review-disposition target=<lane> head=<sha> --> span=<id> (two with several title bullets keep one bullet); the 52 re-roll/round notes with free-text spans are re-tagged <!-- ai-review-note … --> so they are no longer ledger records. pr_status.py --disposition-gate now reports 91 records, 0 violations. Bodies are otherwise unchanged (edit history is on each comment). The remaining readiness red is the r118 REQUEST_CHANGES on this head, which clears when the reviewer re-reviews.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Rebased 9cd0688 -> 3d3973d onto main f9e2e76. One import-line conflict in src/kiro_crew/dashboard/handlers/files.py (main's session_runs_remotely import from #19833 beside this PR's is_contested_root import); kept both. Content otherwise identical to the previous head; maintainer commit patch-id unchanged. Focused gates: 254 tests, isort/flake8/mypy/black gate green.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Re-rolled 3d3973d -> dc750f0: clean rebase onto main 3af84a4 (6 commits, no file overlap), content identical, maintainer commit patch-id unchanged. Reason: the Opus 5.5 Review lane on 3d3973d never ran -- its lane run failed at actions/checkout with Failed to connect to github.com port 443 (runner network), so it reported "review incomplete" with no verdict. Every other check on that head was green (89). Focused tests + black gate green on the rebased tree.

@billygerhard

Copy link
Copy Markdown
Contributor Author
span=continuation-retained-hold

GPT on dc750f0:

  • F1 (continuation.py, release the conversation hold while a start claim is retained) -- accepted, fixed. The finally in continue_conversation_async_impl dropped _continuation_starts[conv_key] on every exit, including when claim_and_start had retained the start for retry after a failed post-claim write; that retry re-enters the gate with the cached founding root, so the hold has to outlive the call. It now releases only when the id is not in _retained_claims, and retry_retained_claims lets go once the retry settles (the pump's _dispatch_async_impl idiom). Pin: test_a_retained_start_claim_keeps_the_continuation_hold (fails on the old code: the hold was {} while the claim was retained, so a rival from another chat was admitted). Spec sentence updated. Folded into the first commit; maintainer commit untouched.
  • F2 (pump.py:788, refused STARTING row whose best-effort failed write did not land) -- standing taskq_fail publishes a refusal before its failed write lands; a lost write leaves a claimed row for the boot reconcile to requeue #17397. The refusal's durability is taskq_fail's, which fix(subagent): settle a refused task-queue row before publishing #18165 makes retry-until-written and hold the row meanwhile; this PR's _ended_record clause only stops a commit-point-refused row from being requeued (which left a stale _queue entry refusing the next continuation). Ordering with fix(subagent): settle a refused task-queue row before publishing #18165 is the open maintainer call from r117.

Pushed dc750f0 -> 0819013.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Re-rolled 0819013 -> f7b43e1: clean rebase onto main db4f0a3 (6 upstream commits, no file overlap), content identical, maintainer commit untouched. The GPT fork lane on 0819013 ended "review incomplete" before any review step ran (the runner could not reach the OIDC token endpoint: getIDToken connect refused after 12 retries), so this is a fresh roll for that lane, not a change.

@buluoray

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: for reference, the downgraded tab-routing finding from this PR's review is tracked in #22827. It is not a blocker here; it will be picked up after this PR merges.

@buluoray

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: @billygerhard, checking in on this PR, which #13116 and #13244 point at.

What blocks it today at f7b43e1: the 21 Oct request for changes is answered (the follow-up it asked for is #22946, linked in the description) but has not been re-reviewed yet, and Backend Tests shard 4 and Coverage Gate are red on this head, so PR Readiness fails; after that it waits on a maintainer.

Do you still plan to finish it? If there is no reply within 7 days, a maintainer may take the PR over to land the fix.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Yes, still on it. At f7b43e1 the 21 Oct request for changes is addressed (the follow-up it asked for is tracked in #22946) and the branch is waiting on re-review. Backend Tests shard 4 is the known flake tracked in #23382, and Coverage Gate is downstream of that shard, so it needs a maintainer rerun rather than a new push; I would rather not churn the head while review is pending. Happy to rebase or re-roll if a maintainer prefers.

A trusted chat stores approval_policy="auto" on its own session key. A
subagent's key is subagent:<id>, which the shared-runtime path never
registers in the session store, so the spawn gate, the run loop's
tool-permission branch and the interactive approver all read "" for a
grandchild's parent and fell through to a prompt no tab could show.

SubagentManager.root_session_key walks parent_session_key links to the
chat that started the tree (stopping at a non-subagent key, an unknown
id, an empty parent or a cycle); resolve_approval_policy reads the
root's policy. The spawn gate and run loop use it, and the gateway
resolves a subagent parent's approval slot from the root chat so the
prompt lands in that tab and its slot trust applies.

A continuation's start claims its conversation for the length of its
awaits (_continuations_starting, keyed on the conversation rather than
flagged on the founder's record, which may be evicted), and
_conversation_busy answers the claim under the id the start will run as.
Without it a rival continuation admitted while the start awaited could
contest the conversation, finish and be evicted before the start
committed, leaving the gate's commit-point check -- which adopts a
contest from retained records -- nothing to adopt, and the founding root
the start read before its awaits to grant a chat trust another chat had
written past.
@billygerhard

Copy link
Copy Markdown
Contributor Author

Rebased f7b43e1 -> 4642dd3 onto main 91d4998 to re-roll the two reds on the old head (Backend Tests (3.12, 4) and Coverage Gate). Clean rebase, no conflicts, content unchanged. The PR's own backend tests pass on the rebased tree (1292 passed).

@iamwhatever could you re-review when you get a chance? The one open item from r118 (folding the marker-to-slot guards into one resolver) is tracked in #22946 and linked in the description. The remaining items, sign-off on the Trust-inheritance change and the ordering with #18165 for #17397, are maintainer decisions.

@billygerhard

Copy link
Copy Markdown
Contributor Author
span=contested-child-tab-root span=legacy-alias-release-founder

Both blocking findings on 4642dd3 are accepted and fixed in dc5b80c (+112/-13, 6 files).

  • GPT F1 (admission_surface.py, a contested child's tab moved to a later chat): fixed. Admission now captures the child's tab-routing root (tab_root_session_key on the run record, stamped in admission/gate.py beside root_session_key / conversation_root_session_key, only for a contested: root). root_session_key_for returns that captured value first, so a later continuation from chat D no longer pulls C's file card or lifecycle frames into D. Pin: test_subagent_nested_trust_routing.py::test_a_later_continuation_from_another_chat_does_not_move_a_contested_childs_tab (drives the real manager.spawn and the files.py path).
  • Opus F1 (continuation.py, an expired legacy alias deleted its founder's session): fixed. When the released id resolves to a different founder and still has its own alias mapping or TTL entry, _release_prefix retires only that alias and leaves the founder's mapping, TTL entry, keep flag and native files alone. A post-upgrade continuation id with no mapping of its own still releases the founder, as before. Pins: new test_an_expired_legacy_alias_never_releases_its_recently_continued_founder (drives the TTL sweep) and the updated test_releasing_a_legacy_alias_is_keyed_on_the_founders_conversation.

Both pins fail on the unfixed code. Gates: the PR's test files 1294 passed; release/sweep/routing callers 1585 passed; black, isort, flake8 and mypy clean on the changed files.

…ion contested

subagent_queued carries one parent's queue depth and the client stores
it per slot as a value, so routing a nested parent's count to the root
chat's tab overwrote the root chat's own wave count; it keeps its
literal parent's slot. An in-memory queued continuation re-entered with
its first entry's conversation stamp, so a contest a rival wrote while
it waited was lost and it ran on the founding chat's trust; the gate's
commit point now adopts a contest any retained record carries.
@billygerhard

Copy link
Copy Markdown
Contributor Author
span=continuation-run-pin

GPT on dc5b80c:

  • F1 (continuation.py, founder resolution discarded the continued run's model selection): accepted, fixed in c5d25fc. Both continuation entries now read the model and effort of the run the caller named before switching to the founder id, and pass them to _continue_prelude through a _run_pin keyword (sync continuation.py:465-480, async :555-565, prelude :882-884). They read the retained record, or the run's own state.json if the record was evicted. The founder id stays the only key for conversation identity, busy checks and trust provenance. Pin: test_subagent_nested_trust.py::TestNestedTrustInheritance::test_continuing_a_continuation_keeps_its_own_model_and_effort ([async|sync] x [retained|evicted]); all 4 cases fail on the old code.
  • F2 (subagent_wiring.py, workflow grandchild cards split across tabs): downgraded by the adjudicator, not changed here. The same split already exists on main for depth-one workflow spawns, and the full fix touches every per-frame, status, sidebar and replay path.

Gates: the PR's test files 1298 passed; the 19 files that call _continue_prelude / continue_conversation 804 passed; black, isort, flake8 and mypy clean.

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head c5d25fc5e7646dcef8d67740d0099bc90b020382.

No P0 found. I did not find a path where an untrusted chat's requests get auto-approved. I spot-checked the trust paths (trust_root_for, turn_approvals.py, the spawn gate, the retry path), not every line.

Both GPT 6.1 blockers on this head reproduce in the code:

  1. src/kiro_crew/subagent_manager/admission/pump.py:788 (P1). _ended_record skips the give-back of a taken start because the failed write was posted. That write only logs on failure, so under lock contention the row can stay STARTING and a restart can run work the caller was told was refused. This is the base-level gap tracked in #17397. This PR now relies on it in a new place, so the merge order with #18165 matters.
  2. src/kiro_crew/subagent_parts/admission_surface.py _tab_root_below_contest (P2). The climb reads top.root_session_key but never the captured top.tab_root_session_key. A grandchild spawned after another chat continues the ancestor conversation shows its cards in that other chat's tab. Display only, not trust, but a one-line fix: check top.tab_root_session_key at each hop before following the parent.

On size. The PR is +6138 lines: about 3760 tests, 1690 production, 406 for the screenshot script, 256 for the spec. Of the production lines, about 550 are # comments before docstrings, so the logic is about 1000 lines.

Most of that logic comes from the second goal, the contested-conversation marker, not from the first (trust reaching every spawn depth). The marker needs its own guard in card routing, the Slack DM path, retry, reconnect replay and the queue. Suggestion: split it. A PR that only carries trust down the spawn tree would be much smaller and easier to land. The contested marker can follow as its own PR under the RFC in #15457, with the three marker-to-slot guards (turn_approvals.py, subagent_wiring.py, ws.py) folded into one resolver there.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Closing this attempt. The scope grew well past the bug, and the reviewed direction is a much smaller change. The bug itself is filed as #28364 with the suggested minimal approach, so a maintainer can pick it up. Thanks to everyone who reviewed.

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

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A finished subagent conversation continued from a second chat runs under that chat's Trust, not its founder's

4 participants