Skip to content

feat(mcp): --output-max-size with post-response disk eviction#41031

Open
Skn0tt wants to merge 2 commits into
microsoft:mainfrom
Skn0tt:feat-output-max-size-disk
Open

feat(mcp): --output-max-size with post-response disk eviction#41031
Skn0tt wants to merge 2 commits into
microsoft:mainfrom
Skn0tt:feat-output-max-size-disk

Conversation

@Skn0tt
Copy link
Copy Markdown
Member

@Skn0tt Skn0tt commented May 28, 2026

Alternative to #41021 implementing @pavelfeldman's suggestion: examine the response for new output-folder entries and remove oldest entries on disk, instead of intercepting at the write layer with OutputFile/OutputDir.

Approach

After Response.serialize() builds its sections, _enforceOutputBudget() recursively lists the output directory, sorts by mtime ascending, and unlinks oldest files until total <= outputMaxSize. Files written by the current Response are tracked in _writtenFiles and never evicted, so artifacts the response references stay readable.

Trade-offs vs #41021

  • +73 / -0 lines vs +391 / -44. No new types, no evictable plumbing.
  • Trace and sessionLog need no special-casing — their mtime bumps keep them young, naturally last to evict.
  • Sees externally-written files (downloads, trace bundles); they count against the budget and evict by age.
  • Self-healing on external filesystem changes.
  • Cap can briefly exceed during a single tool call that writes a large artifact; feat(mcp): add --output-max-size for output dir eviction #41021 pre-evicts so the cap is a hard ceiling.
  • Weaker pin guarantee for session.md and tracing — recency-based instead of flag-based.

…aft)

Alternative to microsoft#41021 implementing Pavel's suggestion: instead of
intercepting writes in code with an OutputFile/OutputDir layer, let
tools write whatever and prune the outputDir from disk after each
tool call.

After Response.serialize() builds its sections, _enforceOutputBudget
recursively lists outputDir, sorts by mtime ascending, and unlinks
oldest files until total <= outputMaxSize. Files written by the
current Response are tracked in _writtenFiles and never evicted, so
artifacts referenced in the response stay readable.

Config: same outputMaxSize field, --output-max-size CLI flag, and
PLAYWRIGHT_MCP_OUTPUT_MAX_SIZE env var as microsoft#41021.

Trade-offs vs microsoft#41021:
- ~74 lines added vs ~390; no new types or evictable plumbing.
- Trace/sessionLog need no special-casing — their mtime bumps keep
  them young, naturally last to evict.
- Sees externally-written files (downloads, trace bundles) — they
  count against the budget and evict by age.
- Self-healing on external fs changes.
- Cap can briefly exceed during a single tool call that writes a
  large artifact; microsoft#41021 pre-evicts so the cap is hard.
- Weaker pin guarantee for session.md (recency-based, not flag-based).
@Skn0tt Skn0tt changed the title feat(mcp): --output-max-size with post-response disk eviction (draft) feat(mcp): --output-max-size with post-response disk eviction May 28, 2026
@Skn0tt Skn0tt marked this pull request as ready for review May 28, 2026 07:18
@github-actions
Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [webkit] › mcp/output-max-size.spec.ts:22 › evicts oldest evictable files before write exceeds cap, pinned session.md survives @mcp-macos-latest-webkit

7232 passed, 1113 skipped


Merge workflow run.

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