GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): opening a large database no longer blocks startup for minutes by t3dotgg · Pull Request #21122 · pingdotgg/t3code

Conversation

@t3dotgg

@t3dotgg t3dotgg commented Oct 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Opening a database without planner statistics blocked server startup for minutes. Since #18471, the server runs PRAGMA optimize = 0x10012 on open. When sqlite_stat1 is missing, that pass reads every page of the large tables: 108.5 s cold on an 11 GB copy of a real database, and almost 4 minutes on 48 GB. Stats taken while a table is small also make the planner scan it once it grows. That is the #19916 freeze: 2 ms with no stats, 1.7 s with stale-small stats.

Fix

Stop using planner statistics.

  • After migrations, the server clears sqlite_stat1 and reloads with ANALYZE sqlite_schema. That reads no user table. Stats that older builds collected go away, and the writer connection stops using them. The reader worker starts after setup, so it never loads them.
  • Without stats, SQLite assumes tables are large and uses indexes. Only two queries picked a worse index, and each now names its index with INDEXED BY, as other event-store reads already do:
    • ThreadFind revision lookup: walked every V2 event backwards, which took seconds on long-idle threads.
    • getTurnStartContext node read: read every node in the thread instead of looking up the root node by key.
  • Check for Updates in the desktop menu now calls activate instead of ensureMain. It no longer opens the main window before the backend is ready, which left the renderer on a failed auth bootstrap.

Cold open of the 11 GB copy, with its stats removed or restored: main 108.5 s, this branch 50 to 66 ms.

How we know stats are not needed

We extracted every static SQL statement from the server and ran EXPLAIN QUERY PLAN with and without stats on 10 real databases (0.2 to 26 GB, macOS and Linux). 452 statements prepare.

Query No stats With stats No stats + hint
ThreadFind revision 9 to 3,205 ms 0 ms 0 ms
Turn-start node read 0 to 28 ms 0 ms 0 ms
Thread text search 1 to 126 ms 1 to 173 ms no change needed

The no-stats plan depends only on the schema, so it is the same on every machine. I reviewed it for every location whose plan changed on any machine. I timed the risky ones on the largest database: agent event reads by thread, the startup recovery query, and thread search. None was slower without stats. Some, such as the provider-thread reads at ProjectionStore.ts:3139 and :3156, use an index only without stats.

Takeover

This continues #19407 by @thymikee, whose commits are kept with his authorship. His PR seeded fixed sqlite_stat1 rows instead of collecting them. The fleet measurements showed that the stats themselves are not needed, so this branch removes them. His desktop menu fix is unchanged.

#19917 (hourly PRAGMA optimize) goes the other way and would bring the stats back.

Verification

  • New test: an older build's stale-small stats on a probe table are cleared on reopen. On the same writer connection, a recursive walk then uses the index. The test fails with the old optimize line, and it fails if the reload is missing.
  • vp test run passes for Sqlite.test.ts, ProjectionStore.test.ts, ThreadFind.test.ts, TurnStartReads.test.ts, ProviderTurnControlService.test.ts, ProviderTurnStartService.test.ts and DesktopApplicationMenu.test.ts. Server and desktop typecheck pass. Lint and format pass on the changed files.
  • Not checked: Windows databases, and clicking Check for Updates in a packaged desktop build during a slow startup.

Reviewed with sol-loop: 3 rounds with GPT-6.1 Sol. Sol verdict: approved

Original work by Michał Pierzchała with Claude Opus 5.5 in Claude Code. Takeover by Claude Opus 5.5 in Claude Code, working in T3 Code.

