Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): reconcile orphaned provider sessions #7719

Mergedt3-code-bot[bot](GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/7719/headmerged by maria-rcks View on GitHub

what changed

  • reconcile projected provider sessions that did not survive a server restart before opening the command gate
  • mark orphaned sessions as error, clear stale active turns, and stop persisted runtime bindings without losing resume cursors or runtime payload
  • isolate provider inventory, directory, and per-thread dispatch failures so startup still completes
  • add focused and temporary-sqlite restart regressions for luna's stuck starting state

why

an oom or restart can leave durable orchestration state in starting or running after the provider process is gone. recent null-turn messages then keep settle and snooze blocked, and the stale runtime binding prevents clean recovery.

this repairs that split-brain state immediately on restart while leaving genuinely live provider sessions alone.

fixes #6560

verification

  • vp test run apps/server/src/provider apps/server/src/orchestration apps/server/src/serverRuntimeStartup.test.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts (801 passed, 6 skipped; one unrelated provider-registry timing test passed on focused rerun)
  • vp test run apps/server/src/serverRuntimeStartup.test.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts apps/server/integration/orphanedProviderSessionStartup.integration.test.ts (13 passed)
  • vp run --filter t3 typecheck under node 24.13.1
  • vp lint apps/server/src/serverRuntimeStartup.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts apps/server/integration/orphanedProviderSessionStartup.integration.test.ts
  • vp fmt --check apps/server/src/serverRuntimeStartup.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts apps/server/integration/orphanedProviderSessionStartup.integration.test.ts
  • git diff --check

checklist

  • this pr is small and focused
  • i explained what changed and why

request provenance

  • requested by: @maria-rcks

Note

Medium Risk Touches server startup and durable session/projection state. Failures are isolated so one bad thread should not abort startup, but incorrect orphan detection could mark live sessions as error.

Overview After a restart, projected sessions that are still starting/running (or have a stale activeTurnId) but have no live provider process are repaired before the command gate opens.

reconcileProviderSessions marks those sessions error with a fixed last-error, clears the active turn, and stops directory bindings while keeping resume cursors. Live sessions are left alone. Per-thread directory and dispatch failures are retried once then logged so one bad entity cannot block later repairs or global startup; interruption is still propagated.

This unblocks settle, snooze, and new turns that were stuck after OOM/restart split-brain. Unit and sqlite restart tests cover multi-orphan repair, retry-then-continue, and inventory-read failure.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 757f62f8efd17f2a0f38de1abdaa1cc2ece99450. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add reconcileProviderSessions startup phase to repair orphaned provider sessions after restart

  • Adds a new provider-sessions.reconcile startup phase in serverRuntimeStartup.ts that runs after reactors start. It reads live session IDs from ProviderService.listSessions, compares them against the command read model, and identifies orphaned threads whose provider session is no longer live.
  • For each orphaned thread, it stops the ProviderSessionDirectory binding (setting status to stopped, clearing runtimePayload.activeTurnId while preserving other fields like resumeCursor) and dispatches a thread.session.set command to mark the session as error with activeTurnId set to null.
  • Projection dispatch is retried once on transient failure; persistent failures are logged as warnings and do not abort startup. Interruptions are rethrown. If the provider inventory cannot be read, reconciliation is skipped entirely.
  • Adds unit tests in serverRuntimeStartup.reconcile.test.ts and an integration test in orphanedProviderSessionStartup.integration.test.ts covering retry-success, persistent-failure continuation, and post-reconciliation command behavior.
  • Adds a guideline in effect-service-conventions.md for multi-entity startup reconciliation: preserve interruption, retry transient per-entity failures, and isolate persistent failures.
Macroscope summarized 757f62f.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

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

      Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire13.4 KiB13.4 KiB+27 B (+0.2%)15.1 KiB✅
      CodexThread snapshot wire6.9 KiB6.9 KiB+10 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.5 KiB6.6 KiB+17 B (+0.3%)7.8 KiB✅
      CodexLive turn WebSocket decoded55.0 KiB55.0 KiB0 B (0.0%)66.4 KiB✅
      CodexLive turn messages16160 (0.0%)21✅
      ClaudeTotal thread wire13.5 KiB13.5 KiB−8 B (−0.1%)15.1 KiB✅
      ClaudeThread snapshot wire6.9 KiB6.9 KiB−1 B (−0.0%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.6 KiB6.6 KiB−7 B (−0.1%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded55.8 KiB55.8 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages16160 (0.0%)21✅

      Baseline: 21e80a0 · PR result: 757f62f · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 109.4 KiB
      • Claude decoded thread snapshot: 110.1 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

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

      Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — This PR modifies a .macroscope/ configuration file, which controls Macroscope review behavior and requires human review. Additionally, the production changes add new server startup reconciliation logic that modifies runtime behavior for orphaned provider sessions.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. maria-rcks merged this0929907

    5. maria-rcks closed this

Sign in to join this conversation.