Skip to content

improve: prepare MCP prompt names without rendering tool APIs - #146083

Merged
steipete merged 1 commit into
mainfrom
codex/v8-mcp-prompt-plan
Sep 12, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/v8-mcp-prompt-plan

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Preparing the Code Mode prompt for an MCP catalog builds tool scopes and recursively renders parameter documentation merely to list the available servers. Large catalogs repeat this unused work whenever the catalog refreshes.

Why This Change Was Made

Share the existing server grouping and naming plan between prompt preparation and runtime construction. Prompt preparation consumes the server names directly; runtime construction still prepares callable tools and their API documentation.

User Impact

Code Mode catalog preparation and refresh become faster, with identical prompt text, server names, callable namespaces, and generated API files.

Evidence

  • 49 focused tests passed across namespaces, registered MCP tools, QuickJS execution, and node plugin tools.
  • Actual catalog preparation matched full prompt bytes and every runtime API file across small and large catalogs, nested schemas, collisions, restrictions, and refreshes.
  • The regression proves that prompt preparation does not inspect tool parameter schemas while runtime documentation still includes them.
  • Independent review completed cleanly against the final source.
  • Required hosted CI passed at the reviewed head 562b3186c7d84717a38d788cc1721e7f3d67a657. Local focused proof passed; broad gates used hosted CI.

Actual catalog operations, median seconds per operation:

Synthetic catalog / operation Node 24.19.0 before → after Node 26.8.2 before → after
2,000 simple-schema tools / apply 0.037938 → 0.020034 0.022745 → 0.014080
2,000 nested-schema tools / apply 0.192308 → 0.021175 0.120167 → 0.015737
2,000 nested-schema tools / refresh 0.155214 → 0.002471 0.100464 → 0.002041

The full matrix includes 0, 2, 100, 500, and 2,000 tools with simple and nested schemas. Two-tool cases improve on both runtimes. Empty-catalog refresh is unchanged; empty apply is approximately 9.8 → 9.6 microseconds on Node 24 and 9.7 → 10.7 microseconds on Node 26. That small absolute control cost is included rather than claiming every case improves.

Measurements ran on Windows 11 / AMD Ryzen AI MAX+ 395, using 15 warmup operations per variant and nine alternating before/after rounds, with 1,000 operations per small-catalog sample, 100 at 100 tools, and 10 at larger sizes. Full prompt bytes, namespace descriptors, and every runtime API file match, including twelve name-collision/order rotations, restriction, and rebinding. Synthetic nested schemas contain twelve array parameters with eight object fields each.

Fresh-process memory proof used before/after/after/before ordering per runtime, each running an initial apply plus 20 repeated applies over 2,000 nested-schema tools. Peak RSS was inconclusive: Node 24 measured 576–608 MiB before versus 603–645 MiB after; Node 26 measured 534–542 MiB before versus 520–542 MiB after. Cold-import working sets varied substantially, so this PR makes no claim of lower peak RSS. Observed heap-used growth from the post-import/preparation checkpoint to the post-work snapshot fell from 125–254 MiB to about 41 MiB on Node 24, and from about 222 MiB to 12 MiB on Node 26. These are heap snapshots without a final collection, not retained-heap or total-allocation measurements. The two runtimes' memory-only sequences ran concurrently; their elapsed times are excluded from latency evidence.

The performance harness runs actual Code Mode catalog application and refresh using synthetic MCP catalogs. It checks complete prompt text and runtime API files. Timings measure catalog preparation, excluding MCP server/network latency.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@steipete
steipete marked this pull request as ready for review September 12, 2026 15:09
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 11:15 AM ET / 15:15 UTC.

ClawSweeper review

What this changes

The PR lets OpenClaw Code Mode prepare MCP server names without constructing callable tools or rendering their parameter documentation, while retaining those operations for execution.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, focused optimization: current main still performs the unnecessary schema work. No introduced correctness or security defect was found, and the maintainer-protected PR should remain open.

Priority: P2
Reviewed head: 562b3186c7d84717a38d788cc1721e7f3d67a657

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with meaningful regression coverage and no identified defect; required performance measurements remain outstanding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports catalog preparation and runtime API equivalence checks; scoped performance measurements remain a separate required validation step.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports catalog preparation and runtime API equivalence checks; scoped performance measurements remain a separate required validation step.
Evidence reviewed 7 items Introduced change: The pinned merge-base-to-head diff extracts server grouping and naming into one shared plan. Prompt rendering consumes that plan; runtime construction retains tool mappings, schema rendering, and invocation checks. Host-verified test-merge evidence limits the merge result to the same two files.
Current main still performs the unnecessary work: On fetched main, describeMcpNamespaceForPrompt still calls createMcpNamespaceModel, whose tool loop calls buildMcpParamDocs for each entry before the prompt selects only server names.
Latest release comparison: The latest supplied release, v2026.9.4, also constructs the full MCP namespace model to describe server names; it does not contain this optimization.
Findings None None.
Security None None.

How this fits together

OpenClaw Code Mode turns the available tool catalog into model instructions and an executable tool namespace. MCP server naming feeds both the prompt and the runtime API declarations.

flowchart TD
  A[Available MCP tool catalog] --> B[Shared server naming plan]
  B --> C[Prompt server list]
  B --> D[Runtime namespace construction]
  D --> E[Parameter documentation and API files]
  D --> F[Guarded tool invocation]
Loading

Before merge

  • Resolve merge risk (P1) - The size of the performance improvement and its RSS effect remain unquantified in the available evidence.
  • Complete next step (P2) - Add the promised Node 24/26 before/after performance evidence, including elapsed seconds and RSS, as required by src/agents/AGENTS.md.
Agent review details

Security

None.

PR surface

Source +13, Tests +24. Total +37 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 28 15 +13
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 52 15 +37

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep server naming under one shared planner and reserve schema documentation and callable construction for runtime preparation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep server naming under one shared planner and reserve schema documentation and callable construction for runtime preparation.

Do we have a high-confidence way to reproduce the issue?

Yes, source establishes the unnecessary work: catalog preparation and refresh call the prompt renderer, which on main constructs parameter documentation before selecting server names. No runtime benchmark was executed during this read-only review.

Is this the best way to solve the issue?

Yes. Sharing the existing naming algorithm removes unused preparation work without introducing a competing naming policy or changing the runtime tool contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 99be6bd6a27b.

Labels

Label changes:

  • add P2: This is a bounded catalog-preparation performance improvement without evidence of an urgent user-facing outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports catalog preparation and runtime API equivalence checks; scoped performance measurements remain a separate required validation step.

Label justifications:

  • P2: This is a bounded catalog-preparation performance improvement without evidence of an urgent user-facing outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies this as maintainer-authored, so the external-contributor proof gate does not apply. The body reports catalog preparation and runtime API equivalence checks; scoped performance measurements remain a separate required validation step.

Evidence

What I checked:

  • Introduced change: The pinned merge-base-to-head diff extracts server grouping and naming into one shared plan. Prompt rendering consumes that plan; runtime construction retains tool mappings, schema rendering, and invocation checks. Host-verified test-merge evidence limits the merge result to the same two files. (src/agents/code-mode-namespaces.ts:337, 562b3186c7d8)
  • Current main still performs the unnecessary work: On fetched main, describeMcpNamespaceForPrompt still calls createMcpNamespaceModel, whose tool loop calls buildMcpParamDocs for each entry before the prompt selects only server names. (src/agents/code-mode-namespaces.ts:493, 99be6bd6a27b)
  • Latest release comparison: The latest supplied release, v2026.9.4, also constructs the full MCP namespace model to describe server names; it does not contain this optimization. (src/agents/code-mode-namespaces.ts:493, 3a9d69db306c)
  • Production entrypoint and implementation boundary: applyCodeModeCatalog refreshes the exec description through createCodeModeExecDescription, which invokes the changed prompt renderer. Execution separately constructs the namespace runtime in code-mode-execution.ts. docs/tools/code-mode.md explicitly distinguishes this OpenClaw implementation from Codex Code Mode; no changed dependency contract requires sibling Codex inspection. (src/agents/code-mode.ts:360, 562b3186c7d8)
  • Focused regression coverage: The added test observes that prompt preparation never reads schema properties, then verifies runtime API output still includes the parameter. Existing cases cover invocation, reserved identifiers, prototype-sensitive arguments, and node-label truncation. Tests were inspected, not executed, under the read-only review contract. (src/agents/code-mode-namespaces.test.ts:38, 562b3186c7d8)
  • Performance validation requirement: The fully read agent policy requires before/after performance measurements including seconds and RSS. The captured PR body reports 49 focused tests and catalog/prompt/API equivalence checks, but explicitly leaves final Node 24/26 timings pending. A live body read matched that evidence statement. (src/agents/AGENTS.md:9, 562b3186c7d8)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Record the promised paired Node 24/26 before/after measurements, including elapsed seconds and RSS, in the PR evidence.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 28c97ff into main Sep 12, 2026
264 of 265 checks passed
@steipete
steipete deleted the codex/v8-mcp-prompt-plan branch September 12, 2026 16:03
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant