perf(server): per-thread settlement and PR checks no longer rebuild the whole thread list - #13691
Conversation
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: Scenario and decoded snapshot size10 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.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
|
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 configurationConfiguration used: Repository: pingdotgg/t3code/.coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughSingle-thread sweeps in the pull-request and settlement reactors now read thread-scoped snapshots. Full sweeps continue to read full snapshots. The tests track thread-specific reads and verify requests for the expected thread, including a missing-thread backfill case. ChangesThread-scoped reactor snapshots
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Reactor as ThreadPullRequestReactor
participant SnapshotReader as readSweepSnapshot
participant Query as ProjectionSnapshotQuery
Reactor->>SnapshotReader: Request snapshot for threadId
SnapshotReader->>Query: Read snapshot sequence
SnapshotReader->>Query: Look up thread by ID
SnapshotReader->>Query: Load related project shells
SnapshotReader-->>Reactor: Return targeted snapshot
Suggested reviewers: Merge Risk: ⚪ Minimal · up to No actionable merge-blocking risk is identified; merge after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — This is a contained server performance refactor that preserves full-sweep behavior and narrows only already thread-scoped reads, with parity and reactor tests covering the changed paths. It introduces no schema, deployment, security, billing, authentication, product-default, or static-analysis-suppression changes. Notes:
You can add or adjust custom eligibility rules. Learn more. |
ef53ace to
0fcc5b0
Compare
Dismissing prior approval to re-evaluate 0fcc5b0
…he whole thread list ThreadSettlementReactor and ThreadPullRequestReactor read the full shell snapshot for every sweep, even when an event asked about one thread. That is every active thread, six queries, and a repository identity check for every project. One turn end queued about three of these full reads. Sweeps for one thread now read only that thread, the projects it names, and the snapshot sequence. The sequence is read first, so the thread is at least as new as the sequence that guards the dispatched command. The one-minute sweeps and merge sweeps still read the full snapshot. Discovery now prunes pending backfills only for the thread it read, since a one-thread read cannot show which other threads are gone. The per-thread settleThread decision no longer opens a span. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
A one-thread read already returns only that thread, so the per-thread filters in discovery and settlement are gone. Pruning no longer copies the pending backfill keys. The tests now record full and one-thread reads in one queue. A return to the full read fails with an assertion instead of a timeout. A new check confirms that an event for one thread keeps other pending backfills. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The reactor tests stub the query service, so they cannot show that a one-thread read returns the same thread as the full shell snapshot. This test seeds real SQLite rows (a linked PR, a branch PR in another project, a latest turn, a session) and asserts that readSweepSnapshot returns the same sequence, thread, and project shells as getShellSnapshot. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
0fcc5b0 to
bebf1ef
Compare
Dismissing prior approval to re-evaluate bebf1ef
| * thread reads that thread and the projects it names, not every thread. | ||
| */ | ||
| export const readSweepSnapshot = ( | ||
| snapshots: ProjectionSnapshotQuery.ProjectionSnapshotQueryShape, |
There was a problem hiding this comment.
This production Effect helper accepts ProjectionSnapshotQueryShape as an explicit service dependency. Could it acquire ProjectionSnapshotQuery.ProjectionSnapshotQuery with yield* instead, and have both reactors and the parity test provide the query through their layers? That keeps service dependencies in the Effect environment rather than passing service instances between production modules.
Posted via Macroscope — Effect Service Conventions
There was a problem hiding this comment.
Note
🤖 Claude Opus 5.5 responding on behalf of Theo
Keeping the argument. readSweepSnapshot is a read helper, not a service factory: both reactors already acquire ProjectionSnapshotQuery with yield* in make (ThreadPullRequestReactor.ts:107, ThreadSettlementReactor.ts:83) and pass that instance down. Reading it from the environment inside the helper would leak the requirement into ThreadSettlementReactor.start, which calls runSweep directly for merge events (ThreadSettlementReactor.ts:378), so it would need an extra Effect.provideService to keep its Effect<void, never, Scope> type.
…PR checks no longer read every thread Main made single-thread settlement and pull request sweeps read only that thread. V2 had the same shape: every finished run, detached session, checkpoint or metadata change queued a one-thread request, and each one read every thread before filtering to the one it wanted. - ThreadSettlementServiceV2: getSettlementCandidates takes an optional thread id and filters in SQL (and in the memory store), and a sweep with no candidates stops before reading projects. - ThreadPullRequestServiceV2: a one-thread request reads the thread's sequence, then its shell via getThreadShell, instead of getShellSnapshot (every active and archived thread). As on main, a one-thread read only clears that thread's pending backfill. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
## What's Changed * feat(observability): write a server heap snapshot on SIGUSR2 by @t3dotgg in pingdotgg/t3code#13694 * perf(server): shutdown no longer rewrites every stopped session row by @t3dotgg in pingdotgg/t3code#13688 * perf(server): build the thread list snapshot without decoding it twice by @t3dotgg in pingdotgg/t3code#13693 * fix(client): slow servers finish loading the thread list instead of loading it twice by @t3dotgg in pingdotgg/t3code#13683 * perf(web): hidden terminal drawers no longer keep full thread history in memory by @t3dotgg in pingdotgg/t3code#13686 * perf(server): per-thread settlement and PR checks no longer rebuild the whole thread list by @t3dotgg in pingdotgg/t3code#13691 * fix(mobile): running threads open at the latest message by @AKolenda in pingdotgg/t3code#13530 * feat(observability): record event loop stalls in the server trace by @t3dotgg in pingdotgg/t3code#13697 * perf(server): stop re-running git for every project each minute by @t3dotgg in pingdotgg/t3code#13689 * fix(usage): hide the Cursor keychain prompt when Cursor isn't set up by @Gigioxx in pingdotgg/t3code#13714 * feat(web): add chat width setting for wide screens by @otavio in pingdotgg/t3code#11594 * fix(opencode): accept v2 serve ready line when spawning server by @shirishpothi in pingdotgg/t3code#13651 * fix(editors): stop treating the agy CLI as the Antigravity IDE by @ishaanko in pingdotgg/t3code#7079 * fix(web): make the empty workspace draggable on desktop by @otavio in pingdotgg/t3code#13713 * fix(server): installed editors no longer vanish when discovery is slow by @bfowler in pingdotgg/t3code#13669 * fix(git): exclude SSH ports from provider URLs by @GaMeRaM in pingdotgg/t3code#12537 * fix(web): Mod+B bolds on non-Latin layouts by @ValeraZSD in pingdotgg/t3code#13409 * fix(server): prune expired replay-protection files from the secrets directory by @t3dotgg in pingdotgg/t3code#13695 * fix(web): terminal links drop a trailing colon by @ValeraZSD in pingdotgg/t3code#13408 * fix(server): bump node-pty to 1.2.0-beta.15 for linux-arm64 prebuild by @Ephraim-9 in pingdotgg/t3code#13748 * Show a focus ring on sidebar thread and draft rows by @ryanilano in pingdotgg/t3code#13344 * fix(mobile): keep composer within folded screen after resume by @PixPMusic in pingdotgg/t3code#13310 * fix(server): let OpenCode generate session titles by @macodev00 in pingdotgg/t3code#13368 * fix(server): let Antigravity inspect unsupported files by path by @Bil0000 in pingdotgg/t3code#13339 * fix(mobile): link URLs with ports and single-label hosts by @Yash-Singh1 in pingdotgg/t3code#13795 * feat(web): add keyboard navigation for usage by @tris203 in pingdotgg/t3code#10158 * perf(observability): stop writing empty spans on spawns, projected events, and idle polls by @t3dotgg in pingdotgg/t3code#13756 * perf(server): opening Diagnostics no longer loads the whole trace ring into memory by @t3dotgg in pingdotgg/t3code#13763 * perf(clients): sort projects and settled threads without re-parsing dates per comparison by @t3dotgg in pingdotgg/t3code#13759 * fix(observability): the renderer trace proxy stops tracing itself by @t3dotgg in pingdotgg/t3code#13761 * perf(server): background sweeps only read threads that can still settle by @t3dotgg in pingdotgg/t3code#13765 * perf(clients): saving the thread list cache no longer freezes the UI by @t3dotgg in pingdotgg/t3code#13767 * perf(server): cut idle wakeups from the Connect relay and session reaper by @t3dotgg in pingdotgg/t3code#13774 * fix(mobile): keep trailing underscores and tildes in autolinked URLs by @Yash-Singh1 in pingdotgg/t3code#13807 * fix(web): queued messages send while their thread is not open by @t3dotgg in pingdotgg/t3code#13764 * fix(server): background git status fetches no longer fill the disk with failed repacks by @t3dotgg in pingdotgg/t3code#13812 * fix(mobile): thread list shows the pull request icon instead of # by @flamboh in pingdotgg/t3code#13742 * fix(accessibility): correct control announcements and sidebar traversal by @blinding-pixels in pingdotgg/t3code#13491 * fix(usage): tolerate newer provider variants by @tris203 in pingdotgg/t3code#10076 * fix(usage): omit Cursor warning when no login is saved by @tris203 in pingdotgg/t3code#13820 * fix(usage): identify client version mismatches by @tris203 in pingdotgg/t3code#8208 * fix(web): stop mistaking offline servers for updates by @tris203 in pingdotgg/t3code#13083 * test(usage): assert contract mismatch details by @Yash-Singh1 in pingdotgg/t3code#13861 * fix(build): validate Linux node-pty prebuilds in Windows artifacts by @Yash-Singh1 in pingdotgg/t3code#13867 ## New Contributors * @otavio made their first contribution in pingdotgg/t3code#11594 * @shirishpothi made their first contribution in pingdotgg/t3code#13651 * @bfowler made their first contribution in pingdotgg/t3code#13669 * @GaMeRaM made their first contribution in pingdotgg/t3code#12537 * @ValeraZSD made their first contribution in pingdotgg/t3code#13409 * @Ephraim-9 made their first contribution in pingdotgg/t3code#13748 * @ryanilano made their first contribution in pingdotgg/t3code#13344 * @macodev00 made their first contribution in pingdotgg/t3code#13368 * @blinding-pixels made their first contribution in pingdotgg/t3code#13491 **Full Changelog**: pingdotgg/t3code@v0.0.43-nightly.20260926.2282...v0.0.43-nightly.20260926.2318 Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.43-nightly.20260926.2318
Merges `pingdotgg/t3code` up to `eeea71a88` (55 commits after base `ebdcda135`). This PR is based on `main`; no other merge PR is open. ## Resolution - **Files that landed:** 271, against 272 in the upstream range. The one missing is `apps/server/src/cli/pair.ts`, which stays deleted under `deletedUpstreamPaths`. The fork delta is 756 files, the same as the last merge. - **Conflicts (4):** - `apps/server/src/cli/pair.ts` (modify/delete): kept deleted. - `ProviderSettingsPanel.tsx`, `SettingsSidebarNav.tsx`, `useAvailableSettingsSearchItems.ts` (converged): kept the fork's gates, search filters and feature-flag read. Took upstream's `scopeSearch` argument and `cursorKeychainUsageEnabled` prop. - **New fork gate:** the `cursor-keychain-usage` search item from pingdotgg#13714 is now `providerConfigurationOnly`, because its row sits inside `UsageProviderSettings`, which the fork hides. Upstream's test now asserts against `FEATURES.providerConfiguration` and gained the fork's `forgejoEnabled` field. That field was the only typecheck failure. - **Lockfile:** re-derived with `install.mjs`. The install left it unchanged, and the fork's edges are present. - **Sweep:** new upstream files matched none of the owned-concern keywords, and upstream added no workflows. - **Unsupported methods:** nothing to add or drop. ## Verification The full `verify.mjs` run passes all 10 checks: duplicate-adds, tripwires, resolution-check, unsupported-methods, lockfile, fmt, lint, typecheck, build and test. ## Usable as-is - Chat width setting (a client setting) (pingdotgg#11594) - The "agents working" banner links to the Agents panel (pingdotgg#13572) - Composer fixes: paste lands in the composer after clicking away (pingdotgg#13553), the collapsed composer bar keeps its labels while scrolling (pingdotgg#13555), focus returns after saving a citation note (pingdotgg#13450) - Nested task states stay out of parent bullets (pingdotgg#11477). Compact provider instance badges are back (pingdotgg#13700), and the OpenAI logo is updated (pingdotgg#13611) - Client runtime: sync status no longer flickers (pingdotgg#13551), slow servers finish loading the thread list once instead of twice (pingdotgg#13683), hidden terminal drawers release thread history (pingdotgg#13686) - Mobile fixes: Android control sizing, project icons, Home row performance, and running threads open at the latest message - The worktree setup label fix (pingdotgg#13590). It applies to UI that `FEATURES.worktreeSelection` gates. ## Unsupported in Moatless / needs implementation - **Cursor, OpenCode and Antigravity usage history** (pingdotgg#10409), and the Cursor keychain usage toggle `cursorKeychainUsageEnabled` (pingdotgg#13714). They read usage in `apps/server/src/usage/*UsageReader.ts`, and the toggle is written through `server.updateSettings`, which the backend does not dispatch. The toggle stays hidden under `FEATURES.providerConfiguration`. - **Android foldable controls in the Device panel** (pingdotgg#13534, pingdotgg#13574). They sit under `FEATURES.deviceHub`, which is off. - **Desktop and server only:** `RunningThreadKeepAlive` (pingdotgg#13554), the desktop compile cache (pingdotgg#13501), the Linux .deb auto-updater (pingdotgg#13575), OTLP environment variables (pingdotgg#13492, pingdotgg#13641), the heap snapshot on SIGUSR2 (pingdotgg#13694), event-loop stall tracing (pingdotgg#13697), and the `t3 trace` CLI (pingdotgg#13698). None of these applies to the Moatless web deployment. ## Backend behavior to consider reproducing in Moatless Added to `docs/fork/gaps.md`, under *Runtime fixes upstream made to its own server*: - Settling a thread closes its idle shells: `terminal/Manager.ts` (pingdotgg#13673) - Usage reads Cursor, OpenCode and Antigravity history (pingdotgg#10409) - Newer Codex models get the runtime instructions again: `CodexDriver.ts`, `RuntimeInstructions.ts` (pingdotgg#13547) - Background work no longer scales with every thread or project: - no per-minute git reruns (pingdotgg#13689) - no thread-list rebuilds for per-thread settlement or PR checks (pingdotgg#13691, pingdotgg#13720, pingdotgg#13693) - PR sync reads only threads with a linked PR (pingdotgg#13704) - the SQLite WAL shrinks after large writes (pingdotgg#13684) - shutdown no longer rewrites every stopped session row (pingdotgg#13688) - Also: the OpenCode v2 serve ready line (pingdotgg#13651), and retrying failed SQLite statement preparations (pingdotgg#10584) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- Moatless task: https://moatless.soaplabstest.com/tasks/0af5f959-42c9-4219-b6ff-2f43e9e72a5d
On a long-running server with about 5,000 threads and 130 projects, the settlement and PR discovery reactors read the full shell snapshot for every per-thread event. One full read loads every active thread, runs 6 queries, and resolves repository identity for every project. One turn end queued about 3 of these full reads, and the drain worker does not merge duplicates. This came from a long-uptime slowdown report (0.0.40, 9 days of uptime).
Fix
readSweepSnapshot(snapshots, threadId | null)inThreadPullRequestReactor.ts.null, it callsgetShellSnapshot()as before. The 1-minute sweeps, merge sweeps, and settings sweeps do not change.getSnapshotSequence, thengetThreadShellById, thengetProjectShellsfor the thread's project and the project its saved PR names. Settlement checks that second project.thread.auto-settleandthread.pull-request.sync. A race can only cause a rejected command. It cannot hide a change.ThreadSettlementReactorandThreadPullRequestReactoruse this helper for all sweeps.settleThreaddecision no longer opens a span. A full sweep made one span per candidate thread.PullRequestSyncReactordoes not change here. #13704 already moved it to a query that reads only threads with linked PRs.Related: #12161 added the per-thread settlement triggers.
Verification
ProjectionSnapshotQuery.test.tsseeds a thread with a linked PR, a latest turn, and a session, plus a thread whose branch PR names another project. It asserts thatreadSweepSnapshotfor each thread returns the same sequence, thread, and project shells asgetShellSnapshot. It fails if the helper drops the PR's project or ifgetThreadShellByIddrifts from the full snapshot.vp test runonLayers/ProjectionSnapshotQuery.test.ts,ThreadPullRequestReactor.test.ts,PullRequestSyncReactor.test.ts, andLayers/OrchestrationReactor.test.ts: 64 passed.vp test run ThreadSettlementReactor.test.ts -t ThreadSettlementReactor: 20 passed. The "storage cleanup" tests in this file also fail on unchanged main on this machine. They pass in CI.vp lintandvp fmton the changed files, andvp run --filter t3 typecheck.Made by Claude Opus 5.5 (1M context) in Claude Code, running in T3 Code.
🤖 Generated with Claude Code
Summary by CodeRabbit