Repository navigation
Conversation
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
First Principles Review (Opus 5.5, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The transport-level withdrawal (withdraw_if, ApprovalWithdrawn, approval_withdrawable, withdrawal_check) adds permanent surface across six files. It closes a millisecond window inside a defect the author already calls doubly improbable. Not justified as shipped
What this change shipsInventory (5 items) — 4 justifiedIntent: once a user stops a sub-agent, it never gets another tool approved, even when teardown fails. FIX.
[FIRST-PRINCIPLES-REVIEWED] 3877d64 Description read[DESCRIPTION-READ] a2439ce67f58641c5b8cdb571852ba71af88cf1b87f4d8668cfd021ec92bcb2c That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check before merge: the session-sharing stop path ( Suggestions
[DESIGN-REVIEWED] 3877d64 Description read[DESCRIPTION-READ] 8dda611e99a919f9ba57923f334616f872588cb6607465c25e1b624b81342a93 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
f1b91bb to
2008a13
Compare
2008a13 to
503e3d0
Compare
503e3d0 to
e84bd3e
Compare
|
Amended the PR's one commit, in test/test_subagent_stop_refuses_permission.py only: the 10 s settle ceiling is now 30 s and the two 10 ms poll loops wait with async_wait_until, the form the repo's wait-discipline ratchet (test/test_wait_discipline_ratchet.py) accepts. |
e84bd3e to
671151e
Compare
|
671151e answers each point; the branch is rebased onto main 65df088 and is still two commits. GPT: Stop still permits approval of an already-dequeued request (span 3b96d9d7798e). Fixed at the commit point, for every approver. Design: a stopped run with a live stream keeps running (span 56a8325fbe5c). The stop bail now ends the run, as the limit bails do. The loop breaks after it ( Design suggestion: one check where the swallowed cancel resumes the loop (span a8e0f52a2122). Taken, where it applies: the run checks right after the approval returns (after First principles: the loop continues after the bail. Same change as the Design point above: the loop now breaks. CI. The two backend shards that failed on the previous head failed in |
iamwhatever
left a comment
There was a problem hiding this comment.
This PR makes a sub-agent run that is being stopped refuse every further tool request, even when its session teardown and the kill fallback both fail. It does this with a live Policy.stopping predicate that the run loop, settle, the _allow commit point and, through withdraw_if, both ACP transports all read. The run-loop and ladder reads fix the root cause, and I could not get a grant, a gate hit or a person's yes past them: there is no await between _allow's read and wire.allow, and the only Wire implementations (AcpWire and the test fake) accept the new argument. One regression remains, and it is on the existing chat path, not on sub-agents. In src/kiro_crew/acp/runtime.py:5448, checks() now runs the caller's before_write before _refuse_write_if_dead(). For a timed grant, that caller check is grant_check, so an expired grant on a runtime that died during the lock wait now raises GrantEnded instead of AcpRuntimeDead. dashboard/chat_runner.py:14589 then sets approval_sent = None and shows a person an approval card for a dead runtime, so session-reset recovery waits a whole approval window. This is the Opus lane's advisory finding on a712e6f, and no disposition has answered it. Suggested fix: run only the withdrawal ahead of the liveness check. For example, in session_handle.approve_tool, pass the runtime a before_write that runs raise_if_withdrawn and leaves grant_check until after _refuse_write_if_dead, or split the hook into pre-liveness and post-liveness parts, and add a test that a dead runtime plus an expired grant still raises AcpRuntimeDead. Please also post a disposition for the First Principles CONCERNS item (the transport-level withdraw_if layer). — crew-pr-reviewer (deep re-check)
A Stop tears the sub-agent's session down first and cancels the run task after that. The dashboard approval wait turns that cancel into a denial, so the run loop resumes and reads its next event. When the session reset hangs or raises and the kill fallback also fails, the stream is still live, and the next permission request went through the normal ladder: a grant such as slot trust or --approval yolo approved a tool after the user pressed Stop. The permission branch now bails every request as "stopped" once _reap_started, user_stopped or reaped is set, before any grant or person is consulted. The bail is the ladder's own: the SEL row is written with error "stopped" and the request is rejected bare on the wire. "stopped" joins BailReason and the sub-agent refusal rows, and the run's ladder-entry ratchet counts the new bail. The cancel swallow in ApprovalCoordinator.request is unchanged; it is documented as intended (deny on timeout or cancellation).
The stop check at the top of the permission branch ran once, before the branch's own awaits (the diagnostics write and the subagent_tool event) and before the ladder's (the spec hooks, the gate, a person's wait). A Stop landing in any of them, while its session reset was still hanging, let the request reach the wire as an approval: parent_policy=auto, the gate's auto-approve or a person's yes sent approve_tool after the Stop. Policy gains a live stopping predicate. settle reads it before its first stage and before it asks a person, and _allow reads it at the commit point of every approval. Once it holds, the request goes through the same audited stopped bail. The run passes its predicate (_reap_started, user_stopped or reaped). _allow also hands the predicate to the wire, because approve_tool still awaits the security floor's thread hop and the stdin write lock before it writes the allow. AcpWire passes it as withdraw_if to a provider type that declares approval_withdrawable (AcpProvider, AcpSessionProvider), and both transports read it after the floor and under the write lock, right before the frame is written: AcpClient through its before_write check, the shared runtime through a withdrawal_check it runs ahead of its own liveness check. Once it holds, no byte is written, the request's records are put back, and ApprovalWithdrawn makes _allow bail the request as stopped: audited, and answered once with the agent's reject. A timed grant's deadline stays in the runtime's before_write, which runs after the liveness check, so a runtime that died during the lock wait still raises AcpRuntimeDead rather than GrantEnded. The stop bail now ends the run, as the limit bails do: the loop breaks instead of continuing, after the bail at the top of the branch and after a settle the ladder bailed as stopped, and the stream's own ending arms record the stop. A person's no that a stop's cancel caused still reads on, so a stream the stop tore down ends at its next read, as before.
a712e6f to
3877d64
Compare
|
Thanks for the deep re-check. The new head is 3877d64, rebased onto origin/main ac8a96a with no conflict, still two commits.
The body's transport bullet, the Removes nothing line and the Tests section are updated for the split; Goal, Why it matters and Not a goal are unchanged. |
1 similar comment
|
Thanks for the deep re-check. The new head is 3877d64, rebased onto origin/main ac8a96a with no conflict, still two commits.
The body's transport bullet, the Removes nothing line and the Tests section are updated for the split; Goal, Why it matters and Not a goal are unchanged. |
|
span=bcc96c0ead6d
|
|
|
span=47d4f3e83df1
|
|
span=705140069842
|
|
This makes a sub-agent run that is being stopped refuse every further tool request, even when its teardown and kill fallback both fail: a live |
|
Thank you @javenciu for finding this and for a careful fix with thorough tests. Main split #20743 is green with readiness passed, so I'm closing this one in its favour. Your branch is left as it is. Thanks again! |
Pull request was closed
Problem / Motivation
Goal: A sub-agent that the user has stopped never gets another tool approved, even when its session teardown fails.
A Stop on a running sub-agent tears its session down first and cancels the run task after that (
subagent_manager/terminal.py, the reset in_force_reap, then_cancel_task_intentionally). When the run is waiting on a person for a tool approval through the dashboard,ApprovalCoordinator.requestturns that cancel into a denial, so the run loop resumes and reads its next event.When the teardown works, that read hits the dead stream and the run ends. The trigger needs two failures together: the session reset hangs past
_RESET_TIMEOUTor raises, AND the SIGKILL fallback after it also fails to stop the process. Then the stream is still live. The backend's next permission request went through the normal ladder, and a grant that answers without a card (slot trust,--approval yoloorreads,auto_approve_sources,parent_policy=auto, a hook grant) approved a tool after the user pressed Stop.Observed in-process with the real run loop, the real stop and the real approval coordinator, with fakes for the backend, the reset and the kill. The order in every run was: Stop, reset, kill failed, cancel, the approval returns denied, tool A rejected, the backend sends tool B, B is granted,
approve_toolis sent for B.Why it matters
A tool that runs after a Stop is the worst outcome a stop can have: the user pressed Stop to prevent exactly that. The likelihood is low, because it needs both a failed session reset and a failed kill.
Not a goal
ApprovalCoordinator.request(except (asyncio.TimeoutError, asyncio.CancelledError): return False), or its question twin. That behaviour is documented as intended ("Request interactive approval and deny on timeout or cancellation",DashboardState.request_approval). Re-raising there would change that documented contract for every caller ofDashboardState.request_approval, not only sub-agent runs; this fix closes the hole at the one place that approves tools for a sub-agent run.shutdown())._force_reapsets_reap_startedbefore either branch, so the guard applies there too, but that path was not driven separately.What changed (motivation → approach → change)
subagent_manager/run.pynever checked whether a stop was in progress. The stop's own ordering (teardown before cancel) was the only thing that kept the request from being read, and that ordering does not hold when the teardown fails. A check made once, at the top of the branch, is not enough either: the branch awaits the diagnostics write and thesubagent_toolevent, and the ladder awaits the spec hooks, the gate and a person, so a stop can land after the check and before the approval is sent.tool_permission.Policygainsstopping, a live predicate.settlereads it before its first stage (tool_permission.py:410) and before it asks a person (tool_permission.py:437), and_allowreads it at the commit point of every approval (tool_permission.py:521), with no await between that read andwire.allow. A grant, the gate's hit and a person's yes all reach the wire only through_allow, so once the predicate holds the request is answered bytool_permission.bail(..., "stopped"): the SEL row is written witherror: "stopped"and the request is rejected bare on the wire. The run passes its predicate (_reap_started,user_stoppedorreaped;subagent_manager/run.py:279, wired atsubagent_manager/run.py:2079) and also reads it when it reads a request (subagent_manager/run.py:3258), before any floor, grant or person is consulted."stopped"joinsBailReasonand the sub-agent refusal rows, so a Stop is recorded as a stop, not as a turn limit or a person's no._allow's read:approve_toolstill awaits the security floor's thread hop and the stdin write lock before it writes the allow._allowhands the predicate to the wire (tool_permission.py:524), andAcpWirepasses it aswithdraw_ifto a provider type that declaresapproval_withdrawable(tool_permission.py:553):AcpProviderandAcpSessionProvider, while any other provider keeps the baseapproval_withdrawableofFalse(providers/base.py:119). Once the floor's thread hop returns, both transports readwithdraw_ifagain (acp/session_handle.py:2520,acp/client.py:9979), and once more under the write lock right before the frame is written (acp/session_handle.py:2547,acp/client.py:10001). The shared runtime reads it aswithdrawal_check, ahead of its own liveness check (acp/runtime.py:5447), and keeps a caller'sbefore_write, where a timed grant's deadline goes, after that check (acp/runtime.py:5450): a runtime that died while the answer waited for the lock raisesAcpRuntimeDead, so the chat path takes the session-reset recovery instead of asking a person about an ended grant.AcpClienthas no liveness check under its lock and reads the withdrawal in itsbefore_write, ahead of the deadline. Once it holds, no byte of the allow is written, the request's records are put back, andpermission_floor.ApprovalWithdrawnmakes_allowbail the request asstopped(tool_permission.py:525), answered once with the agent's own reject option.subagent_manager/run.py:3267) and after a settle the ladder bailed asstopped(subagent_manager/run.py:3356), and the stream's own ending arms record the stop (with_reap_startedset, the reap's ending:subagent_manager/run.py:3621). A person's no that a stop's cancel caused reads on, so a stream the stop tore down still ends at its next read, as before.docs/system-specs/modules/subagent.mdanddocs/system-specs/common/injected-messages.mdlist the new bail beside the two limit bails, and the first says where the stop is read and what ends the run;docs/system-specs/modules/acp-client.mddocumentswithdraw_if.Backwards compatibility
Compatible: a run with no stop in progress takes exactly the path it takes today; the new branch runs only for a run that is already being stopped, and it answers each request through the existing bail. An approval without
withdraw_ifreaches the transport exactly as before: each layer passes the keyword on only when it is given.Removes nothing: the change adds one refusal rung, one optional
Policyfield (stopping, defaultNone, so the task runner's ladder takes its path unchanged) and the reads of it, the optional keywordswithdraw_if(approve_toolon both providers and both transports) andwithdrawal_check(AcpRuntime.send_responseand its protocol), the class attributeapproval_withdrawable(defaultFalse) andpermission_floor.ApprovalWithdrawn; no key, row, rung, path or public function is removed or renamed.Tests
In short: Red and green,
pytest -n 0, 3 of 3 serial runs each. This round, rebased on origin/main ac8a96a: the new runtime ordering test fails 3 of 3 on the previous head a712e6f (diedraisesGrantEnded) and passes 3 of 3 here; 20 more-n 0passes and 10-n 4passes of its file, no failure. The new transport test on this PR's previous head 671151e: 4 failed, 2 passed (the no-stop controls); each failure is anallow_onceframe written after the Stop. The PR's two stop test files copied onto origin/main 10350b7, run with the deny-notice suite: 26 failed, 190 passed. On this branch the three changed test files: 217 passed. Then the 425 other test files that import a changed module (test/test_acp_client.pyleft out: it builds paths under the real home directory), run with-n 16: 24,737 passed, 66 skipped, 19 failed. The 19 are intest/test_acp_spawn_offload.py,test/test_auto_improvement_members.pyandtest/test_native_skill_projection.py, and the same 19 fail on origin/main 10350b7 with the same command.test/test_subagent_stop_refuses_permission.py, new, driving the realSubagentManagerrun loop,cancel,_force_reapandApprovalCoordinator.requestagainst a fake backend:test_a_stop_whose_teardown_fails_approves_no_further_tool[hangs]and[raises]: the reset hangs or raises and the kill fallback fails. B is rejected, no grant is consulted, noapprove_toolis sent after the Stop, B's SEL row isdenied/stopped, and the run ends right after B is rejected: request C is never read. On mainapprove_tool:102andapprove_tool:103are sent after the Stop; with this PR's first commit alone, C was still read.test_a_stop_landing_before_the_answer_bails_the_request, 13 cases: what would approve B (parent_policy=auto, the gate's auto-approve, a person's yes) times the await the Stop lands in (the stream, the diagnostics write, thesubagent_toolevent, the gate, the person's wait), with the reset held so the stop stays in progress. B ends in the auditedstoppedbail, no person is asked when the stop landed before the ask, and C is never read. On main all 13 sendapprove_tool:102after the Stop; with this PR's first commit alone, 10 do, and the 3 stream cases read C.test_a_stop_whose_teardown_works_ends_the_run_before_the_next_requestandtest_a_request_with_no_stop_is_settled_as_before: controls; both pass on main.test/test_tool_permission.py:test_a_stop_read_at_entry_bails_before_any_stage, andtest_a_stop_landing_in_any_stage_bails_the_request_not_an_approval[floor|gate|grant|person], where each policy would approve and the stop lands while the named stage runs.test_every_subagent_bail_is_audited_and_barestill covers the rung throughBailReason.test/test_tool_permission.py:test_a_stop_landing_in_the_transport_awaits_writes_no_approval[shared|dedicated-floor|write_lock|none]drivessettlethroughAcpWireand the real providers and transports (AcpSessionProvideroverAcpSessionHandleandAcpRuntime;AcpProvideroverAcpClient) into a fake backend's stdin. A grant approves, and the Stop lands on the floor's worker thread or while the approval waits for the write lock behind another frame. The one frame written is the agent'sreject_once, the SEL row isstopped, no approval row is written, and after the floor only the reject takes the lock. The twononecases are controls: oneallow_once.test/test_transport_permission_floor.py:test_what_the_shared_runtime_reports_when_the_grant_ends_during_the_lock_wait[died|alive|died-and-withdrawn]holds a realAcpRuntime's write lock, lets a timed grant end while the approval waits for it, and indiedmarks the runtime dead in the same wait (_mark_dead, as a sibling's stall does).diedraisesAcpRuntimeDead,aliveraisesGrantEnded,died-and-withdrawnraisesApprovalWithdrawn, and nothing is written in any case. On this PR's previous head a712e6f,diedfails 3 of 3 withGrantEnded: 52; on this head all three pass 3 of 3. Movingbefore_writeback ahead of the liveness check fails onlydied; moving the withdrawal after it fails onlydied-and-withdrawn.test/test_eval_subagent_deny_notice.py: the run's ladder-entry count stays{"settle": 1, "bail": 3}.settleentry read, the read before a person is asked, the_allowcommit read, the run's break after astoppedsettle), 7, 2, 6 and 10 of the tests above fail. In the transports, with the read after the floor removed, the read under the lock, or the put-back of the records, 2, 2 and 2 of the transport cases fail.The new file's autouse
_pinned_data_homepinsKIROCREW_HOMEandKIROCREW_WORKSPACEthrough the isolation floor's own_floor_monkeypatch, and every wait in it is bounded by the file's_SETTLE_SECS.mypy (the nine changed source files), flake8, isort, black (no changed file is baselined),
scripts/check_black_formatting.py,scripts/check_subprocess_encoding.py,COMMENT_HISTORY_BASE_REF=origin/main scripts/check_comment_history.py,./scripts/docs-lint.shandtest/test_wait_discipline_ratchet.py(39 passed, on this head over origin/main 10350b7): all exit 0.This round, on origin/main ac8a96a,
-n 0in one process: the PR's test files,test/test_transport_permission_floor.py, the sixtest/test_acp_runtime*.pyfiles and the threetest/test_chat_runner*.pyfiles that cover approvals, 1,503 passed. The 69 test files that nameacp/runtime.py,acp/session_handle.pyorchat_runner.py(-n 8): 8,824 passed, 2 skipped. The wait-discipline, flake-pattern, pid-reader, tmpdir-helper and dir-fd ratchets: 127 passed. mypy on the two changed source files, flake8, isort, black,scripts/check_agent_sdk_boundary.py,scripts/check_black_formatting.py,scripts/check_subprocess_encoding.py,COMMENT_HISTORY_BASE_REF=ac8a96a242 scripts/check_comment_history.pyand./scripts/docs-lint.sh: all exit 0.Manual verification
N/A: the trigger needs a session reset and a kill that both fail, which the unit tests drive with fakes; no real process is signalled.
Related Issues
None found. Searched open and merged PRs and issues for "approval CancelledError", "stop approval subagent tool", "swallowed cancel approval" and "tool after stop".
Pattern harvest
Rule candidate: review-prompt
Pattern: a stop that relies on its own ordering (tear down, then cancel) to keep a loop from acting, with no check of the stop flag at the point where the loop grants or executes work.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)