Co-authored-by: Michał Pierzchała [email protected]

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Oct 18, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 18, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — The PR changes the default SQLite planner policy for every server database, clears persisted statistics at startup, and alters query plans on existing request paths. The update-menu change is small, but the server-wide runtime default warrants human review.

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Oct 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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 5.0 KiB 5.0 KiB −7 B (−0.1%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB −7 B (−0.6%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 20.9 KiB 20.9 KiB 0 B (0.0%) 29.3 KiB ✅
Codex Live turn messages 2 2 0 (0.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB +7 B (+0.1%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +7 B (+0.6%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅
Claude Live turn messages 2 2 0 (0.0%) 8 ✅

Baseline: 9ba6143 · PR result: 425abfa · 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: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

macroscopeapp[bot]
macroscopeapp Bot reviewed Oct 18, 2026
View reviewed changes
Comment thread apps/desktop/src/window/DesktopApplicationMenu.ts Resolved

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Team
  • Run ID: 303d6808-7079-49d0-a5a2-78962a70836e
📥 Commits

Reviewing files that changed from the base of the PR and between d414e5a and 425abfa.

📒 Files selected for processing: 4
  • apps/server/src/orchestration-v2/ProjectionStore.ts
  • apps/server/src/orchestration-v2/ThreadFind.ts
  • apps/server/src/persistence/Sqlite.test.ts
  • apps/server/src/persistence/Sqlite.ts

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

📝 Walkthrough

SQLite setup now clears collected planner statistics and reloads them for the connection. Two orchestration queries specify indexes. The desktop update-check handler activates the main window before starting the check.

Changes: SQLite Query Planning

Layer / File(s) Summary
Clear planner statistics during setup
apps/server/src/persistence/Sqlite.ts, apps/server/src/persistence/Sqlite.test.ts, apps/server/src/serviceLauncher.ts, docs/internals/server-updates.md
SQLite setup clears sqlite_stat1 when present and runs ANALYZE sqlite_schema. The test checks that statistics are cleared and that a recursive query uses the primary-key index. The launcher comment and documentation remove the reference to open-time optimization.
Specify indexes for orchestration queries
apps/server/src/orchestration-v2/ProjectionStore.ts, apps/server/src/orchestration-v2/ThreadFind.ts
The root-node query specifies the primary-key autoindex. The revision query specifies idx_orch_events_stream_sequence.

Desktop Update Menu

Layer / File(s) Summary
Activate the main window before checking
apps/desktop/src/window/DesktopApplicationMenu.ts
The update-check handler activates the main window before checking for updates, replacing its call to ensureMain.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: maria-rcks, otavio

Merge Risk: ⚪ Minimal · up to 425ab

The change avoids slow server startup on large databases by clearing planner statistics and pinning two query indexes. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly identifies the primary change: preventing large database startup from blocking for minutes.
Description check Passed The description clearly covers the problem, technical changes, scope, performance impact, verification results, and untested areas. It includes issue and pull request references, although it does not …
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.
Full details: Description check

Explanation

The description clearly covers the problem, technical changes, scope, performance impact, verification results, and untested areas. It includes issue and pull request references, although it does not use the template's exact “Scope and approval” heading or provide an explicit approval comment.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

thymikee and others added 5 commits October 18, 2026 01:27
@thymikee @claude @t3dotgg
fix(server): opening a large database no longer blocks startup for mi…
280eb87
…nutes

Opening a database without planner statistics ran PRAGMA optimize, which
reads every page of the large tables: 3 min 47 s on a 48 GB database before
the server could answer. Seed fixed sqlite_stat1 rows, measured on that
database, for indexes that have none instead. Rows a database already has
are kept.

Check for Updates no longer opens the main window before the backend is
ready, which left the renderer on a failed auth bootstrap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thymikee @claude @t3dotgg
fix(server): seed planner statistics in one write transaction
b2593c7
The server and a CLI command can open a database without statistics at the
same time. Each could read the same missing indexes before either inserted,
and sqlite_stat1 has no unique key, so both rows stayed. The read and insert
now share one BEGIN IMMEDIATE transaction.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3dotgg @thymikee @claude
fix(server): drop planner statistics for the removed V1 projections
a09be3b
Migration 063 dropped the V1 projection tables after this branch was
written, so their seeded rows named indexes that no longer exist.

Co-Authored-By: Michał Pierzchała <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3dotgg @claude
fix(server): drop planner statistics and pin the two indexes that nee…
08b1086
…d them

Fleet measurements on 10 databases showed only two queries get slower
without sqlite_stat1, and an INDEXED BY hint makes both as fast as with
stats. Stats taken while a table is small also make the planner scan it
once it grows. So drop the table on open instead of seeding fixed rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3dotgg @claude
fix(server): reload planner statistics after clearing them
425abfa
A connection loads sqlite_stat1 when it opens, so dropping the table left
the writer planning with the old rows. Delete the rows and reload with
ANALYZE sqlite_schema, which reads no user table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@t3dotgg
t3dotgg force-pushed the t3/large-db-planner-stats branch from d414e5a to 425abfa Compare October 18, 2026 08:38
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Oct 18, 2026
@t3dotgg
t3dotgg merged commit eb1d80c into main Oct 18, 2026
29 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@t3dotgg
t3dotgg deleted the t3/large-db-planner-stats branch October 18, 2026 09:03
This was referenced Oct 18, 2026
[Bug]: Server freezes ~80 s per thread open after a long uptime: planner stats loaded at startup are never refreshed #19916
Closed
fix(server): opening a large database no longer blocks startup for minutes #19407
Closed
fix(server): refresh planner stats so a long uptime cannot freeze the server #19917
Closed
AdEx-Partners-DE pushed a commit to AdEx-Partners-DE/t3code that referenced this pull request Oct 18, 2026
@t3dotgg @claude @AdEx-Partners-DE
fix(server): opening a large database no longer blocks startup for mi…
a2d3800
…nutes (pingdotgg#21122)

Co-authored-by: Michał Pierzchała <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit eb1d80c)

Fork: replaces the hourly PRAGMA optimize adopted from pingdotgg#19917 (eb76cb8), which upstream closed as superseded by this change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
AdEx-Partners-DE added a commit to AdEx-Partners-DE/t3code that referenced this pull request Oct 18, 2026
@AdEx-Partners-DE @claude
test(server): drop the hourly planner-stats test with the refresh it …
19752c6
…covered

Upstream pingdotgg#21122 stops using planner statistics, so the fork's hourly PRAGMA optimize (from pingdotgg#19917) is gone and its test with it; the file now matches upstream.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@thymikee

thymikee commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

Thanks for getting this in, appreciate it!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Oct 18, 2026
@github-actions
nightly: 0.1.1-nightly.20261018.3315
fd50660
## What's Changed
* perf(web): switching threads no longer re-renders the chat view for an unchanged preview list by @juliusmarminge in pingdotgg/t3code#21130
* fix(server): opening a large database no longer blocks startup for minutes by @t3dotgg in pingdotgg/t3code#21122
* perf(web): switching threads no longer re-renders the outgoing thread's rows by @juliusmarminge in pingdotgg/t3code#21123
* perf(web): reasoning rows skip the tool-failure text scan by @juliusmarminge in pingdotgg/t3code#21146
* perf(web): pull request chains parse each link's URL once by @juliusmarminge in pingdotgg/t3code#21147


**Full Changelog**: pingdotgg/t3code@v0.1.1-nightly.20261018.3302...v0.1.1-nightly.20261018.3315

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.1.1-nightly.20261018.3315
github-actions Bot added a commit to davidvanderklay/t3code-flake that referenced this pull request Oct 18, 2026
@github-actions
nightly: 0.1.1-nightly.20261018.3315
7d26ff0
## What's Changed
* perf(web): switching threads no longer re-renders the chat view for an unchanged preview list by @juliusmarminge in pingdotgg/t3code#21130
* fix(server): opening a large database no longer blocks startup for minutes by @t3dotgg in pingdotgg/t3code#21122
* perf(web): switching threads no longer re-renders the outgoing thread's rows by @juliusmarminge in pingdotgg/t3code#21123
* perf(web): reasoning rows skip the tool-failure text scan by @juliusmarminge in pingdotgg/t3code#21146
* perf(web): pull request chains parse each link's URL once by @juliusmarminge in pingdotgg/t3code#21147


**Full Changelog**: pingdotgg/t3code@v0.1.1-nightly.20261018.3302...v0.1.1-nightly.20261018.3315

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.1.1-nightly.20261018.3315
@andrewcai8 andrewcai8 mentioned this pull request Oct 18, 2026
chore: merge upstream pingdotgg/t3code through 9c161462c9 andrewcai8/t3code#222
Merged
@filipgutica filipgutica mentioned this pull request Oct 18, 2026
chore(workbench): sync T3 Code upstream through e1f33e0 filipgutica/t3code#163
Merged
Pipyakas pushed a commit to Pipyakas/t3code that referenced this pull request Oct 18, 2026
@t3dotgg @thymikee
@claude @Pipyakas
fix(server): opening a large database no longer blocks startup for mi…
664a4fe
…nutes (pingdotgg#21122)

Co-authored-by: Michał Pierzchała <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit eb1d80c)
@henrychu04 henrychu04 mentioned this pull request Oct 19, 2026
Merge upstream/main 07d38b8d17 into coder-only henrychu04/t3code-coder#206
Merged
@juliusmarminge juliusmarminge mentioned this pull request Oct 19, 2026
Local Windows desktop disconnects during 36–44 second server stalls with a 12.5 GB database #21539
Closed
This was referenced Oct 19, 2026
[Bug]: Starting a turn in a long thread freezes the server for 0.3–0.4 s (0.03–0.05 s with one index) #21578
Closed
fix(server): turn starts in long threads no longer stall the server #21585
Closed
@juliusmarminge juliusmarminge mentioned this pull request Oct 19, 2026
[Bug]: Startup migration exits on "database is locked" instead of waiting, so a CLI holding statev2.sqlite crash-loops the desktop backend #21736
Closed
Pipyakas pushed a commit to Pipyakas/t3code that referenced this pull request Oct 19, 2026
@t3dotgg @thymikee
@claude @Pipyakas
fix(server): opening a large database no longer blocks startup for mi…
e361ddf
…nutes (pingdotgg#21122)

Co-authored-by: Michał Pierzchała <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit eb1d80c)
This was referenced Oct 21, 2026
[Bug]: 26.5 GB V2 state database: thread-shell and recovery queries take 2–22 s; six indexes cut startup from ~137 s to ~17 s #22659
Closed
[Bug]: Thread-shell and recovery queries take 2–22 s on a 26.5 GB V2 database; six proposed indexes (follow-up to #22659) #23000
Closed
@vifar vifar mentioned this pull request Oct 22, 2026
[Bug]: the other ProjectionStore reads take the write lock instead of the reader connection #23687
Closed
2 tasks done
incognitojam pushed a commit to incognitojam/styal that referenced this pull request Oct 25, 2026
@t3dotgg @incognitojam
fix(server): opening a large database no longer blocks startup for mi…
25a0f2f
…nutes (pingdotgg#21122)

Co-authored-by: Michał Pierzchała <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>

Fork adaptation: Keep the fork's runAllMigrations entry point before clearing planner statistics so fork migrations and the V1 history-table renames still run before upstream drops the original tables. Replace the earlier fork sampling assertion with upstream's statistics-clearing and indexed-query-plan test because opening the database no longer collects statistics.

(cherry picked from commit eb1d80c)
Upstream-PR: 21122
@mubeda mubeda mentioned this pull request Oct 31, 2026
Storage: report database size and free space, create new stores with incremental auto-vacuum, and add an offline bibcode storage compact mubeda/BibCode#230
Closed
10 tasks
@Motaghi Motaghi mentioned this pull request Oct 31, 2026
fix(server): look up a run's turn-start items by run, not by walking thread history #28343
Merged
@olafura olafura mentioned this pull request Nov 7, 2026
test(features): ledger upstream T3 Code through 30d0138540 hal-c2/hal-c2#1125
Merged
@Vantrongs Vantrongs mentioned this pull request Nov 12, 2026
perf(server): events stop maintaining the stream sequence index #35023
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@macroscopeapp macroscopeapp[bot] macroscopeapp[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@t3dotgg @thymikee @juliusmarminge
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.