Repository navigation
Replies: 1 comment
|
The evidence points to a classification bug after a successful provider response, rather than a real overflow. A nonempty Codex Responses completion with an explicit |
|
The evidence points to a classification bug after a successful provider response, rather than a real overflow. A nonempty Codex Responses completion with an explicit |
Uh oh!
There was an error while loading. Please reload this page.
Summary
llm-pi-aican turn a successfully completed Codex Responses answer intoCONTEXT_WINDOW_EXCEEDEDwhen the response's input usage exceeds the installed model catalog'scontextWindow. The same finish-reason mapping is used for compaction requests, so a completed summary can also be discarded by this local check.This report provides a deterministic successful-SSE reproduction and a locally tested patch. It is related to #8587 (Codex catalog capacity) and #7520 (false overflow after switching models), but focuses specifically on classification after the provider has completed the response. No model switch is required.
Environment
5badb15009ae1756c3afe0ae0cef1faafc290ccc, package version0.2.1-alpha.1.@earendil-works/pi-ai:0.87.1.openai-codex, API:openai-codex-responses, model:gpt-6-astra.272000.v25.5.0, pnpm11.7.0.The local desktop checkout also has unrelated customizations. Those are excluded from the attached patch; the reproduction exercises the existing adapter through a real Loader composition and a scripted HTTP/SSE boundary.
Observed behavior
A long-running session failed with:
The failed
assistant/attemptcontains nonempty response text and the following usage:usage.input)usage.cacheRead)The session also recorded 20 failed compaction attempts and no persisted summary. Auxiliary response streams were not retained on those failures, so I cannot establish that every failed summary actually completed upstream. The deterministic compaction-purpose regression below demonstrates that a successful summary response is vulnerable to the same mapping bug.
No account identifiers, OAuth credentials, private conversation text, or original session files are included here. Usage counts are the only data taken from that session. The recorded-session regression uses authored text and fake credentials.
Root cause
In
packages/llm/llm-pi-ai/src/stream.ts,mapStopReason()always calls:pi-ai's usage heuristic classifies a
stopresponse as overflow when its input plus cached-input usage exceeds that catalog window. That local inference overrides the server's successful terminal response, even when nonempty output was returned.A catalog capacity remains useful for scheduling proactive compaction. It should not retroactively invalidate an accepted and completed Codex response. This report does not claim that any particular larger context limit applies to every Codex model or account.
Deterministic reproduction
The patch adds three levels of coverage:
stopReason: 'stop', input281, cached input379648, output944, and catalog capacity272000. Before the fix,mapStopReason()returns an overflow error; after the fix it returns{ kind: 'stop' }. The case also verifies a custom provider name using the same Codex protocol.transport: sse, and serveresponse.completedwith nonempty output and the same usage. Run both a conversation request and a request withpurpose: 'compaction'. Both must preserve the response text, usage, and successful finish. Only the external HTTP response is scripted; no live account or API call is required.codex-completed-over-catalog. The authored transcript must contain a normalassistant/messageand a completedturn/end. The fixture supplies terminal Codex SSE from the canonical recording while retaining the real adapter and loop.Proposed fix and preserved behavior
For
message.api === 'openai-codex-responses'andmessage.stopReason === 'stop', omit the catalog window when callingisContextOverflow(). Keep the existing window for other protocols and terminal states.The patch retains:
lengthoverflow detection.EMPTY_RESPONSEfor a completed response with no content blocks.The test HTTP server also decodes zstd request bodies, because the real Codex adapter sends compressed requests.
Validation
Focused adapter/composition and compaction tests:
Latest local output:
Additional completed checks:
The desktop app and Host were restarted to load the rebuilt adapter. The original long conversation has not yet been retried against the live service, and no real-API e2e run is claimed. The coverage above verifies successful Codex SSE mapping, the compaction-purpose adapter path, and persisted turn completion.
Patch
Since external PRs are currently not accepted, the complete focused patch is included below for maintainers. It contains the adapter change, regression tests, paired README updates, and the new keyless recorded-session scenario. It applies to the base checkout listed above and excludes unrelated local OAuth/UI changes.
Complete patch (adapter, tests, docs, recorded-session fixture)
All reactions