Repository navigation
fix(keepalive): retry a ping that failed fast while the cache lives - #710
Merged
Merged
Conversation
A ping that failed in transport refreshed nothing, but the keeper had already moved its clock to the ping's start and used one of its pings. So the next ping came a full idle period after the FAILED one, past the cache's lifetime, and re-wrote the prefix. Now a transport failure that comes back while the cache entry is still alive gives the ping back: the clock returns to its last good refresh, the ping count drops by one, and the next sweep tick retries. Once per run of failures. A failure that returns after the cache expired is not retried, because a retry can then only re-write. Refs #703 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
amiddavid
commented
Oct 25, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | d541f9d377aa |
approve |
Verdict: approve
Findings
None.
Non-blocking
keepalive/keeper.go:1229andkeepalive/keeper.go:1260— a ping the limiter refuses ("no spare
concurrency") is skipped, but Sweep already movedstartedAtand spent one ping. The next ping
then comes a full Idle later, past the cache lifetime, and re-writes the prefix. This is the same
#703 symptom on a path this fix does not cover. It is pre-existing, so it needs its own issue
rather than a change on this branch.keepalive/keeper_test.go:239— the comment onTestPingErrorFailsOpensays a failure "must
still count against K". After this change a fast failure is given back and does not count, once
per run. The test still passes. Only the words are now wrong.keepalive/keeper.go:1430— the TTL values (5 min, 1 h) are written a second time; they already
exist incachePhaseAt(keepalive/substitute.go:33). One shared helper would stop the two
copies from drifting.keepalive/keeper.go:1433— after a first-miss ping re-writes the prefix,refreshedAtstays on
the last read by design. A later fast transport failure then gets no retry, because the TTL check
sees the entry as dead. The schedule is still anchored on the write, so the cost is small. I note
it so the choice is visible.
What I checked
- Read the full diff:
keepalive/keeper.go,keepalive/failedping_test.go,
proxy/keepaliveplan_test.go. ReadCLAUDE.mdand the keep-alive rows ofdocs/design.md. - Traced the give-back against the entry lifecycle.
Arrivedeletes the entry,Recordreplaces
it, retirement and eviction clear it. A give-back that lands on a removed entry mutates an
orphan, so it cannot corrupt live state. Thee.pings != j.pingguard stops a double decrement. - Traced the schedule. Sweep stamps
startedAtandpingsunder the lock before the ping, which
also stops a second ping while one is in flight. The give-back runs under the same lock after the
call returns, so no retry can overlap the ping it restores. - Checked the retry bound.
e.retriedallows one give-back per run of failures and is reset only by
a read (notePingRead) or a new entry fromRecord. A route that keeps failing gets one retry,
asTestARunOfTransportFailuresIsRetriedOnceasserts. Total successful pings stay bounded by
MaxPings plus one per failure that a later read pays back, and the hard(K+1) x Idletimer is
untouched, so no entry outlives its deadline. - Checked the TTL guard. It reads
e.ttl1h, the tier the provider billed, ande.refreshedAt,
whichRecordandrecord1set only on a real refresh. A slow failure past the TTL gets no
give-back, whichTestAFailureAfterTheCacheExpiredIsNotRetriedasserts. The guard usesk.now(),
the same clock the production ticker passes toSweep(keeper.go:512). - Verified the test arithmetic by hand: Idle 280 s, TTL 300 s,
pingTimeout60 s. All three new
tests and the updated plan test produce the asserted counts and times under those values. - Checked the other tests that model ping failures (
TestPingErrorFailsOpen,
TestATransportErrorIsNotAFailure,TestAnyOther4xxStops). None sweeps twice after a transport
failure, so none contradicts the retry. - Checked the substitute paths. A substitute that declines or errors falls through to the ordinary
ping in the samefirecall, so the fix covers those failures too. - Checked the repo rules. Library change only, no
proxyimport fromkeepalive. Data dependence
unchanged: the give-back reads keeper metadata (refreshedAt,ttl1h,pings) already held in
memory, sodocs/data-dependence.mdneeds no row. Commit carries DCO andAssisted-By:. - Live tests were not approved, so I read the code only.
amiddavid
commented
Oct 25, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | d541f9d377aa |
blocking |
Verdict: blocking
Findings
- keepalive/keeper.go:1429 — the retry guard knows only Anthropic cache lifetimes, so an OpenAI thread never gets the retry
- What fails: an OpenAI
/v1/responsesthread (GPT-5.6+) has a 30-minute cache minimum and pings at a 28-minute Idle. Its ping fails fast in transport atrefreshedAt + 28 min.giveBackFailedPingthen testsnow < refreshedAt + 5 min, becausettl1his always false for OpenAI. The test fails, so no retry is given. The next ping comes a full Idle later, at+56 min, past the 30-minute guarantee, and re-writes the prefix. This is the exact #703 pattern, and it stays unfixed for every OpenAI thread. - Proof:
keeper.go:789forcesttl1hfalse for OpenAI (ResolveTier(...) && provider != bschemas.OpenAI).keeper.go:1429-1432picks the ttl fromttl1halone: 5 minutes or 1 hour.proxy/keepalive.go:440-444sets an OpenAI entry's Idle toOpenAIIdle, whose default ismodelinfo.OpenAIDefaultKeepAliveIdle = OpenAIMinimumCacheTTL - 2 min(28 min,internal/modelinfo/cachefrac.go:11-12).eligible()(keepalive/ping.go:82-90) admits these threads, so the keeper does ping them. No test covers an OpenAI entry infailedping_test.go. - Fix: derive the ttl from the entry itself. For
e.provider == bschemas.OpenAI, usemodelinfo.OpenAIMinimumCacheTTL. Add one test with an OpenAI entry whose ping fails fast.
- What fails: an OpenAI
Non-blocking
- keeper.go:1295-1359 — a 429 or 5xx answer gets no give-back. It also refreshes nothing and comes back fast while the cache lives, so the next ping comes a full Idle later and can re-write the prefix. Refusing an immediate retry is right for 429 (a rate limit), but a 5xx could take the same retry. The debug line at
keeper.go:1357("retrying at the next slot") now overstates what happens: the next slot is a full Idle away. - keeper_test.go:239-241 — the comment is now stale. It says a transport failure "must still count against K". After this PR, a fast failure is given back and does not count against K. The bound now comes from the
retriedflag. Update the comment, not the test. - keeper.go:1404-1409 —
retriedis reset only bynotePingRead. A summary or sweep substitute that reads the cache (substitute.go:209), or a manual ping (manual.go:165), updatesrefreshedAtbut does not resetretried. A transport failure later in the same idle span then gets no retry. Conservative direction; minor. - keeper.go:1260-1264 — a refused spare slot keeps the stamp. The ping is never sent, but
startedAtande.pingsstay spent, so the next ping comes a full Idle later. Same shape as #703. Pre-existing; out of scope here. - keeper.go:1753 —
Plan.NextPingcan now be in the past. After a give-back the retry is due immediately, so the plan reportsprevStartedAt + Idle, a past time. The proxy test embraces this ("the retry due at ..."). A host that renders it as a future instant should treat a past value as "due now".
What I checked
- The full diff (3 files) and the code around each change:
Sweep's stamp,fire's error path,noteOutcome,record1, both substitutes,PingNow,Plans, the route breaker and the dead-credential marks. - The timing math of the three new tests and the changed proxy test. All consistent: the inline
Gorunner makes each failure and its give-back synchronous insideSweep, and the shared clock makes the timeout case cross the 300 s boundary before the give-back runs. - Existing tests that transport-fail a ping (
TestPingErrorFailsOpen,TestATransportErrorIsNotAFailure): both still pass. Each sweeps once, and the give-back changes no field they assert. - The retry bound:
retriedis set once per run of failures and reset only by a cache read. Attempts per idle span stay at most K+1. The hard deadline timer and the credential hold are untouched, so the security bound holds. - Concurrency:
giveBackFailedPingtakesk.mu; thee.pings != j.pingguard blocks a give-back onto a newer ping; a give-back onto an entry already dropped fromk.livemutates a dead object and cannot reach the map. No new race. - Fail-open: the error path still only counts and logs. No new stop, panic or drop path.
- Money: a retry can only fire earlier than the old schedule, never later. If the entry is dead, the retry writes once and stops, the same write the old schedule would have paid later. No path spends more than before.
- Data dependence: no change. The fix reads timestamps, counters and flags only.
docs/data-dependence.mdneeds no new row.
The retry guard chose the cache's life from the billed tier alone, 5 minutes or 1 hour. An OpenAI Responses thread never sets that tier, but its cache lives 30 minutes and it pings at 28. So every OpenAI fast failure looked past the cache's life and was never retried. The guard now asks the entry (kaEntry.cacheTTL). Also fixes 2 stale texts the review found: the comment on TestPingErrorFailsOpen and the debug line for a 429 or 5xx answer. Refs #703 Refs #707 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
Collaborator
Author
|
Replies to round 1, at head Reviewer 1, finding 1 (OpenAI ttl in the retry guard): fixed.
Non-blocking, fixed:
Non-blocking, out of scope here (each a separate change):
How it was tested (eval box):
|
amiddavid
commented
Oct 25, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 40f651d8d75c |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Reviewer 1, finding 1 (the retry guard knew only Anthropic lifetimes, so an OpenAI thread never
got the retry): fixed.kaEntry.cacheTTL()returnsmodelinfo.OpenAIMinimumCacheTTL
(30 min,internal/modelinfo/cachefrac.go:11) for an OpenAI entry, else 1 h or 5 min by the
billed tier.giveBackFailedPingnow asks the entry. I verified the pieces myself:- Every OpenAI entry in the keeper is GPT-5.6+ on
/v1/responses:eligible
(keepalive/ping.go:82) gates it at Record, andGPT56OrLateraccepts the test's
azure/gpt-5.6-luna. So the 30-minute minimum applies to exactly the entries that reach the
guard. ttl1his always false for OpenAI (keeper.go:789), so the OpenAI case cannot be shadowed by
the tier cases.- Test arithmetic: Idle 28 min (
OpenAIDefaultKeepAliveIdle), the failure at 28 min 1 s, the
guard's window 30 min, so the give-back fires and the retry lands 2 s later. I also checked the
mutation claim by hand: without the OpenAI case the guard sees the entry as dead at 28 min, no
give-back, the second sweep is not due until 56 min, and the test'swant 2fails.
- Every OpenAI entry in the keeper is GPT-5.6+ on
- Reviewer 2, non-blocking (the limiter-refused ping keeps the stamp): deferred by the author,
reason accepted. It is pre-existing and out of this branch's scope. Issue #707 ("after a failed
ping, the next ping is too late") is still open and can carry it. - Reviewer 2, non-blocking (stale comment on
TestPingErrorFailsOpen): fixed. The comment now
names theretriedflag as the bound. - Reviewer 2, non-blocking (TTL values written twice): partly fixed, reason accepted.
cacheTTL()is now the one place inkeeper.go.cachePhaseAtinsubstitute.gokeeps its own
copy; the author left it because its callers are outside this fix. The two copies answer
different questions (entry method vs. free function), so I accept leaving it. - Reviewer 2, non-blocking (
refreshedAtstays on the last read after a miss-write): accepted as
by design. The cost is one idle span at most. - Reviewer 1, non-blocking items (429/5xx no give-back,
retriedreset only by an ordinary read,
refused spare slot,Plan.NextPingin the past): all deferred or accepted by the author with
reasons I checked and agree with. The debug line for a 429 or 5xx is fixed and now tells the
truth: without a give-back, the next ping is a full Idle away.
The new commit
40f651d8— I reviewed it as a first review.cacheTTL()readse.providerande.ttl1h, both
set once at Record and read underk.muingiveBackFailedPing. No new state, no new race. The
new test builds its OpenAI entry through the realRecordgate, so it exerciseseligible,
pingBodyon/v1/responses, and the give-back together. The two text fixes (test comment,
debug line) match the code. No defect found.
What I checked
- Last review: round 1,
d541f9d377aa82b80428b760f27e861c1fe564d0, 2026-10-25T17:43:50Z. - New commits read: 1 —
40f651d8"fix(keepalive): give an OpenAI fast failure its 30-minute retry
window". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files).
- New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (17:44:38Z): read it all, checked its finding 1 and its five
non-blocking notes against the code. - The author's reply comment (18:02:29Z): read it all, checked every claimed fix and every
deferral reason against the code. - Commit
40f651d8: read the whole diff and the code around each change.
- Reviewer 1's round-1 review (17:44:38Z): read it all, checked its finding 1 and its five
- Verified the OpenAI constants (
OpenAIMinimumCacheTTL30 min,OpenAIDefaultKeepAliveIdle
28 min),GPT56OrLateronazure/gpt-5.6-luna,eligible's OpenAI gate,relayServesClaude
(true for non-Anthropic), andpingBody's/v1/responsesbranch. - Checked the author's eval-box test table against the code: the pass and the mutation fail are
both what the code predicts. Live tests were not approved for me, so I read the code only. - Repo rules: library change only, no
proxyimport, data dependence unchanged (the TTL comes from
e.providerande.ttl1h, metadata already in memory), DCO andAssisted-By:present.
amiddavid
commented
Oct 25, 2026
amiddavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.310 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 40f651d8d75c |
approve |
Verdict: approve
Findings
None.
Round-1 findings
- Mine, finding 1 (the retry guard knew only Anthropic lifetimes): fixed.
kaEntry.cacheTTL()(keeper.go:1413-1422) returnsmodelinfo.OpenAIMinimumCacheTTLfor an OpenAI thread, else 1 h or 5 min by the billed tier.giveBackFailedPingnow reads it (keeper.go:1444). The new test proves the retry: without the give-back the entry is not due again until+56 min, so the second sweep would send nothing. I traced the test's gates myself: the fixture passeseligible()(route/v1/responses,GPT56OrLater("azure/gpt-5.6-luna")is true), the prefix clearsMinPrefixTokens, and the failure at28 min + 1 sis inside the 30-minute window. - Mine, non-blocking (stale comment on
TestPingErrorFailsOpen): fixed. The comment now names theretriedflag as the bound. - Mine, non-blocking (misleading "retrying at the next slot" debug line): fixed. It now says the next ping comes a full idle period later.
- Mine, non-blocking, deferred by the author — I accept each reason. A 5xx gets no give-back (a policy choice for the owner; an immediate retry can add load to an overloaded upstream).
retriedis reset only by an ordinary read (conservative; at most one missed retry). The refused spare slot keeps the stamp (pre-existing, needs its own issue).Plan.NextPingin the past means "due now" (no host renders it as a countdown). - Reviewer 2, non-blocking (TTL values duplicated): partly addressed, reason accepted.
keeper.gonow has one place,cacheTTL().cachePhaseAt(substitute.go:32-38) keeps its own copy, and the author did not change it because its callers are outside this fix. I checked: unifying it would change the substitute's phase behavior for OpenAI, which is genuinely a separate change. See the non-blocking note below. - Reviewer 2, non-blocking (
refreshedAtstays on the last read after a first-miss write): rejected by the author, reason accepted. A write refreshes nothing that was there before; I verified in round 1 thatrecord1gatesrefreshedAtonCacheRead > 0for exactly that reason.
Non-blocking
- keepalive/substitute.go:36-38 —
cachePhaseAtstill models every non-1h thread as a 5-minute cache, so it now disagrees withcacheTTL()on OpenAI. Effect: 28 minutes into a 30-minute life the phase readsCold, so apre_expirysubstitute candidate never fires on an OpenAI thread and the ordinary ping goes instead. Fail-open and conservative, and the behavior is unchanged by this PR. File a follow-up issue so the two functions cannot drift further apart.
What I checked
- Last review: round 1,
d541f9d377aa82b80428b760f27e861c1fe564d0, 2026-10-25T17:44:38Z. - New commits read: 1 —
40f651d8fix(keepalive): give an OpenAI fast failure its 30-minute retry window. Read the full diff and the code around each change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: reviewer 2's round-1 review (posted before mine, so unread in round 1 by rule; read now) — its two unique points are answered above; the author's reply comment at 18:02:29 — every item in it is addressed above; the new commit — reviewed as a first review.
- The new commit's correctness:
cacheTTL()case order and semantics; onlygiveBackFailedPingreads it, so no other path changes behavior. Non-OpenAI entries get the same 5 min / 1 h as before. - The new test's arithmetic: Idle 28 min, failure at
28 min + 1 s, retry at28 min + 3 s, both inside the 30-minute window. The eligibility gates for the OpenAI fixture (eligible,GPT56OrLater,relayServesClaude, prefix floor, turn count) all pass by trace. - Repo rules: the change is library-only,
keepaliveimports no host package (internal/modelinfois internal, which a library package may import). DCO sign-off andAssisted-By:present on the commit. Data dependence unchanged:cacheTTL()reads the entry's provider and billed tier, both already in memory;docs/data-dependence.mdneeds no row. - Live tests were not approved, so I read the code only. The author's eval-box results (test PASS, mutation FAIL,
-raceclean) are consistent with my trace but not rerun by me.
This was referenced Oct 25, 2026
amiddavid
added a commit
that referenced
this pull request
Oct 25, 2026
- A ping the sweep's question replaced uses no output-budget step (#712), so the next plain pings differ. - A failed question is not a transport failure of a ping: it does not set #710's retry flag, the ordinary ping goes out in its place, and a question that billed asks once per idle period. - A held answer and its drop records stay on their own thread key, so a thread that moves to another id (#711 prevents it for a resume) does not carry them. Tests only. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
added a commit
that referenced
this pull request
Oct 25, 2026
… what it earns (#404 PR C) (#695) feat(sweep): apply the held answer on the next cold request, and book what it earns The sweep asked at the keep-alive ping and held the answer, and nothing used it. This change applies it. The sweep now saves money. - Cold apply (point 3): on the next cold request of a thread, rechecks the held answer and replaces each valid output with a shape descriptor and a <<cg:HASH>> marker. The original is stashed, so expand returns it byte for byte. Each drop writes a record (cg:swd:), and every later request of the thread replays the same bytes. A warm request with an unchanged conversation never changes (H1). - Changed prefix (point 4): a rewind, an edited turn or a fork applies only the held drops after the first changed message. The ones before it stay held. Counted apart as sweep_applied_changed_prefix. - Fail open: a store that cannot hold an original refuses that drop. A panic in the apply restores every message it touched, writes no record, and forwards the request unchanged. - Dashboard (point 9): the answer cost is booked once, on the ping row the question replaced, in its own column (sweep_answer_usd). The expands of sweep markers come off the sweep's credit at the write rate. - Quality signals (point 7): an expand of a sweep marker is charged to the sweep, and a later turn that uses something a dropped output introduced counts as a false drop. False-drop rate per thread and overall, in the Components tab and in /stats (keepalive.sweep_drops). Ids, hashes and counts only. - The ping carries the forwarded body after a cold apply (point 15), by test. - The shadow-only ask gate is gone. shadow stays a setting and applies nothing. - xhigh runs the sweep again. The other presets are unchanged. - From the #508 notes: registerPing no longer keeps a conversation copy for a thread with no candidate and prunes on every registration (D); the sweep reads its own cg:swd: record, not cg:res: (F); BuildFallbackAsk and the sweep-only pricing in prefix_econ.go are removed (coref keeps what it uses). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(sweep): serialise putHeld, claim before the cold apply, retry a panicked apply once - putHeld takes heldMu and never overwrites a newer AskedAtMs, so a claim that read an old answer cannot overwrite a new one, and two asks of one thread cannot land out of order. - The cold apply claims the held answer first. A panic in the apply or the recheck restores every message, is counted (sweep_apply_panic), and hands the answer back once. A second panic leaves it spent. - The ask-level slot refusal counts as sweep_concurrency_full, not sweep_ask_failed. - The cold test now uses the summary reserve's ColdApplyPhase. - The sweep row carries the net saving and the cold-apply cache numbers for L1 and C2. - docs/data-dependence.md: the sweep row now says it stashes originals for expand. PENDING. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> docs(sweep): fix the xhigh and housellm preset rows; record the data-dependence approval presets.md: xhigh and housellm now describe the sweep as it is: it asks at the keep-alive ping and removes content only on a cold request. The old max_calls and "adjudicates at depth on an expired cache" text is gone. data-dependence.md: Decided by records David Amid's approval of 2026-10-25 (#695). Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(sweep): round 1 review fixes for the false-drop signal and the commit window - A marker shared by two threads lists every owner. An expand credits the thread that made it, and only a thread that carries the marker. With no thread known (the request-path repair), every owner is credited. - The reference scan, the expand note and the commit take dropMu, so a flag is not lost. - The commit is atomic in effect. A panic after the first record tombstones every record and marker owner this attempt wrote. Applied and sweep_applied_* are counted last. - The change point is computed from the answer the claim returns. - Shadow mode keeps replaying drops that already exist. It only stops new applies. - Rename AppliedChangedPrefx; fix the stale selectAffordableDrops hint; document the next-warm imprecision. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> fix(sweep): release dropMu when the reference scan panics, and close the panic paths - scanReferences held dropMu with a plain Unlock inside a function that recovers panics. A panic in the Store or the ledger left the lock held for good, and every later scan, expand note and commit blocked. The locked part is now a closure with a deferred unlock. - The extraction savings metrics are booked after the commit, with the events and ledger. - A panic at the held trim gives back the untrimmed answer, so the drops after the change point are not lost. - An expand of a marker with no thread known counts once in the total. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]> test(sweep): pin the sweep question against #710, #711 and #712 - A ping the sweep's question replaced uses no output-budget step (#712), so the next plain pings differ. - A failed question is not a transport failure of a ping: it does not set #710's retry flag, the ordinary ping goes out in its place, and a question that billed asks once per idle period. - A held answer and its drop records stay on their own thread key, so a thread that moves to another id (#711 prevents it for a resume) does not carry them. Tests only. Part of #404. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
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
A keep-alive ping that fails fast in transport (EOF, a reset or refused connection) is now retried at the next sweep tick, while the cache is still alive. A ping that times out is still not retried, so this PR fixes only part of the problem (see Limit). Before, the keeper counted the failed ping as sent and restarted its clock from it. The next ping then came after the cache had expired, and it re-wrote the whole prefix.
What we found
On the live proxy (port 8789), 2 of the 3
missedpings since the proxy started came right after a ping that failed. These 2 failures are the proxy's wholefailedcount:The 3rd miss (Oct 25, 12:13:11, $1.88) had no failed ping before it, and it is not part of this fix.
In the older log of the same proxy, fast failures also happen:
EOF(Oct 15 and Oct 20),broken pipe(Oct 20) and TCP read timeouts.Example from the main thread:
Why it happens
Sweepsetse.startedAt = nowande.pings++before it sends a ping (keepalive/keeper.go). On a transport error,firecounts the failure and returns, and it keeps both changes. So a failed ping:What changed
giveBackFailedPing. On a transport error it restores the clock to the last good refresh and gives the ping back. The next sweep tick (2 s later) then retries.kaEntry.retried, reset on a good read). A route that keeps failing gets one retry, not one every 2 s.refreshedAt). After that, a retry can only re-write, which costs more than it saves.cache keep-alive ping failedgainsretry=true|false.Limit: a timed-out ping is still not retried
pingTimeoutis 60 s and the default idle is 270 s, so a ping that times out returns about 30 s after the cache expired. This PR does not retry that case, because the retry would only re-write. Both live misses above were timeouts, so this PR would not have prevented either of them. It prevents a miss after a fast failure (EOF, reset, broken pipe). Options for timeouts are in Open questions.How it was tested
All runs are on the eval box.
TestAFastTransportFailureIsRetriedWhileTheCacheLivesorigin/main+ testthe entry shows 1 pings used, want 0TestARunOfTransportFailuresIsRetriedOnceorigin/main+ test1 pings sent inside one lifetime, want 2TestAFailureAfterTheCacheExpiredIsNotRetriedorigin/main+ testmainnever retries)giveBackFailedPing10 pings sent inside one lifetime, want 2a failure past the cache's lifetime was given backgo test -race ./keepalive/...go test -race ./proxy/...go vet,gofmt -lI changed one existing test.
TestKeepAlivePlanCountsOnlyPingsThatRefreshedexpected "2 pings left" after a fast failure, which is the old behaviour. It now expects 3 pings left and the retry due at once. Its second half (a later ping that reads updatesRefreshedMS) is unchanged and passes.Data dependence
No change. The keeper stores no new data. The new field is a flag on an entry it already holds in memory.
Open questions
Refs #703
Refs #707 (fast failures only; a timed-out ping is still not retried)
🤖 Generated with Claude Code