Skip to content

test(history): corrupt the index the health query plan actually reads - #7995

Merged
lidge-jun merged 1 commit into
devfrom
fix/request-history-health-plan-20261030
Oct 30, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/request-history-health-plan-20261030

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

Fixes the macOS failure in manual Cross-platform CI run 41050393474 (lane=all, dev ac0833bc5), macOS 1/4: request-history integrity lifecycle (#7966) > routing health marks query corruption for repair and recovers current historical evidence (tests/usage/request-history-integrity.test.ts:413). The test expected {} and received live health evidence.

The test corrupts idx_requests_model and expects the routing-health query to read it. That query (WHERE provider = ? AND model = ? AND timestamp >= ? ORDER BY timestamp DESC) can be served by the provider, model or timestamp index. Which one the SQLite planner picks depends on the build: Bun bundles SQLite 3.53.4 on Linux and Windows, where the plan is SEARCH requests USING INDEX idx_requests_model, while macOS uses the system library. On macOS the query never touched the damaged B-tree and correctly returned healthy rows. The other corruption cases, which filter by model only, passed on the same macOS job, so the corruption mechanism itself works there.

The test now asks EXPLAIN QUERY PLAN which index this build uses for that query shape and corrupts that index. It asserts that the plan names an idx_requests_* index, so a full-scan plan fails loudly. The probe statement is prepared and finalized; a cached query() statement held a table lock and made the later rebuild fail with SQLITE_LOCKED. Product code is unchanged.

Verification

  • bun test tests/usage/request-history-integrity.test.ts on Windows (Bun 1.4.4, SQLite 3.53.4): 20 pass / 0 fail.
  • Planner simulation (scratch copies, not committed): fake sqlite_stat1 rows made idx_requests_model unselective so the planner picks another index, as on macOS. The previous test body then failed with the same signature as CI (- Expected -1 / + Received +6), and the new body passed.
  • NOT RUN: native macOS locally (no Mac host). The batched lane=all dispatch on dev after merge covers macOS. Full local suite not run: the host is shared with other test lanes.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (Test-only.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. (Test-only; no security surface.)

The routing-health integrity case corrupted idx_requests_model and expected the health query to hit it. The query can be served by the provider, model or timestamp index, and macOS's system SQLite picks a different one than Bun's bundled SQLite, so macOS 1/4 of lane=all run 41050393474 read healthy rows. Ask EXPLAIN QUERY PLAN which index this build uses and corrupt that one.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 30, 2026 12:08
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 2 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between a2ae482 and 468d152.

Files selected for processing: 1
  • tests/usage/request-history-integrity.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Oct 30, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration (lane L1, cross-platform CI). Squash-merging into dev under the maintainer-integration exception in MAINTAINERS.md. This records the decision; it is not a self-approval.

Exact head: 468d152b9aaec6792f939f28314c9f6cbff5c68a
Exact-head CI: CI run 41053074502: gates, test changed, storage policy, api usage and ci success; enforce-target, hygiene and label pass.
Review: a fresh independent reviewer, not the author, returned PASS at this head. It found the planner explanation consistent with the provider, model and timestamp indexes the health query can use, and found the statement finalized. It confirmed that the plan assertion fails loudly when no index is used and that the original {}, repair and canonical-bytes assertions are kept. It ran the file on Windows: 20 pass, 0 fail. It noted a maintenance risk: the EXPLAIN mirror follows this test's input (no accountRef), so a change to the production query shape may require updating it.
Union check vs current dev: one existing test file is modified. There is no layout or baseline entry, and git merge-tree is clean.
macOS confirmation comes from the next batched lane=all dispatch on dev.

@lidge-jun
lidge-jun merged commit b692a8a into dev Oct 30, 2026
26 checks passed
@lidge-jun
lidge-jun deleted the fix/request-history-health-plan-20261030 branch October 30, 2026 12:22
lidge-jun added a commit that referenced this pull request Oct 30, 2026
)

The routing-health case read the index before corrupting it and relied on PRAGMA shrink_memory to evict the cached pages. macOS's system SQLite kept them, so the read after corruption was served from cache (macOS 2/4 of lane=all run 41056253802, after #7995). Reopen the index after the pre-check so the corruption lands on a connection that has not cached it, like the other corruption cases.

Co-authored-by: JUN <243035832+lidge-jun@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant