fix(server): a Pi permission granted in one thread no longer approves the next #15760
main fromrefs/pull/15760/head·opened View on GitHubProblem#
PiAdapterV2 kept an in-memory sessionApprovals set so a repeat "trust this project?"
confirmation could be auto-answered with acceptForSession. It was keyed on dialog title plus
message, and -- the defect -- it was never deleted. The session-switch and rollback paths
cleared every neighbouring field but not this one.
The user-visible effect is an authorization failure: a permission granted in one app thread silently auto-approves the same confirmation in a later thread on the same process. A user who trusted project A once would find project B's identical prompt auto-approved without ever being asked.
This was the only authorization-shaped defect in a static audit of the merged orchestrator-v2 work (#2829).
Alongside it, several adapters kept per-session state that outlived or escaped the session that owned it, and one correctness bug let a queued steer survive into an unrelated turn.
Change#
Split by adapter so each concern reviews on its own.
PiAdapterV2-- the authorization fix.sessionApprovalsis cleared on every session-changing boundary (registerThreadbefore the lifecycle request,rollbackThreadbefore the fork), and the key is now everyconfirmpayload field exceptid, canonically ordered. The old key was a strict subset of the new one's equality relation, so the new key can only ever ask more, never auto-approve more. A final commit adds a precautionary check: at turn finalize the session file Pi reports is compared against the one the thread is bound to, and approvals are cleared when they differ or when the state cannot be read -- an unknown identity is not trusted. That matters because the adapter forwards a leading/so Pi's own slash commands keep expanding; a/newor/resumeinside Pi would change the native session with no adapter command and no event to observe. Pi is an external CLI, so its command set cannot be read from this repo -- treat that commit as defense in depth.OpenCode2AdapterV2-- a stranded steer no longer replays into an unrelated turn. The unload guard omittedstrandedSteers, and a reattached thread rebuilt state with an empty set, so a steer queued before unload was injected into a later unrelated turn.hasPendingBackgroundWorknow accounts for stranded/reverting/clearing state, which is the root cause -- cheaper and more robust than a timer.CodexAdapterV2-- per-turn scoping.planDeltasmoves onto the active turn context; the old session-wide map bled a previous turn's plan text into the next turn's.turnTokenUsagestops recreating released entries.- State reclamation.
OpenCodeAdapterV2gainsunloadThreadandsession.deletednow clears its thread state (and cancels active turns -- otherwise a turn hangs on a dead session).OpenCode2AdapterV2dropssessionGates,stagedReverts,clearingandannouncedon unload. Claude releaseswakeBuffersand wake reports on native-process transitions. The write-onlystate.messagesmap is deleted.
Not changed: Claude's wakeBuffers is released but still unbounded per native thread --
openQuery closes superseded siblings so the count tracks live processes, but there is no hard
cap. The commit body says so rather than implying the audit item is closed. The two adapters'
ownership helpers are deliberately not unified: different state models, one shared helper
would be worse.
Scope and approval#
Follow-up work from a static audit of the merged orchestrator-v2 work (#2829). The Pi item is a real authorization defect and stands on its own; the rest are the correctness and reclamation defects from the same subsystem that share the same invariant - per-session state is released with the session that owns it.
No issue exists for the authorization defect: searches for cross-thread approval leaks, reused "trust this project" confirmations, and Pi-specific approval handling return nothing. The closest open reports (#15082, #14878, #15503, #15353) are all Claude or OpenCode scoped and concern mode semantics or elicitation, not a memoized confirm key surviving a session boundary.
Maintainer decision this touches. #15308 explicitly reserves it: "preserving old native
approvals after interrupt and thread unload remains a maintainer lifecycle decision." This branch
decides that question for Pi, at the adapter layer. The decision it makes is that an approval
memoized for one native session does not survive a change of that session - which keeps the
existing behaviour and closes the cross-thread leak, rather than newly preserving approvals across
sessions. If the intent is the opposite, the clear sites are registerThread, rollbackThread,
and turn finalize, and they can be narrowed.
Relationship to adjacent work. #13331 item 4 / #14187 established unloadThread for Codex;
this extends that existing reviewed interface to a second adapter with a different trigger
(session.deleted), it does not re-propose it. #15571 addresses the same invariant across
the same four adapters but for a different trigger - an interrupt during session open, versus a
session boundary here. They are adjacent and may be worth sequencing.
Verification#
pnpm exec vp test runon the five adapter suites -- 458/459 pass.- The Pi table
does not reuse session approvals after %sruns 8 boundaries (new thread, switch, rollback, empty rollback, fork, prompt metadata, pending switch, pending rollback). The load-bearing assertion is on the outbound wire (assert.isFalse(fake.allRequests() .some(r => r["id"] === "ask-again"))), not on adapter internals. Pre-fix, the second emit was auto-confirmed. CodexAdapterV2.test.tsassert.deepEqual(plans, ["OLD", "NEW", "NEW"])-- the old session-wide map yields"OLDNEW". Theclosedarm'sturnTokenUsage?.inputTokens === 5(vs20) fails while released state is recreated.OpenCode2AdapterV2.test.tsdrives a strict request transcript including...noOpenRequests, so a straysession.inbox.cancelon the reattached turn fails the test. The unload arm supplies the same guard and asserts a retry actually releases the failed cancellation -- it previously could only pass becauseunloadThreadearly-returned and did nothing.pnpm exec vp linton the changed files -- exit 0, five pre-existinglayerunused warnings, none on changed lines.pnpm --filter t3 typecheck-- exit 0.
Not verified: no real-client pass -- no live Pi/Codex/OpenCode binary was exercised, and the changes alter live paths (approval memoization, per-turn plan text, session release). The slash-command mitigation in the last commit is precautionary and unverifiable from this repo.
Pre-existing failure not caused by this change: ClaudeAdapterV2.test.ts:2533 asserts a
failure message contains /synthetic/project, which on Windows is C:\synthetic\project.
Introduced by de34391427 (the #2829 base); this branch leaves the assertion untouched.
Implemented with gpt-6.1-sol through the Codex harness (initial implementation) and opencode/space-bunny-free through the OpenCode harness (audit fixes and new coverage).
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge closed this
Sign in to join this conversation.
Note
This comment is posted by Julius' dot
The Pi approval leak is worth fixing, but this also repairs Codex plan text leaking between turns, OpenCode stranded steers, and separate adapter state cleanup. Those fixes can ship independently of the Pi change, so this violates one problem per PR. Please split them into focused PRs, keeping the approval-boundary tests with the Pi fix.