Repository navigation
fix(identity): salt derived session ids per process so a restart re-mints them - #160
Conversation
CanonicalSessionID re-encodes a conversation signal from the server key and the seed alone, so the upstream `x-opencode-session` was identical in every process on the same UTC day. The free tier keeps charging that session, so after a 429 a gateway restart no longer changed anything upstream: the same `ses_…` walked into the new exit's bucket and 429'd again. Mix a 16-byte nonce, minted once per process, into the hash. A running gateway still derives one stable session per conversation, while a restart re-mints the ids and starts a fresh upstream identity. Official client sessions are still forwarded verbatim. Refs jasonxu114514#159, jasonxu114514#158
|
Keeping this open as identity hygiene, with the framing corrected: it is not the fix for the 429s reported in #159. Measured today on one fixed exit: the session from the original report ( This PR is still worth having for the reason it was written: If it lands, the claim to put in the commit and README is "a restart presents a new session for a conversation", not "this fixes the free-tier 429". |
Summary
CanonicalSessionIDderivedses_…from the server key and the conversation seed alone, so every process on the same UTC day forwarded the byte-identicalx-opencode-session. The free tier keeps charging a session, so once it 429'd, restarting the gateway after an egress change replayed the same id and failed again — measured as a ~0.7 s 429 within: 0.This mixes a 16-byte nonce, minted once per process, into the re-encoding hash. A running gateway still derives one stable session per conversation (affinity, sticky proxy, prompt cache keep working); a restart re-mints the ids. Official client-minted
ses_…bypass the salt and stay verbatim, as before.Scope and deviations
internal/identity/request.go: salt synthesized sessions withbootNonce.internal/identity/request_test.go: new tests for per-process stability, restart change, and official-id passthrough.README.md/README.zh-CN.md: document the restart behaviour.README.vi.mdandREADME.it.mdare not updated (translation); the owner may want to sync them.Verification
go test ./internal/identity→ok opencode2api/internal/identitygo vet ./...→ cleango build -o /tmp/o2a-check ./cmd/opencode2api→ successTwo separate runs of the patched build with the same fixed seed:
Within one process the same seed returns one id; both ids satisfy the free tier's
ses_shape (descending time part, counter 1,…ffe).CI: all 5 checks pass on 4bc4fff (Go 1.24.x and stable, ubuntu and windows, plus formatting/WebUI syntax; run 40837307779).
Field check (single deployment, reported by the reporter, not a controlled run): after changing IP and restarting on this patch, the same conversation reached upstream instead of 429. The exit changed at the same time, so Derived session ids survive a restart, so a burned ses_… keeps 429ing after the egress changes #159 asks for the fixed-exit A/B to confirm which key the limiter uses.
Risks
bootNoncefrom the hash inCanonicalSessionID.Closes #159. refs #158.