Repository navigation
perf(agents): keep file edits from blocking other chats - #158443
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: blocked before merge. Reviewed September 26, 2026, 3:47 AM ET / 07:47 UTC (Revision 7). ClawSweeper reviewWhat this changesMoves built-in file edit and write planning to a bundled compute worker and adjusts active workspace quota scans to tolerate temporary file renames. Merge readiness⛔ Blocked before merge - 8 items remain The performance fix remains useful because current main still computes file diffs on the caller thread. Two previously reported correctness findings remain on this head, so the PR is not ready to merge. Priority: P2 Review scores
Verification
How this fits togetherAgent file tools receive requested edits or complete file contents, then plan, write, and verify the result. The Gateway separately scans inbound worker workspace transfers against size and entry limits before accepting them. flowchart LR
A[Agent file request] --> B[File mutation queue]
B --> C[Planning worker]
C --> D[Current authority check]
D --> E[File write and verification]
F[Inbound workspace transfer] --> G[Quota scan]
G --> H[Accept or abort transfer]
Decision needed
Why: The branch intentionally changes an existing write outcome, and the PR body's acceptance claim is not independently confirmed in the discussion. Before merge
Findings
Agent review detailsSecurityNeeds attention: The patch adds no dependency or secret access, but its active-transfer rename handling can defer quota enforcement. PR surfaceSource +61, Tests +278, Docs +9, Other +4. Total +352 across 27 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep file computation off the Gateway thread while preserving existing write outcomes, enforcing transfer limits throughout active sync, and confirming that upgrades acquire the worker. Do we have a high-confidence way to reproduce the issue? Yes. Current main performs edit and write diff computation on the caller thread, and the PR reports before/after measurements through the built-in tool definitions; this read-only review did not run a Gateway. Is this the best way to solve the issue? No, as submitted. The existing worker pool is an appropriate compute boundary, but optional receipt failure should not change the write outcome without an explicit maintainer choice, and active quota checks must remain complete. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 67adcce7e304. LabelsLabel changes: No label changes. Label justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
Exact-head CI reported the sealed worker entry as unused because it is built and launched by path. Register it alongside the existing deployed workers without excluding it from dependency or export analysis.
The package-output contract treated the newly registered sealed worker as a normal .js package entry. Include it in the existing worker cases and bundled-dependency assertions. All 45 tsdown configuration tests pass in 272.39 seconds wall time; focused lint and independent review pass.
Merge current main and repair the filesystem-walk integration exposed by hosted CI. Ignore vanished paths only during active transfer scans; keep the final quota scan strict and preserve abort-and-join for other scan failures. The original CI group reproduced the ENOENT before this repair and passes afterward (879 Node and 124 Bun tests). A deterministic real-rename regression fails before the fix and all 13 focused tests pass afterward. Independent P0-P2 candidate review is clean.
Register the file planning worker in the existing executable graph assertion. All 32 runtime-config tests pass (59.81 seconds wall, 0.261 seconds test time); targeted lint and independent review are clean.
Launch the copied PR wrapper through the fixture Bash binary. Hold a writable descriptor across spawn to deterministically exercise Linux ETXTBSY without retries. The old direct-exec variant fails with ETXTBSY; all 146 operation-lock tests pass after the fix on Linux Testbox in 56.53 seconds wall time. Lint and independent P0-P2 review pass.
Incorporate the existing main fixes 20f3170 and 66b812f, which remove the suppression while preserving native JSON ToNumber semantics. Adding the proposed baseline entry now fails the guard, so no exception change is retained. The suppression, workspace-transfer, and file-planning selections pass all 23 tests; fresh candidate review is clean.
Incorporate canonical main fix 6c7544a for the closing-database archive fixture failure seen on main and PR CI. The source repair awaits database resource drainage before resetting and reopening the fixture. The canonical focused two-test file passes in 313.36 seconds wall time; the equivalent repair passed the captured 273-test group. Fresh candidate review is clean.
) * perf(agents): keep file-tool computation off the main thread * test(agents): check complete file plans and patch receipts * fix(agents): package file planning for portable workers * refactor(agents): avoid redundant diff options copy * test(workers): consolidate portable artifact assertions * test(workers): distinguish artifact paths from install input * fix(ci): register deployed file planning worker for Knip Exact-head CI reported the sealed worker entry as unused because it is built and launched by path. Register it alongside the existing deployed workers without excluding it from dependency or export analysis. * test(build): classify deployed file planner as a worker The package-output contract treated the newly registered sealed worker as a normal .js package entry. Include it in the existing worker cases and bundled-dependency assertions. All 45 tsdown configuration tests pass in 272.39 seconds wall time; focused lint and independent review pass. * test(build): cover planner worker schema inlining Register the file planning worker in the existing executable graph assertion. All 32 runtime-config tests pass (59.81 seconds wall, 0.261 seconds test time); targeted lint and independent review are clean. * test(pr): avoid executing a writable fixture inode Launch the copied PR wrapper through the fixture Bash binary. Hold a writable descriptor across spawn to deterministically exercise Linux ETXTBSY without retries. The old direct-exec variant fails with ETXTBSY; all 146 operation-lock tests pass after the fix on Linux Testbox in 56.53 seconds wall time. Lint and independent P0-P2 review pass.
What Problem This Solves
Fixes other chats becoming unresponsive while a built-in file tool plans a fuzzy edit or computes a large replacement diff.
User Impact
Edit and write tools keep their existing file contents, no-op behavior, preview output, and receipts while allowing the Gateway event loop to serve other clients during expensive computation. The first operation pays worker startup cost; subsequent operations reuse the worker pool.
Why This Change Was Made
Edit execution previously computed the same Myers diff twice for its numbered display and unified patch. Pure edit planning, fuzzy matching, and both receipt formats now share one prepared patch in the existing bounded
WorkerTaskPoolwith shared compute admission. Write and preview consumers use the same computation owner. The canonical runtime-process registry resolves that worker for normal installations and sealed portable bundles; the bundle artifact list and build entries migrate together.The file-tool caller retains the file mutation queue, filesystem access, persisted-byte verification, and recovery. It rechecks cancellation and current authority after planning and before mutation. Worker failure does not fall back to expensive synchronous execution. Write's existing byte, line, and edit-distance receipt limits remain intact. No Gateway protocol, configuration, database schema, dependency, or capability changes.
Evidence
Synthetic benchmark of the real edit/write definitions using injected in-memory filesystem operations, Node 26.9.0 on Apple M3 Ultra. Baseline and candidate alternate in one process for four measured operations per row after startup. Every operation verifies the persisted bytes and identical receipts. The measured baseline file-tool sources match the pre-change branch. A queued
setImmediatewitnesses event-loop availability; process CPU includes worker computation.The host was running a parallel development campaign, so elapsed time includes substantial scheduling noise. The 5,000-line edit nevertheless cuts measured process CPU from 7.04 s to 3.40 s, while leaving the event loop available in 0.44 ms. Write already shared its overwrite patch computation; its benefit here is moving CPU work off the caller, not lowering total CPU. The larger write cases still omit receipts at the existing edit-distance limit.
Separate source-mode process snapshots peaked at 449.5 MiB RSS before and 475.2 MiB after; these include source loaders and workers and are not retained-heap measurements. The first worker operation pays startup cost; subsequent operations reuse the existing pool's bounded admission, cancellation, and idle retirement.
Validation:
node scripts/run-vitest.mjs src/agents/sessions/tools/{edit.test.ts,edit-formatting.test.ts,edit-diff.test.ts,write.test.ts,file-tool-planning.test.ts,edit.legacy-input.test.ts} --maxWorkers=1: 134 tests passed, 687.40 s wall. Compiled subprocess fixture preparation consumed 450.61 s; most remaining time was transformation/import work.node scripts/run-vitest.mjs <file> --maxWorkers=1also passed:edit.test.ts84.06 s,write.test.ts94.53 s,edit-formatting.test.ts51.83 s.edit-diff.test.ts10.85 s (24 tests).file-tool-planning.test.tsalone: 6 tests passed, 184.48 s wall with warmed compiler outputs. Tests defer the real planner result and verify active, revoked, and aborted authority before either mkdir or write, without timers or polling.diffpackage and missing-planner-artifact rejection. Canonical compiled fixture preparation accounted for 443.17 s; the existing archive-build fixture is shared across its runtime cases. Gateway bundle/bootstrap and final planning/formatting siblings also passed; the complete six-file selection passed 145 tests in 1,642.04 s wall across three routed test groups. The sealed-build test file accounts for 202.13 s of Vitest file time: it must build and execute the relocated package to prove the worker is self-contained; pure planner tests cannot catch a missing deployed artifact.bundle.test.tspassed in 289.00 s,bootstrap.test.tsin 269.19 s, andcheck-cli-bootstrap-imports.test.tsin 216.06 s. A laterworker-deploy-build-plugin.test.tsrun hit its existing 180 s beforeAll build timeout (437.49 s wall, 13 passed, 5 runtime cases skipped). Its earlier full-selection run passed all 18 cases; both packaging runs used the same pre-merge head. A bounded diagnosis built only the newly added worker using the canonical configuration: 0.70 s wall / 0.38 s CPU, 61,597 bytes, so that artifact does not explain the aggregate build timeout. The precise aggregate-fixture cause remains uncertain; no timeout or assertion was weakened and the earlier pass is not claimed as a fix.node scripts/check-changed.mjs: all selected guards, all typechecks, coercion/deprecation checks, and all three dead-export scans passed. The full invocation was operator-interrupted during lint after lengthy package-boundary preparation (4,984.36 s wall); it did not return zero. Resumed lint passed script and extension shards, then caught a redundant options-object spread (812.91 s wall); the copy was removed. After main integration, core lint ran 701.94 s and found three existing line-limit violations in files unchanged by this PR (src/gateway/server-kernel.test.ts,src/agents/embedded-agent-runner/run/attempt-session-replay.test.ts, andsrc/config/sessions/session-accessor.sqlite-entry-cache-publication.ts). It also found that our bootstrap assertions crossed that file's line limit; consolidating the repeated assertions preserves every explicit artifact-path check and removes ten lines. Focused type-aware lint for the corrected planner and bootstrap test passed (190.09 s wall); the affected npm-bootstrap contract passed withnode scripts/run-vitest.mjs src/gateway/worker-environments/bootstrap.test.ts --maxWorkers=1 -t "installs only the exact npm package without transferring a tarball"(1 passed, 39 intentionally filtered; 670.05 s wall). Its shared compiler preparation took 433.41 s for 13,435 inputs and 17,010 outputs; the Vitest phase reported 98% transformation time. A supplemental post-merge write/planning/bootstrap selection was stopped after 720.04 s without test results; native sampling showed an idle event loop and a filesystem worker blocked insiderename. The precise cause is uncertain, and this interrupted run is not claimed as passing proof. Stylesheet lint passed (53.80 s wall); import-cycle checks passed with 0 runtime cycles (129.42 s wall). The final cleanup and registry conflict resolution pass formatting and diff whitespace checks.9e8037adfc9ef2c5f2c82044568e7fad9f59bfb5: scoped-clean, no accepted/actionable findings.Landing validation: CI run 36210003889 failed at
check-dependencies: Knip reported the new sealed worker entry as unused because it is built and launched by path. Commitc3f858ba5529dc5cbe6841b9e78112b52b3919c4registers that exact entry alongside the existing deployed workers. Independent Codex autoreview of the correction at P0–P2 is scoped-clean;pnpm deadcode:full, formatting, and whitespace checks pass. No failed run was rerun to obtain green.CI run 36211213334 then exposed the missing planner classification in
tsdown-config.test.ts; one assertion expected.jsfor this deployed.mjsworker and fail-fast cancelled the remaining jobs. Commit4fd6195dfa37e6132482ad5c6607a7de70839833adds the planner to the existing worker table, dependency-bundling cases, and sealed-output assertions.pnpm test test/scripts/tsdown-config.test.ts --maxWorkers=1: 45 passed, 272.39 s wall, 215.95 s test time on the loaded local host. The two added bundled-dependency cases took 5.96 s and 7.20 s; this existing suite builds and executes relocated package artifacts, which a config-only assertion cannot prove. Targeted type-aware lint, formatting, whitespace, line-cap ratchet, and independent P0–P2 Codex autoreview pass. This head was superseded by the main-integration repair below.The coordinator-approved runtime behavior retains explicit pre-mutation failure when worker planning is unavailable or shared admission is exhausted, including optional write-receipt planning; there is no expensive synchronous fallback. ClawSweeper called out this availability tradeoff. The new artifact participates in the existing content-hashed bundle and receipt checks; a live upgrade of an existing deployment was not performed.
CI run 36212490910 exposed an incoming-main regression from
a99102804ebab7cc2e99687f7ca8ed34e576a9f1: the new fs-safe quota walker aborted a live rsync when a listed temporary file was renamed before stat. The captured CI test group reproduced the same error locally (64 files / 878 tests passed; the original large Git sync test failed). Main was merged, not rebased, and586325fb03e8c6ffd2a633710a613bb15a17b106tolerates missing paths only during periodic active-transfer scans; the final post-transfer quota scan stays strict, and other scan errors still abort and join the transfer.The deterministic real-rename regression fails on the pre-fix code and passes afterward.
pnpm test src/gateway/worker-environments/workspace-sync.test.ts --maxWorkers=1: 13 passed, 48.58 s wall (about 0.2 s test time, with compiled fixture preparation dominating). Replaying the captured original CI group after the repair passed 879 Node tests across 65 files (321.37 s wall) and 124 Bun tests across 16 files (21.80 s wall). Bun printed a non-fatal directory-mismatch diagnostic while returning success. Targeted lint, formatting, whitespace checks, and fresh independent P0–P2 review of the complete candidate pass. Hosted CI will gate this new head.CI run 36214983604 exposed the remaining schema-inlining assertion omission in
tsdown-runtime-config.test.ts. Commit23c6a99e873c88f1b103ec662352cee076102c1cregisters the planner in the existing executable graph set without changing its assertions. The full file passes 32 tests, 59.81 s wall, 0.261 s test time; compiler/fixture preparation dominates. Targeted lint, formatting, whitespace, and independent P0–P2 review pass. Both sibling tsdown graph-classification tests now account for the planner. Superseded by the fixture repair below.CI run 36216017676 hit Linux
spawn ETXTBSYbefore a copied PR-tooling fixture could launch. Commita5bd2fffda54688ae678fc341d4ea9f62c59cc75launches that copied shell entry through the fixture Bash binary and holds a writable descriptor across spawn as a deterministic regression condition. It preserves all freshness, artifact, and lock assertions without retrying. Blacksmith Testboxtbx_01m3dzvrndnn6k7c566zq1rqtj(run) verified the old direct-exec path fails withETXTBSY, then passed the full 146-test file in 56.53 s wall usingpnpm test test/scripts/pr-operation-lock.test.ts --maxWorkers=1. This existing process-lifecycle suite exercises real Git/process/lock ownership; no new test case or process boot was added. The lease stopped successfully; the wrapper returned zero despite a portal-sync timeout warning. An earlier Testbox attempt stopped before tests because the proof command incorrectly compared its carrier commit with the local head; that command precondition was corrected. Formatting, lint, whitespace, and independent P0–P2 review pass. Hosted exact-head CI reached the unrelated main blocker below.Resolved incoming-main blocker (historical): exact-head CI 36218454003, job
108339678398, failedtest/scripts/lint-suppressions.test.tsbecause incoming main containssrc/gateway/server-chat-progress-snapshot.ts|no-implicit-coercion|1, absent from the approved suppression list. Introducing main commit:2f2ec46dd56c1a3d115bae63c52bd84dcc8b6f79(#158572); the same failure is independently recorded in #158641. The unary-plus operation deliberately preserves native JSON rejection of custom BigInt coercion, so replacing it withNumber()would change behavior. No owning fix or explicit baseline-exception approval was found. No allowlist expansion, gate bypass, or rerun was performed. Native preparation and merge have not started.The suppression blocker is now resolved on main by
20f3170d3672de0d491c5bb9cf9bf7e22e9658a7and66b812f26e725cd709e08860d2cb46ba496cd308:Reflect.apply(Math.max, undefined, [value])preserves native ToNumber behavior without a suppression. Adding the proposed exact baseline entry now demonstrably fails (77 actual vs 78 expected); unchanged main passes all four guard tests, so no exception change or redundant PR was retained. Merge commit85446077f9f42ada7650beb353f968e9fcf3456dincorporates main without rebasing. The merged candidate passes 23 tests across suppression, workspace-transfer, and file-planning selections (280.47 s wall, compiled fixture preparation dominates). Fresh independent P0–P2 candidate review is clean. Superseded by the following main-fixture integration.CI 36227460292, job
108364742434, hit the same archive/Undo fixture race as main CI36227000289: the fixture used a synchronous reset while asynchronous database resources were still closing. The unchanged local 22-file replay passed, so it is not claimed as a fix. The exact async-drain correction proposed in #158655 passed the captured 273-test group; before a duplicate could be published, main landed the canonical scoped correction as6c7544adc9826fa637425a2fa967389e0507a800. Mergeffb9401f43a4352fc7a0c873a506d195b0667fd5incorporates it. The canonical archive fixture passes both cases in the merged candidate (313.36 s wall, compiled preparation and fixture startup dominate). Fresh independent P0–P2 review and whitespace checks pass; no duplicate fixture repair is retained. The final observed CI result is recorded below.Final outcome: merged at
0042f8a570d48f01e7f4f667e3e4833caa68d80aon 2026-09-26T08:55:55Z from headffb9401f43a4352fc7a0c873a506d195b0667fd5. Fetching current main andgit merge-base --is-ancestorboth returned zero. The merge occurred concurrently while this landing task investigated CI 36230265207, job108372555642: its remaining failure was the incoming-main fs-safe import boundary for three Codex plugin files, introduced by #158613 and also observed in #158598 and #158441. That CI run is not claimed green. No filesystem-boundary exception or further source repair was made by this task.