Repository navigation
perf: avoid temporary entries in bounded JSON traversal - #138017
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: blocked before merge. Reviewed September 4, 2026, 10:59 AM ET / 14:59 UTC. ClawSweeper reviewWhat this changesThis PR removes the private generator used by bounded JSON byte counting, iterates enumerable own object fields directly, and adds coverage for JSON field filtering and early termination. Merge readiness⛔ Blocked before merge - 3 items remain Keep open for normal maintainer handling. No blocking correctness or security issue was found in this behavior-preserving cleanup, but the maintainer label and incomplete exact-head check rollup require maintainer confirmation before merge. Priority: P3 Review scores
Verification
How this fits togetherBounded JSON byte counting is a shared core helper that lets OpenClaw reject oversized structured values without fully serializing them. MCP result shaping, worker request admission, and persisted tool-detail handling consume its complete/incomplete result to decide whether to retain, truncate, or reject data. flowchart LR
A[Structured tool or worker data] --> B[Bounded JSON byte counter]
B --> C{Fits byte limit?}
C -->|Yes| D[Preserve structured value]
C -->|No| E[Truncate or reject safely]
D --> F[MCP, worker, and session consumers]
E --> F
Decision needed
Why: The author is a repository member and the PR carries the protected maintainer label, so this workflow must leave the final merge judgment to a maintainer despite the clean code review. Before merge
Agent review detailsSecurityNone. PR surfaceSource -4, Tests +22. Total +18 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the direct traversal refactor, which removes temporary iterator-entry work while preserving the existing lazy bounded-prefix contract, once a maintainer confirms the complete exact-head check state. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a behavior-preserving performance refactor, and the relevant observable contracts are the bounded helper's JSON-equivalence and early-stop cases. Is this the best way to solve the issue? Yes. Inlining the existing generator body at the byte-counting owner preserves enumeration and lazy property-read behavior; an eager AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a6a979cf6d61. LabelsLabel 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
HistoryReview history (6 earlier review cycles)
|
88f0240 to
170163f
Compare
sylvesterkaczmarek
left a comment
There was a problem hiding this comment.
Direct traversal is the better owner here. It keeps enumeration order and, importantly, preserves the early-stop behavior without evaluating later getters.
170163f to
6d6ba71
Compare
|
Merged via squash.
|
…9-prep * commit '407a8f453c0f0306af1ddc0aafa8697c1d49a9e7': (312 commits) perf(ui): coalesce automation event refreshes (#138065) fix: reject incomplete Skill Workshop directory reads (#138082) test(ui): decouple rendering checks from generated wording (#138283) perf: avoid temporary entries in bounded JSON traversal (#138017) fix(irc): render complete messages before splitting (#138328) perf: prepare worker trajectory payloads only for recorded events (#138086) fix(mcp): paginated listings no longer time out after a forward clock step (#137206) fix(codex): page native transcripts and bound UI previews (#136282) feat(gateway): apply more settings without restarting (#138112) fix(docs): preserve mirrored ClawHub maturity links (#138241) fix(test): own UI animation and legacy database setup (#138296) fix(tts): preserve literal directives in Markdown code (#138319) fix: load chat widgets behind authenticated gateways (#138074) chore(ui): cover native approval finalization (#137259) fix(cron): cancel conditions before main-session handoff (#138313) fix(backup): preserve text after embedded NUL characters (#138327) fix(android): align composer control sheets (#137442) fix(ci): wait for replacement PR runs instead of stale failures (#138307) fix(sessions): keep Gateway responsive with long transcripts (#138094) fix(computer): map window inputs to delivered image coordinates (#138271) ... # Conflicts: # scripts/release-check.ts # test/release-check.test.ts
Additional instructions
Maintainers can edit this branch.
What Problem This Solves
Bounded JSON byte counting creates a generator for every object and temporary entry pairs for every field it visits. Tool details, nested activity and MCP responses all use this helper to enforce their payload limits.
Why This Change Was Made
Traverse the object's enumerable own fields directly at the existing byte-counting owner. This removes the private generator while preserving field order, getter timing, omitted values and the exact point at which a byte limit stops traversal. String encoding, cycles, arrays and custom serialization rules are unchanged.
User Impact
The same payloads fit or exceed the same limits with less temporary work. There is no API or configuration change. Production LOC: +6/−10 (net −4); tests: +22/−0.
Evidence
The existing 22-test owner suite passed before editing. The candidate extends the same behavioral coverage for own enumerable fields, omitted properties, escaped keys and stopping before a later getter. The focused owner, MCP result and pagination suites passed 36 tests. Independent source review and a fresh isolated Codex P0–P2 review found no actionable issues; the complete changed-file gate passed, including core and test type checks, dead-code scans, lint and repository guards.
A quiet A/B/B/A probe executed 30,000 actual helper calls per process against the pinned original and candidate source. All four runs returned the same checksum and expected byte/complete decisions. Original measured loops took 1451.4 and 1465.6 ms; candidate loops took 858.5 and 857.2 ms. This is a synthetic helper workload, not a whole-Gateway latency or memory claim. Source hashes and process cleanup receipts are retained locally.
Independent source review found no actionable difference in enumeration or early-stop behavior. The existing
Object.entriesalternative would eagerly allocate and read fields beyond the bounded prefix; direct traversal preserves that important boundary.Real Gateway comparison
A fixed real OpenAI Responses workload completed ten turns in both the original build and a combined eight-change candidate: Code Mode and Tool Search, web fetch, file reads, large Unicode output, session history and two 65-second idle observations. Both source/build/dependency identities stayed stable, all required results matched, and every Gateway exited cleanly with its ports released.
The two Unicode-stage main-isolate sampled allocation estimates changed from 102,775,912 to 85,136,936 bytes and from 121,232,968 to 108,344,904 bytes. After requested main-isolate GC at idle, Code Mode Gateway RSS changed from 489.375 to 488.141 MiB while heap used changed from 268.414 to 269.567 MiB; Tool Search RSS changed from 483.953 to 481.031 MiB while heap used changed from 259.947 to 259.968 MiB. External/ArrayBuffer readings were essentially unchanged.
This is one sequential original/combined-candidate comparison, not randomized or attributable to this PR alone. Sampling includes collected objects and is not exact allocated or retained bytes; RSS includes Gateway worker threads, while heap and allocation samples cover the main isolate. No retained-heap reduction is claimed.
Maintainer disposition of the 13:14 UTC review
The two failed checks cited by that review belong to the earlier head. The refreshed exact head
6d6ba712d4c7468a83355a7f13733b7244bee049now has 175 terminal checks: 132 successful, 42 skipped and one neutral, with no failed or pending check. Its aggregate CI gate passed.The earlier 120-second Linux non-isolated-runner failure remains part of the evidence. This head includes the landed census-order repair #138294, whose local comparison preserved the four lifetime censuses and independent manual/automock retention controls. Those local runs did not reproduce the full Linux timeout, so its complete causal explanation remains unproved. The JSON traversal patch itself is unchanged.
The maintainer has authorized landing this focused change with the
maintainerlabel retained. This explicitly addresses both Rank-up moves: current exact-head validation and protected-label handling. Repository-native review, required-check and merge gates remain in force.