Repository navigation
feat(acp): OpencodeHarness, opencode on the shared runtime with per-session checks (not routed) - #37620
feat(acp): OpencodeHarness, opencode on the shared runtime with per-session checks (not routed)#37620chenmingwei23 wants to merge 1 commit into
Conversation
…ession checks (not routed) opencode 1.19.1 serves several sessions from one `opencode acp` process and runs their turns in parallel, but everything Crew checks for it ran on AcpClient, one process per session: the version gate and the read-back of its resolved permission config at spawn, the per-tool deny rules seeded on OPENCODE_CONFIG_CONTENT, the refusal of a withheld server opencode mounts from its own config, the hosted fall-back refusal, and holding a shell permission back until its command update reaches the trusted cache. OpencodeHarness serves opencode on AcpRuntime. The spawn gates run once per process, under the child's own environment (agent.env and the chat's overlay, now on SpawnContext) and in its folder, through a probe object so the measured functions run unchanged. The harness holds no state: the seed rides SpawnPlan.spawn_env and the read-back rides SpawnPlan.host_state, which the runtime hands to each prepare_session. Per session: the mirror's projection is held to the deny rules in force (new projection_extras seam), a withheld server mounted natively refuses that session, the hosted fall-back closes that session alone, the permission parser gets the session's server names (new harness_mcp_server_names seam), and the turn loop reads a deferred shell permission's command update first (new defers_shell_permission seam). Teardown is session/close. Registered ahead of routing, like claude and goose: no session reaches it until the chat-sharing change names opencode.
c1cbf68 to
0a33494
Compare
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: nothing is routed to this harness yet, every new seam defaults to a no-op, and the plan carries the spawn's state, so the harness itself stays stateless. Notes
[DESIGN-REVIEWED] 0a33494 Description read[DESCRIPTION-READ] 2336484e435240e34cf6b3750f706b6a5f35066eedd616608f163ee81a2917c6 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 blocks. One duplicated predicate: the new shell-permission deferral is the third inline copy of the same frame check. Notes
What this change shipsInventory (10 items) — 9 justifiedIntent: let an opencode session run on the shared ACP process with every existing opencode check, each scoped to the process or to the one session. ADDITION (staged, not routed).
[FIRST-PRINCIPLES-REVIEWED] 0a33494 Description read[DESCRIPTION-READ] 55cb8fb7791747596f7bf141aa7e992f662210caac5c89119710089c830680c6 That sha256 names the PR description this verdict read. Recompute it with |
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: |
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: |
|
Closing without merging; the branch Why: this harness only pays off once opencode chats can share a process, and they cannot today without leaking tools between chats.
So opencode chat sharing waits on opencode registering MCP servers per session and removing them on |
Problem / Motivation
Goal: an opencode session can run on the shared ACP process (
AcpRuntime) with every check Crew runs for it onAcpClient, each check scoped to the right thing: the process or the one session.opencode 1.19.1 serves several sessions from one
opencode acpprocess and runs their turns in parallel (measured: one session running a 60 s shell command, the other answering in 0.13 s;session/closedrops one session andsession/loadrestores it on the same process). But every check Crew runs for opencode lives on the one-process-per-session path:opencode debug config), the per-tool deny rules seeded onOPENCODE_CONFIG_CONTENT, and the refusal of a switched-off tool on a server opencode mounts from its own config;tool_call_updatecarrying its command has filled the trusted cache.Why it matters
This is the second of three PRs that let opencode dashboard chats share one process under the ACP runtime sharing preview, split like goose (#37535, #37562, #37567). The first, #37602, moves opencode's session code off
AcpClient. Users see no change from this PR: no session is routed to the shared runtime for opencode yet.Not a goal
opencodeis not added toACP_BACKENDS_ACP_RUNTIMEor to the chat-sharing set. The third PR adds the switch, the placement rules and the real-opencode lane test.session/close; two sessions in one folder see each other's tools, and a same-named server is replaced. Keeping same-folder chats apart is the placement's job and lands in the third PR.What changed (motivation -> approach -> change)
The checks run per process on a path with no session -> the measured gate functions get the session facts they read from a probe object, and what the spawn found travels on the plan -> a stateless
OpencodeHarnessand four small seams.OpencodeHarness(acp/harness/opencode.py), registered in_HARNESSESahead of routing like claude and goose.resolve_spawn: the same gates asOpencodeLaunch, same order (mask preflight, version gate, seed, sandboxed read-back, deny settlement), under the child's own environment and folder. The seed carries the spawning agent's deny rules.test_no_harness_holds_state_beyond_its_backend_id): the seed rides the newSpawnPlan.spawn_env, applied afterapply_spawn_env; the read-back rides the newSpawnPlan.host_state, which the runtime hands to eachprepare_sessionashost_state. A process with no read-back serves no session.prepare_session: refuses a session whose withheld server opencode mounts natively.after_session_start: refuses an inheriting session on the hosted fall-back model, closing that session alone.session/close, awaited.HarnessAdapter, each a no-op default so every other host is asked exactly as before:projection_extras(state): keyword arguments for the mirror'ssession_projection; opencode passesharness_denies_in_force, so a server whose rule is not in force is withheld whole, as onAcpClient. Passed only when the session has host state.harness_mcp_server_names(state): the session's placed servers plus those opencode's config mounts, handed to the permission parser so a fused<server>_<tool>title splits back exactly.defers_shell_permission: the turn loop reads the session's next frame before judging a shell permission whose command is not cached yet (defer_shell_permission, the twin ofOpencodeAcpClient._defer_shell_permission). Frames read ahead go on a local front queue the loop drains first.SpawnContext.agent_envandextra_env, so a pre-spawn read-back resolves the same config files the child will.Backwards compatibility
Compatible: no session is routed to
OpencodeHarness; every other host's plan carries nospawn_envorhost_state, its_mirrored_session_mcpcall gets no new keyword, andhost_defers_shell_permissionis False for it.Reader: src/kiro_crew/acp/runtime_session_setup.py:_mirrored_session_mcp -- gains an optional
projection_extras, passed only for a session with host state -- test_the_runtime_hands_the_projection_the_rules_in_forceReader: src/kiro_crew/acp/harness/base.py:SpawnPlan -- gains
spawn_envandhost_state, both empty by default -- test_the_spawn_hands_its_plan_to_the_child_and_to_every_sessionTests
test/test_opencode_shared_runtime.py(25): the gates run under the child's environment and folder; the seed carries the spawning agent's deny rules and reaches the child through the plan; a failed read-back or an untested major refuses the spawn; a process with no read-back serves no session; each projection is held to the rules in force; a withheld server mounted natively refuses that session; the parser gets placed plus configured server names; an inherited hosted model closes only that session, a pinned or configured model never does; the shell-permission deferral reorders only a same-session, same-call, in-progress command update and returns every other frame; only a deferring host waits; the turn defers before building the permission event; through a realAcpRuntime.create_session, the projection receives the rules in force and a hosted fall-back closes the session and keeps the process. Each fails if its rule is removed.test_acp_harness_contract.py: opencode joinsALL_BACKENDSandREGISTERED_AHEAD_OF_ROUTING, so every per-harness contract test runs on it.test_runtime_bindings.py: the_mirrored_session_mcpsignature digest and the spawn owner's written fields follow the change.test_goose_shared_runtime.py,test_claude_shared_runtime.py,test_session_handle_bindings.py,test_harness_parity.py,test_acp_opencode_backend.py,test_client_bindings.py, and every test file that names_mirrored_session_mcp,SpawnContext(,SpawnPlan(orprepare_session(. mypy oversrc/kiro_crew/is clean.test_security_posture.pyflagsacp/harness/goose.py, and seven dispatch test files (test_transport_permission_floor.py,test_stuck_turn_watchdog.py,test_engine_fallback.py,test_acp_runtime_native_children.py,test_codex_native_subagent_cards.py,test_stale_watchdog_rearm.py,test_tool_call_classification_provenance_bound.py) fail the same way on feat(acp): GooseHarness, goose on the shared runtime with per-session checks (not routed) #37562's heada755c6817dwithout this PR and pass onmainfaac7eaa17: they come from the goose PR's per-session refusal in the turn loop meeting MagicMock runtimes.Proof: not provable -- other: not routed; unit and runtime-level coverage here, a real opencode run in the PR that routes it
Manual verification
N/A -- nothing reaches this path yet. The routing PR runs real opencode on the shared runtime, in a pod, with the switch on and off.
Screenshots / video
N/A -- no UI change.
Related Issues
Part of #5033. Stacked on #37562; moves to
mainonce the goose stack merges.Checklist