Repository navigation
feat(acp): DeepseekHarness, dsh on the shared runtime with a per-session gate ledger (not routed) - #37643
Conversation
4aeb51b to
2a70bf1
Compare
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: no session is routed to the new harness, and every new seam ( Notes
[DESIGN-REVIEWED] 5dc27e6 Description read[DESCRIPTION-READ] d0378101c833d6668cf89789e95c7c378d1df9add7f86d138516d0ac355f0e18 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing here changes what anyone gets today. Deepseek is registered on the shared runtime but nothing routes to it until #37646. The new tripwire is a second copy that the description defers on purpose. Notes
What this change shipsInventory (9 items) — 7 justifiedIntent: let one shared
[FIRST-PRINCIPLES-REVIEWED] 5dc27e6 Description read[DESCRIPTION-READ] b5777099de79a3203403ed0131efe7fd30724a65f7df50b5a0d13e73d63d57e5 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
dfca5f3 to
831f0a2
Compare
831f0a2 to
b022725
Compare
Code change approver recommendation: A person should decideWhy: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own. Adds DeepseekHarness to the shared runtime, registered but not routed. It keeps a gate ledger per session, kills the whole process when a call runs past the gate, adds a session/resume restore path, and moves the unstartable-MCP prune into a shared module. At this head nothing a user sees changes: ACP_BACKENDS_ACP_RUNTIME is still {kiro, kas, codex}. None of these routed backends is in the RESUME_WITHOUT_LOAD, LOAD_WITHOUT_MODES or PRUNE_UNSTARTABLE_MCP sets, and the new HarnessAdapter hooks default to the old behaviour. can_restore_session gives the same answer as the inline code it replaces. Checked: every permission request that passes the earlier refusals reaches _refuse_by_harness, and the only approval path, approve_tool, records the yes after the answer is written. The runtime is marked dead before kill(), which matches how the ownership gate counts leases (dead runtimes' leases are excluded). The new behaviour is covered by tests and CI is green. An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
b022725 to
02bf782
Compare
835635f to
c7331e3
Compare
c7331e3 to
8614c3f
Compare
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Thanks for this. The review found one test-determinism problem that needs a fix before this can merge.
test/test_deepseek_shared_runtime.py:364(also the tripwire tests at about lines 350, 404 and 506). These tests call_refuse_moved_permission_statewithout stubbingsel_module.sel, so each one writes a real audit row through the backgroundsel-writerthread. Aftertest_a_cancel_during_the_kill_still_leaves_the_runtime_dead_and_killedreturns, that thread is still importingkiro_crew.security.redaction_structured.engine. The next redaction on the main thread gets the partly initialised module, andcompat._loadthen marks redaction as failed for the rest of the worker. Trigger: run this file and thentest/test_acp_runtime_permission_trust.pyin one worker, in that order (pytest -n0 test/test_deepseek_shared_runtime.py test/test_acp_runtime_permission_trust.py). Outcome:test_shared_permission_event_carries_redaction_provenance_without_secretandtest_fidelity_unaware_consumer_gate_rejects_and_auditsfail on every run. In the reverse order everything passes. Under-n autothis can red unrelated PRs, and it breaks thetests-are-deterministicrule. Smallest fix: add one fixture in this file that stubssel_module.selfor every test that reaches_refuse_moved_permission_state, the same waytest_a_trip_is_audited_as_the_call_that_ran_not_as_a_mode_changealready does. With that fixture in place, the two-file run passed 45 of 45 on every attempt.
Optional:
test_only_a_written_yes_records_an_approvalchecks the approve hook only through source text. If the hook moves into thefinallyblock, or records on another session's ledger, every covering test still passes. A behavioural test on a real handle would pin it: approve thencompleteddoes not trip;GrantEndedthencompletedtrips; approving A leaves B's ledger unchanged.- No spec under
docs/system-specs/covers the newsession/resumerestore verb,gate_tripwire_issue, or the rule that one chat's trip ends the whole process (acp-client.md and agent-host-contract.md). Either update them here, or say in the body that #37646 owns the docs. - The Backwards compatibility section names
note_permission_rejected, but the hook this diff adds isnote_permission_approved. You can fix that with a body edit.
8614c3f to
a1b891a
Compare
|
Fixed in a1b891a: |
…ion gate ledger (not routed) One dsh --profile acp process serves several sessions: dsh 0.2.0-rc.2 runs their turns in parallel, mounts each session's MCP servers on that session alone, and restores a closed session with session/resume. DeepseekHarness runs DeepseekLaunch's own spawn (sealed plugin, --patch overlay, read-back probe) once per process, against a stand-in carrying the runtime's extra_env, agent.env snapshot and work dir. The nonce and the pinned mode ride the new SpawnPlan.child_env, so the harness keeps no state; the vault key is read in apply_spawn_env, off the loop. The completed-unasked tripwire keys on each session's own ledger: an ask is recorded through permission_refusal, a no through the new note_permission_rejected hook on the handle's reject path, and a tool_call_update is judged through session_update_issue. A call past the gate fails the runtime (permission_state_issue_ends_process), since the gate is the process's. The shared runtime reads sessionCapabilities.resume and sends session/resume for ACP_BACKENDS_RESUME_WITHOUT_LOAD, and accepts a restore answer without modes for ACP_BACKENDS_LOAD_WITHOUT_MODES, as AcpClient does. Registered ahead of routing: no session takes this path.
a1b891a to
5dc27e6
Compare
|
5dc27e6: the audit stub fixture now patches through |
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
This head fixes the earlier blocking item. The new autouse fixture stubs the audit log through _floor_monkeypatch, and the order-dependent two-file run (-n0 test_deepseek_shared_runtime.py test_acp_runtime_permission_trust.py) passed 45 of 45 on two runs in a row. The earlier body item is fixed: Backwards compatibility now names note_permission_approved. The other two earlier items were optional, and they are still open below.
The review checked the whole source diff against the hosts that are routed today (kiro, kas, codex). can_restore_session gives the same answer as before outside RESUME_WITHOUT_LOAD. The prune, session/resume and load-without-modes branches fire only for sets that hold no backend in ACP_BACKENDS_ACP_RUNTIME. SpawnPlan.child_env is empty for every other host. The ratchet edits re-pin counts to their true values and do not loosen them. Removing the prune gate or the modes check makes the tests fail. Done well: the ledger records Crew's yes rather than its refusals, so every way a request can end without approval counts as not approved, and each session keeps its own ledger, so a reused id like call_0 in one chat cannot vouch for another.
Security: the trust-boundary changes (the per-session gate ledger, the process kill on a trip, the vault key in the child env) do nothing yet, because no session is routed to DeepseekHarness. On the deepseek arm, every approve path goes through approve_tool after _refuse_by_harness has recorded the ask. _mark_dead before kill() gets through the ownership gate and still refuses a live tenancy. The vault read runs in the off-loop env hop, and READ_ONLY auto-approve fails closed on the runtime path.
The design is signed off under the standing maintainer sign-off for changes by team members.
Optional:
- Before #37646 routes deepseek, add a behavioural test of the approve hook on a real handle. Approve then
completedshould not trip.GrantEndedthencompletedshould trip. Approving in A should leave B's ledger alone. Moving the hook intofinallystill passes every current test. You could also record the approval in thebefore_writehook, so it can never land after dsh reports the callcompleted. - The Documentation checkbox is ticked, but no spec changed.
runtime-ownership.mdstill says every kill path releases before it signals, and theacp-client.mdmodule row still lists only ProcessAdapters. Neither spec mentionssession/resumeon the runtime. The_refuse_moved_permission_statedocstring still says only the session closes. Update them, or name the PR that owns the update. SpawnPlan.child_envadds a field to the shared spawn seam for one consumer. Keeping the resolved launch on the harness and applying it inapply_spawn_env, as CodexHarness does, would remove that field.
Problem / Motivation
Goal: the shared runtime can drive one
dsh --profile acpprocess for several sessions, with Crew's tool gate and its completed-unasked tripwire still holding for each session; no session is routed there yet.deepseek chats each start their own
dshprocess today (AcpClient+DeepseekLaunch). The shared runtime (AcpRuntime) had no harness for deepseek, and three things about deepseek did not fit it: the gate (a--patchplugin, a read-back probe and a nonce) is built per process; the completed-unasked tripwire keeps its ledger on the client; and dsh restores withsession/resume, which the shared runtime never sends.Why it matters
deepseek dashboard chats are next to share one ACP process, the way KAS, codex, claude and goose chats can, which saves one Node process per chat. Measured on dsh 0.2.0-rc.2 with Crew's gate plugin composed, two sessions on one process: a 60 s command in A took 60.1 s while B answered at 2 s and 30 s in 0.02-0.03 s; no text or tool crossed sessions (same folder or not); each session's model calls saw only its own MCP tools; B kept working after A closed;
session/resumebrought A back on the same process with only its own tools; every permission request named its ownsessionId.This is the second of three PRs. Stack and merge order: #37641 (PR1, deepseek code off
AcpClient, merged) -> #37562 (GooseHarness: thepermission_refusal/session_update_issueseams this reuses, merged) -> this PR -> #37646 (the switch). This branch is one commit on main.Not a goal
ACP_BACKENDS_ACP_RUNTIMEor to chat sharing. That is the next PR, behind a switch that defaults off.AcpClient+DeepseekLaunch).client_permissions._tripwire_pi_gate) stays as it is: it is shared with pi and MiMo Code (pending asks, the shell-only arm), so folding it ontogate_tripwire_issueis its own change.What changed (motivation -> approach -> change)
The gate is the process's, the ledger is the session's -> run
DeepseekLaunch's own spawn once per process, and keep the tripwire's asked/denied ids per session in the runtime's per-session harness state -> one new harness plus small runtime hooks.DeepseekHarness(acp/harness/deepseek.py), registered in_HARNESSESahead of routing.resolve_spawnrunsDeepseekLaunch.resolve_spawnagainst_RuntimeProbeSession, a stand-in carrying the runtime'sextra_env,agent.envsnapshot and work dir, so the read-back boots in the environment the child gets. The gate plugin asks about every call of every session and reads no nonce at run time, so one composition serves all sessions on the process.DSH_PERMISSION_MODEtravel on the newSpawnPlan.child_env, which the runtime places on the child just beforeapply_spawn_env.apply_spawn_envreads the provider key from Crew's vault (it runs in the launch's off-loop env hop) and strips kiro-cli'sKIRO_API_KEY.prepare_sessionreturns a_DeepseekSessionledger.permission_refusalrecords the ask (refuses nothing); a newHarnessAdapter.note_permission_approvedhook, called from the handle'sapprove_toolonly after Crew's yes is written, records the approval;session_update_issuetrips on acompletedcall that was never asked about or never approved, and consumes the ids at the terminal frame. Recording the yes rather than the no means every refusal path (the floor, the batch guard, a person), a cancel and an unanswered request all count as not approved. Because the ledger is per session, an ask in A is never counted for a call in B under the same provider id.HarnessAdapter.permission_state_issue_ends_process(True only here):_refuse_moved_permission_statemarks the runtime dead before any await, then kills it underasyncio.shield(AcpRuntime.kill, now on the handle's runtime contract), so a Stop landing during the kill cannot leave the process serving. Marking it dead first is also what lets this tenant through the ownership gate, which counts only a live runtime's leases. Nosession/closeis sent on this path: the process is ending and dsh keeps the record. goose keeps closing only the one session.can_restore_session(agent_sdk/backends_sessions.py), now used by both drivers:AcpClient._initialize_sessiondrops its inline copy andAcpRuntimecalls it afterinitialize.load_sessionsendssession/resumeforACP_BACKENDS_RESUME_WITHOUT_LOADand accepts a restore answer withoutmodesforACP_BACKENDS_LOAD_WITHOUT_MODES, asAcpClientdoes.SpawnContextgainsextra_envandagent_env, filled by the runtime.AcpClientruns forACP_BACKENDS_PRUNE_UNSTARTABLE_MCPmoves toacp/mcp_prune.py(prune_session_servers,record_pruned), and the runtime'screate_sessionandload_sessioncall it too, so an element whose command cannot start is left out of the array and reported failed instead of failing the wholesession/neworsession/resume.HarnessAdapter.permission_state_audit: a deepseek trip is written to the audit log as the call that ran (ran_without_gate/ran_without_approval, reasonpi_gate_tripwire), not as a mode change.Trade-off: one chat's tripwire ends every chat on the process
What happens to the other chats: their running turn ends with the runtime's death (the death sentinel wakes it, it does not hang), the process is killed, and each chat is restored on a new process with
session/resume. Nothing is lost: dsh keeps each session's record in its own home. Measured: two sessions on one dsh process, B answered once and A in the middle of a 60 s command, the process SIGKILLed; on a fresh process bothsession/resumecalls succeeded, B answered with its earlier turn in the model's history (3 messages) and A with its interrupted turn in history.Why not close only the chat that tripped: the tripwire means a tool call completed that Crew's gate never saw. The gate is one plugin composed into the process, so that observation is about the process, not the chat; the per-session client stops its process on the same frame. Keeping the other chats on it would leave each of them able to run one more ungated call before its own tripwire could fire, because the tripwire only sees a call after it completed. The cost is an interrupted turn in the other chats, which is rare (it needs the harness to bypass the gate) and recoverable.
Backwards compatibility
Compatible: no session is routed to
DeepseekHarness. For every other hostSpawnPlan.child_envis empty,note_permission_approvedis a no-op,permission_state_issue_ends_processis False,can_restore_sessiongives the old answer on both drivers, andload_sessionsendssession/loadand requiresmodesas before.AcpClient._initialize_sessionreplaces its inline restore-capability branch withcan_restore_session, same answer.DeepseekHarness.resolve_spawnhands the shared runtime the credential maskDeepseekLaunchresolved (extra_hidden_dirs), so the runtime's sandbox wrap hides the same directories a per-chat dsh process hides.Reader: src/kiro_crew/acp/client_start.py:_initialize_session -- chat -- test_both_drivers_read_the_restore_capability_with_one_function
Reader: src/kiro_crew/acp/runtime_spawn_launch.py:_spawn_admitted -- chat -- test_the_spawn_composes_the_gate_and_proves_it_in_the_runtimes_environment
Tests
test_deepseek_shared_runtime.py: registration and seams; the spawn composes the gate and proves it in the runtime's environment (stand-in'sextra_env,agent.env, work dir;--patchargv;child_envcarries the read-back's nonce;vars(harness) == {}); a read-back that did not see the gate refuses the spawn; the vault key reaches the child andKIRO_API_KEYdoes not; a bad key mapping refuses; resume capability reading for deepseek vs codex, and both drivers use the one reader; tripwire on unasked, asked-once, denied, failed and non-tool updates; two sessions on one process: A's permission frame is recorded on A's ledger only (through the handle's_refuse_by_harness), so B's completion of the same id trips and A's does not; an asked call that completes without Crew's yes trips; a call past the gate marks the runtime dead and then kills it, a cancel during the kill still leaves it dead and killed, and a goose mode move still closes only its own session; only a written yes records an approval (no reject path does); a tripwire in one chat on a realAcpRuntimewith two sessions wakes the other's queue with the death sentinel, and a fresh runtime restores that other session withsession/resume; a realAcpRuntimestarts and closes a session with its ledger and restores one from an answer with nomodes. The shared prune drops an unstartable server on a new and on a resumed session and reports it failed; a trip writes the call's audit row.test_acp_harness_contract.py: deepseek joinsALL_BACKENDSandREGISTERED_AHEAD_OF_ROUTING.test_acp_deepseek_backend_session.py: the restore pin now reads the shared reader.test_goose_shared_runtime.py,test_claude_shared_runtime.py,test_acp_runtime_load_session.py,test_acp_runtime.py,test_acp_runtime_session_start.py,test_acp_runtime_spawn.py,test_acp_harness_wire_parity.py,test_acp_goose_backend.py,test_runtime_bindings.py,test_session_handle_bindings.py,test_harness_parity.py,test_client_bindings.py,test_acp_deepseek_backend*.py,test_side_readonly_deepseek.py: all pass.scripts/check_harness_parity.pypasses; black, isort, flake8 and mypy on the changed files are clean.Proof: not provable -- other: no session is routed to this harness; the two-session and kill-then-resume behaviour it relies on was measured on a real dsh process (numbers above) and the end-to-end chat run lands with the switch PR
Manual verification
Real
dsh --profile acp0.2.0-rc.2 with Crew's gate plugin composed, driven over stdio against a loopback model stub: two sessions on one process, and a SIGKILLed process whose two sessions resume on a new one. Results in "Why it matters" and "Trade-off". The pod run with real chats, process counts and memory comes with the switch PR, which is the first one that routes a chat here.Related Issues
Part of #5033
Checklist