Conversation
| const rows = await db.execute<FsRow>( | ||
| "SELECT * FROM agent_os_fs_entries WHERE path LIKE ? AND path != ?", | ||
| `${prefix}%`, | ||
| "SELECT * FROM agent_os_fs_entries WHERE substr(path, 1, length(?)) = ? AND path != ?", |
There was a problem hiding this comment.
🟠 Medium · Literal prefix lookups still scan the entire filesystem table
Applying substr to path makes the path index unusable; EXPLAIN QUERY PLAN reports SCAN agent_os_fs_entries for this predicate. Because this helper backs every directory read and emptiness check, each operation examines every VFS entry, and the identical rename predicate has the same cost. Use an indexable binary range instead: since every normalized prefix ends in /, bind the lower bound to prefix and the exclusive upper bound to `${prefix.slice(0, -1)}0`, then apply the same predicate to the descendant query. This remains literal and case-sensitive while allowing the existing path index to bound the scan.
This branch has not been deployed
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.
Description
createDatabaseVfsfound a directory's children and descendants withpath LIKE '<dir>/%'. In SQLiteLIKE,_and%are wildcards and ASCII letters match without regard to case, so a directory named/my_diralso matched/myXdir/...and/MY_DIR/....readDir("/my_dir")listed files from those sibling directories,removeDirfailed withENOTEMPTYon an empty directory whose name has_or%, andrename("/work_dir", "/moved")also moved the files of/workXdirand/Work_Dirinto/moved.substr(path, 1, length(?)) = ?.database-vfs.test.ts, which runs the VFS against a real in-memory SQLite database (node:sqlite, as inunstable/migrations.test.ts).Note: the same
LIKEprefix pattern appears in the Rust port in the draft #5309.Type of change
How Has This Been Tested?
pnpm vitest run src/agent-os/fs/database-vfs.test.tsinrivetkit-typescript/packages/rivetkit. Onmainall 3 tests fail:readDirreturns[ 'other.txt', 'upper.txt', 'own.txt' ],removeDir("/a_b")throwsENOTEMPTY, and the renamed directory containssibling.txtandupper.txt. With this change all 3 pass.biome checkis clean on the changed files.tsc --noEmitfor the package reports no errors in the changed files.vitest run srcfor the package: the only failures are the same 3 that fail onmainin my local setup (inline-websocket-adapter.test.tsandruntime.test.tsfail to load, and oneworkflow/driver.test.tscase), so this change adds no new failures.Checklist: