Repository navigation
fix(search): replace ANY($n) array params with IN-list for Bun.SQL compat - #25
Conversation
…mpat Bun.SQL misserialises nested JavaScript arrays passed as PG ANY($n) parameters, causing "number of array dimensions (N) exceeds maximum allowed (6)" when the repo ID is ≥7. Replace with IN-list interpolation for validated integer repo IDs and individual $n placeholders for file paths. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryFixes a Confidence Score: 5/5Safe to merge; the bug fix is correct and the one edge case flagged is theoretical and doesn't affect any realistic input. Both changes correctly address the root cause (Bun.SQL nested-array misserialisation) by inlining validated integers and parameterising strings. Repo IDs are validated before interpolation throughout. The only concern is a P2 edge case where an empty resultRepoIds would produce IN () in query.ts — but in practice this path is unreachable because every file result maps to currentRepoId when r.repoId is absent. No P0/P1 issues exist. src/search/query.ts — add a resultRepoIds.length === 0 early-exit guard to future-proof the IN () edge case. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant searchPg
participant searchPgInTransaction
participant BunSQL as Bun.SQL (pg.unsafe)
Caller->>searchPg: searchPg(repoIds, ..., useBlobSchema=true)
searchPg->>searchPgInTransaction: withRepoScope → searchPgInTransaction(tx, ...)
Note over searchPgInTransaction: validate repoIds as integers
searchPgInTransaction->>BunSQL: buildBlobFileQuery → SELECT from file_blobs JOIN repo_files WHERE repo_id IN (1,2,...)
BunSQL-->>searchPgInTransaction: junctionRows[]
alt junctionRows.length > 0
Note over searchPgInTransaction: validate repoIdArr as integers, build pathPlaceholders $1,$2,...,$n
searchPgInTransaction->>BunSQL: SELECT id, repo_id, file_path FROM files WHERE repo_id IN (1,2,...) AND file_path IN ($1,$2,...)
BunSQL-->>searchPgInTransaction: idRows[] → idMap
end
searchPgInTransaction-->>Caller: SearchResult[]
Note over Caller: if includeSnippet:
Caller->>withSnippets: withSnippets(repoRoot, config, results, query, currentRepoId)
Note over withSnippets: validate resultRepoIds as integers, build pathPh $1,$2,...,$n
withSnippets->>BunSQL: withRepoScope → SELECT repo_id, file_path, skeleton_entries FROM files WHERE repo_id IN (101,...) AND file_path IN ($1,$2,...)
BunSQL-->>withSnippets: rows[] → entriesMap
withSnippets-->>Caller: SearchResult[] with snippets
Reviews (1): Last reviewed commit: "fix(search): replace ANY($n) array param..." | Re-trigger Greptile |
Adds a length check to prevent invalid `IN ()` SQL if resultRepoIds is ever empty. Practically unreachable today but future-proofs the path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
P2 empty
|
Both branches converged on the same fix (replace ANY($n) array params with IN ($1,$2,...) positional placeholders to work around Bun.SQL nested-array misserialisation). Resolved src/search/query.ts and src/search/search-pg.ts in favour of full positional parameterisation for both repo IDs and file paths, and kept the empty-resultRepoIds guard from main (PR #25). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Summary
cidx searchcrash: "number of array dimensions (N) exceeds the maximum allowed (6)" when searching repos withstore: pganduseBlobSchema: trueBun.SQL.unsafe()misserialises nested JS arrays passed as PGANY($n)parameters — the repo ID value gets interpreted as array dimensionsANY($n)withIN(...)interpolation for validated integer repo IDs and individual$nplaceholders for file paths in two queries (search-pg.ts,query.ts)Test plan
cidx search "main exports and public API" --include-skeleton --top-n 10 --format prettyfrom mpp-next (repo_id=101) returns results without errorbun run checkpasses (lint + typecheck)--include-snippetflag also works (exercises thequery.tsfix)🤖 Generated with Claude Code