Skip to content

feat(mcp): report truthful index freshness from checkout evidence - #1561

Open
tmonestudio wants to merge 4 commits into
DeusData:mainfrom
tmonestudio:codex/bt-240-truthful-index-freshness
Open

feat(mcp): report truthful index freshness from checkout evidence#1561
tmonestudio wants to merge 4 commits into
DeusData:mainfrom
tmonestudio:codex/bt-240-truthful-index-freshness

Conversation

@tmonestudio

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes verbose index_status distinguish the live checkout from the generation that was actually indexed.

  • persists indexed_checkout_sha only at the staged-generation publication boundary
  • reports bounded tracked/untracked checkout evidence
  • returns machine-readable current, stale, or fail-closed unknown
  • preserves the lean default response and legacy databases
  • handles Windows porcelain-v2 rename/copy records and bounded git subprocess failures

This is intentionally separate from #1181 and #1065.

Local verification

  • production Windows/MinGW build passed with the repository warnings-as-errors flags
  • focused test runner: git_context mcp store_nodes exited 0
  • existing database smoke: 27,369 nodes / 78,605 edges; legacy generation returned unknown/indexed_checkout_unavailable
  • database SHA-256 was identical before and after the smoke

Checklist

  • Every commit is signed off (git commit -s)
  • Full test suite is delegated to CI
  • Focused tests pass locally
  • New behavior is covered by reproduce-first tests

No runtime binary, cache, ACL, or corpus was modified.

A live checkout SHA is not proof of the generation that produced graph
content, so the freshness verdict must come from the indexed-checkout
identity recorded with the DB. Legacy DBs record no such identity: verbose
index_status now exposes the graph generation separately (indexed_generation)
and fails closed with verdict=unknown, indexed_checkout_sha=null and
reason=indexed_checkout_unavailable.

The default status call stays lean and the freshness block is report-only —
it never triggers indexing. Add focused coverage for the fail-closed verdict
and for its omission from the default output.

Signed-off-by: Leonardo trindade miranda <tmonestudio@gmail.com>
Record the frozen git HEAD at the same successful staged-generation boundary
as graph coverage. cbm_coverage_meta_t gains indexed_checkout_sha; new
writable DBs create a nullable indexed_checkout_sha column and existing
writable DBs are migrated idempotently in init_schema, while read-only
legacy DBs without the column still open, read and report no identity
instead of erroring. coverage_replace_ex writes/updates the SHA inside its
existing transaction, so failure/rollback retains the prior identity.

Full, delta-incremental and legacy-incremental generation templates set it
from the pipeline's refreshed git context (NULL/empty for non-git repos).

index_status freshness now derives from the recorded identity: no indexed
SHA -> unknown/indexed_checkout_unavailable; differs from the live git HEAD
-> stale/indexed_checkout_mismatch; equal -> current. Emits indexed_generation,
indexed_checkout_sha, checkout_sha, a stable reasons array and
recommended_action; stays verbose-only and read-only.

Add store round-trip/rollback coverage and MCP verdict tests for matching
current and mismatched stale (git fixtures, platform-skipped on Windows).

Signed-off-by: Leonardo trindade miranda <tmonestudio@gmail.com>
Add cbm_git_worktree_status: parse git status --porcelain=v1 -z
--untracked-files=all record-by-record over a bounded chunk buffer
(4K chunks, 16K field cap). Counts advance for the whole stream while
only max_samples paths per class (tracked/untracked) are retained;
exceeding the cap sets *_truncated. Rename/copy records consume their
second NUL-separated source path without counting it, so one rename
counts once. available is true ONLY when git exited 0 and every record
parsed cleanly; any shell-unsafe path, spawn failure, nonzero exit,
malformed/oversized/trailing record leaves available=false with zero
counts - callers must never read that as a clean worktree.

Index the snapshot into the verbose freshness block (status_available,
tracked_changes{count,paths,truncated}, untracked_source{...}). Verdict
composition: clean matching SHA -> current; tracked changes or SHA
mismatch -> stale; untracked-only, unavailable status or missing live
HEAD -> unknown. Reasons array keeps every applicable code in stable
order with the dominant reason first; recommended_action derives from
the verdict. Report-only, verbose-only, read-only: no indexing or
mutation is ever triggered.

Owner gates corrected: restored missing #endif around canonical_root
tests; rename/copy detection checks both XY columns; introduced
cbm_pipeline_indexed_checkout_sha accessor because cbm_pipeline_t is
opaque in pipeline_incremental.c (HEAD accessed git_ctx.head_sha
directly and could not compile); Windows tests force git add -f so a
user's global excludes cannot silently drop the tracked fixture;
rollback test now mutates row detail so the shadow rebuild actually
executes before the replace is rolled back.

Tests now shell out through cbm_popen (isolated spawn) instead of
system(), so the git-backed freshness/status tests run on Windows too;
only a genuinely missing git skips. Prior SHA persistence (staged-
generation boundary) is the anchor the new worktree status refines.

Signed-off-by: Leonardo trindade miranda <tmonestudio@gmail.com>
Signed-off-by: Leonardo trindade miranda <tmonestudio@gmail.com>
@tmonestudio
tmonestudio requested a review from DeusData as a code owner August 12, 2026 04:21
@github-actions

Copy link
Copy Markdown

Thanks for opening this — it has been seen, and it is queued.

This note is automated, but it is not a brush-off: it exists so you know where your PR stands instead of having to guess from silence.

Current review status: working through a backlog. 0.9.1-rc.1 is out, so the release freeze that held reviews is over — but it left a large queue of open pull requests behind it, and we are reading through them oldest-first. The background is in discussion #1144.

What that means for this PR, concretely:

  • It will not be closed for inactivity. No stale bot touches pull requests here.
  • It may still sit a while before a human reads it. That is on us, not on you.
  • Older PRs are read first, so a recent one is not being skipped — it is behind a queue.

Things that will genuinely speed it up whenever review does happen:

  • Keep it rebased on main — the tree is moving quickly right now, and a conflicting branch cannot be reviewed as the diff you intended.
  • Get CI green, or say which failures you believe are pre-existing.
  • Keep the change to one claim. Bundled features and refactors get split before they get merged, which costs you a round trip.
  • Every commit needs a sign-off (git commit -s) — CI enforces DCO.

If this fixes a bug, a reproduction we can run is worth more than a description of the symptom.

Thanks for contributing, and sorry in advance for the wait.

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.

1 participant