Repository navigation
refactor(agents): defer unused MCP mirror serialization - #148929
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 2:46 PM ET / 18:46 UTC (Revision 7). ClawSweeper reviewWhat this changesDefer building the duplicate JSON text for MCP tool results until a text block needs comparison, then reuse it. Merge readiness✅ Ready for maintainer review This remains a useful, narrowly scoped optimization absent from fetched main and the latest release. No actionable correctness or security findings remain. Priority: P3 Review scores
Verification
How this fits togetherOpenClaw converts MCP server results into content the agent can consume. This adapter preserves structured data, recovery text, and media while removing exact duplicate JSON text. flowchart TD
A[MCP server result] --> B[Result projection]
B --> C[Canonical structured text]
B --> D{Text block present?}
D -->|Yes| E[Build and reuse mirror comparison]
D -->|No| F[Preserve media and other content]
E --> G[Agent result]
F --> G
C --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5. Total +5 across 1 file. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the optimization inside the existing result adapter while preserving exact mirror suppression and all other projected content. Do we have a high-confidence way to reproduce the issue? Not applicable as a behavior bug: source confirms the unnecessary eager serialization, and the supplied benchmark measures its cost; no code was executed during this read-only review. Is this the best way to solve the issue? Yes. Lazy initialization inside the existing filter avoids unused work without adding another owner or changing the transported-JSON output contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against eb8bca1326c4. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
|
Merged via squash.
|
What Problem This Solves
MCP structured results build a duplicate JSON string even when no text block needs comparison against it.
User Impact
JSON-transported MCP results retain canonical formatting, recovery text, media content, and exact mirror suppression.
Why This Change Was Made
Create the mirror string only when a text block needs it, then reuse it for subsequent comparisons.
Evidence
Earlier proof passed 34 MCP materialization cases and 21 node-plugin tool cases. Managed P2 review found no actionable findings within the transported-JSON contract. Retained exact-head CI run 34986844660 passed.
A separate composition run passed all 36 cases in
src/agents/agent-bundle-mcp-tools.materialize.test.ts, including both newer cancelled-catalog cleanup cases. It combined this PR's projection with the materialization owner, complete fixture, and stable-stringify owner fromd886b8e374ebe4652fd35204a87a44e9294bf244, using the existing dependency graph at6ef6f0fb0c7bf1ccd3502c2f5d5880c9bba31dd2. All four source overlays were restored after verified process completion. This establishes the selected-owner composition in that fixed context; it is not a full current-main installation or live MCP transport test. The fixture supplies ordinary explicit MCP names and does not exercise the retained older allowlist alias branch.Paired Projection Benchmark
Eight fresh Node 26.8.2 processes exercised the exported
projectMcpCallToolResultadapter. Each process ran 32 warmups and 2,048 timed projections of the same synthetic 128-record search page (64,411 bytes of compact structured JSON). The no-text shape has an empty content array. The mirror shape has the exact pretty-JSON mirror plus pagination guidance. Complete projected output, unchanged input/details, structured-data identity, and raw guest-data preservation passed in every process. Input and output hashes matched between arms.Pair 1 ran before then after; pair 2 reversed that order. Each arm ran no-text then mirror in separate processes. Only this PR's
mcp-content.tschange differed between arms. Both used the selectedstable-stringify.tssource from5016e177ab99597874859b643f29f3f9fcf7715dwith the existing dependency graph at6ef6f0fb0c7bf1ccd3502c2f5d5880c9bba31dd2, including fs-safe 0.11.0. This qualifies that fixed source/dependency composition, not an exact current-main installation.The no-text loop took 15.6–17.5% less time in these samples. Mirror loop time changed by +0.38% and -1.08%. Mean peak RSS increased by 679,936 bytes for no-text and 958,464 bytes for mirror; these measurements show no RSS saving.
Loop timing excludes fixture preparation, warmup, and full acceptance checks.
/usr/bin/time -lprocess seconds and peak RSS include those steps plus loader/import work. There were two observations per arm and shape, without competing campaign workloads; desktop/OS activity remained uncontrolled. These results cover synthetic adapter projection, not live MCP transport, Gateway performance, allocation totals, or retained heap. All eight processes completed successfully, and both source overlays and original file modes were restored after independently verified cleanup.