Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): Pi extension wakes get an owned continuation turn #17214

MergedStiensWout(GitHub profile, opens in a new tab)merged 5 commits intomain fromrefs/pull/17214/headmerged by Yash-Singh1(GitHub profile, opens in a new tab) View on GitHub

Pi extensions can start work after a turn settles, but T3 kills that work as an unowned run. Registered threads now buffer the wake and request an orchestration continuation, which adopts its events without sending a duplicate prompt.

User prompts can claim an outstanding wake. Model-change dialogs stay answerable while adoption is pending, and stale or stopped wakes are retired. A joining prompt that Pi rejects fails its turn only after the native work settles. Rollback refuses to run over a held wake, and stops one that starts during its fork, so output from a discarded session is never replayed.

Fixes #15589.

Validation: focused Pi adapter tests (66 passing), server typecheck, and scoped lint. Silent background jobs remain subject to the existing idle reaper until they emit a wake. If a committed continuation never starts, Pi keeps running with its output buffered until that reaper or a Stop.

Prepared for Wout by claude-opus-5-5 and gpt-6.1-sol in T3 Code via Claude Code and Codex.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR changes the live Pi orchestration lifecycle so provider-native work can continue after a turn, be adopted by user prompts, and participate in rollback and shutdown coordination. The production adapter changes involve substantial concurrency and ownership behavior, so they require human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 943b71a2-f6ef-430b-bbd7-d94fc9373709
      📥 Commits

      Reviewing files that changed from the base of the PR and between 12069eefd707f78eafc27812027c994eea0613cf and 534ae519300f9203471ff3a5c19b449226f1a92f.

      📒 Files selected for processing (2)
      • apps/server/src/orchestration-v2/Adapters/PiAdapterV2.test.ts
      • apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


      📝 Walkthrough

      Walkthrough

      The Pi adapter now routes eligible provider-native work through continuation requests. Turns can adopt buffered wakes, while thread ownership, wake retirement, and rollback are coordinated with pending native events.

      Changes

      Pi native wake handling

      Layer / File(s)Summary
      Route Pi-native work to continuation requests
      apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/PiAdapterV2.test.ts
      The adapter buffers eligible native events and offers continuation requests for attached app threads. The test helpers can inject continuation requests and create continuation messages.
      Adopt wakes into turns
      apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/PiAdapterV2.test.ts
      Turns distinguish provider continuations from user prompts. User turns can adopt pending wakes, use steer behavior, and wait for prompt acknowledgement before settlement. Tests cover rejected prompts, model-selection dialogs, and wake adoption.
      Enforce wake ownership and retirement
      apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/PiAdapterV2.test.ts
      The adapter restricts pending wakes to their thread and retires them on interruption, restart, transport failure, archive, or stop. Tests check wake clearing and cancellation.
      Serialize rollback with native work
      apps/server/src/orchestration-v2/Adapters/PiAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/PiAdapterV2.test.ts
      Rollback is blocked during conflicting native work. A barrier drains earlier native events before thread and conversation-head references are updated. Tests cover rollback with and without a pending wake.

      Priority: ➖ Normal

      Estimated code review effort: 4 (Complex) | ~60 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Sequence Diagram(s)

      sequenceDiagram
        participant Pi
        participant PiAdapterV2
        participant ProviderContinuationRequests
        Pi->>PiAdapterV2: Start native work without an active turn
        PiAdapterV2->>ProviderContinuationRequests: Offer continuation request
        ProviderContinuationRequests->>PiAdapterV2: Dispatch continuation
        PiAdapterV2->>PiAdapterV2: Attach turn and replay buffered events

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to 534ae

      Pi background wakes are now buffered and handed to a continuation turn instead of killing the session. Rollback and thread switches are coordinated with that pending work. No concrete defect remains. The two concerns raised about deadlocks and service wiring were checked against the source and did not hold.

      Security Architecture Review

      Security architecture risk: 🟡 Moderate · up to 534ae

      Background work can now continue while its output waits for an owning turn. Ownership and rollback checks constrain the handoff, but a stalled handoff can retain unlimited output and threaten server availability.

      Retained concerns

      • Medium · reliability · inferred: A pending wake retains native output without an aggregate byte or event limit while the provider continues running. If continuation startup stalls, accumulated output can exhaust server memory and affect unrelated sessions sharing that process. The base terminated this out-of-turn execution. Stop, archive cleanup, transport teardown, and idle expiration constrain lifetime, but do not bound memory before retirement.
      Security review details

      Security Blast Radius

      • inferred — The new execution route is scoped to an already registered Pi session and app thread, rather than a new unauthenticated network entrypoint. Resource exhaustion could extend beyond that thread to other sessions in the same server process; tenant and deployment isolation were not established.

      Security Findings and Attack Paths

      • inferred — The supported risk path is native activity followed by delayed or failed continuation startup and sustained event retention, potentially causing memory pressure or server failure. This is an availability and failure-containment concern; unauthenticated reachability, cross-thread privilege escalation, and a concrete attacker exploit were not established.

      Trust Boundaries and Controls

      • observed — Production startup derives execution identities from thread-scoped projections, opens the corresponding session, and ensures or resumes the native thread before delivery. Session opening rejects a second app thread for single-thread providers. These controls counter the hypothetical wrong-thread call reaching configuration changes before final wake validation.

      Resilience and Maintainability Implications

      • observed — Current-wake retirement cancels pending dialogs and terminates native execution. Archived or deleted threads clear their offer; Stop handles a pending wake without an active turn. Session teardown and transport failure also retire pending ownership, limiting stale execution and replay.

      Hardening Proposals

      • proposed — Introduce an aggregate retained-output budget and an adoption deadline, with explicit terminal cleanup when either is exceeded. This would bound the stalled-handoff failure mode independently of ordinary idle expiration.
      🚥 Pre-merge checks | ✅ 4
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly identifies the server-side fix for Pi extension wakes and owned continuation turns.
      Description check✅ PassedThe description explains the problem, implementation, behavioral scope, linked issue, verification results, and known limitations. It does not include the template headings or explicit maintainer appr…
      Linked Issues check✅ PassedIssue #15589 requires Pi-native wake work to avoid session termination and to deliver the completion notice through a normal run or an equivalent safe path. The PR summary reports that Pi buffers nati…
      Out of Scope Changes check✅ PassedThe reported source changes and tests stay within Issue #15589. Wake buffering, continuation adoption, prompt arbitration, wake retirement, rollback ownership, and related tests support safe delivery …
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    4. Thanks for fixing this. Hope can make it to nightly soon

    5. Yash-Singh1(GitHub profile, opens in a new tab) approved these changes

Sign in to join this conversation.