Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): stop a second server from resending Claude turns #13295

Mergedcestercian(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/13295/headmerged by t3dotgg(GitHub profile, opens in a new tab) View on GitHub

Fixes #13275

Summary

One user message was starting two Claude provider turns when the desktop backend and the background service share a state directory.

A failed command on the lagging server reconciled by republishing every event since its stale snapshot, including the other server's thread.turn-start-requested. That server's provider reactor has its own turn-start dedupe cache, so it cold-started Claude and called sendTurn again with the same user text under a new turn id (often while the first turn was still running). Extra projection turns land with pending_message_id = NULL because the first turn.started already consumed the pending slot.

Reconcile still projects recovered events onto the local command model. It only republishes events this dispatch itself appended.

Test plan

  • OrchestrationEngine.test.ts — shared-database case: stale thread.meta.update on server B must not republish server A's turn-start
  • Existing "append persists but projection fails" case still passes
  • CI green on this PR

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where a failed update on one server could republish another server’s events and start an unintended duplicate turn. Failed updates now avoid triggering turns from events already handled elsewhere, while successful updates continue to publish their own events.
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

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

      Review profile: CHILL

      Plan: Advanced

      Run ID: bca2c49a-3cfe-4508-bd51-f5f696ddcd3a

      📥 Commits

      Reviewing files that changed from the base of the PR and between f5ef0ddb90a8c36584e181b1913e7b8a5df30ffc and 4e83dc2cb00a31aaa38c10b0d3eef4e941bd0e0a.

      📒 Files selected for processing (2)
      • apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts
      • apps/server/src/orchestration/Layers/OrchestrationEngine.ts

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


      📝 Walkthrough

      Walkthrough

      The orchestration engine tracks event IDs appended during each dispatch and limits failure-path republishing to those events. A test covers a local dispatch failure when two orchestration systems share a database.

      Changes

      Dispatch event reconciliation

      Layer / File(s)Summary
      Track and filter dispatch events
      apps/server/src/orchestration/Layers/OrchestrationEngine.ts, apps/server/src/orchestration/Layers/OrchestrationEngine.test.ts
      The engine records IDs for events appended by the current dispatch and republishes only those events during failure reconciliation. A test checks that events from another server's turn are not published after a local dispatch fails.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 4e83d

      The shared-database regression is covered, and no issue requiring correction before merge was identified.

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly identifies the server bug fix: it prevents a second server from resending Claude turns.
      Description check✅ PassedThe description explains the problem, the cause, the implemented fix, and the test plan. It is focused and provides relevant validation details. The custom Summary and Test plan sections cover the req…
      Linked Issues check✅ PassedIssue [#13275] requires one thread.turn-start-requested event and one provider turn per user message. OrchestrationEngine.ts now records event IDs appended by the current dispatch and republishes …
      Out of Scope Changes check✅ PassedThe changes are limited to failure-path event publication in OrchestrationEngine.ts and a regression test for shared-database reconciliation. Both changes directly support issue [#13275]. No unrelat…
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      Comment `@coderabbitai help` to get the list of available commands.
    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 4e83dc2

      Macroscope's review found this PR approvable — This is a narrowly scoped orchestration bug fix that prevents failed reconciliation from republishing events handled by another server, while preserving local recovery and successful dispatch behavior. A focused shared-database regression test covers the affected path.

      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).
    4. juliusmarminge added labelsmacroscope-review

Sign in to join this conversation.