fix(agents): detect silent context overflow (stopReason=length, output=0)#14157
Closed
0xRaini wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix(agents): detect silent context overflow (stopReason=length, output=0)#141570xRaini wants to merge 1 commit intoopenclaw:mainfrom
0xRaini wants to merge 1 commit intoopenclaw:mainfrom
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
src/agents/pi-embedded-runner/run.ts
Outdated
| !aborted && | ||
| !promptError && | ||
| lastAssistant?.stopReason === "length" && | ||
| (lastAssistant.usage as Record<string, unknown> | undefined)?.output === 0; |
Contributor
There was a problem hiding this comment.
inconsistent type casting - use UsageLike like line 459
Suggested change
| (lastAssistant.usage as Record<string, unknown> | undefined)?.output === 0; | |
| (lastAssistant.usage as UsageLike | undefined)?.output === 0; |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/pi-embedded-runner/run.ts
Line: 480:480
Comment:
inconsistent type casting - use `UsageLike` like line 459
```suggestion
(lastAssistant.usage as UsageLike | undefined)?.output === 0;
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.…+zero output When a session's context exceeds the model's window, some providers return stopReason='length' with output=0 instead of an explicit error. This was treated as a successful (empty) completion, leaving the session permanently stuck with silent empty replies. Detect this condition (stopReason=length + output=0) as a context overflow and trigger the existing auto-compaction recovery flow. Fixes #14064
This comment was marked as spam.
This comment was marked as spam.
Member
|
Banning user due to spam/slop + copying other users PRs and pinging users |
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.
Problem
When a session's accumulated context exceeds the model's window, some providers (notably OpenRouter/OpenAI) return:
{"stopReason": "length", "output": 0, "content": []}instead of an explicit context overflow error. This causes:
The workaround is manually deleting the session file, which most users won't know to do.
Fixes #14064
Root Cause
In
pi-embedded-runner/run.ts, the overflow detection (line ~473) only checks:promptErrorcontaining context overflow keywordslastAssistant.stopReason === "error"with overflow-like error textWhen
stopReason === "length"withoutput: 0, neither condition fires — the run is treated as a successful (but empty) completion.Fix
Add a
isSilentOverflowdetection before the existing overflow check:When detected, this feeds into the existing
contextOverflowErrorflow, triggering auto-compaction → retry — the same recovery path used for explicit overflow errors.Testing
All 75 existing pi-embedded-runner tests pass. The change is additive — it only catches a case that previously fell through silently.
Greptile Overview
Greptile Summary
Added detection for silent context overflow when providers return
stopReason: "length"with zero output tokens instead of explicit error messages. The fix properly triggers auto-compaction by feeding into the existingcontextOverflowErrorflow, resolving the issue where sessions would become permanently stuck with empty responses.stopReason === "length"withoutput === 0Confidence Score: 5/5