Repository navigation
feat(keepalive): share the ping with the summary call (#404 point 10) - #688
Conversation
cea7b42 to
0211b4d
Compare
d9506f9 to
f995427
Compare
0211b4d to
173180d
Compare
f995427 to
315d9ea
Compare
amiddavid
left a comment
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 | 315d9ead01fe |
blocking |
Verdict: blocking
Findings
-
keepalive/keeper.go:1779 — the new fail-open path of the priority rule has no test: a summary candidate that declines must still send the ordinary ping and must not let the sweep ask.
- What fails: the PR's central rule changes behavior here. Before, a declined summary fell through to the sweep. Now the sweep must not ask, and the ordinary ping must go out. No test covers this combination.
TestKeepAliveSubstituteFallsBackToPingOnFailurehas no sweep candidate. S1 andTestKeepAliveSummaryTakesThePingBeforeTheSweepuse a summary that succeeds. So a regression on this path — the sweep asking after a declined summary, or a lost ping — passes the whole suite. - Proof: I listed every
kaCandidate*call site (substitute_test.go:83, 118, 149, 189, 324, 358, 417, 581, 628; sweepsubstitute_test.go:264, 400, 452). None pairs a failing or declining summary model with a registered sweep candidate. - Fix: add one keeper test. Register both candidates. Give the summary model an error. Assert: 1 ordinary ping, 0 sweep asks,
sweep_summary_took_ping+1.
- What fails: the PR's central rule changes behavior here. Before, a declined summary fell through to the sweep. Now the sweep must not ask, and the ordinary ping must go out. No test covers this combination.
-
keepalive/keeper.go:1575 — the two new
/statscounters are not in the counters documentation.- What fails: an operator reads "did it fire at all?" from the listed plain-ping reasons.
docs/components/advanced-offload.md:522and:578listsweep_no_inventory,sweep_already_asked,sweep_model_declined,sweep_ask_needs_shadow,sweep_concurrency_fullas the reasons a ping stayed plain.sweep_summary_took_pingandsweep_summary_in_flightare two new reasons of the same class, and they are documented nowhere. The repo's own config doc says unexplained counters invite an invented reading. - Proof:
grep -rn "sweep_summary_took_ping" docs/returns nothing. The doc section names every other plain-ping reason. - Fix: add both counters to the "Counted at the ping" list in
docs/components/advanced-offload.md, with one line each saying what they mean.
- What fails: an operator reads "did it fire at all?" from the listed plain-ping reasons.
-
PR #688 description — the PR does not state its data dependence, as CLAUDE.md requires for every PR that changes a feature.
- What fails: CLAUDE.md says every PR that adds or changes a feature states its data dependence at each storage level. The PR changes the keep-alive substitute feature and states no dependence. The claim map is metadata only, in memory, and no doc row needs to change — but the PR must say so.
- Proof: the PR body's "What changed" and "Technical notes" describe behavior and counters. Neither mentions data dependence.
- Fix: add one line to the PR description: "Data dependence: none added. The claim reads registry existence (metadata, in memory) and stores nothing."
Non-blocking
components/offload/ping_claim.go:85— theinFlight.peekcheck is check-then-act. A detached summary can start on the request path after the peek, and then run while the sweep question runs. The new comment inkeeper.go:1245("never race on one thread") is stronger than the code. Today the overlap is harmless: both calls only read the prefix, and the store writes use different keys. Tighten the comment, or the check, before PR C makes the overlap matter.components/offload/ping_claim.go:100— aPingNoneclaim is released before the two lookups run. A candidate registered in that window can take a sweep slot with no claim held. The PR body says a thread never holds a slot without its claim. The window is narrow and theaskedflag and single-flight still protect the thread.- The
no_candidatecounters now count fewer pings. When one component owns the ping, the other's lookup no longer runs.summarySubstituteNoCandidateandsweepPingNoCandidatetherefore undercount against the old meaning. The PR body notes thenoneclaim runs both lookups, but not that the counters narrowed. pingGuardBusyis keyed bythread.Key(session, thread), with no tenant. Two tenants that share a session id force each other to plain pings. The candidate registries use the same key, so this is a pre-existing pattern, and the failure is fail-open.ColdApplyPhaseis exported for PR C and unused in this PR.ping_claim_test.go:118—for claimed.Load() < 16 {}spins with noruntime.Gosched(). Go's preemptive scheduler makes it safe; a yield would be kinder to a single-CPU test box.
What I checked
- The full diff of 315d9ea against 8f06983: all six files, every changed line.
ping_claim.goagainst what it guards:keepAliveCandandsweepPingCandregistries,inFlight(summarize_async.go),sweepSlots. Keying is consistent (thread.Key(session, thread)everywhere). Locks never nest.Releaseis idempotent and safe on a plain claim.- Fail-open: every claim choice ends in an ordinary ping or a substitute. The claim is released by a
defer, so a panic frees the thread. A busy thread sends a plain ping. No path loses a ping. - Slot lifecycle: the sweep's collection slot is taken and freed inside
SweepPingSubstituteon every exit; the ask takes its own slot. Confirmed the PR body's claim. - The priority rule against #404 point 10 and the PR body: summary first, one substitute per ping, no fall-through to the sweep. The behavior matches the stated design.
- Stats wiring:
SweepPingCountersreads the new atomics;Keeper.Statsmaps them; JSON tags are additive, no rename, so the/statsappend-only contract holds. - Tests: read all new tests and the shared helpers (
testKeeperinline runner,registerSweep,kaCandidate,waitPings). Traced the scenarios by hand; they test what they claim. - Docs:
docs/design.md,docs/data-dependence.md(sweep and keep-alive rows),docs/components/advanced-offload.mdcounters section. - The PR body, the single commit's DCO sign-off and
Assisted-By:line.
amiddavid
left a comment
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 | 315d9ead01fe |
blocking |
Verdict: blocking
Findings
- docs/components/advanced-offload.md:522 — the two new
/statscounters are not documented- What fails: the PR adds
sweep_summary_took_pingandsweep_summary_in_flightto the keeper'sStats(keeper.go:1576-1580, filled at keeper.go:1638-1639, json tagssweep_summary_took_ping/sweep_summary_in_flight). The component doc lists every other ping-time counter and says each "names a reason the ping stayed plain" (advanced-offload.md:522-552). The two new reasons are absent. An operator who sees these counters in/statshas no doc that explains them. The doc itself makes the case: "counters with no explanation invite an invented reading" (advanced-offload.md:510). - Proof:
grep -rn "sweep_asked\|sweep_model_declined" docs/hits only advanced-offload.md:522-552; neither new name appears anywhere underdocs/. - Fix: add both counters to the "Counted at the ping" list at line 548, one sentence each: took-ping = the summarizer's trigger fired so the summary owned the ping; in-flight = a summary was already running for the thread.
- What fails: the PR adds
Non-blocking
- ping_claim.go:86-88 — the summary "owns" the ping on registration, not on use.
keepAliveCandis re-registered on every turn with commission material (cache_aware_summarizer.go:886-895), even after a checkpoint exists. So when the summary substitute itself declines (checkpoint exists, over budget, phase mismatch, in flight, call failed), the sweep no longer asks and a plain ping goes out. Before this PR the sweep asked in those cases. This matches #404 point 10 as written, and the skip is counted, so I read it as intended. Worth a line in the PR description, because it is a real capability change on summarizer-active threads. - ping_claim.go:153-155 —
sweep_summary_took_pingcounts the skip even when the summary then declined the ping too. The name says "took"; the refusal reason lives only in the keeper'ssummarySubstitute*counters. Consider naming or doc wording that says "owned" rather than "took". - keeper.go:410-414 — the
summarySubstituteNoCandidatecomment is now too broad. A ping where only the sweep registered no longer runs the summary lookup, so that counter does not count it. ThePingNonedoc in ping_claim.go states the new rule correctly; the keeper comment does not. - No counter for a busy thread. A ping that stays plain because an earlier substitute still holds the claim (ping_claim.go:62-65) is counted nowhere. Every other plain-ping reason has a counter.
- ping_claim.go:93 — the in-flight check is one-way. A detached summary started by a real request after
ClaimPing'sinFlight.peekcan still run concurrently with the sweep's ask. The guard narrows the race; it does not remove it. The file comment "never race on one thread" (keeper.go:1245) overstates this. - ping_claim.go:107 —
ColdApplyPhaseis exported ahead of PR C. No non-test caller exists on this head. Fine as scaffolding for the series; remove it if PR C slips. - sweepsubstitute_test.go:445-447 —
sumBis never registered, so thesumB.calls == 0assertion is vacuous. It cannot fail. Register it as thread B's summary model, or drop it. - ping_claim_test.go:125 —
for claimed.Load() < 16 {}spins with no sleep orruntime.Gosched. It terminates (async preemption), but every other wait in these files sleeps. Match the file's idiom.
What I checked
- Read CLAUDE.md, docs/design.md, and the full diff of the one commit (315d9ea) against base 8f06983.
- Traced
fire→fireSubstitute→ClaimPing→fireSummarySubstitute/fireSweepSubstitute(keeper.go:1213-1306, 1774-1786; substitute.go:67-335) and checked every decline path falls back to the ordinary ping. Fail-open holds on all paths I traced, panic paths included (deferredclaim.Release()runs first infireSubstitute; the sweep's own recover inSweepPingSubstituteandfireSweepSubstituteis unchanged). - Checked lock discipline:
pingGuardMu,keepAliveCandMu,sweepPingMuandsummaryFlight.muare taken one at a time, never nested; the claim is a map entry held with no mutex across the substitute call. No deadlock path found. - Verified key agreement:
thread.Key(session, thread)is the key forkeepAliveCand(cache_aware_keepalive.go:177),sweepPingCand(extract_sweep_ping.go:282),inFlight(convKey, state.go:523) and the new guard. Session keys are tenant-scoped (session.Scoped), so no cross-tenant collision in the newpingGuardBusymap. - Verified the claim's value is real: a summary-substitute call can outlive the keeper's idle interval (300 s call vs 280 s idle), so a later ping on the same thread can arrive while a substitute runs; before this PR that ping could start a sweep question concurrent with a summary on one thread. The guard closes exactly that.
- Checked counter wiring end to end:
sweepSummaryTookPing/sweepSummaryInFlight→SweepPingStats(extract_sweep_ping.go:187) → keeperStats()json fields. Field reorder inStatschanges no json names; no golden test parses that order. - Checked the new tests against the mechanics: S1 both directions, the two-thread case, the busy/in-flight/single-holder/race cases in ping_claim_test.go, and the slot-release test. All helpers used exist; imports are present; the wait loops and assertions line up with the code paths they name. Existing tests that register both candidates (TestKeepAliveSummaryTakesThePingBeforeTheSweep) stay valid under the new rule.
- Read issue #404 for point 10's wording and the S1 acceptance test; the implementation matches both, and S1 is covered by tests in both directions.
- Confirmed no data-dependence change: the PR stores nothing new and reads no stored content beyond what the substitutes already read.
- Did not run builds or tests (not approved). Go is not installed on this machine.
…nt 10) A due ping can be replaced by the summary call or the sweep question. ClaimPing is now the single per-thread choice and single-call guard for both. When the summarizer's trigger fired (it registered a candidate), the summary takes the ping and the sweep does not ask. The skip is counted as sweep_summary_took_ping. A summary already running counts as sweep_summary_in_flight. A thread is held until the attempt ends, so 2 calls never run at one ping for one thread. ColdApplyPhase exposes the summary reserve's cold-apply test for the sweep's cold apply. Summary behavior with the sweep off is unchanged. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
315d9ea to
edd46ef
Compare
Round 1: replies to every findingFixed
Not changed
Tests on eval box 1 ( |
amiddavid
left a comment
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 | edd46effc5f3 |
approve |
Verdict: approve
Findings
None. Every round-1 finding is fixed, and the fix commit adds no new defect.
Earlier findings
- Mine, finding 1 (two new counters undocumented): fixed.
docs/components/advanced-offload.md:550-553now documentssweep_summary_owned_ping,sweep_summary_in_flightandsweep_ping_thread_busy, each with one sentence saying what it means. The wording matches what the code counts. - Reviewer 1, finding 1 (no test for the declined-summary path): fixed.
TestWhenTheSummaryDeclinesTheSweepStillDoesNotAskAndAPlainPingGoesOutregisters both candidates, gives the summary model an error, and asserts 1 ordinary ping, 0 sweep asks, 0 sweep substitutions, owned-ping +1. I traced it by hand: the claim picks the summary,commissionSyncreturnsCommitted: falseon the model error,firefalls through to the ordinary ping. The assertions match that path. Helpers and theerrfield onfakeSummaryModelexist;errorsis imported. - Reviewer 1, finding 2 (docs): fixed. Same doc change as my finding 1.
- Reviewer 1, finding 3 (no data-dependence statement): fixed. The PR body now says "Data dependence: none added. The claim reads registry existence (metadata, in memory) and stores nothing." I read the body and confirmed the line, plus a plain statement of the decline behavior change.
- My non-blocking items: all addressed. The counter is renamed
sweep_summary_owned_ping(complete rename, no old name left anywhere in the repo; it had not shipped). ThesummarySubstituteNoCandidatecomment now says the lookup must run for it to count (keeper.go:409-414). The busy thread has its own counter,sweep_ping_thread_busy, wired end to end (ping_claim.go:55,83 → extract_sweep_ping.go:190 → keeper.go:1646) and asserted inTestClaimPingAllowsOneHolderPerThread. The "never race" comments in keeper.go:1246-1248 and ping_claim.go:28-32 now state the check-then-act gap honestly and hand the decision to PR C.sumBis removed — the author's reason is right: registering a summary on thread B would make B a summary thread and remove the sweep ask the test exists to check. The spin loop now callsruntime.Gosched(). ColdApplyPhasestays exported: accepted. The author says PR C is being built now and calls it. That was always its stated purpose.- Reviewer 1's "not changed" items: accepted. The
PingNonerelease window is protected by theaskedflag and the summary's single-flight, as the reply says. The tenant-scoping of session keys is what I verified myself in round 1.
Non-blocking
- ping_claim.go:83 — the busy counter counts only claims that reach
ClaimPing. A ping refused earlier (no spare slot,k.spareinfire) never claims, so it is not in this counter either. That is consistent with the other plain-ping reasons, which also count only inside the substitute decision. No change needed; noting it so the counter's denominator is clear.
What I checked
- Last review: round 1, 315d9ea, 2026-10-25T11:54:39Z.
- New commits read: 2.
c7da7351is the retargeted base — its tree is byte-identical to the old base8f069839(verified:git diff 8f069839 c7da7351 --statis empty), so the retarget introduces no new code.edd46effis the point-10 commit, rewritten with the fixes; I read its full diff against both the new base and my round-1 head (git diff 315d9ead edd46eff, 97 insertions, 37 deletions, 6 files). - 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 1's round-1 review (posted one second before mine, so I read it only now — its findings overlap mine and one adds the missing decline test); the rewritten head commit with the fixes; the author's reply comment of 2026-10-25T12:34:25Z. I checked each reply claim against the code: the doc lines, the rename, the busy counter wiring, the new test's assertions, the
sumBreasoning, theGoschedfix, and the PR body's data-dependence line. All are as stated. - Re-checked the fix diff for new defects: the busy counter sits on the busy exit only; the rename touched every declaration, mapping and test; the new test uses existing helpers and imports; the corrected comments match the code's actual behavior.
- Did not run builds or tests (not approved). Go is not installed on this machine. The author reports
go test ./...41 ok and-raceclean on the two touched packages, plus 9 failing mutations; I could not verify that myself.
amiddavid
left a comment
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 | edd46effc5f3 |
approve |
Verdict: approve
Findings
None. The reworked commit fixes every finding from both reviewers and adds no new defect.
Status of earlier findings
Mine, round 1:
- Missing test for the declined-summary path — fixed.
TestWhenTheSummaryDeclinesTheSweepStillDoesNotAskAndAPlainPingGoesOut(sweepsubstitute_test.go:515) registers both candidates, fails the summary model, and asserts 1 ordinary ping, 0 sweep asks,sweep_summary_owned_ping+1. I traced it: the claim goes toPingSummary,commissionSyncruns the model once, the error declines the commit,firefalls through to the ordinary ping. The assertions match that path. The "sweep asks after the summary declines" mutation would fail it. - Undocumented counters — fixed.
docs/components/advanced-offload.md:550-553now documentssweep_summary_owned_ping,sweep_summary_in_flightandsweep_ping_thread_busy, each with its meaning. - No data-dependence statement — fixed. The PR body now says: "Data dependence: none added. The claim reads registry existence (metadata, in memory) and stores nothing." That matches the code.
Reviewer 2, round 1:
- R2-1 (docs, same as my finding 2) — fixed. Checked myself; see above.
- Non-blocking items — addressed:
sweep_summary_took_pingrenamed tosweep_summary_owned_ping(the name now matches the "owned, not took" semantics); newsweep_ping_thread_busycounter, tested inTestClaimPingAllowsOneHolderPerThread; the "never race on one thread" comment corrected in both files; thesummarySubstituteNoCandidatecomment now states the lookup rule; the vacuoussumBremoved;runtime.Gosched()added to the spin loop. - Declined with a reason, checked by me:
- PingNone release window stays open. I agree. The window is narrow,
askedand the summary's single-flight still prevent two calls of one kind, and the gap is now documented inping_claim.goand the PR body for PR C. - Tenant-less
pingGuardBusykey. The reason is right and my round-1 note was wrong. I verified it myself:apply.sessionIDFrom(apply.go:1367) builds the session id throughsession.Scoped(tenant, ...)(session.go:151), which prefixes the tenant id, and the proxy records threads with that scoped id (proxy/keepalive.go:378). Two tenants cannot share athread.Key. ColdApplyPhasestays exported. Fine. PR C calls it; it is tested here.
- PingNone release window stays open. I agree. The window is narrow,
Non-blocking
sweep_ping_thread_busycounts every busy claim, including one held by a summary substitute on a thread with no sweep candidate. The name sits in the sweep's counter block. The doc wording ("an earlier substitute still held the thread") is accurate, so this is a naming choice, not a defect.
What I checked
- Last review: round 1, 315d9ea, 2026-10-25T11:54:38Z
- New commits read: 2 in
315d9ead..HEAD.c7da7351is the new base (#508 squashed into main; outside this PR's diff, reviewed in its own PR).edd46effis the reworked PR commit; I read its full diff against the base (git diff c7da7351..HEAD, 7 files) and diffed it file by file against the round-1 head. The changes are exactly the ones the author listed: the rename, the busy counter, the corrected comments, the new decline test, thesumBremoval,runtime.Gosched(), and the doc paragraph. No hidden 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, and what I did:
- Reviewer 2's round-1 review (posted 1 s after mine, so unread then). Read now; its one finding matched my finding 2, its non-blocking list matched mine plus the rename, the busy counter and
sumB. Each checked above. - The author's reply comment (2026-10-25T12:34:25Z). Every "Fixed" claim verified in the diff; every "Not changed" reason checked and accepted.
- The updated PR body. Data-dependence line, the "What changes" capability statement, and the PR C gap note are all present and match the code.
- Reviewer 2's round-1 review (posted 1 s after mine, so unread then). Read now; its one finding matched my finding 2, its non-blocking list matched mine plus the rename, the busy counter and
- Re-checks on the reworked code: the busy counter is added after
pingGuardMuunlocks; no oldsweep_summary_took_pingname remains anywhere (grepover Go and docs); the new test's helpers and imports exist; fail-open paths unchanged from round 1 and still sound (claim released bydefer, every decline ends in an ordinary ping). - Did not run builds or tests (not approved). Go is not installed on this machine.
Summary
What changed
offload.ClaimPing(threadKey)incomponents/offload/ping_claim.go. It returnssummary,sweep,noneorplain, and it holds the thread untilRelease().sweep_summary_owned_ping+1. This also counts pings where the summary then declined.sweep_summary_in_flight+1.sweep_ping_thread_busy+1.fire()callsfireSubstitute, which callsClaimPingonce, runs what the claim names, and frees the claim with adefer. A panic frees the thread too.offload.ColdApplyPhase(phase)is the summary reserve's own graduation test (cacheAwareApplyPhase): cold or unknown. This PR builds no sweep apply.sweep_summary_owned_ping,sweep_summary_in_flightandsweep_ping_thread_busyin/stats, and in the "Counted at the ping" paragraph ofdocs/components/advanced-offload.md.no_candidatecounters now count only the lookups that run. A ping whose claim goes to the sweep alone does not look the summary up, sosummarySubstituteNoCandidatedoes not rise.How it was tested
Eval box 1,
-count=1.gofmtandgo vet ./...clean.go test ./...: 41 packages ok, 0 failed.-racepasses onkeepaliveandcomponents/offload.TestWhenTheSummarizerTriggerFiresTheSummaryTakesThePingAndTheSweepDoesNotAsk(keepalive)TestWhenTheSummarizerTriggerDoesNotFireTheSweepAsks(keepalive)TestWhenTheSummaryDeclinesTheSweepStillDoesNotAskAndAPlainPingGoesOut(keepalive): 1 ordinary ping, 0 sweep asks, owned-ping +1TestOnePingNeverRunsBothCallsWithTwoThreadsDue(keepalive)TestAClaimedPingFreesTheThreadAndTheSlotOnEveryExit(keepalive)TestClaimPingChoosesPerThread(offload)TestClaimPingAllowsOneHolderPerThread,TestClaimPingRaceHasOneWinner(16 goroutines)TestClaimPingGivesTheSweepNothingWhileASummaryRunsTestColdApplyPhaseIsTheSummaryReservesRuleTestKeepAliveSummaryTakesThePingBeforeTheSweepMutation checks (each made a test fail, then restored):
Releasedoes not free the threadOpen questions
None.
Technical notes
trigger.Firespassed on the thread's last request. Nothing changes between that request and the ping, so a registered candidate already means "the trigger fired".deferinfireSubstitute. The sweep's collection slot is freed by adeferinSweepPingSubstitute. A ping holds neither after the call.askedflag still stop two of the same kind. PR C decides whether to take the summary's flight inClaimPing.Part of #404.