anomalyco / anomalyco/opencode
bug: recover context-limited length completions before durable output
@neriousy is already working on this.
Since Aug 24, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Problem
A provider can return reason: "length" before durable assistant output when the prompt plus the configured output budget exceeds the model context window. The session runner currently persists that length finish and stops instead of compacting the context and retrying.
Reproduction
With a model limit of context = 20_000 and output = 1_000, return a step-finish event with reason: "length", inputTokens: 19_900, and outputTokens: 40, without text, reasoning, or tool events. The runner makes one request; the expected sequence is original attempt, compaction summary, then retry.
A deterministic regression test on the unmodified source fails with:
Expected length: 3
Received length: 1
Proposed Fix
Treat that narrow event shape as recoverable only before an assistant message has started, then reuse the existing one-time overflow-compaction path. Do not retry when the response actually reached the configured output limit.
Verification
The failing-first regression and an output-limit guard test are included in the accompanying PR. The current Windows worktree cannot complete the green run because Bun reports EPERM while resolving existing .bun dependency links, before the test module reaches its assertions; the PR describes this limitation explicitly.
Related upstream precedent: earendil-works/pi#7540.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.