Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(server): restarts no longer replay PR discovery for every old thread #13757

Closedt3dotgg(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromt3code/pr-backfill-recentopened View on GitHub

Every server restart ran pull request discovery again for every settled branch thread with no saved PR. A "no PR" result is not saved, so each boot repeated the full pass: several git spawns and a gh call per thread, and up to 5 lookups per thread when gh fails. On a 5,000-thread scale bench with gh missing, that was about 3,850 git spawns/min for about 5 minutes after each boot.

Fix

The startup backfill from #10101 now only covers threads settled in the last 7 days (BACKFILL_WINDOW).

The check uses settledAt, not updatedAt. Auto-settle sets settledAt to the last activity, but sets updatedAt to the settle time. With updatedAt, one mass auto-settle would put every old thread back in the window for a week of restarts.

Decision: 7-day window or delete the backfill

The backfill was a one-time migration for threads from before #10101 (merged 2026-09-06, shipped in v0.0.39). Since v0.0.39, the 1-minute pass checks every unsettled branch thread, so each thread is checked until it settles. The backfill only matters for a settled thread with no saved PR.

WhoToday7-day window (this PR)Delete
Users upgrading from 0.0.38 or olderAll settled threads get a lookupOnly threads settled in the last 7 daysNo settled thread gets a lookup
Users who fix gh later, or open a PR outside T3 Code after the thread settledAll settled threads found on next restartOnly threads settled in the last 7 daysNot found
Cost on every restartAll settled threads with no PRThreads settled in the last 7 days with no PRNone

In both lost cases, unsettling the thread runs discovery again. Deleting also removes the retry state in the reactor (about 50 lines) and 2 of its tests.

I kept the window because it is the smaller behavior change. Deleting it is an easy follow-up if we prefer that.

Verification

  • vp test run apps/server/src/orchestration/ThreadPullRequestReactor.test.ts: 16 passed, including the unsettled-vs-full-read parity test from #13765.
  • The new test seeds a recent settled thread, an old one, and an auto-settled one (old settledAt, recent updatedAt). Only the recent one gets a sync. Keying the check on updatedAt makes it fail.
  • vp lint and vp fmt on the changed files, and vp run --filter t3 typecheck.
  • I did not re-run the scale bench on this build.

Made by Claude Opus 5.5 (1M context) in Claude Code, running in T3 Code.

🤖 Generated with Claude Code

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

    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 startup behavior by suppressing pull-request discovery for older settled threads, rather than merely optimizing an unchanged path. Although the implementation is small and tested, the cutoff can affect whether significant Git/GitHub processing and PR links are created after restarts.

      No code changes detected at d1273a3. Prior analysis still applies.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. 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.5 KiB13.5 KiB+15 B (+0.1%)15.1 KiB✅
      CodexThread snapshot wire7.1 KiB7.1 KiB+4 B (+0.1%)7.3 KiB✅
      CodexLive turn WebSocket wire6.4 KiB6.5 KiB+11 B (+0.2%)7.8 KiB✅
      CodexLive turn WebSocket decoded56.2 KiB56.3 KiB+44 B (+0.1%)66.4 KiB✅
      CodexLive turn messages910+1 (+11.1%)21✅
      ClaudeTotal thread wire13.5 KiB13.5 KiB+4 B (+0.0%)15.1 KiB✅
      ClaudeThread snapshot wire7.1 KiB7.1 KiB−9 B (−0.1%)7.3 KiB✅
      ClaudeLive turn WebSocket wire6.4 KiB6.5 KiB+13 B (+0.2%)7.8 KiB✅
      ClaudeLive turn WebSocket decoded57.0 KiB57.0 KiB0 B (0.0%)66.4 KiB✅
      ClaudeLive turn messages990 (0.0%)21✅

      Baseline: 8872666 · PR result: d1273a3 · 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: 114.0 KiB
      • Claude decoded thread snapshot: 114.7 KiB

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

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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: Team

      Run ID: c330807d-ce27-4e63-9ffc-46f8a962bcec

      📥 Commits

      Reviewing files that changed from the base of the PR and between 80bd4c88930f55855ae9d1aff1706e961492ceca and d1273a3fee172007a4a01b5aa406dffbc4414df7.

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

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


      📝 Walkthrough

      Walkthrough

      Startup backfill now queues settled threads without a branch pull request only when their settlement timestamp is within the previous seven days. If settledAt is absent, the filter uses updatedAt. A test checks the cutoff and timestamp behavior.

      Changes

      Startup backfill

      Layer / File(s)Summary
      Filter startup backfill by settlement time
      apps/server/src/orchestration/ThreadPullRequestReactor.ts, apps/server/src/orchestration/ThreadPullRequestReactor.test.ts
      The reactor applies a seven-day cutoff using settledAt, or updatedAt when settledAt is absent. The test checks which threads are synchronized.

      Priority: ➖ Normal

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

      Change: Bug fix

      Suggested reviewers: juliusmarminge

      Merge Risk: ⚪ Minimal · up to d1273

      The seven-day startup backfill limit has no identified issue requiring a fix before merge.

      🚥 Pre-merge checks | ✅ 5
      ✅ Passed checks (5 passed)
      Check nameStatusExplanation
      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…
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly and concisely describes the main change: preventing repeated pull-request discovery for old threads after restarts.
      Description check✅ PassedThe description explains the problem, the seven-day settledAt-based fix, the rationale, trade-offs, and verification results. It does not use the template headings or include the checklist, but it is …
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR

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

    6. juliusmarminge assignedjuliusmarminge

    7. Taking over this one. The reactor has moved to the v2 service; I’ll port the seven-day settlement cutoff onto current main as one focused replacement, preserve author credit, and link it here before closing this PR.

    8. Thanks @t3dotgg — the original correctly identified repeated startup lookups for old settled threads and the need to prefer settledAt over updatedAt after auto-settle.

      Rebuilt this as the single-layer replacement #21620, because the v1 ThreadPullRequestReactor was removed and discovery now lives in the v2 ThreadPullRequestService. I compared the full original diff against the replacement: the inclusive seven-day window, settledAt preference, updatedAt fallback, and regression all landed there. The obsolete reactor path and string parsing were replaced with the v2 DateTime values; the constant stays private. The original's deliberate recovery tradeoff remains documented.

      The replacement credits you in its body and commit co-author trailer. One rewritten service regression is red on main and green after the port; 52 focused tests, server typecheck, lint/format pass, and both independent whole-PR reviews found no blockers. Before/after service proof is linked in its body. CI follow-up continues on the replacement; it remains unmerged. Closing this obsolete version in favor of #21620.

    9. juliusmarminge closed this

Sign in to join this conversation.