Skip to content

fix(agents): detect silent context overflow (stopReason=length, output=0)#14157

Closed
0xRaini wants to merge 1 commit intoopenclaw:mainfrom
0xRaini:fix/detect-empty-length-stop-as-overflow
Closed

fix(agents): detect silent context overflow (stopReason=length, output=0)#14157
0xRaini wants to merge 1 commit intoopenclaw:mainfrom
0xRaini:fix/detect-empty-length-stop-as-overflow

Conversation

@0xRaini
Copy link
Copy Markdown
Contributor

@0xRaini 0xRaini commented Feb 11, 2026

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:

  1. Silent empty replies — the user gets no response
  2. Session permanently stuck — every subsequent message gets the same empty response
  3. No auto-compaction — the existing overflow recovery only triggers on explicit error text

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:

  • promptError containing context overflow keywords
  • lastAssistant.stopReason === "error" with overflow-like error text

When stopReason === "length" with output: 0, neither condition fires — the run is treated as a successful (but empty) completion.

Fix

Add a isSilentOverflow detection before the existing overflow check:

const isSilentOverflow =
  !aborted &&
  !promptError &&
  lastAssistant?.stopReason === "length" &&
  lastAssistant.usage?.output === 0;

When detected, this feeds into the existing contextOverflowError flow, 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 existing contextOverflowError flow, resolving the issue where sessions would become permanently stuck with empty responses.

  • prevented silent context overflow by detecting stopReason === "length" with output === 0
  • triggers existing auto-compaction recovery flow for silent overflows
  • minor style inconsistency with type casting that could be improved

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is well-targeted and additive, catching a previously unhandled edge case without modifying existing logic paths. All 75 existing tests pass, and the fix properly integrates with the existing overflow recovery flow. The only issue is a minor style inconsistency in type casting.
  • No files require special attention

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 11, 2026
Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

!aborted &&
!promptError &&
lastAssistant?.stopReason === "length" &&
(lastAssistant.usage as Record<string, unknown> | undefined)?.output === 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@0xRaini

This comment was marked as spam.

@thewilloftheshadow
Copy link
Copy Markdown
Member

Banning user due to spam/slop + copying other users PRs and pinging users

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Session exceeding context window produces silent empty replies — no compaction triggered

2 participants