Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): PR wakeups follow provider handoffs #17828

Closedvoltcrash(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/17828/headopened View on GitHub

Problem

An older PR-watch wake queued during a Codex turn could undo a later provider handoff. After the replacement provider finished, promoting the wake restored Codex as the thread's provider; subsequent PR updates then hit the same usage limit. Fresh watch updates could also start more turns while that provider was already limited.

Reproduction: start a turn with a PR watch active, queue a watch update during it, hit the provider's usage limit, then send a takeover prompt using another provider. Before this fix, the old update runs on the original provider and switches the thread back.

Change

Queued monitor updates resolve the thread's current model, options, and provider conversation when they start. The run, attempt, execution node, and checkpoint references are rebound together. Queued user prompts keep their explicitly selected model.

Fresh monitor updates stay queued while their selected provider is blocked by a usage limit. The saved updates can run after a successful retry or a provider change. This fixes the shared server path used by web, desktop, mobile, and MCP without client, contract, or provider-adapter changes.

Scope and approval

This is a focused correction to existing PR-watch delivery: a background update must not override an explicit provider handoff. The quota guard keeps those same updates from repeatedly retrying a provider that cannot run. It introduces no new feature, setting, or product default and qualifies for the obvious-bug exception in CONTRIBUTING.md. The reported thread's durable events confirmed the unexpected switch, and the new regression tests reproduce it on the original implementation.

Verification

  • New regressions against the original implementation: four failures, covering stale model/provider selection, immediate retries after a usage limit, and the cross-provider switch back. The queued-user-prompt control passed.
  • vp test run apps/server/src/orchestration-v2/runtimeLayer.test.ts apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts: all 146 tests pass, including provider/model changes, preservation of queued user selections, quota recovery by retry or provider switch, and actual delivery of a stale PR wake to the takeover provider.
  • Targeted lint and formatting checks, server typecheck, and git diff --check pass. Lint reports the existing unused layerUnavailable warning.
  • Backend tests use isolated state, persisted-event milestones, and effect-worker draining. No browser or live-install writes were needed.

Model: GPT-6.1-Sol. Harness: Codex in T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR changes production orchestration behavior across provider selection, durable execution references, and usage-limit queueing for background PR wakes. Its focused tests are valuable, but the stateful handoff and autonomous queue-gating changes are substantial enough to require human review.

      Notes:

      • Diff unchanged. Approvability was decided on eligibility alone.
      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: d6531092-ea9e-4ea6-af85-3fd00adf9547

      📥 Commits

      Reviewing files that changed from the base of the PR and between 98beed1a226c42b85c52ff5ee9d5dbb67d776a77 and d6024d2c8fd895f0d47f83da467df5b88ddd9511.


      📒 Files selected for processing (3)
      • apps/server/src/orchestration-v2/Orchestrator.ts
      • apps/server/src/orchestration-v2/runtimeLayer.test.ts
      • apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts

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



      📝 Walkthrough

      Walkthrough

      Queued monitor notifications can be queued during usage limits and started using the thread’s current provider selection. Startup updates the associated provider thread, checkpoint scope, root node, and run attempt. Other queued messages retain their stored selection.

      Changes

      Queued monitor provider selection

      Layer / File(s)Summary
      Queue notifications during usage limits
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/runtimeLayer.test.ts
      Monitor notifications can be queued when the selected provider has a usage-limited run, even if no run is active. Tests cover queued updates waiting for recovery and starting one at a time.
      Select the provider for queued startup
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/testkit/ProviderSwitch.integration.test.ts
      Queued monitor notifications use the thread’s current selection. Startup reuses a matching provider thread or creates a pending one. Other queued messages retain their stored selection. The integration test covers a queued PR-watch wake during provider takeover.
      Synchronize run and checkpoint records
      apps/server/src/orchestration-v2/Orchestrator.ts, apps/server/src/orchestration-v2/runtimeLayer.test.ts
      Startup updates checkpoint scopes, root nodes, and attempts when their provider-thread references do not match the selected provider. Tests check record consistency after model-selection changes.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~25 minutes

      Change: Bug fix

      Suggested reviewers: juliusmarminge


      Merge Risk: ⚪ Minimal · up to d6024

      The change makes queued PR-watch wakeups follow the current provider after a handoff and keeps them queued during usage limits. No actionable merge-blocking risk was found.

      Architecture Summary

      Architecture risk: 🟡 Medium · up to d6024

      The change affects 1 system.

      Changed systems: apps/server

      Architecture concerns No architecture-level concerns identified.

      Review details

      Systems and components

      • observed — apps/server (service) was modified; 3 changed files map to changed impact.

      Before / after behavior

      • observed — Modified behavior in apps/server/src/orchestration-v2/Orchestrator.ts: Queued-run startup now loads the queued message and uses the thread’s current model selection for monitor notifications; other messages continue using the run’s stored selection.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Orchestrator.ts: The usage-limit guard now blocks startup only when the blocked run’s provider matches the selected model’s instance, instead of blocking for any provider’s limit.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Orchestrator.ts: A prior provider failure now holds queued runs only when its provider matches the selected model’s instance; previously the comparison used the queued run’s provider.
      • observed — Modified behavior in apps/server/src/orchestration-v2/Orchestrator.ts: Startup reads execution identity and the legacy queued turn item from storedQueuedRun, and finds the queued provider thread as storedProviderThread. This replaces reading those values from the formerly selected queued run before provider reassignment.

      Reliability and maintainability

      • inferred — Risk-relevant change factors for apps/server: blast_radius_1; direct_dependents_1

      Pre-merge checks | Passed 4
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main change: PR wakeups now follow provider handoffs.
      Description checkPassedThe description includes all required sections. It clearly explains the problem, change, scope exception, approval rationale, focused verification, observed results, and limitations. It also identifie…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.

      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge added labelsmacroscope-review

    5. Note

      Written by gpt-6.1-sol on behalf of Maria

      Thanks for documenting the stale-provider wakeup. The defect still exists on main, but this 623-line submission exceeds what we can take over from an unvouched contributor. Right now we are only taking focused bug fixes from outside contributors, within the review capacity described in Read this first. Please preserve the reproduction in a bug issue and submit a smaller focused fix with its regression evidence for reconsideration.

    6. maria-rcks closed this

Sign in to join this conversation.