Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): recover runless native child provider turns #14434

Closedkiiwee(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/14434/headopened View on GitHub

Native subagent child turns have no run attempt. Bounded runtime recovery omitted them, leaving their persisted provider turns running after their process disappeared.

Include nonterminal provider turns attached to runless roots in the recovery projection and cancel them during reconciliation. Extend the persistence regression to verify the live child turn settles without rewriting completed history.

Validation: the focused FoundationPersistence.test.ts suite passes all 39 tests; changed-file lint, type-aware/type-check lint, formatting, and git diff --check pass. The original regression was confirmed failing before the source fix. A persisted waiting-root case also fails if waiting is removed from the node filter, and passes with the production query unchanged.

Targets the Orchestrator V2 branch, not main.

Production implementation: Grok 4.6 Build via Grok CLI. Follow-up waiting-root regression and scoped verification: GPT-6.1 Sol (xhigh) via Codex. Independent review: Claude Opus 5.5 (high) via Claude Code (claude -c).

    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

      🟠 High orchestration-v2/ProjectionStore.ts:3943

      Runless-root provider turns in starting or waiting state are loaded for recovery but never reconciled to a terminal state, so a process loss leaves them stuck indefinitely. The outer status predicate admits both states through this branch; restrict the runless-root branch to pending and running, or extend reconciliation to cancel every state it admits.

      -                       AND status IN ('pending', 'running', 'waiting')
      +                       AND status IN ('pending', 'running')
      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/orchestration-v2/ProjectionStore.ts around line 3943:
      
      Runless-root provider turns in `starting` or `waiting` state are loaded for recovery but never reconciled to a terminal state, so a process loss leaves them stuck indefinitely. The outer status predicate admits both states through this branch; restrict the runless-root branch to `pending` and `running`, or extend reconciliation to cancel every state it admits.
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Would Approve

      Macroscope's review found this PR approvable — This is a narrowly scoped orchestration recovery bug fix with targeted production changes and regression coverage for running and waiting runless child roots, while preserving completed turns. Separate unresolved Medium/High findings identify material issues in other server paths and remain important risks for the overall change set.

      Not approved because:

      • 7 blocking correctness issues found at or above your repo's Minimum Blocking Severity
      Adjust the Minimum Blocking Severity for this repo — including turning it Off — in [Settings](https://app.macroscope.com/pingdotgg/settings#Repos). You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. This appears to be a false positive caused by mixing provider-turn states with run/node states.

      The pinned OrchestrationV2ProviderTurn contract admits only pending and running as nonterminal provider-turn states. starting and waiting are not valid provider-turn states, and the new reconciliation cancels both valid states. The broader outer SQL literals predate this PR and do not create additional valid provider-turn states.

      The suggested change at ProjectionStore.ts:3943 instead removes waiting from the root-node predicate. waiting is a valid nonterminal node state, handled by the existing root-node recovery loop, so excluding it would skip waiting native-child roots and introduce a regression.

      Please re-evaluate this finding against the provider-turn contract and retain the node waiting case. No source change is warranted for this finding.

    5. Sorry, I'm unable to act on this request because you do not have permissions within this repository.

    6. juliusmarminge added labelsmacroscope-review

    7. juliusmarminge closed this

    8. juliusmarminge added labelstriage:keep-open

    9. juliusmarminge reopened this

    10. @@ -0,0 +287,21 @@
      287+ ).pipe(Effect.ignoreCause({ log: true }));
      288+
      289+ const recheckAndBind = Effect.gen(function* () {
      290+ // The projection was read before the potentially slow git work
      291+ // above; a concurrent binding (for example from the UI) could have
      292+ // attached the thread in the meantime. Re-check before committing so
      293+ // the race cannot leave a second, untracked worktree.
      294+ const recheck = yield* loadThread(scope);
      295+ if (recheck.thread.worktreePath !== null) {
      296+ return yield* alreadyInWorktree(recheck.thread.worktreePath);
      297+ }
      298+ // Mirror the up-front archived check: the thread may have been
      299+ // archived during the slow git work, and an archived thread must
      300+ // not be bound to a fresh worktree it can never use.
      301+ if (recheck.thread.archivedAt !== null) {
      302+ return yield* failure(
      303+ "invalid_request",
      304+ `Thread '${scope.threadId}' was archived while the worktree was being created; the handoff was rolled back.`,
      305+ );
      306+ }
      307+ yield* threadManagement
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium mcp/WorktreeMcpService.ts:307

      An archive committed after loadThread returns can still be followed by thread.metadata.update, so this handoff binds a newly created worktree to an archived thread and reports success even though the queued continuation cannot run; the worktree and branch are then left attached. Make the archive check part of the atomic metadata update precondition (or otherwise reject the binding when archiving races it).

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/mcp/WorktreeMcpService.ts around line 307:
      
      An archive committed after `loadThread` returns can still be followed by `thread.metadata.update`, so this handoff binds a newly created worktree to an archived thread and reports success even though the queued continuation cannot run; the worktree and branch are then left attached. Make the archive check part of the atomic metadata update precondition (or otherwise reject the binding when archiving races it).
      @@ -0,0 +32,21 @@
      32+ success: Project,
      33+ failure: OrchestratorMcpFailure,
      34+ failureMode: "return" as const,
      35+ dependencies: [McpInvocationContext, ThreadManagementService, ProjectService, Crypto.Crypto],
      36+};
      37+const ProjectListTool = Tool.make("t3_project_list", {
      38+ ...shared,
      39+ description:
      40+ "List registered projects in this environment. Pages use the current project snapshot and may shift between calls.",
      41+ parameters: Schema.Struct({
      42+ cursor: Schema.optional(NonNegativeInt),
      43+ limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),
      44+ }),
      45+ success: Schema.Struct({
      46+ projects: Schema.Array(Project),
      47+ nextCursor: Schema.NullOr(NonNegativeInt),
      48+ }),
      49+})
      50+ .annotate(Tool.Readonly, true)
      51+ .annotate(Tool.Destructive, false);
      52+const ProjectReadTool = Tool.make("t3_project_read", {
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟠 High project/tools.ts:52

      t3_project_read lets a normal MCP credential read the full configuration of any registered project, including workspaceRoot, repository identity, and saved scripts. Its handler accepts the caller-supplied projectId without enforcing caller.projectId, so an agent can list IDs with t3_project_list and then access other projects; restrict reads to the caller's project or require full-access authorization.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/mcp/toolkits/project/tools.ts around line 52:
      
      ` t3_project_read` lets a normal MCP credential read the full configuration of any registered project, including `workspaceRoot`, repository identity, and saved scripts. Its handler accepts the caller-supplied `projectId` without enforcing `caller.projectId`, so an agent can list IDs with `t3_project_list` and then access other projects; restrict reads to the caller's project or require full-access authorization.
    11. Warning

      Review limit reached

      Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.

      Next included review available in 41 minutes.

      Check out review usage here.

      View limit details

      Limit details: You’ve used all 10 included reviews currently available.

      Learn how review limits work.

      Review configuration:

      ⚙️ Run configuration

      Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 8a80e81f-e73e-4923-a89f-ed402fda5940

      📥 Commits

      Reviewing files that changed from the base of the PR and between cc1e634bfa62edd56ff792eea666e436fdef788f and d2de5c6678b0d1be3a2fd00211e9ee02ae1e7efc.

      📒 Files selected for processing (3)
      • apps/server/src/orchestration-v2/FoundationPersistence.test.ts
      • apps/server/src/orchestration-v2/ProjectionStore.ts
      • apps/server/src/orchestration-v2/ProviderRuntimeRecoveryService.ts
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Autopilot is currently an internal CodeRabbit preview.


      Comment `@coderabbitai help` to get the list of available commands.
    12. Note

      Written by claude-opus-5-5 on behalf of Maria

      Hi! We are cleaning up open PRs, and this one appears to have been created with an older model (grok 4.6). If this change is really important, we recommend rebuilding the PR with a newer model if possible.

    13. maria-rcks closed this

Sign in to join this conversation.