Skip to content

Cache immutable MCP source archives - #1792

Merged
xeophon merged 1 commit into
feat/nano-as-v1from
codex/cache-mcp-source-archives
Jun 21, 2026
Merged

Cache immutable MCP source archives#1792
xeophon merged 1 commit into
feat/nano-as-v1from
codex/cache-mcp-source-archives

Conversation

@xeophon

@xeophon xeophon commented Jun 21, 2026

Copy link
Copy Markdown
Member

Overview

Cache immutable source archives used to provision sandboxed MCP tool and user runtimes, avoiding repeated tar and gzip work within an eval worker.

Reasoning

Each sandbox launch uploads the same Verifiers checkout and environment package. Archive construction happens synchronously while evaluating the arguments to runtime.write, before the coroutine can yield, so rebuilding an identical archive adds startup latency, blocks the event loop, and allocates a fresh compression buffer for every runtime.

An eval worker already treats imported code as a startup snapshot. This change applies the same lifetime to its source archives: VF_BUILD_INPUTS and the member selector become immutable tuples, and _tar_source is cached by source root plus member tuple. Different roots and filters remain distinct cache keys. Tar contents, exclusions, sandbox upload bytes, extraction, and installation behavior are unchanged.

If development-time source mutation becomes a supported workflow, the cache should move to an explicit shorter lifecycle rather than refreshing process-global data implicitly.

Performance impact

A five-call repeated-build benchmark used the 624,058-byte Verifiers archive containing 353 tar members. Timings use time.perf_counter; transient allocations use tracemalloc.

Metric Before After Saved
Median wall time per repeated call 236.046750 ms 0.006334 ms 236.040416 ms (99.9973%)
Synchronous event-loop stall per repeated call 236.046750 ms 0.006334 ms 236.040416 ms (99.9973%)
Five-call wall time 1,200.168833 ms 0.033917 ms 1,200.134916 ms (99.9972%)
Median peak traced allocation 1,277,922 bytes 80 bytes 1,277,842 bytes (99.9937%)

The first build for each distinct key is unchanged. A cached key retains its immutable archive payload (624,058 bytes in this workload) for the worker lifetime, while upload volume remains unchanged.


Note

Low Risk
Process-local memoization only; tarball bytes and sandbox install paths are unchanged, with stale archives possible only if on-disk source changes mid-worker (already the eval snapshot model).

Overview
Caches gzipped source archives used when _install_in_sandbox uploads the Verifiers checkout and env package, so repeated sandbox launches in the same worker do not rebuild identical tarballs on every runtime.write.

_tar_source is wrapped with functools.cache, keyed by source Path and the member filter tuple. VF_BUILD_INPUTS and the default member list are tuples so they are hashable cache keys. Tar layout, exclusions, and upload/install behavior are unchanged.

The docstring notes that archives are treated like the worker’s startup code snapshot; if live source edits become supported, the cache should move to an explicit shorter lifecycle instead of process-global reuse.

Reviewed by Cursor Bugbot for commit 587e25d. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Cache _tar_source results to avoid re-tarring identical MCP source archives

Decorates _tar_source in launch.py with @functools.cache so repeated calls with the same (src, members) arguments return cached bytes. Also converts VF_BUILD_INPUTS from a list to a tuple to support hashability. Risk: passing a list for members will now raise TypeError at call time due to cache key hashing requirements.

Macroscope summarized 587e25d.

@macroscopeapp

macroscopeapp Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Simple performance optimization adding memoization to an internal tarball-creation helper. Changes are mechanical (list→tuple for hashability) with appropriate documentation of caching assumptions.

You can customize Macroscope's approvability policy. Learn more.

@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: 587e25d9fe

ℹ️ 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 verifiers/v1/mcp/launch.py
@xeophon
xeophon merged commit 9d8ef41 into feat/nano-as-v1 Jun 21, 2026
5 checks passed
pull Bot pushed a commit to Stars1233/verifiers that referenced this pull request Jun 23, 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