Repository navigation
Check query function coverage per PR, audit plans nightly and on dev and diagnostics servers - #7302
Merged
Merged
Conversation
…s servers The test-suite guard from #7292 only judges queries that tests execute, and its allowlist could keep entries after their fixes landed: #7288 and #7289 merged before it, so it shipped with seven stale entries. A Query plan audit CI job now runs @bb/db and @bb/server unsharded in report mode. check:query-plan-report fails on findings missing from the allowlist, on allowlist entries no test reported, and on exported query functions in packages/db/src/data that no test runs. A TypeScript scan finds those functions: exported functions that call a query builder or prepare on a connection. The report records the data functions on each prepared statement's stack. Four functions never ran: getEarlyAdopter had no callers and is deleted; updateProject, getSkippedAppUpdate and setPluginArtifactGitCheckoutRoot gain tests. The server now runs the same audit at runtime when BB_QUERY_PLAN_AUDIT is set (pnpm dev, pnpm start:worktree and pnpm desktop:worktree default it to 1) or the performanceDiagnostics experiment is on. The connection's statement instrumentation hands each new statement and parameter shape to the auditor, which captures the stack and plans the statement on setImmediate against a read-only connection. Unallowed findings log "Slow SQLite query plan" once per caller. Bundled frames are attributed through esbuild's module comments rather than the 17 MB source map, which costs about 120 MB of heap to load. A shape already seen adds about 0.3 us per query. Audits in tests are also deferred to each file's afterAll, so EXPLAIN work no longer runs inside time-budgeted code such as thread pruning. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The guard reads callers from POSIX stack paths, so attribution is inactive on Windows; the docs now say the audit logs nothing there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The unsharded db and server run took about five minutes per PR push. PRs still fail on new slow plans through the per-file guard in their existing test shards; the nightly workflow on main catches stale allowlist entries and untested query functions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Linux test shards set BB_QUERY_PLAN_EXECUTED, so the @bb/db and @bb/server test guards record the data functions on each prepared statement's stack in .query-plan/executed.jsonl. It is a Turbo test output, so a cached run restores it. The shard that runs @bb/db also writes the query function list. A new "Query functions run in tests" job downloads both, installs nothing, and fails when an exported query function in a packages/db/src/data file the PR changed never ran. Stale allowlist entries and functions in untouched files stay with the nightly audit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
added a commit
that referenced
this pull request
Nov 9, 2026
## Human comments ## What was wrong The query-plan test guard formats and parses a stack for every prepared SQLite statement on Windows, although its POSIX-only attribution cannot identify Windows callers. This unsupported-platform limitation was documented in #7302, and the bundled attribution test already skips Windows. The work consumes time without producing findings or query-function coverage there. ## What changed Return an empty test guard on Windows before patching SQLite's prepare method. This is a three-line test-support change in `packages/db/src/query-plan-test-guard.ts`; its callers are the database and server test setup files. Runtime query auditing and Linux/macOS test auditing and function-coverage reporting are unchanged. No test or assertion is removed. Windows attribution remains unsupported; enabling it later must include this platform gate. ## How you verified - Same-runner Windows ABBA comparison of the four slow server files passed every round (137 tests passed, five existing platform skips): [diagnostic run](https://github.com/get-bb/bb/actions/runs/42714915975). Baseline wall times were 90.22/68.09 seconds; candidate 62.68/54.48 seconds. Average 79.16 → 58.58 seconds, a 20.58-second (26%) reduction for this four-file invocation, not a claim about total CI time. Both candidate rounds beat both baseline rounds despite machine/warmup variation. - The same deliberate real `events` full-scan query passes with zero guard findings on unmodified Windows baseline, confirming the existing attribution limitation: [baseline Windows proof](https://github.com/get-bb/bb/actions/runs/42716605198). The diagnostic prints `DELIBERATE FULL SCAN win32 []`. Earlier instrumentation also observed 611 and 1,406 prepares with zero attributed callers; that initial run had diagnostic temp-path failures and is excluded from timing claims. - On macOS, a temporary real `events` full-scan query fails with the expected `full-scan` finding and exact source function under the changed guard. The probe was removed afterward. - Existing query-plan auditor tests and database typecheck pass through Turbo; formatting and diff checks pass. Independent review found no issues. Normal final-head CI is green at `2a31a2745eff30b9575e9de9296bf301cff3b609`, including all three Windows server shards and both Linux server shards: https://github.com/get-bb/bb/actions/runs/42716684868. > AGENT GENERATED
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.
Human comments
What was wrong
The slow-query-plan guard from #7292 only judges queries that tests run, and nothing noticed when an allowlist entry outlived its fix. #7288 and #7289 merged just before #7292 and #7287 just after it, so main carries seven entries for queries that are no longer slow.
What changed
Nightly coverage and stale-entry check.
Query Plan Auditworkflow (.github/workflows/query-plan-audit.yml, nightly on main and runnable by hand) runs@bb/dband@bb/servertests unsharded in report mode. It is not part of PR CI: an unsharded run took 5.2 min per PR push. PRs still fail on new slow plans through the per-file guard in their existing test shards.check:query-plan-report(renamed fromcheck:query-plan-allowlist) fails on:packages/db/src/datathat no test runs.packages/db/scripts/query-functions.tsfinds those functions with the TypeScript AST: exported functions that call a query builder orprepareon a connection. In report mode, the guard records the data functions on each prepared statement's stack.getEarlyAdopterhad no callers and is deleted.updateProject,getSkippedAppUpdateandsetPluginArtifactGitCheckoutRootgain tests.Per-PR check for changed query functions.
BB_QUERY_PLAN_EXECUTED=.query-plan/executed.jsonl. The@bb/dband@bb/servertest guards record the data functions on each prepared statement's stack while still failing on slow plans as before..query-plan/**), so a cached run restores it.@bb/dbalso writes the query function list.Query functions run in testsjob (scripts/check-pr-query-functions.mjs) downloads both, installs nothing, and fails when an exported query function in apackages/db/src/datafile the PR changed never ran. On this PR it took 11 s, and the server and packages-host shards showed no measurable change.Runtime audit on dev and diagnostics servers.
BB_QUERY_PLAN_AUDIT=1or theperformanceDiagnosticsexperiment is on, the server logsSlow SQLite query planonce per rule, table and caller for unallowed findings.pnpm dev,pnpm start:worktreeandpnpm desktop:worktreedefaultBB_QUERY_PLAN_AUDITto1.start:worktreeruns its server withNODE_ENV=production, soNODE_ENVcan't identify dev servers.packages/db/src/connection.ts) hands each new statement and parameter shape to the auditor, which also covers cached statements. The auditor captures the stack synchronously. It plans the statement onsetImmediateagainst a read-only connection to the same file (apps/server/src/services/system/query-plan-audit.ts).// pathmodule comments esbuild writes intoapps/server/dist, resolved againstapps/server. The bundle's 17 MB source map took about 0.9 s and 122 MB of heap to load. Resolving against the filesystem would also misattribute an npm-installed bb-app, whose bundle sits undernode_modules.Test guard.
afterAll, so EXPLAIN work no longer runs inside time-budgeted code.query-plan-guard.ts, shared by tests and the server. The prototype patch, report rows and report comparison live inquery-plan-test-guard.ts, exported as@bb/db/query-plan-test-guard.Docs.
docs/configuration.md: the env var row and theperformanceDiagnosticsdescription.docs/debugging-and-qa.md: a new "Slow SQLite query plans" section.bb guidecustomization chapter.Windows. Callers are read from POSIX stack paths, as in #7292, so the runtime audit logs nothing on Windows and the bundle test skips there.
Server/daemon wire. No daemon wire change.
How you verified
check:query-plan-reportprinted "Query plan report matches the allowlist (45 findings) and runs all 362 query functions."pnpm start:worktree(ESMdistbundle): with thelistThreadSearchMatchRowsallowlist entry temporarily removed,GET /api/v1/threads/search?query=hellologgedSlow SQLite query planwithcaller: "packages/db/src/data/threads.ts#listThreadSearchMatchRows".BB_QUERY_PLAN_AUDIT=0 pnpm start:worktree --perf-diagnostics: a search logged nothing while the experiment was off. Afterbb settings experiment performanceDiagnostics true, the same search logged the finding without a restart.countAppSettingsRowstoapp-settings.ts. The check named only that function, given the db record plus server records. Against this PR's real diff it passed: "Every query function in 1 changed data file(s) runs in a test."packages/db/.query-planand rerunning the cached@bb/dbtest task restored all 603 rows.query-plan-guard.test.tsbundles a query function with esbuild and loads it with Node's nativerequire. It asserts the audit is deferred untilflush()and that the caller is attributed toapps/demo/src/latest-event.ts. It fails when bundle-marker resolution is disabled.ci-selection.test.mjscovers the job selection.pnpm exec turbo run typecheck lint --filter=@bb/db --filter=@bb/server --filter=@bb/config --filter=@bb/scriptspasses.thread-pruning.test.ts(with or without the guard) andbuiltin-plugins.test.tshot-reload failed once each. Both pass on their own. Stop pruning tests depending on the 20 ms advance budget #7298 since removed the pruning tests' dependence on the 20 ms budget.🤖 Generated with Claude Code