Skip to content

feat: index freshness trust bundle#149

Merged
SutuSebastian merged 6 commits into
mainfrom
feat/index-freshness-trust-bundle
May 27, 2026
Merged

feat: index freshness trust bundle#149
SutuSebastian merged 6 commits into
mainfrom
feat/index-freshness-trust-bundle

Conversation

@SutuSebastian
Copy link
Copy Markdown
Contributor

@SutuSebastian SutuSebastian commented May 27, 2026

Summary

Ships the index freshness trust bundle (slices 1–3):

  • index_freshness on context — commit drift, watcher pending_sync, disk-ahead signals, single warning string
  • MCP / HTTP transport — metadata on tool responses (inline merge or @codemap/index_freshness block); HTTP headers on POST /tool/*; /health includes cheap freshness
  • Boot stderrcodemap mcp / serve warn when concerns remain after watch prime
  • Transport boot order — MCP/HTTP accept traffic only after watch prime completes

Canonical module: src/application/index-freshness.ts.

Test plan

  • bun test src/application/index-freshness.test.ts
  • bun test src/application/watcher.test.ts
  • bun test src/application/mcp-server.test.ts
  • bun test src/application/http-server.test.ts
  • bun run typecheck
  • Changeset added (patch)
  • Manual: codemap context with HEAD ≠ last_indexed_commitwarning populated
  • Manual: edit under codemap mcp --watch, call context during debounce → pending_sync: true

Surface commit drift, watcher pending sync, and disk-ahead signals on
codemap context / MCP context so agents know when structural queries may
lag the checkout. Watcher exposes debouncer state; slice 2 will extend
MCP/HTTP tool responses per plan.
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

🦋 Changeset detected

Latest commit: cbf71a8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stainless-code/codemap Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

Warning

Review limit reached

@SutuSebastian, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 42 minutes and 13 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9dd2e980-8bf9-499e-b79a-56cab6815a2e

📥 Commits

Reviewing files that changed from the base of the PR and between 6712af1 and cbf71a8.

📒 Files selected for processing (14)
  • .changeset/index-freshness-trust-bundle.md
  • docs/agents.md
  • docs/architecture.md
  • docs/roadmap.md
  • src/application/http-server.test.ts
  • src/application/http-server.ts
  • src/application/index-freshness.test.ts
  • src/application/index-freshness.ts
  • src/application/mcp-server.test.ts
  • src/application/mcp-server.ts
  • src/application/watcher.test.ts
  • src/application/watcher.ts
  • templates/agent-content/mcp-instructions.md
  • templates/agent-content/skill/50-maintenance.md
📝 Walkthrough

Walkthrough

This PR introduces index freshness metadata to MCP session bootstrapping, tracking repository synchronization state (commit drift, pending sync, watcher in-flight operations, optional disk drift) via a new computeIndexFreshness() module integrated into the context envelope, with watcher state export and comprehensive test coverage.

Changes

Index Freshness Metadata Feature

Layer / File(s) Summary
Index Freshness Contract & Documentation
src/application/index-freshness.ts, docs/agents.md, docs/plans/index-freshness-trust-bundle.md
Defines IndexFreshness and ComputeIndexFreshnessOpts types capturing pending sync, commit drift, watcher state, and optional disk drift signals. Documents the new context.index_freshness MCP field and formalizes design via a trust bundle plan covering interface contract, computation semantics, and staged rollout.
Watcher Sync State Export
src/application/watcher.ts
Introduces getWatchSyncState() export tracking pending debounced paths and in-flight reindex operations. Updates runWatchLoop to toggle watchReindexInFlight flag during onChange execution and stop() to clear watcher state.
Index Freshness Computation Logic
src/application/index-freshness.ts
Implements computeIndexFreshness() reading last indexed commit from DB and HEAD from git, combining watcher state into pending_sync/pending_paths/reindex_in_flight, computing commit_drift, optionally scanning disk changes via getChangedFiles() for unindexed changes and history incompatibility, and generating warning text via buildFreshnessWarning().
Context Envelope Integration
src/application/context-engine.ts
Extends ContextEnvelope with index_freshness: IndexFreshness field and populates it in buildContextEnvelope() by calling computeIndexFreshness(db, { include_disk_drift: true }).
Test Coverage
src/application/index-freshness.test.ts, src/application/mcp-server.test.ts
Adds test suite validating computeIndexFreshness() behavior (no drift when HEAD matches, drift detection with warnings, pending sync/debouncing), buildContextEnvelope() envelope enrichment with disk drift and warning states, and MCP server context tool assertion of index_freshness fields.

Possibly Related PRs

  • stainless-code/codemap#47: Both PRs modify watcher infrastructure around debounced reindexing and pending paths—this PR builds on the watcher mode implementation by adding getWatchSyncState() export and in-flight tracking used in the new ContextEnvelope.index_freshness field.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit's burrow, once lost in the dark,
Now glows with freshness—a metadata spark!
Commits drift about, pending paths align,
Watcher bells jingle—the index is fine!
MCP agents know now: stay fresh, stay in sync.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: index freshness trust bundle' accurately summarizes the main change - implementation of index freshness metadata as a trust bundle for agents.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/index-freshness-trust-bundle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

HTTP tools emit X-Codemap-* freshness headers without changing JSON bodies;
MCP merges index_freshness into object payloads and appends a second content
block for array-shaped query results. /health includes cheap freshness when DB exists.
…ce 3)

Warn on stderr when index_freshness concerns remain after bootstrap or
watch prime; document index_freshness fields and agent retry guidance in
MCP instructions. Marks trust-bundle plan and roadmap items shipped.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/application/index-freshness.test.ts`:
- Around line 97-120: The test creates a Jest spy on
indexEngine.getCurrentCommit but never restores it, which can leak into other
tests; capture the spy (e.g., const spy = spyOn(indexEngine,
"getCurrentCommit").mockReturnValue("");) and ensure you call spy.mockRestore()
when the test finishes (use a finally block around the async work or call
mockRestore after await handle.stop()), or alternatively add
jest.restoreAllMocks() in an appropriate afterEach; reference
indexEngine.getCurrentCommit and the test that calls
runWatchLoop/computeIndexFreshness to locate where to restore the spy.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3b4e3f0b-1241-4fa8-a130-8d52a76016ca

📥 Commits

Reviewing files that changed from the base of the PR and between df31144 and 6712af1.

📒 Files selected for processing (7)
  • docs/agents.md
  • docs/plans/index-freshness-trust-bundle.md
  • src/application/context-engine.ts
  • src/application/index-freshness.test.ts
  • src/application/index-freshness.ts
  • src/application/mcp-server.test.ts
  • src/application/watcher.ts

Comment thread src/application/index-freshness.test.ts
…-flight

Address PR review: expose watch prime as reindex_in_flight/pending_sync,
await watch ready before MCP connect / HTTP listen, skip redundant DB
reads for context payloads, move HTTP headers to http-server, and extend
tests/docs.
Patch changeset for user-facing index_freshness surfacing; delete the
shipped plan per docs-governance and point docs at architecture instead.
@SutuSebastian SutuSebastian changed the title feat(context): index freshness trust bundle (slice 1) feat: index freshness trust bundle May 27, 2026
Track queued inFlight batches so pending_sync does not false-negative
between serialized reindexes; always emit boot freshness warning after
watch prime settles, including on prime failure.
@SutuSebastian SutuSebastian merged commit 41a4184 into main May 27, 2026
11 checks passed
@SutuSebastian SutuSebastian deleted the feat/index-freshness-trust-bundle branch May 27, 2026 10:51
@github-actions github-actions Bot mentioned this pull request May 27, 2026
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