Skip to content

fix: keep bundled MCP setup responsive on slow storage - #190233

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-main-thread-sync-fs-kernel-attributed-20260919
Nov 1, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-main-thread-sync-fs-kernel-attributed-20260919

Conversation

@steipete

@steipete steipete commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway event-loop stalls when bundled MCP setup prepares a plugin data directory on slow storage.

User Impact

Agent setup waits for directory creation without blocking other Gateway requests. A server whose directory cannot be prepared is still omitted with the existing diagnostic. Configuration and directory ownership are unchanged.

Why This Change Was Made

The directory owner called mkdirSync once per active bundled server; both CLI and Codex consumers were already asynchronous. The owner now awaits mkdir and both consumers await readiness before projecting server configuration. Production LOC delta is zero, with no cache, runtime setting, schema, dependency or version change.

The associated root-traversal investigation found that both fs-safe 0.27.0 and prepared 0.27.1 still perform synchronous component lookup inside Promise-returning APIs. The separate owner repair is openclaw/fs-safe#1054. This PR commits reproducible workloads for both repairs but does not adopt or publish the dependency. Synchronous identity fences and diagnostic flushes remain separate residuals; this is not a Gateway-wide zero-sync claim.

Evidence

The existing real MCP directory/projection test now injects delayed IO and verifies that an independent event-loop turn runs while configuration remains pending. It fails on parent e460144 and passes with the fix. Existing readiness and per-server failure diagnostics assertions remain. The justified regression adds 26 test lines with its own budget allocation record.

62 distinct focused tests passed across nine files. Two commands took 57.04 and 62.64 seconds including wrapper/compilation; the changed seven-test file completed in 2.46 seconds, with the delayed-IO test taking 5 ms on the fix. No touched module is imported by Control UI. Codex integration source was checked against codex-rs/core/src/config/mod.rs:2192–2225; downstream MCP configuration shape is unchanged.

Independent Codex autoreview of the final diff against the parent above was scoped-clean at P0–P2. The simplification pass retained only the owner conversion, both required awaits, the regression and reproducible owner benchmarks. pnpm check:changed completed all phases; its only failure was benchmark-script lint. Braces, the Promise executor and the timer-array annotation were corrected, and the exact failed lint command passed on rerun. All remaining phases were green, including typechecks and both dead-export scans. Exact-head CI run 41297289166 completed successfully at 93b6e88, including openclaw/ci-gate; security and dependency gates are green. No inherited-failure exception is used.

Five interleaved A1/B/A2 batches used an existing plugin directory alongside 62,000 synthetic 18,000-byte files (1.116 GB), with 1,000 preparations per timing batch. Allocation and 100 ms latency injection ran separately. Node 26.12.1, local APFS; host load is recorded. No production data, live Gateway or agent database was used: this owner does not read them. Acceptance is event-loop progress while filesystem IO remains pending, unchanged output/failure behavior, and an explicit decision on the measured warm cost.

Per directory preparation A1 parent Candidate A2 parent control
Warm mean 2.16 µs 13.80 µs 2.24 µs
Warm p95 2.38 µs 18.42 µs 2.42 µs
Main CPU 2.177 µs 8.144 µs 2.245 µs
Total CPU 6.934 µs 20.763 µs 7.170 µs
Sampled allocation 635 B 2,339 B 627 B
Injected IO: timer delay 107.31 ms 1.353 ms 107.78 ms
Synchronous mkdir calls 1 0 1

This trades approximately 6 µs main CPU, 14 µs total CPU and 1.7 KB allocation per preparation for responsiveness under slow IO. These relative warm regressions exceed 20%; the lead explicitly accepted them before merge (see below). The benchmark is scripts/perf/bundle-mcp-mkdir-measure.mjs; root-owner comparison is scripts/perf/fs-safe-root-read-measure.mjs. Both retain A/A controls and report CPU/allocation separately from injected-latency passes.

Lead accepted

The lead explicitly accepted the measured tradeoff on 2026-11-01: with an injected 100 ms lookup, Root.read event-loop delay fell from 106.55 ms to 1.33 ms (2.29 ms maximum). The additional 18–33 µs main-thread CPU and approximately 8 KB sampled allocation per read are accepted for removing this class of blocking lookup. The associated MCP setup cost of approximately 6 µs main-thread CPU and 1.7 KB allocation per server is also accepted. Landing both source fixes is authorized; package publication and adoption remain separate.

Named follow-ups

  • Windows publication-safe async traversal: preserve synchronous Windows traversal until its canonicalization owner supports sharing compatible with concurrent atomic publication; the unrestricted conversion failed five overlap runs with EPERM while the exact parent passed five.
  • Stackless main-thread openat stall: attribute the reported 3,515 ms reply.run_agent_turn stall in btrfs wait_current_trans before choosing the remaining synchronous-open owner. The MCP repair does not establish attribution.

@clawsweeper

clawsweeper Bot commented Nov 1, 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 scripts Repository scripts agents Agent runtime and tooling size: M labels Nov 1, 2026
@steipete
steipete marked this pull request as ready for review November 1, 2026 10:23
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T10:25:12.619216Z 93b6e88 Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 1, 2026
@clawsweeper

clawsweeper Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

The PR makes bundled MCP directory preparation asynchronous and awaits readiness in both CLI and Codex consumers.

Example: Preparing the weather plugin directory takes 100 ms.

  • Before: Synchronous directory creation blocks other Gateway work during that wait.
  • After: Directory preparation yields the event loop, and configuration projection waits for completion.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The production repair is coherent and preserves the existing filesystem contract, but supplied proof does not satisfy the shipped-entry-point requirement.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Other Gateway requests can stall while bundled MCP setup creates a plugin directory on slow storage.
Reason: The maintainer-authored repair addresses a concrete blocking operation using the existing shared owner without adding configuration or changing downstream output.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: current main still blocks directory preparation synchronously, and the production repair preserves the existing ownership and failure behavior.

Priority: P2
Reviewed head: 93b6e887c6a731a09ea3622e4e8443167c15fc37
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should this PR accept the reported increase in warm CPU and allocation per directory preparation in exchange for event-loop responsiveness under slow I/O?
  • Recommendation: Accept the measured cost: Record acceptance of the small absolute per-preparation cost for removing storage waits from the event loop.
  • Why: The performance guidance requires explicit acceptance of worse metrics, and the current PR body expressly says that acceptance remains pending.

Before merge

  • [P3] Move the fs-safe workload to the separate dependency repair (P3) - This added module benchmarks resolveRootPath, Root.read, and fileStore.open, none of which this PR changes. It supports fix: avoid blocking metadata during async root traversal fs-safe#1054 rather than the mkdir repair and is unnecessary scaffolding under the smallest-complete-fix rule. Move it with that dependency work and retain the bundled-MCP benchmark here.
  • [P3] Remove the unnecessary real sleep from the regression (P3) - When the synchronous implementation is exercised, this spy blocks the test process for 25 ms without adding a distinct assertion: the parent already resolves projection before the independent event-loop turn. The deferred Promise supplies the necessary scheduling control. Remove this blocking spy and its incidental call assertion, preserving the observable readiness regression, in accordance with the test guide's prohibition on added real sleeps.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P3] [P3] Move the fs-safe workload to the separate dependency repair — scripts/perf/fs-safe-root-read-measure.mjs:55-59
  • [P3] [P3] Remove the unnecessary real sleep from the regression — src/agents/codex-mcp-config.test.ts:137-141

Tests

  • Low-value test src/agents/codex-mcp-config.test.ts: Remove the exact mkdir call-count assertions and synchronous-spy scaffolding; retain the independently observable pending-projection, directory-readiness, and failure-isolation assertions.
  • Missing end-to-end proof: Provide redacted Gateway output showing an unrelated request completes while bundled directory preparation remains pending, followed by successful setup and unchanged failed-server omission.
Agent review details

How this fits together

Bundled plugin declarations enter the shared directory-preparation owner, which creates required directories and returns surviving MCP servers plus diagnostics to CLI and Codex configuration adapters.

flowchart LR
  A[Bundle declarations] --> B[Server selection]
  B --> C[Directory preparation]
  C --> D[Filesystem]
  C --> E[CLI configuration]
  C --> F[Codex configuration]
  C --> G[Failure diagnostics]
Loading

Technical review

Best possible solution:

Keep the existing owner's async conversion and both awaits, retain the deferred-readiness regression, and separate the dependency benchmark from this focused repair.

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

Current-main source directly shows blocking mkdirSync on the setup path, and the PR reports a parent-failing deferred-I/O regression; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Converting the existing owner and awaiting both consumers is the smallest complete production fix, preserving directory ownership, server selection, and failure isolation.

