codebase-memory-mcp icon indicating copy to clipboard operation
codebase-memory-mcp copied to clipboard

hook-augment returns 0 bytes when payload cwd is an indexed linked worktree

Open bmcnaboe opened this issue 3 months ago • 4 comments

Repro

git worktree add ../wt -b test
# index both the main checkout and ../wt separately

Pipe a PreToolUse payload into hook-augment, varying only the payload's cwd field (process cwd held constant, deadline raised to 8000ms to rule out #1335):

process cwd payload cwd bytes
main main 663
main worktree 0
worktree main 663
worktree worktree 0

The payload's cwd alone decides the outcome; the process's own cwd is irrelevant.

Expected

A payload whose cwd is an indexed linked worktree should return that worktree's own project context — the worktree has its own full index (confirmed via index_status, is_worktree=true, resolving canonical_root back to the main checkout's .git), and search_graph against the worktree's project directly returns correct, non-stale results.

Actual

Empty output (exit 0, nothing on stderr, hook-augment-timeouts.log unaffected) at both the default 2s deadline and an 8s deadline — this is not the deadline/fingerprint issue in #1335, it's a clean no-output path with its own project already indexed.

Notes

index_status already resolves worktree paths correctly (is_worktree, git_common_dir, canonical_root) — the hook's own cwd → project resolution appears not to use that same logic, so an indexed linked worktree's payload cwd fails to resolve to its project. Distinct from #1335 (that's a timeout under the SHA-256 fingerprint cost); this is a resolution defect independent of timing.

Happy to share the full measurement writeup if useful.

bmcnaboe avatar Aug 20 '26 02:08 bmcnaboe

Thanks for the careful reproduction and for separating this from the timeout case — that distinction is genuinely helpful.

I traced this on current main. With both the main checkout and linked worktree indexed under their path-derived project names, the hook should probe the linked worktree project directly before any registry fallback. I could not derive an honest failing test from the current snapshot, so could you please share the following (local usernames and paths may be redacted consistently):

  • the list_projects entries for both checkouts, including project name and root_path;
  • the exact absolute cwd field in the hook payload;
  • the raw hook JSON for one failing request, especially tool_name and tool_input.pattern;
  • the exact direct search_graph arguments that succeed;
  • confirmation that the hook and direct query use the same binary/version and CBM_CACHE_DIR.

Those values will let us distinguish project-key mismatch, payload routing, and environment mismatch and turn this into a deterministic regression. Thank you again.

DeusData avatar Aug 20 '26 07:08 DeusData

Thanks for the report! To move this forward we need a bit more so we can reproduce it ourselves:

  • the codebase-memory-mcp --version you're on
  • the exact steps or command you ran
  • a public repo (or a small dummy snippet) that shows the problem — please don't paste proprietary code

Once that's here we'll pick it straight back up. Heads-up: issues left awaiting-reporter are automatically closed after a few weeks of silence, but a comment reopens the door anytime.

github-actions[bot] avatar Aug 20 '26 07:08 github-actions[bot]

Reporter follow-up: the 0-byte case above was measured on v0.10.5. Re-testing on v0.10.8-based main with two real linked worktrees off the same repo, it no longer reproduces — a payload cwd inside the indexed worktree (or a subdirectory of it) resolves to that worktree's own project, an unindexed worktree gets the explicit "no indexed graph project matched" notice rather than 0 bytes, and the main checkout is unchanged. Same binary and CBM_CACHE_DIR for the hook and the direct query.

So this was fixed somewhere between v0.10.5 and v0.10.8; #1768 pins the behaviour as regression tests on top of main. Fine to close this as not reproducible on current versions — #1768 stands on its own.

bmcnaboe avatar Sep 03 '26 12:09 bmcnaboe

Thank you for re-testing this against the v0.10.8-based main and for reporting that the original zero-byte behavior no longer reproduces.

I have removed awaiting-reporter. Since indexed linked-worktree paths now resolve to their own project and unindexed worktrees return an explicit no-match result, the reported defect is resolved on current versions. PR #1768 remains the regression-test record for that contract.

Closing this as completed. Thank you for coming back with the decisive retest instead of leaving the old-version result ambiguous.

DeusData avatar Sep 03 '26 18:09 DeusData