Skip to content

perf: avoid temporary entries in bounded JSON traversal - #138017

Merged
steipete merged 1 commit into
mainfrom
codex/perf8-json-own
Sep 4, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf8-json-own

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor
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.entries alternative 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 6d6ba712d4c7468a83355a7f13733b7244bee049 now 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 maintainer label 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.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 4, 2026
@steipete
steipete marked this pull request as ready for review September 4, 2026 07:13
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 10:59 AM ET / 14:59 UTC.

ClawSweeper review

What this changes

This 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
Reviewed head: 6d6ba712d4c7468a83355a7f13733b7244bee049
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative production cleanup with behavior-oriented coverage and no actionable correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored internal helper refactor with no directly user-visible flow; real-behavior proof is not a gate, while the focused behavior tests remain useful supplemental evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored internal helper refactor with no directly user-visible flow; real-behavior proof is not a gate, while the focused behavior tests remain useful supplemental evidence.
Evidence reviewed 7 items Introduced traversal change: The introduced hunk removes the generator and keeps the same for...in, own-enumerability filter, lazy property read, omitted-value filter, and byte-counting owner in one loop.
Current-main baseline: Current main still uses the generator at the same traversal point, so the PR remains necessary and is not superseded by main.
Behavioral coverage: The changed owner suite checks JSON-equivalent enumerable own fields and verifies that a later getter is not read after the byte limit is exceeded; these protect the relevant lazy-prefix invariant rather than generator internals.
Findings None None.
Security None None.

How this fits together

Bounded 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
Loading

Decision needed

Question Recommendation
After all exact-head required checks are visibly green, should this maintainer-labelled performance cleanup merge? Merge after check confirmation: Confirm the omitted exact-head required checks are green, then merge this narrow behavior-preserving cleanup.

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

  • Resolve merge risk (P1) - The supplied exact-head check rollup is truncated, so this review cannot establish that every required check has completed successfully.
  • Complete next step (P2) - A maintainer should confirm the omitted exact-head required checks are green, then retain or clear the maintainer label before merge.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source -4, Tests +22. Total +18 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 10 -4
Tests 1 22 0 +22
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 28 10 +18

Review metrics

Metric Value Why it matters
Production versus test LOC production −4, tests +22 Production removes the private generator; added tests cover own-enumerable JSON behavior and limit-triggered lazy termination.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    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.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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 Object.entries replacement would not preserve the early-stop boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a6a979cf6d61.

Labels

Label justifications:

  • P3: This is a small internal performance cleanup with no user-facing contract, configuration, or delivery behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored internal helper refactor with no directly user-visible flow; real-behavior proof is not a gate, while the focused behavior tests remain useful supplemental evidence.

Evidence

What I checked:

  • Introduced traversal change: The introduced hunk removes the generator and keeps the same for...in, own-enumerability filter, lazy property read, omitted-value filter, and byte-counting owner in one loop. (src/infra/json-utf8-bytes.ts:128, 6d6ba712d4c7)
  • Current-main baseline: Current main still uses the generator at the same traversal point, so the PR remains necessary and is not superseded by main. (src/infra/json-utf8-bytes.ts:137, a6a979cf6d61)
  • Behavioral coverage: The changed owner suite checks JSON-equivalent enumerable own fields and verifies that a later getter is not read after the byte limit is exceeded; these protect the relevant lazy-prefix invariant rather than generator internals. (src/infra/json-utf8-bytes.test.ts:83, 6d6ba712d4c7)
  • Caller boundary: MCP result shaping measures structured content before retaining it in the node invocation payload, so unchanged complete/incomplete decisions preserve the caller contract. (src/node-host/invoke-mcp-result.ts:35, 6d6ba712d4c7)
  • Feature history: File history identifies Peter Steinberger's shared-helper refactor as an earlier central change; the later bounded-measurement repair is commit 842301a. Parent blobs needed to prove exact line introduction were unavailable locally, so this is routing evidence rather than attribution. (src/infra/json-utf8-bytes.ts, 264599cc1d32)
  • Codex boundary check: Direct sibling Codex inspection found no boundedJsonUtf8Bytes or json-utf8-bytes use under its protocol/runtime sources. This PR changes OpenClaw core code only, so no Codex dependency contract is implicated. (codex-rs/protocol/src/lib.rs:1, 41e22fee981a63b3698df7ed36bad393cda24715)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Monkey-wusky: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the complete exact-head required-check rollup is green before merge.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-04T07:22:29.616Z sha aa1ec7e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-04T08:17:00.688Z sha aa1ec7e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-04T08:55:20.406Z sha 05dd535 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-04T10:43:11.481Z sha 88f0240 :: blocked before merge. :: none
  • reviewed 2026-09-04T12:37:39.381Z sha 170163f :: blocked before merge. :: none
  • reviewed 2026-09-04T13:14:41.014Z sha 170163f :: blocked before merge. :: none

@steipete
steipete force-pushed the codex/perf8-json-own branch 3 times, most recently from 88f0240 to 170163f Compare September 4, 2026 12:28

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Direct traversal is the better owner here. It keeps enumeration order and, importantly, preserves the early-stop behavior without evaluating later getters.

@steipete
steipete force-pushed the codex/perf8-json-own branch from 170163f to 6d6ba71 Compare September 4, 2026 14:27
@steipete
steipete merged commit a049778 into main Sep 4, 2026
181 checks passed
@steipete
steipete deleted the codex/perf8-json-own branch September 4, 2026 15:13
@steipete

steipete commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 4, 2026
…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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants