Repository navigation
improve: reduce Code Mode source preparation overhead - #154209
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: needs changes before merge. Reviewed September 20, 2026, 8:37 PM ET / September 21, 2026, 00:37 UTC. ClawSweeper reviewWhat this changesCode Mode skips unnecessary JavaScript source parsing, reuses collected results in its QA scorer, and replaces repetitive Unicode tests with focused malformed-source cases. Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this is a useful, bounded optimization absent from current main and the latest release. No actionable correctness or security defect was found in the introduced changes. Priority: P2 Review scores
Verification
How this fits togetherOpenClaw Code Mode prepares agent-written JavaScript before running it in a QuickJS worker with bounded tool access. Its QA scorer checks recorded tool calls and results against expected behavior. flowchart TD
A[Agent JavaScript] --> B{Possible module loader text}
B -->|Yes| C[Existing parser and loader checks]
B -->|No| D[Shell source check]
C --> D
D --> E[QuickJS worker execution]
E --> F[Recorded calls and results]
F --> G[QA behavior scorer]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +4, Tests -3, Other +8. Total +9 across 3 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep source preparation with its existing owner and retain the conservative fast path without changing guest execution or tool permissions. Do we have a high-confidence way to reproduce the issue? Not applicable as a functional bug reproduction: current source confirms unconditional Acorn parsing, and the author supplies before/after performance measurements; those measurements were not rerun here. Is this the best way to solve the issue? Yes. The conservative prefilter removes unnecessary work at the existing owner, while the scorer changes preserve the same result-chain and identity checks. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 2969f4becc06. LabelsLabel changes:
Label justifications:
EvidenceWhat 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
|
|
Merged via squash.
|
Related: #153889. Follow-up to #154001.
What Problem This Solves
Code Mode still constructs an Acorn AST for ordinary JavaScript cells that contain no possible module loader, adding unnecessary source-preparation cost.
User Impact
JavaScript cells without module-loader syntax reach execution sooner. Typed discovery, tool validation, error locations, and sandbox limits are unchanged; no configuration changes are needed. Whole agent-turn latency remains dominated by other work.
Why This Change Was Made
A conservative text check skips Acorn only when
import,require, and Unicode escapes are all absent. Possible loader spellings retain the existing parser and malformed-source checks, and QuickJS still parses every executable cell.The live-matrix scorer now checks call identity before walking result chains and reuses each collected chain. Two malformed-JavaScript Unicode cases replace 192 repetitive valid-AST assertions, covering the fallback that the old loop never reached.
Evidence
On the same isolated AWS host and pinned baseline, source preparation fell from 16.3 to 0.54 microseconds for an 89-byte cell and from 870 to 5.47 microseconds for an 8.3 KiB cell (40 measured batches). Process peak RSS for these probes fell from 108.9 to 101.5 MiB and 116.9 to 100.4 MiB respectively. These are source-preparation microbenchmarks, not whole-task speedup claims. Cold worker startup and ordinary warm-cell timing were broadly unchanged.
Validation included 938 focused runtime/matrix tests across 28 files and passing changed checks. After removing the metadata-transfer experiment, the final source-preparation/matrix tests and private-QA build passed. Independent review of the final diff found no actionable P0–P2 findings. The real-model JavaScript-contract smoke passed on the exact clean commit: 1/1 task behavior and 1/1 interview consistency, with no failures, unavailable cases, or retries.
Benchmark runs: baseline, selected parser optimization (results-A). Selected build and focused proof.
Test cost: the final
src/agents/code-mode-runtime.test.tsproject passed 97 tests in 2.89 seconds including transform/import/setup; all final targeted projects passed 437 tests across four files in 19.22 seconds. CI run passed onf024c40ed11c68c093bafebcd4ea4cea79f12d8d: 795 seconds elapsed, including 92 seconds forchecks-node-changedand 308 seconds for the build job (jobs overlap). The clean committed private-QA build also passed with source and runtime artifact hashes matching the initial build.Live JavaScript-contract proof: explicit OpenClaw runtime,
openai/gpt-5.6-luna, one trial, 13.107 seconds and five upstream calls. The built runtime recorded clean source at the PR commit.