Skip to content

fix(opencode): recover from ContextOverflowError via auto-compaction#14826

Open
PrakharMNNIT wants to merge 3 commits intoanomalyco:devfrom
PrakharMNNIT:fix/context-overflow-recovery
Open

fix(opencode): recover from ContextOverflowError via auto-compaction#14826
PrakharMNNIT wants to merge 3 commits intoanomalyco:devfrom
PrakharMNNIT:fix/context-overflow-recovery

Conversation

@PrakharMNNIT
Copy link

Issue for this PR

Closes #14824

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When the LLM returns ContextOverflowError, the processor now sets needsCompaction = true and breaks to post-catch cleanup, which returns "compact". The prompt loop then creates a compaction task (prune + summarize), allowing the session to continue with reduced context.

Previously the catch block had // TODO: Handle context overflow error which did nothing — the error fell through to kill the session.

How did you verify your code works?

  • Typecheck passes
  • Code trace verified: ContextOverflowError → needsCompaction → return "compact" → SessionCompaction.create → session survives
  • Existing compaction system is battle-tested (used by normal overflow path)

Screenshots / recordings

Backend-only change, no UI changes.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

When the LLM API returns a context overflow error, trigger compaction
instead of killing the session. Previously the catch block had a TODO
comment and fell through to a fatal error (return 'stop').

Now: sets needsCompaction = true and breaks to post-catch cleanup,
which returns 'compact'. The prompt loop then creates a compaction
task, generating a summary and allowing the session to continue.
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

Related PR:

Why it's related: Both PRs implement the same recovery mechanism (triggering auto-compaction when errors occur) to allow sessions to continue instead of failing. They follow the same pattern of setting a flag and initiating compaction.

However, PR #14826 (the current PR) is not a duplicate — it addresses a different error type (ContextOverflowError from LLM directly) with its own distinct implementation. The related PR #14707 handles HTTP 413 errors.

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.

ContextOverflowError kills session instead of triggering compaction

1 participant