Full review comments:

  • [P3] [P3] Move the fs-safe workload to the separate dependency repair — scripts/perf/fs-safe-root-read-measure.mjs:55-59
    This added module benchmarks resolveRootPath, Root.read, and fileStore.open, none of which this PR changes. It supports fix: avoid blocking metadata during async root traversal fs-safe#1054 rather than the mkdir repair and is unnecessary scaffolding under the smallest-complete-fix rule. Move it with that dependency work and retain the bundled-MCP benchmark here.
    Confidence: 0.96
  • [P3] [P3] Remove the unnecessary real sleep from the regression — src/agents/codex-mcp-config.test.ts:137-141
    When the synchronous implementation is exercised, this spy blocks the test process for 25 ms without adding a distinct assertion: the parent already resolves projection before the independent event-loop turn. The deferred Promise supplies the necessary scheduling control. Remove this blocking spy and its incidental call assertion, preserving the observable readiness regression, in accordance with the test guide's prohibition on added real sleeps.
    Confidence: 0.94

Overall correctness: patch is correct
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Bundled MCP directory ownership and CLI/Codex readiness keeps the original intent (f4387b7: Agent Plugins support required persistent plugin directories before external MCP configuration became usable, with failures isolated per server.)
  • Existing Codex directory/projection regression keeps the original intent (330184b: The earlier test consolidation retained distinct lifecycle and failure contracts; the new deferred-readiness assertion extends the retained integration test.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main retains the blocking operation: The fetched main revision still calls mkdirSync inside prepareOwnedBundleMcpDataDirs. (src/agents/bundle-mcp-config.ts:65, f7d677435070)
  • Complete production cutover: The introduced diff converts the existing owner to awaited mkdir and updates both production callers; repository-wide references reveal no remaining synchronous caller of this owner. (src/agents/bundle-mcp-config.ts:54, 93b6e887c6a7)
  • Original directory contract: feat(plugins): support the Agent Plugins bundle format #120115 introduced persistent per-plugin directories and per-server failure isolation; this PR preserves those contracts. (src/agents/bundle-mcp-config.ts:65, f4387b7a5eff)
  • Measured tradeoff explicitly remains pending: The full PR body reports warm main CPU increasing from 2.177 to 8.144 microseconds and sampled allocation from 635 to 2339 bytes per preparation, while injected-I/O timer delay improves from 107.31 to 1.353 ms; it explicitly leaves cost acceptance pending. (93b6e887c6a7)
  • Supporting regression: The changed test exercises the production Codex projection owner with deferred filesystem I/O and retains directory-readiness and failed-server omission assertions; the body reports failure on the parent and success on the candidate. (src/agents/codex-mcp-config.test.ts:131, 93b6e887c6a7)
  • Separate dependency repair and applicable contract: The added root-read benchmark imports and exercises fs-safe's root, store, and advanced implementations, establishing the dependency-policy signal; its separate repair is fix: avoid blocking metadata during async root traversal fs-safe#1054, and no dependency adoption occurs here. (AGENTS.md)

Likely related people:

  • Patrick Erichsen: Raw commit 62d0c5f adds src/agents/bundle-mcp-config.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 62d0c5f3b66c; files: src/agents/bundle-mcp-config.ts)

PR surface

Source 0, Tests +26, Other +348. Total +374 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 5 5 0
Tests 1 27 1 +26
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 3 348 0 +348
Total 7 380 6 +374

Labels

Label changes:

  • add P2: Slow directory preparation can stall unrelated Gateway requests, with impact limited to the bundled MCP preparation path.
  • add merge-risk: 🚨 other: The reported warm CPU and allocation increases require an explicit performance-cost acceptance that the body leaves pending.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Slow directory preparation can stall unrelated Gateway requests, with impact limited to the bundled MCP preparation path.
  • merge-risk: 🚨 other: The reported warm CPU and allocation increases require an explicit performance-cost acceptance that the body leaves pending.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

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

  • Demonstrate Gateway responsiveness during pending bundled-directory preparation.
  • Record the feature owner's explicit acceptance of the measured warm costs.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 1, 2026, 5:39 AM ET / 10:39 UTC.

@steipete
steipete merged commit 4ec943f into main Nov 1, 2026
237 of 239 checks passed
@steipete
steipete deleted the steipete/perf-micro-main-thread-sync-fs-kernel-attributed-20260919 branch November 1, 2026 12:10
@steipete

steipete commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 2, 2026
RomneyDa added a commit that referenced this pull request Nov 18, 2026
(cherry picked from commit 4ec943f)

Release adaptation: retain the production owner and both await sites exactly;
omit standalone performance measurement scripts. Extend the existing real
MCP projection regression with delayed async filesystem I/O.

Companions: 8cd7d87 only retires the allocation record; 0c1481f
and 573fd8c only refactor omitted performance measurement scripts.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant