Skip to content

perf(server): shutdown no longer rewrites every stopped session row - #13688

Merged
t3dotgg merged 4 commits into
mainfrom
t3code/stopall-skip-stopped
Sep 26, 2026
Merged

t3dotgg merged 4 commits into
mainfrom
t3code/stopall-skip-stopped

Conversation

@t3dotgg

@t3dotgg t3dotgg commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Problem

ProviderService.stopAll runs as a finalizer on every quit, update, and restart. It read the whole provider_session_runtime table twice. Then it rewrote every row, one at a time. Each rewrite is a SELECT plus an UPSERT. This included rows that were already stopped. Stopped rows stay on purpose because they hold resume cursors, so long-lived installs have many of them.

A report from one user with about 5,000 threads showed 3,129 stopped sessions, which suggests about 6.3k SQL statements on each shutdown. Those counts came from projection_thread_sessions, not provider_session_runtime, so the exact numbers are not proven. The direction is right: every stopped runtime row was rewritten on every shutdown. The shutdown also bumped lastSeenAt on every row, and sessionCount in provider.sessions.stopped_all counted every row in the table.

Fix

In apps/server/src/provider/Layers/ProviderService.ts:

  • stopAll reads the table once. The listThreadIds read was only used for the analytics count.
  • New isSettledBinding: status is stopped and the payload has no activeTurnId. stopAll skips these rows. A stopped row that still has a stale activeTurnId is rewritten, so the turn is cleared as before.
  • provider.sessions.stopped_all now sends stoppedSessionCount: the rows this shutdown rewrites. It replaces sessionCount, which counted every row. The new name keeps the old and new meanings in separate series, the same way surface was added next to the legacy clientType.

Recovery on next boot does not change. Live sessions are persisted and rewritten as before, so their continuation markers and resume cursors carry over. Skipped rows are not written at all.

Verification

New test: "ProviderServiceLive shutdown leaves settled session rows untouched". It seeds a settled stopped row, a running row with a turn, and a stopped row with a stale turn. Then it closes the service scope. The settled row does not change at all (including lastSeenAt and payload). The other two rows are stopped with activeTurnId null, and stoppedSessionCount is 2.

Mutation checks: the test fails if the filter is removed, and it fails if stopped rows with a stale turn are skipped.

  • vp test run apps/server/src/provider/Layers/ProviderService.test.ts apps/server/src/provider/Layers/ProviderSessionDirectory.test.ts apps/server/src/serverRuntimeStartup.reconcile.test.ts
  • vp lint and vp fmt on the changed files
  • vp 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

  • Bug Fixes
    • Improved session handling during provider shutdown. Sessions that are already stopped with no active work remain unchanged, while sessions with active or stale turn state are marked stopped and their active state is cleared.
    • Shutdown reporting now counts only sessions that required stopping, rather than all sessions found, providing a more accurate total for completed shutdown actions. This keeps reported shutdown totals aligned with the sessions actually updated.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Sep 25, 2026
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

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: aa742b4a-574e-44f3-9542-cc6e4a52ebc8

📥 Commits

Reviewing files that changed from the base of the PR and between b320109 and f53ac44.

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

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


📝 Walkthrough

Walkthrough

Provider shutdown now filters settled bindings before rewriting session state. The stopped-all analytics event reports the number of bindings selected for rewriting. A test covers settled and unsettled bindings.

Changes

Provider shutdown

Layer / File(s) Summary
Select and rewrite shutdown bindings
apps/server/src/provider/Layers/ProviderService.ts, apps/server/src/provider/Layers/ProviderService.test.ts
Shutdown excludes settled bindings from rewrites and reports the selected binding count. The test checks that settled bindings remain unchanged and that unsettled bindings are stopped with active-turn markers cleared.

Priority: ⬇️ Low

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

Change: Bug fix

Suggested reviewers: juliusmarminge

Merge Risk: ⚪ Minimal · up to f53ac

No actionable merge-blocking risk is identified; the shutdown change appears ready for normal merge checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: shutdown skips rewriting settled stopped-session rows.
Description check ✅ Passed The description explains the problem, the fix, and verification. Its Problem and Fix sections cover the template’s What Changed and Why sections. UI changes do not apply, but the Checklist section is …
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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.

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 13.5 KiB 13.5 KiB +27 B (+0.2%) 15.1 KiB ✅
Codex Thread snapshot wire 7.1 KiB 7.1 KiB +2 B (+0.0%) 7.3 KiB ✅
Codex Live turn WebSocket wire 6.4 KiB 6.5 KiB +25 B (+0.4%) 7.8 KiB ✅
Codex Live turn WebSocket decoded 56.2 KiB 56.3 KiB +44 B (+0.1%) 66.4 KiB ✅
Codex Live turn messages 9 10 +1 (+11.1%) 21 ✅
Claude Total thread wire 13.5 KiB 13.5 KiB +19 B (+0.1%) 15.1 KiB ✅
Claude Thread snapshot wire 7.1 KiB 7.1 KiB 0 B (0.0%) 7.3 KiB ✅
Claude Live turn WebSocket wire 6.4 KiB 6.4 KiB +19 B (+0.3%) 7.8 KiB ✅
Claude Live turn WebSocket decoded 57.0 KiB 57.0 KiB 0 B (0.0%) 66.4 KiB ✅
Claude Live turn messages 9 9 0 (0.0%) 21 ✅

Baseline: 6530de0 · PR result: f53ac44 · 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: 113.9 KiB
  • Claude decoded thread snapshot: 114.7 KiB

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

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Sep 25, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at f53ac44

Macroscope's review found this PR approvable — This is a narrowly scoped shutdown performance fix that avoids rewriting settled session rows while preserving updates for active or stale-turn sessions. A focused regression test verifies the persistence behavior and revised shutdown metric.

You can add or adjust custom eligibility rules. Learn more.

@t3dotgg
t3dotgg force-pushed the t3code/stopall-skip-stopped branch from b320109 to e8c351f Compare September 26, 2026 01:08
@macroscopeapp
macroscopeapp Bot dismissed their stale review September 26, 2026 01:08

Dismissing prior approval to re-evaluate e8c351f

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Sep 26, 2026
t3dotgg and others added 4 commits September 25, 2026 19:34
stopAll runs on every quit, update, and restart. It read the whole
provider_session_runtime table twice and upserted every row, including
thousands of rows that were already stopped. Each upsert is a SELECT plus
an UPSERT, and it also reset lastSeenAt on all of them.

Now it reads the table once and skips rows that are already stopped with
no active turn. The stopped_all analytics sessionCount now counts only the
sessions this shutdown stops, not every row ever written.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
sessionCount on provider.sessions.stopped_all used to count every row in
provider_session_runtime. It now counts only the sessions this shutdown
stops. A new property name keeps the old and new values out of one series,
the same way surface was added next to the legacy clientType.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@t3dotgg
t3dotgg force-pushed the t3code/stopall-skip-stopped branch from e8c351f to f53ac44 Compare September 26, 2026 02:35
@macroscopeapp
macroscopeapp Bot dismissed their stale review September 26, 2026 02:35

Dismissing prior approval to re-evaluate f53ac44

@t3dotgg
t3dotgg merged commit 574b180 into main Sep 26, 2026
24 of 25 checks passed
@t3dotgg
t3dotgg deleted the t3code/stopall-skip-stopped branch September 26, 2026 03:24
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Sep 26, 2026
## 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
aorwall added a commit to aorwall/t3code that referenced this pull request Sep 27, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant