Skip to content

refactor: reuse web search request preparation - #148949

Merged
steipete merged 1 commit into
mainfrom
codex/perf-web-search-request-context
Sep 15, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-web-search-request-context

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Web search resolves its request configuration twice before provider discovery, which can repeat complete config serialization for scoped requests.

User Impact

No user-visible behavior change is intended. Provider selection, configured-versus-automatic fallback, errors, cancellation, and returned results remain unchanged. There are no configuration, dependency, schema, or permission changes.

Why This Change Was Made

Pass the existing request-local context from runWebSearch into candidate preparation instead of resolving it again immediately. The change removes six net lines and preserves the later config reads, credential callbacks, and both explicit-selection checks. Context is prepared afresh for every request; nothing is cached across calls.

The avoided work depends on the input. A scoped config that differs from the active source after provenance checking can avoid two full config serializations. Identity and other cheap paths already avoid that work. These counts come from source inspection. In the small synthetic scoped-mismatch case, the actual runWebSearch entry point used 16.06–16.78% less median wall time in the two pair orders, saving 6.38–7.08 microseconds per call. Cheap-path results were mixed, and forcing the input config was slightly slower. No general or network-search speedup is claimed.

Evidence

The maintained test runner executed all three requested files: src/web-search/runtime.test.ts (33 cases), src/web-search/runtime-execution.test.ts (9), and src/agents/tools/web-search.signal.test.ts (8). All 50 passed with no skipped, missing, or unexpected files. The native process and descendants closed successfully.

Codex review through P2 found no actionable defects in the complete changed owner and supplied caller context. Unchanged protected dependencies remained outside that review; the final reviewer found the supplied context sufficient for this narrow change. Earlier blocked or incomplete review attempts remain preserved in the local evidence.

Untimed before/after runWebSearch proof passed 32 calls, including 16 config-case observations and eight control records covering callback reentry, fallback, structured errors, and cancellation. Complete decoded outputs matched; native children closed, candidate source was restored, and generated caches were retired.

The frozen install passed without source or lockfile changes. Independent audit verified all 144 complete decoded timed-phase outputs (112 measured calls and 32 warmups), the retained preflight controls, exact source bindings, worker closure, and generated-cache retirement. No timed sample was rerun or discarded. Hosted exact-head CI remains required; local type-aware lint and broad type checks are not claimed. No live provider/network performance claim or broad release validation is included.

Paired request-preparation measurements and limitations

Darwin arm64, Node 26.8.2. Fixed B1 → C1 → C2 → B2 order, four small config cases per process, two warmups and seven measured calls per case. Each observation is one actual runWebSearch call using synthetic providers. Config publication, assertions, output serialization, and report writes are outside the wall/CPU timer.

Config case B1 → C1 (μs) Wall Δ B2 → C2 (μs) Wall Δ CPU Δ, first / second pair
scoped-mismatch 42.208 → 35.125 -16.78% 39.709 → 33.333 -16.06% -17.39% / -26.00%
identity 8.125 → 7.750 -4.62% 6.750 → 6.917 +2.47% +0.00% / +0.00%
matching-source 10.834 → 10.750 -0.78% 11.375 → 9.709 -14.65% +0.00% / -15.38%
prefer-input 11.459 → 12.333 +7.63% 9.417 → 9.625 +2.21% +0.00% / +9.09%

These small samples are descriptive, not statistical significance or throughput proof. Post-call worker RSS was 1.01–1.13% higher in every pair; it is sampled after assertions and serialization and does not measure per-call allocations. Whole-child peak RSS was also higher (kernel: +2.95% / +1.00%; sampled process tree: +2.54% / +1.01%), so no memory improvement is claimed. Whole-child measures include startup and proof overhead.

All cooperating local product, staging, and review jobs were paused for the timed family; no whole-machine-idle claim is made. One remote correctness command remained active; subsequent source-order and timestamp checks confirmed its final artifact export occurred after the timing window. The local archive was created more than 21 minutes after the window closed. The untimed preflight used the same corpus and inputs; a subsequent source-guard-only change batched reference inspection before the timed run, with the original guard and preflight retained.

@clawsweeper

clawsweeper Bot commented Sep 15, 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.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Sep 15, 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 6:06 AM ET / 10:06 UTC (Revision 2).

ClawSweeper review

What this changes

Web search reuses its prepared request configuration during provider selection, avoiding redundant work without changing intended search behavior.

Merge readiness

✅ Ready for maintainer review

Keep open as a useful, focused refactor: current main still repeats request preparation, and no actionable correctness defect was found. The earlier proof warning does not establish a blocker under the applicable maintainer exemption.

Priority: P3
Reviewed head: 4072d301adc08b07392cfb44e33e0f2146b39385

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused simplification with existing behavioral coverage, carefully bounded measurements, and no actionable findings.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified maintainer authorship exempts this internal refactor from external-contributor proof. The body reports after-change runWebSearch execution on Darwin with synthetic providers and matching outputs; this supports request preparation, without claiming live-provider performance.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified maintainer authorship exempts this internal refactor from external-contributor proof. The body reports after-change runWebSearch execution on Darwin with synthetic providers and matching outputs; this supports request preparation, without claiming live-provider performance.
Evidence reviewed 7 items Introduced change and merge result: The pinned merge-base delta introduces only request-context reuse in runtime.ts. Inspection of the test merge's raw parents confirmed the pinned base followed by the exact PR head; its comparison with that base contains the same focused change.
Configuration equivalence: The complete runtime and snapshot owner show that request preparation uses the existing configuration selector. The removed second selection occurs before provider callbacks or asynchronous execution; subsequent configuration reads, credential checks, explicit-selection checks, and cancellation handling remain intact.
Current main and release necessity: Fetched main retains the original duplicate preparation. The latest supplied release, v2026.9.4, also contains that original implementation, so this optimization remains distinct work.
Findings None None.
Security None None.

How this fits together

OpenClaw's web search runtime receives queries, configuration, and cancellation signals from agent tools and CLI commands. It selects eligible plugin providers and returns search results or errors, allowing fallback only for automatic selection.

flowchart TD
  A[Agent tool or CLI query] --> B[Prepare request context]
  C[Configuration and runtime metadata] --> B
  B --> D[Select eligible providers]
  D --> E[Execute selected provider]
  E --> F{Automatic fallback allowed?}
  F -->|Failure and eligible backup| E
  E --> G[Search result or error]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -6. Total -6 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 8 14 -6
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 8 14 -6

Review metrics

None.

Technical review

Best possible solution:

Keep request preparation local to each search and reuse its context while preserving existing provider selection, credential refresh, and execution boundaries.

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

Not applicable as a bug reproduction: source confirms redundant preparation, and the body reports a bounded synthetic measurement rather than a user-facing failure.

Is this the best way to solve the issue?

Yes. Passing the existing request-local context removes repeated work without adding a cache, changing public APIs, or bypassing later provider checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 00a455554d9f.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified maintainer authorship exempts this internal refactor from external-contributor proof. The body reports after-change runWebSearch execution on Darwin with synthetic providers and matching outputs; this supports request preparation, without claiming live-provider performance.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P3: This is a bounded internal 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: Verified maintainer authorship exempts this internal refactor from external-contributor proof. The body reports after-change runWebSearch execution on Darwin with synthetic providers and matching outputs; this supports request preparation, without claiming live-provider performance.

Evidence

What I checked:

  • Introduced change and merge result: The pinned merge-base delta introduces only request-context reuse in runtime.ts. Inspection of the test merge's raw parents confirmed the pinned base followed by the exact PR head; its comparison with that base contains the same focused change. (src/web-search/runtime.ts:387, 4072d301adc0)
  • Configuration equivalence: The complete runtime and snapshot owner show that request preparation uses the existing configuration selector. The removed second selection occurs before provider callbacks or asynchronous execution; subsequent configuration reads, credential checks, explicit-selection checks, and cancellation handling remain intact. (src/config/runtime-snapshot.ts:400, 4072d301adc0)
  • Current main and release necessity: Fetched main retains the original duplicate preparation. The latest supplied release, v2026.9.4, also contains that original implementation, so this optimization remains distinct work. (src/web-search/runtime.ts:385, 3a9d69db306c)
  • Existing behavioral coverage: Read the runtime, execution, and agent signal tests. They cover matching-source configuration, explicit input preference, provider selection, fallback, structured errors, and cancellation. The PR body reports all 50 cases passing; this read-only review did not execute them. (src/web-search/runtime.test.ts:563, 4072d301adc0)
  • Proof and re-review continuity: The complete supplied body reports Darwin arm64 measurements through runWebSearch with synthetic providers, matching before/after outputs, and explicit limits on performance claims. The previous review at the identical head recorded no findings or rank-up moves. Its historical proof warning is reassessed under the current maintainer exemption. (4072d301adc0)
  • Verified repository role: The live permission endpoint identifies steipete as a repository administrator, resolving the conflicting association fields in the supplied context.

Likely related people:

  • steipete: 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-15T09:08:54.147Z sha 4072d30 :: needs real behavior proof before merge. :: none

@steipete
steipete marked this pull request as ready for review September 15, 2026 09:50
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@steipete
steipete merged commit 5590248 into main Sep 15, 2026
270 checks passed
@steipete
steipete deleted the codex/perf-web-search-request-context branch September 15, 2026 11:20
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 15, 2026
* commit '1226eecf4ff909de172a6837422cfa64723fade8': (39 commits)
  test: align model auth and setup fixtures with current behavior (#149023)
  refactor: reuse web search request context (#148949)
  fix(ci): remove duplicate Copilot auth metadata (#149016)
  test(agents): align auth fixtures with runtime store reads (#149004)
  improve: reduce data fetched during reminder maintenance (#148996)
  fix(cron): skip availability checks when session pruning is idle (#148920)
  fix(auth): guard GitHub Copilot device flow authority (#148999)
  fix(agents): prevent early recovery aborts of foreground exec (#148959)
  fix(github-copilot): remove retired Raptor mini (#116505)
  improve(feishu): reduce preparation work for documents with tables (#148997)
  improve: reduce database work when recording participants (#148841)
  test: accept Bun error labels in plugin assertions (#148955)
  fix(models): clarify saved account health and catalog status (#148987)
  test(plugins): align Copilot auth-choice registry expectations (#148981)
  fix(channels): reject blank integer channel add options (#145534)
  fix(ui): preserve archive undo after chat navigation (#148831)
  feat: show cited source previews in macOS and iOS chat (#148906)
  fix: avoid redundant tab updates while chats stream (#148865)
  test(qa): run Discord through Crabline (#116446)
  perf(crabbox): prepare project runtimes during worker download (#148952)
  ...
vincentkoc added a commit that referenced this pull request Sep 15, 2026
* commit '84114b5a2711764e2ca333e327e808fd88316063': (40 commits)
  improve(sessions): reuse compiled transcript metadata queries (#148773)
  fix(ci): repair Copilot contracts and config failure diagnostics (#149001)
  test: align model auth and setup fixtures with current behavior (#149023)
  refactor: reuse web search request context (#148949)
  fix(ci): remove duplicate Copilot auth metadata (#149016)
  test(agents): align auth fixtures with runtime store reads (#149004)
  improve: reduce data fetched during reminder maintenance (#148996)
  fix(cron): skip availability checks when session pruning is idle (#148920)
  fix(auth): guard GitHub Copilot device flow authority (#148999)
  fix(agents): prevent early recovery aborts of foreground exec (#148959)
  fix(github-copilot): remove retired Raptor mini (#116505)
  improve(feishu): reduce preparation work for documents with tables (#148997)
  improve: reduce database work when recording participants (#148841)
  test: accept Bun error labels in plugin assertions (#148955)
  fix(models): clarify saved account health and catalog status (#148987)
  test(plugins): align Copilot auth-choice registry expectations (#148981)
  fix(channels): reject blank integer channel add options (#145534)
  fix(ui): preserve archive undo after chat navigation (#148831)
  feat: show cited source previews in macOS and iOS chat (#148906)
  fix: avoid redundant tab updates while chats stream (#148865)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
vincentkoc added a commit that referenced this pull request Sep 24, 2026
* refactor(agents): centralize tool description exclusions

* Merge main into refactor/tool-description-exclusions-20260915

* commit '84114b5a2711764e2ca333e327e808fd88316063': (40 commits)
  improve(sessions): reuse compiled transcript metadata queries (#148773)
  fix(ci): repair Copilot contracts and config failure diagnostics (#149001)
  test: align model auth and setup fixtures with current behavior (#149023)
  refactor: reuse web search request context (#148949)
  fix(ci): remove duplicate Copilot auth metadata (#149016)
  test(agents): align auth fixtures with runtime store reads (#149004)
  improve: reduce data fetched during reminder maintenance (#148996)
  fix(cron): skip availability checks when session pruning is idle (#148920)
  fix(auth): guard GitHub Copilot device flow authority (#148999)
  fix(agents): prevent early recovery aborts of foreground exec (#148959)
  fix(github-copilot): remove retired Raptor mini (#116505)
  improve(feishu): reduce preparation work for documents with tables (#148997)
  improve: reduce database work when recording participants (#148841)
  test: accept Bun error labels in plugin assertions (#148955)
  fix(models): clarify saved account health and catalog status (#148987)
  test(plugins): align Copilot auth-choice registry expectations (#148981)
  fix(channels): reject blank integer channel add options (#145534)
  fix(ui): preserve archive undo after chat navigation (#148831)
  feat: show cited source previews in macOS and iOS chat (#148906)
  fix: avoid redundant tab updates while chats stream (#148865)
  ...

* refactor(agents): consolidate tool description exclusions

* chore: merge main for tool summary validation

* commit '926bb1e1d75c6b102bcbf93114c690312c23cf18': (1903 commits)
  refactor(matrix): reuse startup verification account key (#157310)
  perf(config): avoid repeated environment scans during publication (#156457)
  chore(i18n): refresh native locales (#157495)
  fix(update): show quiet step progress and date recorded outcomes (#153407)
  feat(gateway): preserve browser sign-in requirements before connecting (#157454)
  test(scripts): await CLI admission fixture lifetimes (#157424)
  fix(ci): preserve consumer selection across core type stripes (#157373)
  fix(wizard): preserve typed plugin enum values (#127577) (#138090)
  fix(qa): title mock Code Mode fixture calls
  refactor: simplify SQLite worker lifecycle and test fixtures (#157458)
  test: prebuild run-node signal fixture (#157478)
  refactor(exec): reuse approval policy rule keys (#157198)
  fix(ci): reuse prepared runtime for changed-target E2E shards (#157365)
  fix(config): apply Gateway writes without waiting for file events (#157372)
  fix: count recorded nested tool operations once (#157438)
  fix(telegram): stop leaking raw file:// markdown links in messages (#137810)
  refactor(claws): share resource capability changes (#154680)
  improve(channels): reduce redundant preparation for button messages (#157050)
  fix(build): package preparation fails on unrelated test types (#157318)
  refactor(claws): share bounded document reading (#157436)
  ...

Co-authored-by: Vincent Koc <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 25, 2026
…8966)

* refactor(agents): centralize tool description exclusions

* Merge main into refactor/tool-description-exclusions-20260915

* commit '4a994031abb1b54d51b76755a55ac8f6e918162d': (40 commits)
  improve(sessions): reuse compiled transcript metadata queries (openclaw#148773)
  fix(ci): repair Copilot contracts and config failure diagnostics (openclaw#149001)
  test: align model auth and setup fixtures with current behavior (openclaw#149023)
  refactor: reuse web search request context (openclaw#148949)
  fix(ci): remove duplicate Copilot auth metadata (openclaw#149016)
  test(agents): align auth fixtures with runtime store reads (openclaw#149004)
  improve: reduce data fetched during reminder maintenance (openclaw#148996)
  fix(cron): skip availability checks when session pruning is idle (openclaw#148920)
  fix(auth): guard GitHub Copilot device flow authority (openclaw#148999)
  fix(agents): prevent early recovery aborts of foreground exec (openclaw#148959)
  fix(github-copilot): remove retired Raptor mini (openclaw#116505)
  improve(feishu): reduce preparation work for documents with tables (openclaw#148997)
  improve: reduce database work when recording participants (openclaw#148841)
  test: accept Bun error labels in plugin assertions (openclaw#148955)
  fix(models): clarify saved account health and catalog status (openclaw#148987)
  test(plugins): align Copilot auth-choice registry expectations (openclaw#148981)
  fix(channels): reject blank integer channel add options (openclaw#145534)
  fix(ui): preserve archive undo after chat navigation (openclaw#148831)
  feat: show cited source previews in macOS and iOS chat (openclaw#148906)
  fix: avoid redundant tab updates while chats stream (openclaw#148865)
  ...

* refactor(agents): consolidate tool description exclusions

* chore: merge main for tool summary validation

* commit 'e0f58a77476acbe382bff5e55cd520e9d228d478': (1903 commits)
  refactor(matrix): reuse startup verification account key (openclaw#157310)
  perf(config): avoid repeated environment scans during publication (openclaw#156457)
  chore(i18n): refresh native locales (openclaw#157495)
  fix(update): show quiet step progress and date recorded outcomes (openclaw#153407)
  feat(gateway): preserve browser sign-in requirements before connecting (openclaw#157454)
  test(scripts): await CLI admission fixture lifetimes (openclaw#157424)
  fix(ci): preserve consumer selection across core type stripes (openclaw#157373)
  fix(wizard): preserve typed plugin enum values (openclaw#127577) (openclaw#138090)
  fix(qa): title mock Code Mode fixture calls
  refactor: simplify SQLite worker lifecycle and test fixtures (openclaw#157458)
  test: prebuild run-node signal fixture (openclaw#157478)
  refactor(exec): reuse approval policy rule keys (openclaw#157198)
  fix(ci): reuse prepared runtime for changed-target E2E shards (openclaw#157365)
  fix(config): apply Gateway writes without waiting for file events (openclaw#157372)
  fix: count recorded nested tool operations once (openclaw#157438)
  fix(telegram): stop leaking raw file:// markdown links in messages (openclaw#137810)
  refactor(claws): share resource capability changes (openclaw#154680)
  improve(channels): reduce redundant preparation for button messages (openclaw#157050)
  fix(build): package preparation fails on unrelated test types (openclaw#157318)
  refactor(claws): share bounded document reading (openclaw#157436)
  ...

Co-authored-by: Vincent Koc <[email protected]>
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.

1 participant