Skip to content

fix(session-search): read oversized numeric file IDs on Windows - #20551

Merged
Jinwoo-H merged 2 commits into
mainfrom
OrcaWin/session-search-windows-file-id
Sep 14, 2026
Merged

Jinwoo-H merged 2 commits into
mainfrom
OrcaWin/session-search-windows-file-id

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​103
Prod 7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​699 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​697

ELI5

Windows can assign transcript files IDs larger than Node SQLite will return as JavaScript integers. The first indexing pass succeeds, but subsequent passes throw RangeError. Read those IDs in SQLite's REAL representation so the index can reconcile again.

What Changed

Cast dev and ino to REAL in SessionSearchStore.files() and SessionSearchIndexWriter.indexedFile(). Add 11 regression cases covering both reads, unsafe IDs in either field, existing INTEGER rows, null/partial pairs, reopen, unchanged-file decisions, append cursors, and replacement rejection.

Why

Discovery already uses ordinary numeric fs.stat through wslGatedStat; remote discovery also supplies numbers. fileIdentity() passes these numbers through to INTEGER-affinity columns. SQLite stores the integer represented by that double, and REAL recovers the same double without Node's unsafe-INTEGER read exception. This preserves the existing numeric identity contract, including already-written rows, without rebuilding or migrating the database. Offsets and sizes remain integers.

This is not lossless raw filesystem identity: distinct raw IDs that already round to the same number remain indistinguishable. The native repro demonstrated this before storage: raw NTFS inode 11821949025838489 became numeric integer 11821949025838488. Casting to TEXT or stringifying current stats cannot recover those bits. A lossless redesign would need bigint discovery, WSL/remote transport, and storage changes; it is outside this small crash fix. Distinct representable IDs still reject appends and force whole reads through the existing decision path.

No wire, execution-host, folder-workspace, root-refresh, or production-wiring changes. This branches directly from current main; it neither modifies nor stacks on #20516.

Linked Issue

Directly reported Windows bug; no standalone issue supplied. Existing code originated in #19687 (2c984bcdaa7) and #19751 (1fedda14caa), before #20516.

Visual Proof

N/A — database read fix with no visual or interaction changes.

Testing

  • Native Windows / Node 24.18.0 / NTFS / Core Ultra 7 270K Plus, isolated synthetic transcripts and databases only, ORCA_BACKGROUND_LAUNCH=1 throughout.
  • Before: new regression has 7 failures with the reported 25614222884620952 RangeError, independently covering both read sites. Native 5,000-file / 91,617,014-byte corpus indexes successfully, then full and recent reconciliation throw on 11821949025838488.
  • After: 108 focused tests pass, seven existing Windows skips. Suites: file-id, index-writer, index-consumer, index-pass, schema, indexer, store-is-memory, read-decision.
  • Native 5,000-file run including actual unsafe NTFS IDs: unchanged full/recent passes read zero transcripts; a warm parser appends once; a same-size, same-mtime rename replacement reads whole once; cold reopen reads zero; zero errors. Reused the repository's synthetic corpus and isolated-root fixtures; the local harness also recreates one synthetic file until NTFS supplies an unsafe ID.
  • pnpm tc:node, pnpm run check:code-quality:changed, targeted formatting, and git diff --check pass.

Focused tests ran with pnpm exec vitest run --config config/vitest.config.ts <suite paths>. Dependencies were installed with pnpm install --ignore-scripts; these tests use built-in node:sqlite and do not need the optional native postinstall. Linux/SSH execution and a full app build were not run.

Electron scanner IPC and external RPC verification

Added an opt-in reproduction under config/scripts/session-search-file-id-e2e/ (runner, windowless host, small external client, evidence verifier). No additional production changes. All overlay sources, profiles, SQLite DBs, logs and reports remain ignored under notes/search-ipc/.

