Skip to content

fix(orchestration-v2): hold provider session ownership until cleanup finishes - #11492

Open
saphid wants to merge 10000 commits into
pingdotgg:t3code/codex-turn-mappingfrom
saphid:work/ov2-20260913-01
Open

saphid wants to merge 10000 commits into
pingdotgg:t3code/codex-turn-mappingfrom
saphid:work/ov2-20260913-01

Conversation

@saphid

@saphid saphid commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Ports #9806 onto t3code/codex-turn-mapping.

A V2 provider session removed its session-map entry before scope cleanup finished, so a replacement open could start a new process while the old one still owned credentials and resources — and a hung cleanup silently unblocked reuse.

  • Releasing sessions keep a pending-release record until cleanup actually completes; replacement opens and runtime thread attachments (ensureThread/resumeThread/forkThread/startTurn) for its recorded threads are blocked.
  • Repeated close/detach/closeInstance calls join the same cleanup Deferred rather than racing it; a detach that loses its session to a concurrent close joins the pending cleanup instead of reporting success over still-running work.
  • Shared MCP credentials are revoked only when no live session, reservation, or pending release still holds them.
  • The 30s wait reports an honest error projection state without claiming the process stopped; successful cleanup clears the block, failed cleanup keeps blocking until restart.
  • Layer shutdown still only joins live sessions, so a hung pending finalizer cannot stall teardown.

Post-review hardening vs. #9806: the runtime attachment gate runs outside observeActivity (which swallows bookkeeping failures) and outside startTurn's busy/idle catch (a rejected attach must not decrement the peer's busy count).

Test plan

  • vp test run src/orchestration-v2/ProviderSessionManager.test.ts — 53/53 (timeout, replacement blocking after close/detach/closeInstance, retry-joins, late success, cleanup-failure persistence, shared peer credentials, attach-vs-close race, detach-mid-close race, runtime attachment gate, busy-peer guard)
  • Adjacent orchestration-v2 suites — 171/171
  • vp lint / vp fmt / package typecheck clean on changed files
  • Defect reproduced against unmodified base (3 replacement-blocking tests fail without the fix)
  • 5 rounds of independent cross-provider review; no remaining blocking findings

SWE-2 (Devin) via T3 Code / Cursor harness.
Coordination trace: T3 thread 063442b9-45e8-4f0e-bc47-edea523ce7d0; campaign saphid/t3code-personal#298; original implementation #9806.

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

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants