Repository navigation
Conversation
Routing stability for cache affinity: - Retry a transient upstream hiccup once on the same account before spending a failover hop. An empty stream, a first-byte timeout, or a stream that dies before the first event usually recovers on the same worker, and switching accounts throws away the prompt cache. The retry has its own per-request budget, keeps the in-flight slot, and skips any non-transient failure. - Stop the exponential ladder from multiplying a cooldown the upstream declared itself. Transient failures are capped at 60s; a quota reset reported in the response body is used verbatim (>=1m, <=24h) instead of being clamped to the 10-minute rate-limit window, which would have retried a dead account every ten minutes. Durable failures (auth, unhinted rate limits) still escalate. - Keep a session binding through a short cooldown: failover no longer clears the anchor when the account is only cooling, and bindSession/CommitSession leave the anchor alone while its remaining cooldown is 5 minutes or less, so the next turn returns to the cache-warm account. - Default session-affinity TTL 1h -> 4h, with CLI2API_AFFINITY_TTL and CLI2API_AFFINITY_CAPACITY overrides (48h / 1M bindings hard caps). - Classify exhausted routing (503 no_accounts) and undecodable upstream bodies (502 upstream_decode_error) instead of leaking a bare 502 upstream_error. Observability, so the change can be measured: - SessionAffinityStats gains miss_reasons / escape_reasons distributions alongside the existing last-value fields. - RequestUsageTotals gains cache_hit_rate (hit / (hit + miss)), nil when no cache accounting was reported. - SeedComponents reports per-component session-seed hashes; Prepare logs them under CLI2API_AFFINITY_DEBUG so a chat that re-anchors every turn can be traced to a volatile system prefix or a changed first message.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Routing stability for prompt-cache affinity: stop throwing away the warm account on failures that say nothing about the account, and stop inflating cooldowns the upstream already declared.
>=1m,<=24h) instead of being clamped to the 10-minute rate-limit window, which retried a dead account every ten minutes. Durable failures (auth, unhinted rate limits) still escalate.failoverno longer clears the anchor while the account is only cooling, andbindSession/CommitSessionleave the anchor alone while its remaining cooldown is 5 minutes or less, so the next turn returns to the cache-warm account instead of walking the pool.CLI2API_AFFINITY_TTL/CLI2API_AFFINITY_CAPACITY(hard caps 48h and 1M bindings).503 no_accountsand an undecodable upstream body as502 upstream_decode_errorinstead of leaking a bare502 upstream_error.SessionAffinityStatsgainsmiss_reasons/escape_reasonsdistributions (last-value fields kept for older console builds),RequestUsageTotalsgainscache_hit_rate(nil when no cache accounting was reported), andSeedComponentsplus one extra affinity debug log line report per-component seed hashes, so a chat that re-anchors every turn can be traced to a volatile system prefix or a changed first message.No schema change: all state is in-memory plus existing request-log aggregates, so there is no migration.
Tests
go build ./...go test ./...go test -race ./internal/executor ./internal/translatego test -race ./internal/gateway ./internal/store ./internal/accounts ./internal/appgo vet ./...git diff --checkpython scripts/release-notes.py validateMerge order
Independent of other PRs in this series. The follow-up
feat/prompt-cache-toolsis stacked on this commit; rebase it after this lands.