Topology: fix source fe11afadf4e6e4e209d11e60ac1b005a2bbce788; LOCAL integration overlay #20516 head 9845bef63a6d0b80ec37af82b5b275287b8e17df, exported with git archive, never stacked or pushed onto this PR. #20514 CLI overlay was not used. An esbuild-bundled windowless Electron 43.7.0 host installs the production search enablement, shared scanner client, and production spawnAiVaultServiceProcess. It forks the real scanner entry with Electron's bundled Node 24.21.0, ELECTRON_RUN_AS_NODE=1, and real IPC.

External query boundary: separate Node 24.18.0 clients → real Windows named pipe → production UnixSocketTransport → production RpcDispatcher with AI_VAULT_METHODS → production search registry/child service → scanner IPC → production instance/indexer/SQLite engine. Status polling uses registered handlers directly. Search responses are independently checked against active FTS rows and filesystem/DB cursor, size and mtime.

Labelled fixture seams: isolated roots; JSON-backed getSettings supplied to real enablement/settings-change functions; background-launch child environment; passive child/read/IPC observation; explicit search RPC catalog with unused default catalog excluded; fixture runtime ID. No search-result mocks. Production runtime auth/metadata bootstrap is not started: transport is connected directly to dispatcher with a fixture token. This verifies a real external RPC socket, not full authenticated CLI/runtime startup. No UI, packaging, or SSH/relay claim.

Oracle Red (original SELECTs) Green (only two CAST projections)
Actual unsafe NTFS inode 9007199258837484 9007199258837328
Default-off, no DB; enable; initial marker query Pass Pass
Two default 20-second recent cycles First throws RangeError; reconciliation stops advancing Pass
Two full reconciliations and marker queries Not reached after expected failure Pass
Append marker Not reached Pass; observed append read
Equal-size/equal-mtime rename replacement Not reached Old marker absent, replacement present; observed replace read
Scanner restart, then fresh Electron host on same DB Not reached Queries and independent DB checks pass
Disable, append, reconcile, wait 21 seconds Not reached Disabled response; DB unchanged; new marker absent

Red and green use the same oracle. verify.cjs confirms equivalent oracle code after formatter normalization and SHA-256 manifests differing in exactly session-search-store.ts and session-search-index-writer.ts. Green has no search errors. Red host PID 18208 / scanner 5000; green host PIDs 17776 and 3948 / scanners 16892, 19428 and 11600. All scanner exits were 0, and a final OS check found none of the 20 recorded host/scanner/client PIDs running. Processes were closed through their owned handles/protocol; unrelated processes were untouched.

Exact commands from this workspace root:

$env:ORCA_BACKGROUND_LAUNCH='1'
pnpm exec esbuild config/scripts/session-search-file-id-e2e/run.ts --bundle --platform=node --format=esm --packages=external --outfile=notes/search-ipc/run.mjs
node notes/search-ipc/run.mjs red   # expected exit 1
node notes/search-ipc/run.mjs green # lifecycle and fresh-host restart: exit 0
node config/scripts/session-search-file-id-e2e/verify.cjs

Evidence: notes/search-ipc/red/1789365864644/, notes/search-ipc/green/1789365820413/, comparison.json, and cleanup.json. Reproduction README documents topology, seams, commands, and gaps. Harness typecheck, syntax checks, changed-code quality, formatting and diff checks pass.

Secondary coverage, independently run and reported by the supervising Codex agent on macOS at fe11afa: 68 focused tests pass; reverting only both SELECT changes makes 7/11 file-ID tests fail, including the reported RangeError. This is supervisor-reported evidence, separate from the Windows runs above.

Review

  • Small and focused; self-reviewed identity flow, compatibility, and performance.
  • Agent skill upstream boundary: not applicable.
  • No merge requested; ready for review against main.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

node:sqlite raises RangeError when a column returns an INTEGER outside Number.MAX_SAFE_INTEGER, so a files row whose dev/ino came from a rounded fs.stat double on Windows became unreadable once stored. The fix reads both identity columns through CAST(... AS REAL) so SQLite returns the original double.

  • indexedFile() cast — session-search-index-writer.ts now selects CAST(dev AS REAL)/CAST(ino AS REAL); the null/half-pair comparison logic is unchanged.
  • files() cast — session-search-store.ts applies the same casts, so a full row list no longer throws on an oversized ID.
  • Regression coverage — new session-search-file-id.test.ts exercises the unsafe-ID read, round-trip across reopen through files()/indexedFile/read-decision/consumer append, replacement rejection, and already-written INTEGER/half-pair rows.

Verification this run

I reproduced the RangeError on Node v24.19.0 and confirmed CAST(x AS REAL) round-trips the discovery-time double while the raw read throws. files() and indexedFile are the only production readers of dev/ino (retention, delete, and the pass do not select them), and the new assertions are exact, so they fail without the fix. The new file passes 11/11, the four related suites 53/53, and check-changed-code-quality.mjs reports zero findings.

The residual lossy-identity limitation (two raw IDs that already round to the same double stay indistinguishable) predates the PR and is explicitly scoped out — discovery rounds in fs.stat before storage, so this change introduces no new ambiguity.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 49aeefc6-3842-498c-8b31-e370a0e6ebf7

📥 Commits

Reviewing files that changed from the base of the PR and between fe11afa and 025bf49.

📒 Files selected for processing (5)
  • config/scripts/session-search-file-id-e2e/README.md
  • config/scripts/session-search-file-id-e2e/client.cjs
  • config/scripts/session-search-file-id-e2e/host.cjs
  • config/scripts/session-search-file-id-e2e/run.ts
  • config/scripts/session-search-file-id-e2e/verify.cjs

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


📝 Walkthrough

Walkthrough

The change casts dev and ino to REAL when session search reads file records. It adds tests for identity persistence across store reopen, replacement identities, oversized integer values, and null or incomplete identity pairs. It also adds a Windows Electron harness that verifies indexing, replacement, restart, disablement, and red/green results.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 025bf

The file-identity fix preserves reconciliation behavior for unsafe Windows IDs without an identified current-head regression.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 7 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and covers the change, rationale, testing, visual proof, review, and known limitations. However, the required Linked Issue section does not provide an issue link or issue n… Add the issue reference in the Linked Issue section, such as Fixes #<issue-number>. If no issue exists, create or link the required tracking issue before merging.
✅ Passed checks (3 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 and concisely identifies the main change: fixing oversized numeric file IDs during session-search reads on Windows.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 7 files. (1 skipped: 1 unsupported.)

Full details: Description check

Explanation

The description is detailed and covers the change, rationale, testing, visual proof, review, and known limitations. However, the required Linked Issue section does not provide an issue link or issue number.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

Test-only delta since the prior review at fe11afadf4: the production CAST(... AS REAL) fix and its unit test are untouched, and the new commit adds a Windows-only opt-in reproduction harness under config/scripts/session-search-file-id-e2e/.

  • run.ts — asserts native Windows, git archives an overlay export of #20516 head 9845bef63a6 plus the real scanner entry, bundles red/green variants with esbuild while injecting labelled local fixture seams, then runs lifecycle and restart phases against the Electron host.
  • host.cjs — windowless Electron host installs production search enablement, transport, and dispatcher; drives default-off → enable → recent/full reconciliation → append → rename-replacement → restart → disable, cross-checking every marker against an independent read-only SQLite connection and fs.stat.
  • client.cjs — external Node client querying over the real named pipe through aiVault.searchSessions.
  • verify.cjs — asserts red fails with the expected RangeError, green reports succeed with real IPC and a distinct client PID, both oracles are identical after formatter normalization, and exactly the two SELECT source files differ.
  • README.md — topology, fixture seams, and the boundaries deliberately not exercised.

The new files are coherent as an evidence harness: red and green differ only in the two SELECT projections, verify.cjs pins that with a hash diff, and no production path changed in this commit. The residual lossy-identity limitation and the harness's pin to an unmerged external commit remain as documented, opt-in scope rather than regressions.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@Jinwoo-H
Jinwoo-H merged commit 243f443 into main Sep 14, 2026
28 checks passed
@Jinwoo-H
Jinwoo-H deleted the OrcaWin/session-search-windows-file-id branch September 14, 2026 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants