Skip to content

bug: recover context-limited length completions before durable output #44609

Closed as not planned

Description

@cxxCoolStar

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.

Activity

  1. github-actions commented on Aug 24, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    If your case is specifically the narrow pre-durable-output context-window overflow path (not general output-limit truncation), it may be worth referencing those issues in a PR to avoid re-solving overlapping mechanics.

  2. github-actions commented on Oct 24, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions