perf(web/context): concurrent @-reference expansion + web_extract truncate-store robustness - #55207
Merged
teknium1 merged 2 commits intoJun 30, 2026
Conversation
Multiple @-references in one message (esp. @url: refs, each a full web_extract round-trip) were expanded in a serial `for ref in refs: await` loop. Switch to asyncio.gather over the independent _expand_reference calls, reassembling warnings/blocks in original positional order so output is byte-identical to the serial path; the token-budget check is unchanged. Generic + provider-agnostic: helps every web backend equally (exa/tavily/ firecrawl/parallel) since it's above the provider layer. RED/GREEN test: 3 url refs @ 0.2s each = 0.60s serial -> ~0.20s concurrent.
…le offset Two robustness gaps from the NousResearch#54843 truncate-store path: - _store_full_text wrote the full clean page to cache/web with no upper bound (path.write_text(content)); a multi-MB page → unbounded per-extract disk write. Cap at MAX_STORED_TEXT_CHARS (2MB, the pre-truncate-store refusal ceiling) with a marker when capped. - The truncation footer told the model 'read_file ... offset=<line>' — a literal placeholder it had to guess. Compute the real starting line of the omitted middle (head line count + 1) so the first read_file lands in the gap.
tonydwb
reviewed
Jun 30, 2026
tonydwb
left a comment
There was a problem hiding this comment.
LGTM. Clean performance improvement for concurrent @-reference expansion and web_extract truncation. 4 files, well-scoped optimization with proper test coverage.
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two independent, provider-agnostic web/context optimizations + robustness fixes,
both verified with tests. They sit at the core agent layer (not in any
provider plugin), so they help every web backend (exa/tavily/firecrawl/parallel)
equally.
Part 1 — Concurrent
@-reference expansion (agent/context_references.py)A message with multiple
@-references (especially several@url:refs, each afull
web_extractround-trip) expanded them in a serialfor ref in refs: awaitloop — N independent fetches paid back-to-back.
Switched to
asyncio.gatherover the independent_expand_referencecalls,reassembling warnings/blocks in original positional order so output is
byte-identical to the serial path. The token-budget check is unchanged (it runs
once, after all refs expand).
@url:refs @ 0.2s each = 0.60s serial → ~0.20s concurrent.Part 2 —
web_extracttruncate-store robustness (tools/web_tools.py)Two gaps in the truncate-store path (from #54843):
Unbounded stored file.
_store_full_textwrote the full clean page tocache/webviapath.write_text(content)with no upper bound — a multi-MBpage meant unbounded per-extract disk writes. Now capped at
MAX_STORED_TEXT_CHARS(2MB, the pre-truncate-store refusal ceiling), with amarker appended when capped. The model only ever sees
char_limitregardless.Dead
offset=<line>placeholder. The truncation footer told the modelread_file path="…" offset=<line>— a literal placeholder it had to guess.Now computes the real starting line of the omitted middle (head line count
read_filelands in the gap.Why one PR
Both are small, core-layer web/context perf+robustness changes discovered in the
same pass; kept together for review convenience. They touch disjoint files
(
context_references.pyvsweb_tools.py) and can be reverted independently bycommit.
Verification
tests/agent/test_context_refs_concurrent.py(new) +test_context_references.pytests/tools/test_web_extract_robustness.py(new) +test_web_tools_truncate.py+test_web_tools.py