Skip to content

mcpx: one content-addressed cache mechanism (internal/cache) — #1908 Approach C - #2555

Merged
dezren39 merged 1 commit into
mainfrom
queue/3148-1908-mcpx-cache
Oct 30, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/3148-1908-mcpx-cache

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

mcpx: one content-addressed cache mechanism (internal/cache) — #1908 Approach C

New pkgs/mcpx/internal/cache package implementing Approach C of #1908:

  • Layout //; keys are SHA-256 of length-prefixed
    canonical inputs (cache.Key/KeyString). Entries are built in a temp
    dir and renamed into place, so readers never see a half-written entry.
  • Leases pin an entry while an exec uses it (lease file inside a
    directory entry, beside a file entry named for it); eviction never
    removes a leased entry. Leases older than cache.leaseStaleAge are
    treated as abandoned by a crashed process.
  • Eviction by total bytes and age (cache.maxBytes / cache.maxAge, new
    defaults section), plus an optional per-kind entry count for the
    small kinds. Any writer evicts its own kind on store — no separate
    evictor process to race.

Runner migration: prunePrograms, pruneWorkDirs and pruneEntries are
now thin adapters onto cache.Prune (pattern + keep + limits), keeping
their locations and historical count bounds (exec.programs/workDirs/
entries, now limits of the mechanism). pruneWorkDirs also gains the
shared byte/age bounds. Run() acquires leases on the workdir, the
generated program and the launcher/entry it executes.

Surface: mcpx cache lists every kind/entry (size, leased, path;
--json supported), mcpx cache prune runs eviction with the
configured bounds, mcpx cache remove <kind> <key> deletes one entry
and refuses while leased. Local-only, never starts the daemon — the
status decision from #1866. docs/parity.md regenerated.

Open questions from #1908, answered here:

Tests: new internal/cache unit tests (key canonicalisation, put/get
hit, evict-by-bytes, evict-by-age, leased entry survives eviction,
stale lease does not pin, count prune with pattern+keep, remove
refuses leased, list). Laptop: go test ./internal/cache ./internal/runner
./internal/cli ./internal/defaults (targeted) pass; binary smoke test
of mcpx cache list/remove/prune passes.

Pre-existing failures on clean main, unchanged by this PR (verified
against a pristine origin/main worktree): internal/defaults
TestEveryDocumentationLinkResolves, internal/settings
TestEveryDocumentHasAChapter.

No tenant issue (#1913/#1915/#1921/#1917) is closed by this PR; they
integrate under their own issues.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…Approach C

New pkgs/mcpx/internal/cache package implementing Approach C of #1908:

- Layout <cache>/<kind>/<key>; keys are SHA-256 of length-prefixed
  canonical inputs (cache.Key/KeyString). Entries are built in a temp
  dir and renamed into place, so readers never see a half-written entry.
- Leases pin an entry while an exec uses it (lease file inside a
  directory entry, beside a file entry named for it); eviction never
  removes a leased entry. Leases older than cache.leaseStaleAge are
  treated as abandoned by a crashed process.
- Eviction by total bytes and age (cache.maxBytes / cache.maxAge, new
  defaults section), plus an optional per-kind entry count for the
  small kinds. Any writer evicts its own kind on store — no separate
  evictor process to race.

Runner migration: prunePrograms, pruneWorkDirs and pruneEntries are
now thin adapters onto cache.Prune (pattern + keep + limits), keeping
their locations and historical count bounds (exec.programs/workDirs/
entries, now limits of the mechanism). pruneWorkDirs also gains the
shared byte/age bounds. Run() acquires leases on the workdir, the
generated program and the launcher/entry it executes.

Surface: `mcpx cache` lists every kind/entry (size, leased, path;
--json supported), `mcpx cache prune` runs eviction with the
configured bounds, `mcpx cache remove <kind> <key>` deletes one entry
and refuses while leased. Local-only, never starts the daemon — the
status decision from #1866. docs/parity.md regenerated.

Open questions from #1908, answered here:
- Who evicts: any writer, on store, for its own kind; the lease is
  what makes that safe (no daemon evictor).
- Pruners: all three move onto the mechanism (above); their built-in
  count bounds become mechanism limits.
- Daemon schema cache (cacheVersion, internal/daemon/registry.go):
  does NOT join in this PR — it is a single file keyed by config
  fingerprint (Paths.SchemaCachePath), not a per-kind entry set, and
  changing its invalidation is #1866 item 3 territory. Recorded as a
  deliberate non-join, not dropped.
- #1913 prepared deps: tenants should store prepared trees via
  cache.Put under their own kind and let bytes/age eviction bound
  them; whether to lean on runtime-native caches instead stays
  #1913's call — the mechanism supports either (a manifest-only
  entry is just a small entry).

Tests: new internal/cache unit tests (key canonicalisation, put/get
hit, evict-by-bytes, evict-by-age, leased entry survives eviction,
stale lease does not pin, count prune with pattern+keep, remove
refuses leased, list). Laptop: go test ./internal/cache ./internal/runner
./internal/cli ./internal/defaults (targeted) pass; binary smoke test
of `mcpx cache` list/remove/prune passes.

Pre-existing failures on clean main, unchanged by this PR (verified
against a pristine origin/main worktree): internal/defaults
TestEveryDocumentationLinkResolves, internal/settings
TestEveryDocumentHasAChapter.

No tenant issue (#1913/#1915/#1921/#1917) is closed by this PR; they
integrate under their own issues.
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 04:20
@coderabbitai

coderabbitai Bot commented Oct 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 250990b3-5e81-4747-9ac7-33e29c222c55
Commits

Reviewing files that changed from the base of the PR and between 069aff5 and 962a275.

Files selected for processing: 9
  • pkgs/mcpx/docs/parity.md
  • pkgs/mcpx/internal/cache/cache.go
  • pkgs/mcpx/internal/cache/cache_test.go
  • pkgs/mcpx/internal/cli/cache.go
  • pkgs/mcpx/internal/cli/dispatch.go
  • pkgs/mcpx/internal/cli/manual.go
  • pkgs/mcpx/internal/defaults/defaults.go
  • pkgs/mcpx/internal/defaults/defaults.json
  • pkgs/mcpx/internal/runner/runner.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T04:23:59.904898Z 962a275 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 962a2757d5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread pkgs/mcpx/internal/cache/cache.go Resolved
Comment thread pkgs/mcpx/internal/cache/cache.go Resolved
Comment thread pkgs/mcpx/internal/cache/cache.go Resolved
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