MCP: tool-result bytes double-capped at 8KB — replay log loses original blob; doc-comment is wrong #21
Closed
opened 2026-05-12 19:04:54 +00:00 by KofTwentyTwo
·
1 comment
No Branch/Tag Specified
develop
ci/secrets-historical-baseline
feature/security-findings-2026-10
dependabot/npm_and_yarn/webview/npm_and_yarn-3ac77625be
dependabot/npm_and_yarn/webview/packages/bus/npm_and_yarn-c86b58a346
dependabot/npm_and_yarn/webview/vitejs/plugin-react-6.0.2
dependabot/npm_and_yarn/webview/vite-8.0.13
dependabot/npm_and_yarn/webview/zustand-5.0.13
dependabot/npm_and_yarn/webview/types/node-25.9.1
dependabot/npm_and_yarn/webview/vitest-4.1.6
dependabot/github_actions/actions/setup-node-6
dependabot/github_actions/github/codeql-action-4
dependabot/github_actions/actions/checkout-6
dependabot/github_actions/actions/cache-5
dependabot/github_actions/pnpm/action-setup-6
feat/local-first-llm-routing
docs/local-first-llm-routing-spec
fix/v0.2-wave-1-code-fixes
docs/v0.2-wave-1-doc-drift
docs/handoff-2026-05-14
docs/multi-runner-inventory
docs/ollama-baseline-58
fix/ci-env-harness-sqlite-voice-warmup
fix/ci-xcode-26-and-batcher-timing
chore/typecheck-blocking
fix/hud-typecheck-strict-undefined
wip/voice-log-menu-stash4
v0.1.0-dev.71
v0.1.0-dev.68
v0.1.0-dev.64
v0.1.0-dev.50
Labels
Clear labels
area:agent
area:build
area:bus
area:devtool
area:hud
area:logging
area:mcp
area:memory
area:vision
area:voice
audit-finding
bug
carry-forward
comment-cleanup
dependencies
documentation
duplicate
enhancement
epic
good first issue
help wanted
invalid
javascript
migration
question
severity:critical
severity:high
severity:low
severity:medium
wontfix
Something isn't working
Comment / docstring cleanup per .planning/code-commenting-guide.md
Dependency updates
Improvements or additions to documentation
This issue or pull request already exists
New feature or request
Good for newcomers
Extra attention is needed
This doesn't seem right
Pull requests that update javascript code
Further information is requested
This will not be worked on
Milestone
No items
No Milestone
v0.1 — It actually works (basic capabilities)
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: KofTwentyTwo/Jarvis#21
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Summary
Tool-result bytes are 8 KB-capped TWICE — once in the dispatcher's
SanitizeForModel.prepareForBoundary(rawText, capBytes: 8192), then again inToolResultPacker.pack. The orchestrator's "full blob in replay log" promise is a lie:packed.fullBytesis already 8 KB. The "full" intoolResultFullis never larger than 8 KB. Combined with CRIT-1, no production path records the original tool output bytes anywhere on disk.Evidence
packages/MCP/Sources/MCP/MCPToolDispatcher.swift:114— stdio path returnsData(SanitizeForModel.prepareForBoundary(rawText, capBytes: 8192).utf8)packages/MCP/Sources/MCP/InProcess/InProcessAwareToolDispatcher.swift:89— same 8 KB cap on in-process pathpackages/AgentCore/Sources/AgentOrchestrator/AgentOrchestrator.swift:580-587— orchestrator callsToolResultPacker.pack(resultData)which caps AGAIN at 8 KB; then writes.toolResultFull(toolUseId: req.id, bytes: packed.fullBytes)to replaypackages/AgentCore/Sources/AgentCore/ToolResultPacker.swift:23— doc comment says "The full blob still flows to ReplayLog viaReplayEvent.toolResultFull(toolUseId:bytes:)— observability is not lossy (OBS-02)." This is false in production.Root cause / hypothesis
The two layers were designed independently — one in MCP (boundary defense), one in AgentCore (model-facing protection) — and the intended division was "MCP caps the model-facing string, orchestrator passes through to replay". But the orchestrator pipeline doesn't have a "raw bytes" inlet — it consumes the dispatcher's return value as both model-facing AND replay-facing payload.
ToolResultPacker.packunit tests verify capping correctly but on synthetic inputs that haven't gone through the dispatcher's pre-cap;MCPToolDispatcherunit tests verify sanitize correctness on its output but don't trace the byte path into the orchestrator.Recommended fix
Move
prepareForBoundarycall OUT of both dispatchers and into the orchestrator (or intoToolResultPacker.pack). Have dispatchers return the raw helper bytes. Then orchestrator:.toolResultFull(true to the name)prepareForBoundary+ToolResultPacker.packonce, embed capped string in model-facing tool_resultThis also collapses the dead observer dual-write back into a single source of truth, fixing CRIT-1 by deletion.
Test
ReplayEvent.toolResultFull.bytes.count > 8192is achievable in testSource
.planning/audit-2026-05-12/mcp-agent-audit.md(2026-05-12) — finding CRIT-2Cross-references
Closed by v0.1 cluster merges on 2026-05-13. Develop now at
a8c7f1a0.