Skip to content

improve(agents): normalized web_search output contract with boundary-owned wrapping - #110308

Merged
steipete merged 12 commits into
mainfrom
claude/web-search-output-contract
Jul 18, 2026
Merged

steipete merged 12 commits into
mainfrom
claude/web-search-output-contract

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

web_search spread raw provider payloads to the model: 17 bundled providers with divergent shapes (snippet vs description vs snippets arrays, string vs object citations), provider-specific extras leaking through, and no declared output contract — so Code Mode showed -> ? and models paid a raw-inspection exec before using results. Security wrapping of untrusted web text was provider-by-provider convention with nothing enforcing it at the boundary.

Why This Change Was Made

New module src/agents/tools/web-search-output.ts normalizes every provider payload at the core boundary into a closed four-branch contract (error / results / answer / raw), declared as outputSchema and promoted as a complete 691-char quick-index hint.

The boundary owns the untrusted-content envelope outright — no provider-controlled metadata is consulted:

  • All provider prose (title, snippet, siteName, answer content, citation titles, error message) is stripped of any pre-existing or forged envelope framing and re-wrapped exactly once via wrapWebContent.
  • URLs are emitted canonicalized (new URL().href); non-http(s) or unparseable URLs are dropped (citations) or route the payload to raw (rows).
  • published survives only in structural ISO-date shape; query is always the requested query (provider echoes ignored); sparse arrays densified; declared error keys win over empty results.
  • The structured error code is the closed literal "provider_error"; raw provider codes/objects serialize inside the wrapped message; docs must canonicalize as http(s).
  • External SDK providers returning nonconforming payloads pass through verbatim as kind: "raw" (shipped compatibility preserved; data: unknown renders via the opaque-leaf hint rule).

Named tradeoffs (deliberate): provider extras (scores, related searches, inline citation offsets, model ids, queryTerms) no longer reach the model; free-form published values are dropped; error codes are no longer structurally differentiated.

User Impact

Code Mode composes web_search in one exec using trusted declared fields across all providers. Prompt-injection surfaces through unwrapped provider strings, spoofed wrapped markers, URL-slot prose, and error-field text are closed at one owned boundary.

Evidence

  • 51 tests in src/agents/tools/web-search.test.ts: 17-provider fixture table (Brave, Codex, DuckDuckGo, Exa, Firecrawl, Gemini, Grok, Kimi, MiniMax, Ollama, Parallel, Perplexity, QA Lab, SearXNG, Tavily + error + external), wrap/strip behavior, forged-envelope, sparse-array, structured-error, URL and date gates, exact hint snapshot.
  • Autoreview (Codex gpt-5.6-sol, branch mode): eight adversarial rounds; every accepted finding fixed (trust-marker spoofing, wrapping ownership, error precedence, envelope-regex over-matching, sparse arrays, URL canonicalization, closed error code, structured-error diagnostics); final run clean, "patch is correct (0.86)".
  • Depends on the landed wave-1 compactor semantics (perf(agents): wave-1 tool output contracts for code mode #110215, merged as d371ea1); branch is rebased onto that main.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Jul 18, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 17, 2026, 10:14 PM ET / July 18, 2026, 02:14 UTC.

Summary
The branch replaces raw web_search provider payloads with a boundary-owned error/results/answer/raw union, adds an output schema hint, and updates web-search docs and tests.

PR surface: Source +273, Tests +762, Docs +78. Total +1113 across 9 files.

Reproducibility: yes. from source and documentation: select Parallel, perform a search, then attempt the documented follow-up using the prior result’s sessionId; the proposed normalized results payload no longer contains that field.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: vector/embedding metadata: src/agents/tools/web-tools.enabled-defaults.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add a redacted live-provider terminal transcript or runtime log that shows the normalized output after the selected compatibility design.
  • Resolve the documented Parallel and Exa result-field contract through a maintainer-approved migration or compatible replacement.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body reports fixtures, unit tests, and autoreview but provides no inspectable after-fix live-provider transcript, terminal output, recording, or redacted runtime artifact showing a normalized result and the chosen continuation behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] Merging the closed results shape removes documented provider metadata from existing successful searches; Parallel callers can no longer obtain the prior sessionId needed for the documented follow-up flow.
  • [P1] The branch changes a model-facing provider/plugin compatibility boundary without an explicit public migration, replacement continuation contract, or proof that current provider workflows remain usable.

Maintainer options:

  1. Resolve the public result contract before merge (recommended)
    Preserve or deliberately replace the documented provider follow-up metadata with explicit upgrade documentation, compatibility coverage, and live proof before landing.
  2. Accept a breaking contract change
    Approve removal of provider metadata only with an explicit maintainer decision, revised public docs, and a clear migration path for affected workflows.
  3. Pause the runtime normalization
    Keep the existing runtime result payloads and defer closed-union normalization until a provider-agnostic continuation design is sponsored.

Next step before merge

  • [P1] A narrow code change is possible after maintainers choose the public provider-metadata and continuation contract; the protected maintainer label and missing real behavior proof make this a human-owned decision now.

Maintainer decision needed

  • Question: Should the core web_search contract preserve provider-specific follow-up metadata such as Parallel sessionId, or should maintainers approve a new provider-agnostic continuation contract and migration for the documented workflows?
  • Rationale: This is a public tool-result and plugin/provider compatibility choice: preserving the old fields conflicts with the stated closed generic union, while removing them breaks documented behavior. The implementation cannot safely choose the permanent contract without maintainer intent.
  • Likely owner: steipete — The merged wave-1 contract work and this branch place this person closest to the output-contract design, while the final public compatibility decision remains a maintainer choice.
  • Options:
    • Define a compatible continuation seam (recommended): Add a documented provider-agnostic continuation capability that retains Parallel follow-up behavior, migrate the provider docs and tests, and prove it with a live provider run.
    • Preserve documented metadata: Keep the currently documented provider metadata in a compatible output shape and defer the closed-union redesign until a generic replacement is agreed.
    • Narrow this PR to schema hints: Leave runtime payloads unchanged and limit this PR to an output-schema hint that accurately describes the existing result contract.

Security
Cleared: No new dependency, workflow, secret, or supply-chain execution path is introduced; the primary security-sensitive wrapping change remains subject to the compatibility/contract decision above.

Review findings

  • [P1] Preserve the documented provider result contract — src/agents/tools/web-search-output.ts:211-233
Review details

Best possible solution:

Choose and document one compatible public web_search contract before merge: preserve the documented follow-up/metadata capability through a stable generic seam or explicitly migrate and prove every affected provider workflow, then add redacted live-provider output showing the selected contract.

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

Yes from source and documentation: select Parallel, perform a search, then attempt the documented follow-up using the prior result’s sessionId; the proposed normalized results payload no longer contains that field.

Is this the best way to solve the issue?

No. A closed normalization boundary is plausible, but removing documented provider continuation/metadata fields without a stable replacement or migration is not the safest maintainable solution.

Full review comments:

  • [P1] Preserve the documented provider result contract — src/agents/tools/web-search-output.ts:211-233
    This successful-results path emits only the generic row fields, dropping documented Parallel sessionId/searchId/warnings/usage and Exa highlightScores/summary. In particular, callers can no longer perform the documented Parallel follow-up flow because sessionId is absent. Preserve those capabilities through a compatible documented contract, or obtain an explicit migration decision and update the provider workflows before merging.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P2: The PR changes a broadly used agent tool result contract and can break documented provider workflows, but the supplied evidence does not show an active production outage.
  • merge-risk: 🚨 compatibility: The proposed successful-result union omits documented Parallel and Exa fields, including the Parallel continuation identifier.
  • merge-risk: 🚨 security-boundary: The PR changes the boundary that labels and wraps untrusted provider output, so the final public contract requires careful owner approval beyond passing tests.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports fixtures, unit tests, and autoreview but provides no inspectable after-fix live-provider transcript, terminal output, recording, or redacted runtime artifact showing a normalized result and the chosen continuation behavior. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +273, Tests +762, Docs +78. Total +1113 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 279 6 +273
Tests 3 779 17 +762
Docs 3 84 6 +78
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 1142 29 +1113

What I checked:

  • Documented Parallel follow-up contract: Current documentation says Parallel surfaces sessionId so callers can group follow-up searches, and separately promises searchId, warnings, and usage passthrough; the proposed results branch exposes none of these fields. Public docs: docs/tools/parallel-search.md. (docs/tools/parallel-search.md:314, d8f2645c2ced)
  • Documented Exa metadata contract: Current Exa documentation says result payloads preserve raw highlightScores and summary; the branch’s closed result row schema keeps only title, URL, snippet, published, and site name. Public docs: docs/tools/exa-search.md. (docs/tools/exa-search.md:315, d8f2645c2ced)
  • Proposed output boundary: The branch routes every successful runtime result through normalizeWebSearchOutput, so the reduced result shape becomes the observable tool payload rather than only a schema hint. (src/agents/tools/web-search.ts:113, db03106d681a)
  • Prior merged context: The related merged output-contract work introduced schema-hint compaction semantics, but it explicitly described existing tool result fields as unchanged; this branch instead changes web_search result payload behavior. (src/agents/tool-schema-hints.ts:5, d371ea1f0121)
  • Existing review evidence: A review comment independently identified the lost Parallel and Exa fields and the breakage of the documented sessionId follow-up workflow; no supplied follow-up establishes a migration or compatible replacement. (db03106d681a)

Likely related people:

  • steipete: Authored the merged wave-1 tool-output-contract work that established the adjacent schema-hint behavior and is also the historical author of the affected current PR series. (role: recent area contributor; confidence: high; commits: d371ea1f0121; files: src/agents/tool-schema-hints.ts, src/agents/tools/web-search.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-18T01:59:59.961Z sha d0d1a93f53677ab797c6c12715687d46fc6a0c42 :: needs real behavior proof before merge. :: none

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0d1a93f53

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

query,
count: readFiniteNumber(result.count) ?? results.length,
...(tookMs !== undefined ? { tookMs } : {}),
results,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Preserve provider metadata or update provider docs

When a selected provider returns a conforming results array, this normalized branch now emits only the generic fields; existing provider docs still promise web_search pass-through fields such as Parallel sessionId/searchId/warnings/usage and Exa highlightScores/summary (docs/tools/parallel-search.md:123-150, docs/tools/exa-search.md:128-132). For Parallel this also breaks the documented follow-up flow because callers can no longer read the prior sessionId; either include those fields in the declared contract or remove/replace the stale provider-specific docs/workflows.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jul 18, 2026
@steipete
steipete force-pushed the claude/web-search-output-contract branch from db03106 to 1421ccc Compare July 18, 2026 02:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1421ccc04a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

: typeof row.description === "string"
? row.description
: Array.isArray(row.snippets)
? row.snippets.find((value): value is string => typeof value === "string")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Preserve all Brave LLM-context snippets

When Brave is configured for llm-context, the provider emits every pre-extracted grounding chunk in snippets (see extensions/brave/src/brave-web-search-provider.runtime.ts:504-507), but this normalization keeps only the first string. Any result with multiple chunks therefore loses most of the page content before it reaches the model through generic web_search; join and wrap the snippets, or otherwise carry the full set in the normalized contract.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 19296b0 into main Jul 18, 2026
116 checks passed
@steipete
steipete deleted the claude/web-search-output-contract branch July 18, 2026 02:39
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
…owned wrapping (openclaw#110308)

* feat: normalize web search output contract

* refactor(agents): promote web_search contract from a dedicated output module

* fix(agents): wrap unwrapped web_search text and pass unknown provider payloads through as raw

* fix(agents): gate web_search results branch on conforming rows and cover metadata fields

* fix(agents): gate every provider text path at the web_search boundary

* test(agents): align web_search fixtures with boundary-owned wrapping

* fix(agents): make the web_search boundary own the untrusted-content envelope

* fix(agents): report declared web_search errors first and align the documented contract

* fix(agents): bind envelope stripping to real markers and densify result rows

* fix(agents): emit canonical urls and a closed error code from web_search

* fix(agents): keep structured provider error diagnostics in the wrapped message

* fix(agents): satisfy production export and lint gates for the web_search contract
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant