Repository navigation
Fix thread list failure above SQLite variable limit - #1209
Merged
SawyerHood merged 2 commits intoAug 8, 2026
Merged
SawyerHood merged 2 commits into
SawyerHood merged 2 commits into
Conversation
Collaborator
Author
|
🚨 SLOP COP 🚨 · I am the SlopCop. I am reviewing this pull request for security, code quality, performance, architecture, and end-to-end behavior. |
SawyerHood
commented
Aug 8, 2026
SawyerHood
commented
Aug 8, 2026
SawyerHood
left a comment
Collaborator
Author
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5 summary
Think of the thread names as blocks that must fit in a box.
This change uses two boxes, so 16,378 names fit. A later step still uses one box. At 32,767 names, the list breaks again.
Finding
- Medium — The thread-list route still exceeds the SQLite variable limit at 32,767 visible threads. The inline comment has the full trace. Please batch
listLatestGoalEventRowsByThreadIds. The active-thread query has the same one-list pattern.
Review details
- Security: I found no security issues. The raw SQL predicate uses a fixed typed value.
- Code quality: The migration, snapshot, schema, query, and tests agree. Duplicate IDs and chunk results work correctly.
- Performance: The changed query stays below 32,766 variables. Both scans use the new partial index.
- Architecture:
pending-interactions.tshas another local batch helper. A shared database helper can protect all bulk-ID queries.
Validation
- The database suite passed with 368 tests in 28 files.
- The database Turbo type check passed.
- The browser route returned 200 with 16,378 visible threads.
- The same route returned 500 with 32,767 visible threads. The server logged
too many SQL variables. - All GitHub checks passed.
SawyerHood
deleted the
bb/fix-1205-thread-list-route-crashes-at-16-377-vis-thr_287q8zxazx
branch
August 8, 2026 22:57
5 tasks
amadad
pushed a commit
to amadad/bb
that referenced
this pull request
Aug 14, 2026
## Summary - Chunk active background-task count reads at 16,377 thread IDs. - Derive that size from the 32,766-variable limit, 11 fixed values, and two uses per ID. - Batch every thread-list event lookup through one variable-budget helper. - Add and pin a covering partial index for background-task events. - Add boundary, route, result-equivalence, migration, and query-plan tests. ## Reproduction I ran the issue reproduction before any change. A list of 16,376 IDs completed. A list of 16,377 IDs failed with `SqliteError: too many SQL variables`. After the fix, lists of 16,377, 16,378, and 32,754 IDs completed. The thread-list response also completed with 32,767 active threads. ## Measurements I used the 1.45 GB synthetic database from get-bb#1204. It has 30,000 threads and about 595,000 events. It has no background-task events. Thus, these results measure rejection of unrelated events. Correctness tests use real background-task rows. Each cold sample used a fresh process. I evicted the database page cache with `posix_fadvise(DONTNEED)`. I measured reads with `/proc/self/io`. I capped the NVMe device at 1,000 read IOPS. Each value below is the median of three samples. | Thread IDs | Cold reads before | Cold reads after | Cold time before | Cold time after | Warm time before | Warm time after | |---:|---:|---:|---:|---:|---:|---:| | 5,000 | 4,149 | 3 | 3.96 s | 18.7 ms | 29.1 ms | 18.7 ms | | 15,000 | 6,888 | 3 | 6.87 s | 52.7 ms | 75.5 ms | 53.5 ms | The old plan used `events_thread_type_item_kind_sequence_idx` for both task scans. The fixed plan uses `events_background_task_thread_type_item_sequence_idx` as a covering index for both scans. The query has a literal partial-index predicate and two `INDEXED BY` pins. ## Verification - `pnpm exec turbo run test --filter=@bb/db --force`: 370 tests passed. - The focused server route suite passed all 9 tests. - `pnpm exec turbo run typecheck --filter=@bb/db --filter=@bb/server`: passed. - A regression test crosses the old active-task variable boundary. - A regression test compares chunked counts with single-query counts. - A route regression builds 32,767 active thread-list entries. - Query tests cross the goal and request-key limits. - A query-plan test confirms both partial-index scans. - Drizzle generated migration 0089 and its snapshot. Fixes get-bb#1205.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Reproduction
I ran the issue reproduction before any change. A list of 16,376 IDs completed. A list of 16,377 IDs failed with
SqliteError: too many SQL variables.After the fix, lists of 16,377, 16,378, and 32,754 IDs completed. The thread-list response also completed with 32,767 active threads.
Measurements
I used the 1.45 GB synthetic database from #1204. It has 30,000 threads and about 595,000 events. It has no background-task events. Thus, these results measure rejection of unrelated events. Correctness tests use real background-task rows.
Each cold sample used a fresh process. I evicted the database page cache with
posix_fadvise(DONTNEED). I measured reads with/proc/self/io. I capped the NVMe device at 1,000 read IOPS. Each value below is the median of three samples.The old plan used
events_thread_type_item_kind_sequence_idxfor both task scans. The fixed plan usesevents_background_task_thread_type_item_sequence_idxas a covering index for both scans. The query has a literal partial-index predicate and twoINDEXED BYpins.Verification
pnpm exec turbo run test --filter=@bb/db --force: 370 tests passed.pnpm exec turbo run typecheck --filter=@bb/db --filter=@bb/server: passed.Fixes #1205.