Skip to content

improve: reuse snapshotted web search result rows - #139162

Merged
steipete merged 1 commit into
mainfrom
codex/perf10-web-output
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf10-web-output

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Every web-search result list was copied a second time during normalization, including large provider payloads that would ultimately be reduced to ten results or returned through the raw-output branch.

Why This Change Was Made

The normalizer now reuses the result array in its existing JSON snapshot. That snapshot already isolates provider data and converts sparse holes to explicit nulls, so the extra Array.from and its obsolete comment are unnecessary. All rows are still validated before result truncation; error precedence, untrusted-content wrapping, and output budgets remain unchanged.

User Impact

Web-search output remains identical while avoiding one full result-array allocation per call. Production is 2 lines smaller; tests are unchanged. The benefit is modest for ordinary result counts and more visible for large payloads.

Evidence

  • Nine actual-owner before/after cases matched after normalizing only random envelope IDs: dense and sparse arrays, malformed tail rows, error precedence, getters, circular input, and bigint input.
  • 79 tests across web-search output/security/cancellation suites passed before and after. Formatting and diff checks passed; managed P0–P2 review was scoped-clean with no findings.
  • Owner-attributed Array.from samples dropped from about 2.4 MB to zero across 30 calls with 10,000 rows. For five-row results the saved sample was about 33 KB across 500 calls; total allocation noise exceeded that saving.
  • Timings were mixed, so this change makes no general latency, retained-heap, RSS, or whole-Gateway memory claim. No provider API or request behavior changed; this packet's proof is local owner execution, not a separate live-provider run. Current-head CI is recorded separately by the publisher.

@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 5, 2026 15:01
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Sep 5, 2026
@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 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 5, 2026, 11:07 AM ET / 15:07 UTC.

ClawSweeper review

What this changes

Reuses the already-snapshotted web-search result array, avoiding a second allocation while preserving model-facing output.

Merge readiness

✅ Ready for maintainer review

Keep open: this useful optimization is absent from current main and preserves the existing output contract. No blocking correctness or security findings.

Priority: P3
Reviewed head: 8ceb676ad46074576ba2d86842d5e1c24829e407

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization supported by the snapshot invariant and existing behavioral coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor gate does not apply to this maintainer-authored internal optimization. The body reports local normalizer equivalence and allocation measurements, not a live-provider run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this maintainer-authored internal optimization. The body reports local normalizer equivalence and allocation measurements, not a live-provider run.
Evidence reviewed 12 items Verified introduced change: The pinned merge-base-to-head diff replaces Array.from with the existing result array and removes its obsolete comment. The verified test merge produces the same change against its main parent.
Snapshot establishes safe array reuse: snapshotProviderResult serializes and parses provider input before normalization reads it. Sparse holes become explicit null entries; the unchanged row validation rejects them. Subsequent slicing and mapping do not mutate the snapshot array.
Record validation contract: The repository-owned isRecord helper explicitly rejects null and arrays, so densified sparse entries cannot pass row conformance.
Findings None None.
Security None None.

How this fits together

OpenClaw’s managed web-search tool receives provider payloads and normalizes them into results, answers, errors, or raw output. This boundary isolates provider data and applies content safeguards before returning it to the agent.

flowchart TD
  A[Agent search request] --> B[Managed search provider]
  B --> C[JSON snapshot]
  C --> D[Validate and classify payload]
  D --> E[Bounded results or answer]
  D --> F[Error or raw payload]
  E --> G[Protected tool output]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -2. Total -2 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 1 3 -2
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 1 3 -2

Review metrics

Metric Value Why it matters
Production versus test LOC Production net −2: executable lines unchanged, comments −2; tests unchanged The optimization removes redundant allocation without adding implementation or test surface.

Technical review

Best possible solution:

Use one isolated provider snapshot for validation and bounded projection, retaining raw passthrough and existing content safeguards.

Do we have a high-confidence way to reproduce the issue?

Not applicable to a functional bug: source confirms the redundant allocation, and the body reports comparative measurements; no benchmark was rerun during this read-only review.

Is this the best way to solve the issue?

Yes. Removing the second copy at the normalization owner is the narrowest solution; removing the JSON snapshot instead would sacrifice isolation and serialization safeguards.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded allocation optimization with no intended user-visible behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor gate does not apply to this maintainer-authored internal optimization. The body reports local normalizer equivalence and allocation measurements, not a live-provider run.

Label justifications:

  • P3: This is a bounded allocation optimization with no intended user-visible 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: The external-contributor gate does not apply to this maintainer-authored internal optimization. The body reports local normalizer equivalence and allocation measurements, not a live-provider run.

Evidence

What I checked:

  • Verified introduced change: The pinned merge-base-to-head diff replaces Array.from with the existing result array and removes its obsolete comment. The verified test merge produces the same change against its main parent. (src/agents/tools/web-search-output.ts:281, 8ceb676ad460)
  • Snapshot establishes safe array reuse: snapshotProviderResult serializes and parses provider input before normalization reads it. Sparse holes become explicit null entries; the unchanged row validation rejects them. Subsequent slicing and mapping do not mutate the snapshot array. (src/agents/tools/web-search-output.ts:211, 8ceb676ad460)
  • Record validation contract: The repository-owned isRecord helper explicitly rejects null and arrays, so densified sparse entries cannot pass row conformance. (packages/normalization-core/src/record-coerce.ts:2, 8ceb676ad460)
  • Existing behavioral coverage: The existing suite covers sparse-array raw output, unserializable payloads, changing getters, declared-error precedence, and provider output shapes. These tests were inspected, not executed during this review. (src/agents/tools/web-search.test.ts:758, 8ceb676ad460)
  • Validation precedes truncation: Security coverage explicitly preserves raw output when a malformed row follows ten valid rows, and checks result counts, aggregate content limits, citation handling, and source preservation. (src/agents/tools/web-search-output.security.test.ts:250, 8ceb676ad460)
  • Caller and output boundary: createWebSearchTool passes completed provider output through the normalizer, then serializes normalized branches or separately bounds and wraps raw output. Answer citations use their own projection; web_fetch uses separate content wrapping. None requires the removed array copy. (src/agents/tools/web-search.ts:133, 8ceb676ad460)

Likely related people:

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

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.

@steipete
steipete merged commit de71dbf into main Sep 5, 2026
244 checks passed
@steipete
steipete deleted the codex/perf10-web-output branch September 5, 2026 15:23
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to aniruddhaadak80/openclaw that referenced this pull request Sep 5, 2026
* origin/main: (46 commits)
  fix(gateway): keep chat metadata responsive across auth refresh (openclaw#139192)
  fix(doctor): keep Workshop relocation lint read-only (openclaw#139193)
  perf(ui): retain unchanged forwarded avatar publications (openclaw#139181)
  fix(config): guide exec policy migration repairs (openclaw#139143)
  test(i18n): refresh representative Watch key (openclaw#139197)
  fix(agents): preserve recovered scheduled-run outcomes (openclaw#139037)
  refactor(acp): simplify pending operation accounting (openclaw#139189)
  fix(plugin-sdk): harden account scope for pairing requests and challenges (openclaw#139142)
  perf(gateway): avoid redundant PR landing ancestry checks (openclaw#139186)
  perf(ui): release captured audio cache leases directly (openclaw#139174)
  fix(skills): validate names in library forms (openclaw#139184)
  fix(sessions): reduce cold catalog listing delays (openclaw#139146)
  perf(cron): scan preserved action output once (openclaw#139163)
  fix(agents): keep fresh tool results readable under context pressure (openclaw#139165)
  fix(compaction): heartbeat sessions ignore the active transcript byte cap (openclaw#136533)
  perf(agents): reuse snapshotted web search result rows (openclaw#139162)
  fix(onboarding): keep Tauri setup recoverable and verify model results (openclaw#139140)
  fix(memory): rank indexed sessions by source activity (openclaw#139112)
  perf(terminal): avoid rebuilding sanitized link fallbacks (openclaw#139159)
  perf(agents): bound retained tool result projection data (openclaw#139157)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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.

1 participant