Repository navigation
Conversation
… session The free tier ledges free-model usage per session id, not per egress: once a conversation spends its allowance every relay answers 429 "Free usage limit reached" for that session, so exit rotation cannot recover it, and a fork of the conversation keeps the same derived id and stays burned. Re-mint the session once on that exact 429 and retry the routing pass. Only sessions the gateway minted itself are re-minted, so official client session ids keep their affinity, and the replacement is deterministic (bootNonce-salted, memoized) so the rest of the conversation reuses it instead of re-paying the exit walk. A session-scoped 429 no longer cools the exit: the burn is not the relay's fault and cooling it could leave the retry with no exit left.
…e-limit 429 A free-limit 429 follows the session id, not the exit, so every relay and base URL answers it identically. The walk previously spent the whole exit set on guaranteed 429s before doUpstream re-minted the session; a burned conversation cost 9 relays and ~15s on its first request. Break the walk on the first such 429 so the escape costs one rejected attempt plus the retry.
The early break on a session-scoped free-limit 429 must apply only to the original routing pass. On the re-minted retry the answer can still be exit-specific (a relay or its egress may reject the fresh session too), so breaking there left the retry with a single exit and turned recoverable requests into 429s. Mark the retry pass and keep the break for the burned original only.
…p rule escapedSession stopped after four hops, so a conversation that burned five or more session buckets kept resolving to an already-spent id: every request paid an extra escape, and once the next bucket also burned it could not advance at all. Follow the chain to its end (bounded by the memo size) so the lookup always returns the current head. Move the anonymous walk-stop decision into stopBurnedWalk and test it, plus a long-chain test. The earlier regression shipped because that decision had no test. Collapse the duplicate memo value struct into the key type.
The free-model allowance is per egress IP and shared by every session leaving through it, but every "Free usage limit reached" 429 was treated as session-scoped. On a partially spent pool that made the escape stop the walk, re-mint the session, and re-walk straight into exhausted exits, so the request still ended in a 429 after nine attempts. Split the two shapes by the Retry-After: a hint that lands on the next UTC midnight is the exit's daily allowance, so park that exit until the reset and keep walking instead of re-minting. A 429 without that hint stays session-scoped and keeps the existing escape. Daily-quota answers also count as neutral for the lane breaker, since the exit answered and other exits may still have quota. The cursor skips parked exits, and when the whole pool is parked it probes the soonest-reset exit once per request so the client still gets the upstream 429 rather than a gateway error.
The re-encoded id's timestamp part is drawn from the UTC day, so the session is stable for that day; bootNonce rotates it on restart.
The 20 relays are distinct tunnels that share one egress IP — verified by re-registering a WARP container, which returns the same address — so every exit answers a free-limit 429 identically and the per-exit walk only spends attempts. It also let a single dead relay turn a quota answer into a 10 s transport timeout and a gateway 504. Stop the walk on the first free-limit rejection, re-mint the session once even when the client supplied it (a burned bucket has no prompt cache left to preserve), and retry. Only when the fresh session is rejected as well does the exit get parked, which is then a real per-egress signal. Keep the earlier 429 when a later attempt only times out, so the client gets the quota answer instead of a gateway error.
The free tier meters its free-model bucket per session, and one request at the observed sizes consumes it: across 10 consecutive turns, every session reused from the escape memo answered 429, while 21 fresh sessions answered 200 on the first attempt. Reusing the memoized link therefore bought no prompt-cache affinity, only one guaranteed 429 and one counted attempt per turn. Mark a link spent after it serves a request, and have the escaped-session chain mint and record the next link before the request is sent. The first turn of a conversation still pays one escape, since nothing can predict that the client's session is already burned; later turns go straight to a fresh bucket.
A session serves exactly one free-tier request, and the escape memo only existed for chains that had already burned. A conversation starting on the client's own id therefore succeeded once, then had no entry to follow and paid an escape on the second turn. Record the successor when a turn succeeds, so the chain starts on a fresh link from the next turn onward. Also skip links the chain has already used: WithFreshSession is deterministic, so minting from the same key twice returned the same id and the rotation cycled between two spent links.
The escape path records the original-to-replacement mapping after the retry has already succeeded, and that success marked the replacement spent. Remembering cleared the mark, so the next turn replayed the same replacement and paid another 429 — the exact per-turn cycle the spent mark exists to prevent.
|
this implementation is not very efficient, still needs better trigger conditions, so it defaults to old mechanism and when a session id always 429 it starts this rough shaped mechanism instead |
…e-tier 429 by re-minting the session
b9a67f0 to
d246519
Compare
Preserve upstream HTTP failures across transport retries, classify title requests before shaping, and rename legacy functions exactly once. Keep adjacent Responses assistant items together, including interleaved text and calls. Add opt-in prompt environment overrides with matching shell descriptions, strict validation, and WebUI round-trip preservation. Document compatibility boundaries and retain existing defaults. Include the requested test/ ignore rule. Offline zz_ regressions passed and were removed after validation as requested; vet and Windows/Linux builds passed. Refs #173, #175, #176, #178, #179, #181
|
Related conservative fixes landed in main 14faec7: 14faec7 . The latest HTTP rejection now survives later transport failures in static, keyed and WARP paths; resources are released before retrying. This does not remint sessions or adopt the quota hypothesis. Keeping this PR open for revision: the current anonymous success path unconditionally calls advanceSessionAfterSuccess, including diagnostics; WARP does not share the early stop-walk change; escapeBurnedSession adds an already cumulative attempt count to its offset again. Please scope reminting to demonstrated session failures, isolate diagnostic state and reconcile WARP/accounting paths before merging. Offline main regressions passed, but no live upstream session-scope claim was verified. |
|
Withdrawing this rather than revising it — the premise is disproven. The free-tier Consequences for this PR:
Root cause fix is #182: Happy to close this now unless you would rather keep any part of it; nothing in #182 depends on it. |
|
Retest against the merged fix (
And on the live gateway after the fix: 184 routed free-model requests, zero Worth noting the theory was already falsified before the fix: on the pre-fix build a no-tools body carrying one of these "burned" ids returned 200 while a tool-bearing body returned 429 — a session ledger would refuse both, a tool-name gate refuses only the second. |
|
Closing as superseded. The free-tier 429 keys on the |
Problem
The free tier ledges free-model usage per session id and every relay leaves from the same egress IP. Verified on the live pool: 20 distinct WireGuard tunnels, one egress address (
104.28.216.245), and removing a tunnel's registration volume to force a fresh WARP signup returns the same address. So a free-limit429is the same answer on every exit, and walking the pool only spends attempts.Two concrete failures followed from that:
429s, then hit a dead relay that blackholed, spent the 10 s first-event deadline, and surfaced as a gateway504instead of the upstream429.429ing even though a re-minted session is a fresh bucket.Fix
bootNonce-salted) and memoized (bounded, chainable up to 4 hops).429, while 21 fresh sessions answered200on the first attempt. So a served link is marked spent, and the next turn mints the following link before sending — the first turn still pays one escape, later turns do not.Retry-After(or a repeat rejection for another session within the window) bounds the park.429when a later attempt only times out, so the client gets the quota answer rather than a transport error.429counts as neutral for the lane breaker: the exit answered, and the session escape is the remedy.Diagnostics and title requests are skipped (a probe measures the request it was given; titles are answered locally).
Test
go test ./internal/identity ./internal/gateway— marker/memo/derived/remint tests, plusTestStopBurnedWalkcovering official sessions and daily-reset hints,TestDailyQuotaReset,TestExitFreeLimitReset, andTestCursorSkipsDrainedExits/TestCursorProbesFullyDrainedPoolOnce, andTestSessionEscapeRotatesSpentReplacement.429then200on the re-minted session; repeat request reuses the memo;--burn-allreturns429after one bounded retry;--burn-all --daily-quotareturns429with no502.200in 1.6 s on one attempt; no504s since. After the spent-link rotation, 5 of 7 memoized turns answered200on attempt 1 and memo→retry fell from 10/10 to 1/6.No dependency on the custom quota package.