Skip to content

perf(agents): reuse the command broker for isolated file reads - #172476

Merged
steipete merged 3 commits into
mainfrom
steipete/perf-micro-file-read-node-spawn-20260919
Oct 14, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/perf-micro-file-read-node-spawn-20260919

Conversation

@steipete

@steipete steipete commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Agent reads of files under the state directory, database-shaped paths, and hardlink aliases start a fresh Node child for each read. Workspace files under the state directory pay the same startup cost as database files.

User Impact

Gateway reads reuse its existing separate-process command broker, avoiding repeated runtime startup. Filesystem access, error codes, output limits, and CLI operation remain unchanged. No configuration, schema, or migration changes.

Why This Change Was Made

The separate process is required: closing a raw descriptor in any Gateway thread can release its process-wide SQLite POSIX locks. Keep the same fs-safe regular-file reader in the broker, prohibit raw reads in native-resource brokers that can own SQLite connections, and send bounded IPC chunks without imposing a new total file-size limit. Cancellation drops that read's results without killing the shared broker. Broker shutdown joins descriptor closure.

The standalone CLI still needs its existing child path because it has no Gateway broker. Production LOC: +180 net (212 additions, 32 deletions, excluding tests and wrapper inventory). Code grows to preserve that runtime contract, SQLite isolation, arbitrary read sizes, cancellation, and existing broker lifecycle ownership; this introduces no additional process pool or content cache.

Evidence

  • read-file.test.ts: 20 passing cases, including actual broker reuse, concurrent multi-chunk binary reads, empty files, errors, symlink rejection, cancellation, and refusal by native-resource brokers. Test time 3.8 s; wrapper wall time 32.9 s (worker artifact preparation included).
  • read.sqlite-locks.test.ts: passing real POSIX lock probes for main/WAL/SHM and renamed hardlinks through both transports, plus traversal and symlink-escape rejection. Test time 1.8 s; wrapper wall time 13.6 s. Initial new assertion expected the path-escape wording for a symlink; corrected it to accept the distinct existing symlink-escape error.
  • Existing spawn-broker/host.test.ts: all 17 tests pass, including startup failure, native IPC/pipes, broker loss/restart, and shutdown. Wrapper wall time 44.6 s.
  • Independent subagent review (autoreview route unavailable): no actionable P0–P2 findings. The configured autoreview provider selector was rejected before review; no operator configuration was changed.
  • Focused format/lint, export-name collision guard, and git diff --check; broad build/typecheck/suites delegated to PR CI. No Testbox/Crabbox leases.
  • Initial PR CI caught the new broker reader missing from the wrapper source inventory. Added that module and independently reviewed the repair. Focused closure rerun: wrapper closure 3/3 pass; eager closure 16/18 pass, with the two remaining failures caused by the baseline inventory omitting activation-hint-records.ts (already fixed on current main). Final merge-ref CI passes both closure and provisioning jobs; no unrelated fix was copied into this branch.
  • Typed CI lint also found the child lifecycle adapter still accepted the new file-read response variants. Narrowed its message type to match the existing host dispatch; independently reviewed with no findings, and focused core typed lint passed. No runtime change or repeated performance measurement was needed.

Measurement

Isolated Linux sandbox, Node 26.8.2, CPUs 64–127, 64 GiB memory cap, nice 10/idle I/O. Baseline 4f001f643d0107219a6ffadb97720f3781a974ba; same checkout with this patch for after. Used the real readLocalFile entrypoint under the existing broker, synthetic files under OPENCLAW_STATE_DIR, one warmup and 60 sequential reads per size. Broker and read-child entrypoints were compiled with esbuild, excluding TypeScript-loader startup from child timings. Existing spawn diagnostics counted node:agent.file-read.

File size Before mean / p95 After mean / p95 File-read child spawns (60 reads)
4 KiB 119.248 / 167.674 ms 0.111 / 0.231 ms 60 → 0
64 KiB 113.801 / 167.806 ms 0.187 / 0.331 ms 60 → 0
1 MiB 110.707 / 149.161 ms 1.116 / 2.432 ms 60 → 0

At six affected reads/minute, this projects to 6 → 0 file-read spawns/minute (the shared broker already exists). These are burst microbenchmark results, not post-deployment production telemetry. Whole-Gateway heap/GC impact and production spawns/min remain unmeasured; no live Gateway was load-tested.

Final CI

All test, build, lint, typecheck, and security jobs passed for head 8852514a7c3c4dcb8c38c6f17e1547603e8ecaee in CI run 38623983327. Initial closure/provisioning and typed-lint failures were repaired as described above. No inherited-failure exception or CI rerun was used. The benchmark sandbox was removed after measurements.

@clawsweeper

clawsweeper Bot commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment @clawsweeper review. Please avoid repeated requests while a review is queued or running; agents should not request reviews automatically.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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-10-14T19:32:40.056559Z 8852514 New commits
ℹ️ 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.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Oct 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8852514a7c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

throw new SpawnBrokerError("Spawn broker cannot admit a raw file read");
}
fileReads.set(message.id, pending);
const { buffer } = await readRegularFile({ filePath: message.filePath });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cancel the underlying broker file read

When an isolated read is aborted while readRegularFile is still reading a large file or a slow/unresponsive mount, cancellation only rejects the caller and marks the request as canceled; this await continues until the filesystem operation finishes. The request therefore remains in fileReads, consuming broker capacity, and broker shutdown waits for it through the launches set, so a canceled tool call can delay or indefinitely block a Gateway restart. Make the broker-side read abortable, such as by reading incrementally and closing its descriptor when cancellation arrives, rather than merely suppressing its reply.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 0eb61c3 into main Oct 14, 2026
155 checks passed
@steipete
steipete deleted the steipete/perf-micro-file-read-node-spawn-20260919 branch October 14, 2026 20:03
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 15, 2026
…law#172476)

* perf(agents): reuse the command broker for isolated file reads

* fix(build): include broker file reader in wrapper inventory

* fix(process): keep file replies out of child lifecycle messages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant