Skip to content

Conversation

@shanjairaj7
Copy link
Contributor

@shanjairaj7 shanjairaj7 commented Nov 4, 2025

Adds context limit checking to webfetch tool to prevent exceeding model's context window. Truncates large webfetch outputs when they would exceed available context space for the specific chosen model.

This is using the same overflow detection pattern as SessionCompaction.isOverflow().

Some docs like the nextjs docs or shadcn docs for certain components are a lot larger in context length. When fetch is called it exceeds the model's context limit and doesn't continue.

Now there is a search property which the model can use if it only needs specific content from the docs.
Example: The shadcn sidebar documentation is very detailed and long (~50k tokens).

Now the model can search "SideMenuSub" in the webfetch directly, and it would return this specific section only. Which would be just 200-500 tokens.

  • Combination of chunking and tokenising the chunks
  • Finding and adding in table of contents for better context

I've only been using opencode for sometime, but when it stops when it encounters large docs or websites i am not even able to continue or even compact the conversation.

So this is something that fixes that for me with no performance loss.

@shanjairaj7 shanjairaj7 force-pushed the fix-webfetch-context-limit branch from 30b242c to 04ceba4 Compare November 4, 2025 06:06
@shanjairaj7 shanjairaj7 changed the title fix: truncate webfetch output when exceeding context limits fix: truncate/smart search for webfetch output when exceeding context limits Nov 4, 2025
@shanjairaj7 shanjairaj7 changed the title fix: truncate/smart search for webfetch output when exceeding context limits fix: truncate/smart search when long webfetch output exceeds context limits Nov 4, 2025
@shanjairaj7 shanjairaj7 changed the title fix: truncate/smart search when long webfetch output exceeds context limits fix: search through webfetch tool output (when result exceeds context limits & blocks conversation) Nov 4, 2025
@shanjairaj7 shanjairaj7 changed the title fix: search through webfetch tool output (when result exceeds context limits & blocks conversation) fix: search through webfetch tool output (when result exceeds context limits -> blocks conversation) Nov 4, 2025
@shanjairaj7 shanjairaj7 changed the title fix: search through webfetch tool output (when result exceeds context limits -> blocks conversation) feat: search through webfetch tool output (when result exceeds context limits -> blocks conversation) Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant