Follow-up to #8302 (f7ec8b3ce).
Placing the unresolved `previous_response_id` 1008 rejection at the top of the
HTTP bridge turn loop ran before `hooks.BeforeTurn` and before the `historyLost`
1013 (`StatusTryAgainLater`) check from #9203, and rejected valid turn-1 sticky
API-key continuations (`store != false` bound in `stateStore`) as well as Grok
HTTP bridge turns.
Move the 1008 check after `BeforeTurn` and `historyLost`, allow turn-1 API-key
continuations bound to the selected account when `store != false`, and preserve
Grok HTTP bridge handling while keeping all #8302 unresolved-parent cases closed
with 1008.
Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Raise the direct dependency and the pnpm override floor to 3.5.0, the first release patched for GHSA-hrxw-jjj6-2g2j (CVE-2026-144292). pnpm 9 resolves the direct dependency and the transitive copies to 3.5.1. The regenerated lockfile changes only DOMPurify entries.
Root cause: openAIResponsesCompletedEventIsEmpty classified a terminal
response.completed as non-empty whenever usage reported any tokens, so a
stream whose output held only reasoning items (reasoning tokens, no message
text or tool call) was recorded as a successful empty turn (issue #8966).
Change: classify emptiness by the terminal output items instead of usage.
Message items count only with visible text or a refusal; function_call,
custom_tool_call, tool_search_call, image_generation_call and any unknown
item type count as visible products; reasoning-only output is empty. When
output is missing, null, non-array or empty and usage exists, the previous
usage fallback still applies, so partial terminal events are not failed over.
The failover message now says "no visible output".
Tests: table cases for reasoning-only completed (inline and accumulated
usage), message text/refusal, empty message content, tool calls, image
generation, top-level output and malformed output fallback; stream-level
tests assert reasoning-only completed produces UpstreamFailoverError while
reasoning plus message text completes normally.
- The non-ASCII header test now reproduces the case-folded offset bug.
- Add a mixed fake/real data URI test.
- Check the image signature on the first bytes before decoding the whole
payload, and stop pre-growing the output buffer to the input size.
- Describe the accepted residual accurately.
Drop the API-key exemption: the HTTP path also rejects a previous_response_id
whose owner record expired, and the HTTP bridge would strip the id silently.
Only the per-selection strict affinity re-evaluation remains, now pinned by
a regression test for a current-turn failover replay after a continuation.
- Only the payload of a verified image is replaced; the media type and
parameters stay in the scan so prose cannot be smuggled through them.
- The payload is located by regexp submatch indices instead of a
case-folded copy, so non-ASCII header characters cannot shift it.
- The whole payload must strictly decode to a PNG/JPEG/GIF/WEBP file with
its trailer; padding is only accepted at the end.
- Skip the regexp entirely when the text has no ;base64, marker.
Use the configured-manifest candidate set (mapping keys, plus the default
catalog only when an account serves unmapped models) and tag the fallback
log with the group.
- Drop the per-segment 64K truncation: everything forwarded upstream must be
audited, and over-long prompts keep the existing fail-closed timeout path.
- Strip a data URI only when its payload uses the standard base64 alphabet,
is at least 256 characters, and decodes to a PNG/JPEG/GIF/WEBP signature.
Prose dressed up as a data URI (hyphens, spaces, plain letter runs, SVG
markup) stays in the scan.
The fallback list now passes through FilterCodexModelIDsForGroup, the same
listing filter /v1/models uses. A wildcard-only allowlist expands its
patterns against account mappings and the default catalog instead of
falling through to the unfiltered default catalog. Serving the fallback is
logged with the upstream error, since clients only see a 200.
- A current-turn failover replay clears previous_response_id because the
retry payload already carries the full input; the strict affinity check is
now computed on every selection so that replay is no longer rejected with
previous_response_not_found.
- API-key accounts resolve previous_response_id upstream, matching the HTTP
path; a missing local binding forwards the id unchanged instead of failing
loudly. OAuth-like accounts keep the fail-loud behavior.
A pool-mode account hitting a deterministic model-not-found must still fail
the current attempt over (404 is not in the generic failover set), only the
30-minute model cooldown is skipped. Rejected proxy credentials are a local
configuration fault, so only reachability failures skip the transport
cooldown for pool-mode accounts.
WebSocket turns closed the connection with 1013 as soon as the user was
at its concurrency limit, after the client had already uploaded the full
request. Clients such as Codex then retry and eventually switch the
session to HTTP, which resends the whole context on every turn.
Wait in the same bounded per-user queue as HTTP requests instead. The
wait is 60 seconds, longer than the HTTP wait because a rejected
WebSocket turn is more expensive. Timeouts, a full queue and a closed
connection still end with 1013.
Pool mode promises that upstream errors leave local account state alone
and are retried on the same account. Two paths still marked it:
- HandleUpstreamModelNotFound put a 30-minute model rate limit on the
account for a 404 model_not_found, although HandleUpstreamError and
HandleTempUnschedulable already skip pool-mode accounts without custom
error codes. The OpenAI fast path calls it first, so the skip never
applied there.
- tempUnscheduleOpenAITransportError marked the account unschedulable
after a transport error.
A pool-mode upstream that restarts briefly answers 404 for its models
and refuses connections; the account then stayed blocked for up to 30
minutes after the upstream recovered. Custom error codes still opt a
pool-mode account into the model rate limit.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>