Summary
When batch --db <path> supplies the database for a child status command, the child reads counts and index metadata from that database but builds response metadata and Git freshness against the current working directory's canonical repository/database.
One response therefore mixes two repositories and can report a false head_changed: true.
Reproduction
Verified on origin/main at 8d537125aae747c1008ad31b3d59364cb43652f0 with cdidx 1.42.0.
Create or reuse a database for a different scratch project, then run from the CodeIndex repository:
{"command":"status","args":["--json","--compact"]}
{"command":"search","args":["anything","--json","--limit","1"]}
dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll batch \
--db /tmp/cdidx-batch-repro/.cdidx/codeindex.db \
--json-summary < /tmp/cdidx-batch-repro/commands.ndjson
Observed in the child status response:
- file/symbol counts and
indexed_head came from the scratch database;
metadata.db_path pointed at the canonical CodeIndex worktree database;
- runtime Git HEAD/freshness came from the CodeIndex worktree;
head_changed was consequently true even though a direct status --db /tmp/.../codeindex.db was consistent.
Expected behavior
A database inherited from the batch parent must be treated exactly like a child-explicit --db for:
- data reads;
- reported database path;
- project-root resolution;
- indexed/runtime Git provenance;
- freshness and readiness decisions;
- all JSON metadata and diagnostics.
No field in one child response should silently describe a different repository.
Implementation guidance
- Propagate a single resolved database/project context into child dispatch, not only a thread-static reader.
- Prefer injecting the inherited
--db into the child options or passing a typed resolved context through query execution.
- Do not re-resolve canonical DB/project metadata from CWD once a parent-pinned DB is active.
- Ensure nested/batched execution cannot leak context between child records, including exceptions and cancellation.
- Keep child-explicit
--db precedence and mismatch validation deterministic.
Likely implementation areas:
src/CodeIndex/Cli/BatchExecution.cs
src/CodeIndex/Cli/QueryCommandRunner.Database.cs
src/CodeIndex/Cli/QueryCommandRunner.Status.cs
- batch dispatch in
src/CodeIndex/Cli/QueryCommandRunner.Batch.cs
Required tests
Use two repositories/databases with deliberately different paths, file counts, indexed commits, and runtime HEADs.
Cover:
- parent-only
--db;
- child-explicit
--db;
- any permitted parent/child override or mismatch case;
- multiple children to prove no context leakage;
- text, regular JSON, compact JSON, and JSON summary provenance.
Assert every provenance/freshness field belongs to the same selected database. Add English and Japanese changelog fragments.
Regression history
This is a follow-up to #4354, which fixed mixed database behavior when a child supplied an explicit --db. The uncovered case is parent inheritance. It is also related to the CWD Git-provenance leak addressed in #152. Both are closed; no open exact duplicate was found.
Summary
When
batch --db <path>supplies the database for a childstatuscommand, the child reads counts and index metadata from that database but builds response metadata and Git freshness against the current working directory's canonical repository/database.One response therefore mixes two repositories and can report a false
head_changed: true.Reproduction
Verified on
origin/mainat8d537125aae747c1008ad31b3d59364cb43652f0with cdidx 1.42.0.Create or reuse a database for a different scratch project, then run from the CodeIndex repository:
dotnet ./src/CodeIndex/bin/Debug/net8.0/cdidx.dll batch \ --db /tmp/cdidx-batch-repro/.cdidx/codeindex.db \ --json-summary < /tmp/cdidx-batch-repro/commands.ndjsonObserved in the child status response:
indexed_headcame from the scratch database;metadata.db_pathpointed at the canonical CodeIndex worktree database;head_changedwas consequently true even though a directstatus --db /tmp/.../codeindex.dbwas consistent.Expected behavior
A database inherited from the batch parent must be treated exactly like a child-explicit
--dbfor:No field in one child response should silently describe a different repository.
Implementation guidance
--dbinto the child options or passing a typed resolved context through query execution.--dbprecedence and mismatch validation deterministic.Likely implementation areas:
src/CodeIndex/Cli/BatchExecution.cssrc/CodeIndex/Cli/QueryCommandRunner.Database.cssrc/CodeIndex/Cli/QueryCommandRunner.Status.cssrc/CodeIndex/Cli/QueryCommandRunner.Batch.csRequired tests
Use two repositories/databases with deliberately different paths, file counts, indexed commits, and runtime HEADs.
Cover:
--db;--db;Assert every provenance/freshness field belongs to the same selected database. Add English and Japanese changelog fragments.
Regression history
This is a follow-up to #4354, which fixed mixed database behavior when a child supplied an explicit
--db. The uncovered case is parent inheritance. It is also related to the CWD Git-provenance leak addressed in #152. Both are closed; no open exact duplicate was found.