Description
When submitting a prompt with an attached file that exceeds the model's context limit — either by itself or together with the existing conversation context — OpenCode compacts the context and resubmits the request.
Instead of stopping and reporting that the request still exceeds the context limit, OpenCode appears to repeat this process in a loop:
- Send the prompt and attached file.
- The request exceeds the context limit.
- OpenCode compacts the context.
- OpenCode resubmits the same request, including the oversized attachment.
- The request exceeds the context limit again.
- The process repeats.
This can consume the entire token budget without producing a response.
Steps to reproduce
- Start a conversation with enough existing context to significantly reduce the remaining context window.
- Submit a prompt with a large file attachment.
- Ensure that the combined prompt, conversation history, and attachment exceed the model's context limit.
- Observe the automatic context compaction and retry behavior.
Expected behavior
OpenCode should detect that the request still exceeds the context limit after compaction and stop retrying.
It should instead:
- Abort the request safely.
- Display a clear error message.
- Explain that the attached file or combined context is too large.
- Avoid repeatedly resending the same oversized request.
- Preserve the remaining token budget where possible.
Possible recovery options could include:
- Asking the user to remove or reduce the attachment.
- Offering to summarize or process the file in chunks.
- Asking whether older conversation context may be discarded.
- Retrying only if the request size has actually been reduced.
Actual behavior
OpenCode repeatedly compacts and resends the request while the oversized attachment remains part of the request.
This creates a retry loop and consumes all available tokens without completing the request.
Impact
This is potentially very expensive and can exhaust the complete token budget of a session. It also provides no useful result and gives the user no opportunity to intervene.
Suggested fix
Add a guard around automatic context-compaction retries:
- Track the effective request size after each compaction.
- Detect whether compaction actually reduced the request below the context limit.
- Detect repeated retries with equivalent request content.
- Set a strict maximum number of compaction retries.
- Abort with a user-visible error if the request remains too large.
- Do not count failed retry attempts against the user's token budget, if possible.
A message such as the following would be helpful:
The request is still too large after context compaction. The attached file exceeds the available context window. Please remove the attachment, reduce its size, or ask OpenCode to process it in smaller parts.
Environment
- OpenCode version: v1.18.32
- Interface: Desktop
- Attachment type and approximate size: filetype: json 2MB
- model: GPT-6 Astra low
- context limit of the used model: 1'050'000
Description
When submitting a prompt with an attached file that exceeds the model's context limit — either by itself or together with the existing conversation context — OpenCode compacts the context and resubmits the request.
Instead of stopping and reporting that the request still exceeds the context limit, OpenCode appears to repeat this process in a loop:
This can consume the entire token budget without producing a response.
Steps to reproduce
Expected behavior
OpenCode should detect that the request still exceeds the context limit after compaction and stop retrying.
It should instead:
Possible recovery options could include:
Actual behavior
OpenCode repeatedly compacts and resends the request while the oversized attachment remains part of the request.
This creates a retry loop and consumes all available tokens without completing the request.
Impact
This is potentially very expensive and can exhaust the complete token budget of a session. It also provides no useful result and gives the user no opportunity to intervene.
Suggested fix
Add a guard around automatic context-compaction retries:
A message such as the following would be helpful:
Environment