Repository navigation
fix(web-search): later results come back empty when early snippets are long - #179703
Conversation
…e long web_search keeps one 20,000-character budget for a search's untrusted text. Source URLs were already reserved first, but titles, snippets and site names were then charged in result order, so a few long snippets (Exa's default highlights run to several thousand characters per page) used the whole budget and the remaining results came back with an empty title and snippet. Rows are now charged from the least text to the most, each within an equal share of what is left, so results that fit keep everything and only the longest are trimmed. Within a row the title and site name come before the snippet. The aggregate bound is unchanged.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesDistribute the existing web-search text budget across results so long early snippets do not leave later results empty. Example: Brave returns ten snippets containing 12,000, 9,000, and eight times 100 characters.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current web-search defect with a focused, proven repair; the previous conflict is resolved, no actionable findings remain, and exact-head CI is still running. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe core web_search tool normalizes provider responses into bounded, security-wrapped results before returning them to the agent. flowchart LR
A[Agent tool call] --> B[Web search runtime]
B --> C[Provider HTTP adapter]
C --> D[Output normalizer]
D --> E[Shared sanitizer and wrapper]
E --> F[Model-facing tool result]
Technical reviewBest possible solution: Land the shared-normalizer allocation repair after the existing exact-head checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source establishes sequential budget exhaustion, and the supplied built-Gateway captures demonstrate it before the repair; no target code was executed during this review. Is this the best way to solve the issue? The smallest complete fix belongs in the existing output normalizer: measure sanitized row demand, allocate bounded shares, and restore provider order while retaining URL reservation and wrapping. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 642b31d1993b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +28, Tests +53, Docs +7. Total +88 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReviewed October 26, 2026, 2:40 AM ET / 06:40 UTC (Revision 3). |
Captured built-Gateway tool results — #179703Main and candidate each ran the long-excerpt scenario twice, through the shipped Gateway, real Brave plugin HTTP adapter and actual The JSON below is extracted from the actual {
"mainSha": "bdf12f6b6b1235f10ee361687e0c32db94dd3a6b",
"candidateSha": "7b2e3d1be78748172fd55960958c60f5f01213ea",
"longExcerptRuns": [
{
"lane": "main",
"query": "p179703-long-1",
"kind": "results",
"provider": "brave",
"count": 10,
"truncated": true,
"chargedChars": 20000,
"titles": [
"result 0",
"result 1",
"",
"",
"",
"",
"",
"",
"",
""
],
"snippetChars": [
12000,
7763,
0,
0,
0,
0,
0,
0,
0,
0
],
"rawLastResult": {
"title": "",
"url": "https://example.com/9",
"snippet": "",
"siteName": ""
}
},
{
"lane": "main",
"query": "p179703-long-2",
"kind": "results",
"provider": "brave",
"count": 10,
"truncated": true,
"chargedChars": 20000,
"titles": [
"result 0",
"result 1",
"",
"",
"",
"",
"",
"",
"",
""
],
"snippetChars": [
12000,
7763,
0,
0,
0,
0,
0,
0,
0,
0
],
"rawLastResult": {
"title": "",
"url": "https://example.com/9",
"snippet": "",
"siteName": ""
}
},
{
"lane": "candidate",
"query": "p179703-long-1",
"kind": "results",
"provider": "brave",
"count": 10,
"truncated": true,
"chargedChars": 20000,
"titles": [
"result 0",
"result 1",
"result 2",
"result 3",
"result 4",
"result 5",
"result 6",
"result 7",
"result 8",
"result 9"
],
"snippetChars": [
9800,
9000,
100,
100,
100,
100,
100,
100,
100,
100
],
"rawLastResult": {
"title": "\n<<<EXTERNAL_UNTRUSTED_CONTENT id=\"d6d5420e4f83abd9\">>>\nSource: Web Search\n---\nresult 9\n<<<END_EXTERNAL_UNTRUSTED_CONTENT id=\"d6d5420e4f83abd9\">>>",
"url": "https://example.com/9",
"snippet": "\n<<<EXTERNAL_UNTRUSTED_CONTENT id=\"79add66c1434326f\">>>\nSource: Web Search\n---\nssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n<<<END_EXTERNAL_UNTRUSTED_CONTENT id=\"79add66c1434326f\">>>",
"siteName": "\n<<<EXTERNAL_UNTRUSTED_CONTENT id=\"6d7cbba82e70f87d\">>>\nSource: Web Search\n---\nexample.com\n<<<END_EXTERNAL_UNTRUSTED_CONTENT id=\"6d7cbba82e70f87d\">>>"
}
},
{
"lane": "candidate",
"query": "p179703-long-2",
"kind": "results",
"provider": "brave",
"count": 10,
"truncated": true,
"chargedChars": 20000,
"titles": [
"result 0",
"result 1",
"result 2",
"result 3",
"result 4",
"result 5",
"result 6",
"result 7",
"result 8",
"result 9"
],
"snippetChars": [
9800,
9000,
100,
100,
100,
100,
100,
100,
100,
100
],
"rawLastResult": {
"title": "\n<<<EXTERNAL_UNTRUSTED_CONTENT id=\"fbfbc31b1cf38cd3\">>>\nSource: Web Search\n---\nresult 9\n<<<END_EXTERNAL_UNTRUSTED_CONTENT id=\"fbfbc31b1cf38cd3\">>>",
"url": "https://example.com/9",
"snippet": "\n<<<EXTERNAL_UNTRUSTED_CONTENT id=\"b8aff62ba54dc131\">>>\nSource: Web Search\n---\nssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\n<<<END_EXTERNAL_UNTRUSTED_CONTENT id=\"b8aff62ba54dc131\">>>",
"siteName": "\n<<<EXTERNAL_UNTRUSTED_CONTENT id=\"f519047290fdb0b8\">>>\nSource: Web Search\n---\nexample.com\n<<<END_EXTERNAL_UNTRUSTED_CONTENT id=\"f519047290fdb0b8\">>>"
}
}
],
"expansionRuns": [
{
"lane": "main",
"query": "p179703-expansion-1",
"truncated": false,
"chargedChars": 17566,
"rows": [
{
"title": "a",
"url": "https://example.com/a",
"snippetChars": 11500,
"siteName": "example.com"
},
{
"title": "b",
"url": "https://example.com/b",
"snippetChars": 6000,
"siteName": "example.com"
}
]
},
{
"lane": "main",
"query": "p179703-expansion-2",
"truncated": false,
"chargedChars": 17566,
"rows": [
{
"title": "a",
"url": "https://example.com/a",
"snippetChars": 11500,
"siteName": "example.com"
},
{
"title": "b",
"url": "https://example.com/b",
"snippetChars": 6000,
"siteName": "example.com"
}
]
},
{
"lane": "candidate",
"query": "p179703-expansion-1",
"truncated": false,
"chargedChars": 17566,
"rows": [
{
"title": "a",
"url": "https://example.com/a",
"snippetChars": 11500,
"siteName": "example.com"
},
{
"title": "b",
"url": "https://example.com/b",
"snippetChars": 6000,
"siteName": "example.com"
}
]
},
{
"lane": "candidate",
"query": "p179703-expansion-2",
"truncated": false,
"chargedChars": 17566,
"rows": [
{
"title": "a",
"url": "https://example.com/a",
"snippetChars": 11500,
"siteName": "example.com"
},
{
"title": "b",
"url": "https://example.com/b",
"snippetChars": 6000,
"siteName": "example.com"
}
]
}
]
}The Brave expansion pair retains 11,500 and 6,000 snippet characters, untruncated, in both lanes; its 17,566 charge includes Brave’s site names. The separate reviewer counterexample uses raw provider rows without those site names (17,544 total), and failed on the original contributor allocation before the measurement repair: After the repair, captured focused-check output: The additional |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Current-head conflict resolution and regression captureHead: The PR's only changed production file, Scoped Oxfmt/Oxlint and 64 current-head focused tests pass: The relocated expansion regression still fails when only the original contributor production file is restored, and the repaired file was restored after this negative control: |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…e long (openclaw#179703) fix(web-search): share the result text budget so long early snippets don't blank later results Web search results shared one text budget allocated in provider row order, so long snippets in early results used it up and later results came back with blank titles and snippets. Rows are now allocated shortest-first by their real sanitized length, so every result keeps its title and only the longest snippets are trimmed. Evidence: built Gateway agent turns with a local search-provider fixture returning long early snippets, inspecting the actual tool result. On main the last eight of ten results had blank titles and snippets (twice); with this change all ten titles were kept in their original URL and ranking order, and only the longest snippet was trimmed (twice). Both stay within the same 20,000-character budget. A regression for sanitization expansion fails before the repair and passes after. Details: openclaw#179703 (comment). Thanks @Canvinus. Co-authored-by: Ayaan Zaidi <[email protected]>
…e long (#179703) fix(web-search): share the result text budget so long early snippets don't blank later results Web search results shared one text budget allocated in provider row order, so long snippets in early results used it up and later results came back with blank titles and snippets. Rows are now allocated shortest-first by their real sanitized length, so every result keeps its title and only the longest snippets are trimmed. Evidence: built Gateway agent turns with a local search-provider fixture returning long early snippets, inspecting the actual tool result. On main the last eight of ten results had blank titles and snippets (twice); with this change all ten titles were kept in their original URL and ranking order, and only the longest snippet was trimmed (twice). Both stay within the same 20,000-character budget. A regression for sanitization expansion fails before the repair and passes after. Details: #179703 (comment). Thanks @Canvinus. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 47c1c2a) Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit b2d6915dbf99322b12a80a5fc59634016e35bef2)
…s lane FRV tests (#187567) * docs(secrets): include Beam mirror token in credential matrix (cherry picked from commit dfa7774) * test(infra): supply versions list in astral ClawHub detail fixture The backport of #182753 (74e414a) dropped the versions: { items: [] } default that main's readDetail helper supplies, so the release-branch fixture fails the versions response guard. * test(web-search): carry #179703 envelope bound into release security test Main's 47c1c2a raised the aggregate JSON envelope bound from 22,000 to 23,000 because rows now keep their titles and site names (more wrap envelopes); the 20,000-char untrusted content cap is unchanged. The release backport 2b35452 put the new tests in web-search-budget.test.ts and missed this assertion in the release-only security test file. * test(auto-reply): expect preserved multiline /side input in registry test Backport 9b93c22 (#176293, main d7359a7) intentionally preserves multiline /btw, /side and /loop arguments. The release-only registry test still asserted the old first-line truncation for /side; main no longer has that assertion. * test(pdf): hold a Codex OAuth login in the ChatGPT PDF fixture Backport f41ea65 (#181356, main f64e38f) intentionally resolves a ChatGPT catalog row with only an API key as stale, routing it to the Platform contract. Port main's matching fixture update from 280c7c7 (shipped inside an unrelated visitor-access commit) so the test exercises the Codex subscription route it names. * test(auto-reply): expect agent inventory workspace for reply runtime Release backports 23e702a (#185573) and 59b6c10 (main 786cfd7) together adopt #185512's design: replies prepare the configured agent inventory workspace (preserveWorkspaceDirOnRefresh: false) and nested runs borrow it, while the reply workspace stays the execution boundary. Main's copy of this test no longer asserts the acquire input (db8180b). * test(agents): expect unverifiable stateless reasoning to be omitted Backport c93fe0b (#185774, main 86ddabd) intentionally stops replaying reasoning that has neither a replay ID nor authorized encrypted state when store is disabled. Main removed this test earlier (542e074); the release copy still expected the unverifiable item. * fix(plugins): allow retained registrations on reused inspections Catalog scope growth can reuse the same physical registry inspection. Keep its already-owned registrations in place instead of transferring them into their own resource map and failing with a duplicate-custody error. Preserve live-owner validation and all distinct-inspection transfer and disposal behavior. Extend the resource-backed lifecycle regression with self-adoption before abandoned growth and promotion. Proof: regression fails on unchanged production; fixed resource lifecycle and all seven selected catalog cases pass. Targeted native types, typed lint, format, suppression tests, runtime/static cycles and planner pass. Independent review found no actionable P0-P2 findings. (cherry picked from commit 52df852) * test(agents): seed the worker catalog in the isolated-completion owner test Backport 0c77c1d (#182952, main 4c3bf18, which shipped no test) carried a test adapted from another line that seeded discovered rows only through the in-process catalog builder. On this branch Gateway-configured agents load their full catalog through the catalog worker, so the setup never saw the row and the test failed from the commit that added it. Seed the worker mock too and match the row by its own fields (the catalog adds provenance). Verified: the test fails at the lease assertion when #182952's runtimePluginPurpose normalization is removed and passes with it. --------- Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Long early web-search snippets consume the shared text budget in provider order, leaving later results with URLs but empty titles and snippets. Preserve useful later results while retaining provider ranking, source URLs, security wrapping and the existing aggregate cap. Thanks @Canvinus for the original fix and reproduction.
Why This Change Was Made
Allocate prose from shorter rows to longer rows, then place results back in their original order. The allocation demand must use the same unwrapping and existing sanitization measurement that
wrapProsecharges: short special tokens can expand substantially after sanitization. Measuring raw length can unnecessarily truncate rows whose complete sanitized text fits the budget.The repair reuses the existing sanitizer without changing its policy, introduces no options or state, and leaves the 20,000-character URL/prose budget intact. The result-shape documentation now explains that budget and preserved ordering.
Evidence
Inspect the captured built-Gateway tool results and red/green regression output.
Fresh Linux Node 24.22.1 artifacts:
bdf12f6b6b1235f10ee361687e0c32db94dd3a6b.7b2e3d1be78748172fd55960958c60f5f01213ea.Current head
048a7c794a4f2900d85b7197c826db595050c985resolves the merge conflict by keeping main's consolidatedweb-search.test.tsand moving both budget regressions into it. The obsolete security test file stays deleted. The PR's only changed production file is byte-identical to the Gateway-proof candidate, so that evidence carries forward. Current-head focused checks and relocated red/green regression capture.A local Brave-compatible HTTP fixture returns ten results with snippet lengths 12,000, 9,000 and eight times 100. A deterministic local Responses fixture drives a normal Gateway-backed agent turn through the actual Brave plugin and
web_searchtool. The driver records the actual model-facingfunction_call_output; it does not import or replay the normalizer. Both lanes use the same documented direct-tool settings and synthetic keys; search URL guards remain enabled. This is a built-Gateway proof, not a hosted-model claim.Each lane ran twice:
The sanitization-expansion pair also ran twice per lane through Brave: both full snippets survive at 11,500 and 6,000 characters, without truncation. Its charge is 17,566 including Brave's site names. The separate raw-provider reviewer counterexample totals 17,544: the new regression fails on the original contributor allocation (
truncated: true) and passes after this measurement repair, with both complete snippets and no truncation metadata.Focused Validation
pnpm buildsucceeds for both fresh artifacts.Simplification: one normalizer owns allocation and existing security helpers still own sanitization/wrapping. No alternate result path, cache, schema, public export or test-only production seam. Whole-PR deltas: production +41/-13, tests +54/-1, docs +7/-0.
Merge danger: two-way door, fully revertible. No persisted state or configuration changes. Blast radius is the distribution of prose within normalized structured web-search results; an incorrect allocation could clip useful text or waste the existing budget. Provider ordering, URL reservation, aggregate bounds and untrusted-content envelopes remain protected.