Repository navigation
perf(agents): reuse the command broker for isolated file reads - #172476
Conversation
|
ClawSweeper reviews are opt-in for maintainers. If a review is required, finish the work and validation first, then comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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 }); |
There was a problem hiding this comment.
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 👍 / 👎.
…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
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.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.git diff --check; broad build/typecheck/suites delegated to PR CI. No Testbox/Crabbox leases.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.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 realreadLocalFileentrypoint under the existing broker, synthetic files underOPENCLAW_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 countednode:agent.file-read.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
8852514a7c3c4dcb8c38c6f17e1547603e8ecaeein 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.