Repository navigation
Conversation
`attemptHeaders` tells the first attempt from a retry by `attempts`, but `attempt()` incremented the counter before building the headers. The branch therefore never matched, so every request went out under a freshly minted session and `OPENCODE_ZEN_FREE_SESSION_AFFINITY=1` had no effect: two turns of one conversation answered two session ids. A retry also re-minted a session that had never been spent. Build the headers before the counter moves and send that value.
|
Verified locally and merged (rebased onto main as 41a2833 to keep history linear). The diagnosis is exact: Both directions verified: the new test fails against main's provider.mjs and passes with the fix; full suite on the rebased state matches the main baseline (806 pass, the 8 fails are pre-existing local- Side note: this also invalidates the session-pinned arm of some quota experiments I ran yesterday — the pinned session never went out because of this very bug. The project-id arm was capture-verified and stands. Thanks for the sharp catch and the well-built test. |
|
Merged as 41a2833 (rebased). |
What this fixes
OPENCODE_ZEN_FREE_SESSION_AFFINITY=1is documented to keep one session perconversation. It does not: every request goes out under a freshly minted
session, so two turns of one conversation answer two different session ids.
The cause is the order of two statements in
attempt():attemptHeadersdistinguishes the first attempt from a retry withattempts === 0, but the counter has already moved by the time the headers arebuilt. The branch never matches, so:
sessionID()chose is discarded on every request, andwhat the retry is for.
The fix builds the headers before the counter moves and sends that value:
Five lines, no behaviour change outside the attempt counter's ordering.
Test
index.test.mjsgains one case that pins the contract: with affinity on, twoturns of one conversation share a session id, the first attempt of a retried
request still opens under it, and the retry itself does not.
On upstream
main(b6e828e) the new case fails:With the fix, the full suite passes under the declared
bun@1.4.3:Integration check
Deployed as a local patched build of 0.5.11 into a magpie gateway, where the
plugin owns
opencode-zen-free. Real requests through the gateway:Both a streaming and a non-streaming turn were served.
Scope
This is a fix for the affinity regression only. It does not touch the gate,
fingerprint.json, the project-id policy, or the 429 retry's own semantics.Unrelated to this PR, and not claimed as fixed by it: a gateway running 0.5.9
was answering 429 on this route. 0.5.9 has no attempt counter at all, so it
cannot carry this regression.