Repository navigation
fix(apply): count a free 1-hour ping in the cold check, from one cache-lifetime source - #1357
Conversation
f3c88a9 to
00a06fb
Compare
f26b9d7 to
6b395fa
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.331 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 6b395fa10603 |
approve |
Verdict: approve
Findings
None. The change is correct on every path I traced. Details below.
Non-blocking
- apply/apply.go:1365 —
RecordCacheTouchstill derives the alias inline, and now has no non-test caller.TouchAliasFor(added by this PR) holds the same derivation. The PR's own comment onTouchAliasForsays the two "cannot drift", but two copies of one derivation is how they drift.RecordCacheTouchcould beRecordCacheTouchAliasTier(st, TouchAliasFor(tenant, body, provider), nowMs, false)with no behavior change (TouchAliasForreturns "" exactly where the old guards returned). - apply/apply.go:1410 —
EndTouchTiercan move the clock backwards in a narrow race. It does Get, checkms == atMs, then Put, with no store-level atomicity. If a newer touch lands between the Get and the Put, the Put overwrites it with the older plainatMs. Result: a staleprevAt, so a later cold check can read cold on a warm entry. The window needs a route switch-off concurrent with a touch on the same alias, so it is very narrow. NoteRecordCacheTouchAliasTier's monotone check has the same check-then-act shape (pre-existing), so this is the same accepted class. - dash/cachestate.go:298 — stale comment.
threadTTLs's doc says a thread with no write "is absent (ThreadsFor then uses 300)". ThreadsFor now usesbilledTTL(provider, model, 0), which is 1800 on OpenAI GPT-5.6+. The code is right; the comment is old. - keepalive/manual.go:149 — a failed press leaves the two indexes of the 1-hour tier disagreeing. The press deletes the keeper's
oneHourTouchesentry before it dispatches. On a 429, 5xx, 4xx or no-usage answer it returns beforejob.touch, so the storedcg:seen:mirror keeps its:1h. The store is in fact right (a failed press touched nothing), and the disagreement only ends one hour early what the dashboard shows. Safe direction. The PR's technical notes name the same window for a route switch-off but not for this path.
What I checked
- The cold check (apply/apply.go:673-706).
aliasSeenTierreads the tier before the plain write, so the request's own write cannot hide it.lastTouchOneHourcounts the tier only when the alias clock is the latest clock; I traced the bypass path (noaliasSeenTiercall) and the sub-agent path (its own alias), and thealiasAt >= prevAtguard covers both.EntryLifetimetakesmax(Floor, table), andsessionTTLstill persists the request's own ask before the check, so the new verdict is never colder than the old one. - The store format.
parseSeenfails open: an older binary reads<ms>:1has 0, which is never cold, then writes a plain value. I grepped every reader ofcg:seen:; onlyapply(and tests) parse values. The data-dependence claim holds: same key, metadata only. - The keeper.
firesetssentOneHourfrom the body it really sends, before dispatch, and passes the samejcopy torecord1.judgeOneHourandrecord1'sj.touchuse the samestart, soEndTouchTier'sms == atMsmatch holds. On a 2xx free switch,noteOutcomenever returnsoutcomeFailed, so the two writes cannot diverge.oneHourSwitchOffends the stored tier outside the lock.PingNowsetssentOneHourbefore dispatch.recordSubstitutePingreads the entry's tier under the lock.Record'snoteTouchLockedttl for OpenAI GPT-5.6 changes 5m to 30m, but that ttl only feeds the D decision, and D never fires on OpenAI (no 1-hour probes there), so no user-visible change. - The one decision.
CacheLifetime's Exact branch,accrec.EntryFacts,BilledLifetimeMsand the dashbilledTTL/touchTTLSecondsall reduce toEntryLifetimewith the same facts as before. An emptyproviderfrom old rows behaves exactly as the old constants (300/3600), so no dash regression. - The proxy.
attributionTTLMswidens to 1 hour only from the billed tier or a live free ping (OneHourTouchLive, which also checks the route).arriveAtruns at arrival, beforeRecordclears the touch, so the ordering is right. - The tests. I checked each new test's arithmetic against
cacheIsCold(1-minute margin) and the fixtures (kaBody,onWaitPolicy,oneHourKeyOf,proveRoute,testKeeper's inline runner). The expectations match the code's behavior, and the tests fail on the old code by construction (they assert warm where the old 5-minute lifetime said cold). - The rules. The behavior changes are named at the top of the PR with the owner's approval date and a turn-off. Library logic stays in
apply; the proxy only passes facts. No binaries, no LFS. Live tests were not run (not approved); the PR reportsgo test -racegreen on macOS, Go 1.27.4.
6b395fa to
2920199
Compare
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddaid's session | fresh | 2 of 2 | 1 of 2 | 6b395fa10603 |
blocking |
Verdict: blocking
Findings
-
keepalive/keeper.go:870 — a failed real request ends only one of the two tier indexes, and the cold check then reads a warm 1-hour entry as cold
- What fails: a free 1-hour ping at T leaves the entry warm until T+60m. A real request at T+6m gets a 429 or a 5xx.
apply.BodyOptsalready wrote the plain clock at T+6m (aliasSeenTier, apply/apply.go:673), so the stored:1htier ends there. ButRecordreturns at the status gate (keeper.go:870) beforeresolveOneHourProbe(keeper.go:876) deletes the keeper's touch. The next request at T+13m readsprevAt = T+6m, tier gone, lifetime 5m:cacheIsColdsays cold (7m ≥ 5m + 1m margin). A cold-only cut then rewrites a prefix that is warm for another 47 minutes. This is the exact outcome #1350 fixes, and it breaks the PR's own invariant "a real request ends both" (PR body, Technical notes). - Proof: trace.
aliasSeenTierruns inBodyOptsbefore the forward, whatever the upstream status will be.Record's gateif status < 200 || status >= 300 { return }sits beforeresolveOneHourProbe, which is the onlyRecordpath that deletesoneHourTouches. The proxy records every response with its status (recordTouch, proxy/keepalive.go:426-438), so the path is reachable. The two indexes disagree from the failed request until the next accepted one. - Fix: on a non-2xx
Recordfor a thread whoseoneHourTouchLiveLockedholds, re-assert the stored tier at the failed request's time (RecordCacheTouchAliasTier(st, alias, nowMs, true)). This overshoots warmth by the ping-to-failure gap, bounded and in the safe direction. The plain-clock overwrite inaliasSeenTiercannot be undone, so the keeper must write the correction.
- What fails: a free 1-hour ping at T leaves the entry warm until T+60m. A real request at T+6m gets a 429 or a 5xx.
-
keepalive/substitute.go:275 — a substitute touch records the 1-hour tier for a body whose markers are 5-minute
- What fails: on a proven route,
e.ttl1his set by a free 1-hour ping (onehour.go:191). The client's own markers stay plain. The substitute's body is the forwarded body, so it carries plain markers. Per this repo's own model, a plain-marker read moves a 1-hour entry back to 5 minutes —PingNowstates it in manual.go:144-147, and the cold check's tier model in this PR is built on it. ButrecordSubstitutePingpassesoneHour = e.ttl1h || e.pol.HeadTTL1htoj.touch, so the stored clock says:1h. For up to 55 minutes the cold check reads an entry as warm after it died at 5 minutes. - Proof: substitute.go:272-277.
e.ttl1his assigned only at onehour.go:191 (the A path, ping relabelled, client markers untouched). TheHeadTTL1hhalf of the expression is correct: those policies relabel the real requests (apply.go:433), so the substitute body carries 1-hour markers. - Fix: pass the tier the body's own markers state, not the entry's:
oneHour := apply.AllBreakpointsAskExtendedTTL(<substitute body>), asfireandPingNownow do. The error direction is safe (missed savings, no rewrite), so this can also ride a follow-up if the owner prefers.
- What fails: on a proven route,
Non-blocking
- apply/apply.go:702 parses
gjson.GetBytes(body, "model")a second time in the cold block; line 621 already parsed it. Harmless, but the block's own comment argues for one read of one fact. oneHourTouchesis reset wholesale atMaxTurnKeys(onehour.go:185-187). Those threads' stored:1hmirrors then never getEndTouchTieron a route switch-off. The cold check reads warm for up to an hour on a route that downgraded. Safe direction (no cut, no rewrite); the PR body names a neighbouring window.EndTouchTiermatches onms == atMs. A mirror overwritten by a later touch is correctly left alone; verified the write paths (record1,PingNow) use the samestartthe map stores.
What I checked
- The full diff (23 files) and the code around each change:
apply's cold-check block, thecg:seen:read/write paths (aliasSeenTier,parseSeen,RecordCacheTouchAliasTier,EndTouchTier,TouchAliasFor), the keeper's touch paths (Record,fire,record1,PingNow,recordSubstitutePing), the 1-hour route state machine (judgeOneHour,oneHourSwitchOff,resolveOneHourProbe,live), and the dash SQL (r.providercolumn, column/scan order incacheThreadsQuery,billedTTL,applyOneHour). - The alias derivations agree:
TouchAliasFormatchesRecordCacheTouch(bare content hash), and the host-passedTouchAliaswins where tool deferral would shift it (#902). - The downgrade story: an old binary parses
<ms>:1has 0 and fails open; a plain value stays a plain integer. Disk-store key classification is by prefix only, so the value change is transparent. - The one-decision claim: no remaining cache-lifetime literal in the changed packages; the
time.Hour/5 * time.Minutehits left are hold limits, windows and retention, not cache lifetimes. - Rules: the behavior change is named at the top of the PR with the owner's approval (2026-11-24); data dependence is stated (metadata only, same key list, no row change) and matches the code — the tier flag rides the existing
cg:seen:record. - Tests: the new tests exist and drive the real keeper plus real apply; helpers (
testKeeper,proveRoute,touchOf,coldSpy) resolve. I did not run them (live tests not approved). - I did not read the other reviewer's folder or any PR review comment before posting this.
|
Reply to blocking finding 1 (failed real request). Fixed in 9cfdd1b. The finding was right.
|
|
Reply to blocking finding 2 (substitute tier). Fixed in 9cfdd1b. The finding was right.
|
|
Reply to the note on |
|
Reply to the note on the stale comment (dash/cachestate.go:298). Fixed in 9cfdd1b. The comment now says a thread with no write takes the base lifetime of its provider and model (300, or 1800 on OpenAI GPT-5.6+). |
|
Reply to the note on the second |
|
Reply to the note on a failed manual press (manual.go:149). Not changed. The two records already agree on this path.
|
|
Reply to the note on the wholesale reset (onehour.go:185). Fixed in 9cfdd1b. Before the map starts over at |
|
Reply to the note on the
|
9cfdd1b to
7fc2fa0
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.331 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 7fc2fa0eddf9 |
approve |
Verdict: approve
Findings
None. Both blocking findings are fixed correctly, and the fixes introduce no new defect. Details below.
Earlier findings
- Reviewer 2, finding 1 (a failed real request ended only one tier index) — fixed, verified. A real request now writes
<ms>^<pingMs>(aliasSeenState), so the ping's hour survives the plain-clock write.ConfirmRealTouchstrips the carry, and the keeper calls it on the line afterresolveOneHourProbe— the same 2xxRecordthat deletes the keeper's own touch. I traced every path: 429, 5xx and 4xx return at the status gate (keeper.go:870) before both ends, so both records stay; a timeout, a cancel or a missingRecordnever reaches the line, so both stay; a 2xx without usage reaches it, and a cache-aware 2xx touched the entry, so ending both is right. The cold check gates the carry onnow - ping < EntryLifetime(1h), so the verdict is warm exactly while the ping's hour runs, then falls back to 5 minutes from the last request's clock. Never false cold. - Reviewer 2, finding 2 (a substitute touch claimed the entry's tier) — fixed, verified. The touch and the D-touch lifetime now take
apply.AllBreakpointsAskExtendedTTL(j.raw), the markers of the body the question was built from, asfireandPingNowdo.EndTouchTieralso ends a carried ping (carriedAt == atMs), and the wholesale map reset now ends every dropped mirror. All three of reviewer 2's non-blocking notes are fixed too (the singlemodelparse, the reset, theEndTouchTiermatch). - My note on
RecordCacheTouch's duplicate derivation — fixed. It now delegates toRecordCacheTouchTier, which usesTouchAliasFor. One derivation remains. - My note on the stale dash comment — fixed. The comment now names the provider-and-model base lifetime.
- My note on the
EndTouchTierrace — rejected by the author, and the reason is right. A fix needs a compare-and-set in the store; the read-check-write shape is the same pre-existing class as the monotone write. Accepted. - My note on a failed manual press — rejected by the author, and the reason checks out.
PingNowrefuses withErrAtOneHourwhile the touch is live (manual.go:110), so the later delete only removes a touch that is an hour old (the stored mirror expires by the sameEntryLifetimegate, and the carry branch uses the same gate) or one on a route switched off (EndTouchTieralready ended the mirror). No live disagreement remains. Accepted.
Non-blocking
- apply/apply.go:706 — the carry branch ignores the
prevAtguard thatlastTouchOneHourhas. A bypassed request advances the tracker clock (TurnAt) but writes no alias clock, so the store can still hold the ping's:1hwhileprevAtis later. The next request then carries the ping and reads warm for the full hour, although the bypassed request moved the entry back to 5 minutes. False warm only, bounded by the hour, and it needs a bypass between a 1-hour ping and the return. The repo's own rule accepts erring toward warm. Aseen.at >= prevAtstyle guard on the carry would close it. - No direct test for
EndTouchTieron a carried record. The route-switch-off and reset tests end plain:1hrecords; the<ms>^<pingMs>shape is covered only by the parse tests. The code path is symmetric and short.
What I checked
- Last review: round 1, 6b395fa, 2026-11-24T14:21:34Z
- New commits read: 2 — f3ac2a9 "fix(apply): carry the 1-hour ping under an unconfirmed real request; substitute tier from the body's marks", 7fc2fa0 "test(apply): the carried clock value also fails open for an older reader". The branch was also rebased onto f4ee9f8: I diffed the round-1 patch against the current
f4ee9f87..HEADpatch; the same 23 files, and every difference is the two new commits' content. The rebase changed nothing else. - Read in full: 2 reviews, 7 comments, 0 inline comments (from the three files in my folder).
- New items since my last review: reviewer 2's round-1 review (2 blocking, 3 non-blocking — all traced above); the author's 7 replies (2 fix reports for the blocking findings, 3 fix reports for notes, 2 rejections with reasons — both reasons checked against the code and accepted); the 2 new commits.
- The carry mechanism. All three value shapes and every writer:
aliasSeenState(chains the original ping time across unconfirmed requests),RecordCacheTouchAliasTier(a newer ping drops the carry; an older one leaves it),ConfirmRealTouch(strips, keeps the time, no-op without a carry),EndTouchTier(ends:1hand carried records at the ping's time, which is what the keeper's map holds). Downgrade fail-open holds for the new shape:ParseInt("3000^2000")fails and reads 0, never cold (the new test asserts it). Unreadable values read as the zero state. - Races around the carry. A confirm that strips a carry another in-flight request just re-asserted is correct (the accepted request owns the entry's tier). A ping landing between the carry write and the confirm overwrites the record and the confirm then no-ops on the
:1h. Both directions stay consistent or err warm. - The tests.
TestAFailedRealRequestKeepsTheOneHourPingfails on the pre-carry code by arithmetic (7 minutes against a 5-minute lifetime plus margin); the accepted-request and apply-level carry tests assert the exact stored shapes; the substitute test drives the realrecordSubstitutePingwithe.ttl1hforced true and plain markers, which is the case the old rule got wrong.runTouchesconfirms every request, so the round-1 expectations keep their meaning. - The rebase base. f4ee9f8 brings main's #1356 (
headTTL1hinapply.go) and #1342 into the history; the PR's own diff against the new base is the reviewed change plus the two new commits, so no interaction was introduced inside this PR's files beyond the context shift. - Live tests were not run (not approved). The author reports the new tests fail on the old code by mutation checks.
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 7fc2fa0eddf9 |
blocking |
Verdict: blocking
Findings
- keepalive/onehour.go:186 — the wholesale map reset now ends the stored mirrors of live touches, which puts the cold check back on the expensive side of #1350
- What fails: the reset at
MaxTurnKeys(20000) is a capacity event, not a fact about the entry. A dropped thread's free ping may be minutes old on a proven, healthy route — its entry is warm for the hour. The new code callsEndTouchTieron every dropped touch (onehour.go:204-206), which rewrites the mirror as a plain value at the ping's time. That thread's next request, 6 to 59 minutes after its ping, readsprevAt= ping time, lifetime 5 minutes: cold. A cold-only cut then rewrites a warm 1-hour prefix — the exact outcome this PR exists to prevent, now triggered by the keeper's own bookkeeping. - Proof: entries leave
oneHourTouchesonly at a real request (onehour.go:266) or a manual press (manual.go:149). Threads that never return stay in the map, so a deployment using 1-hour-on-wait grows the map to 20000 and fires the reset. At that moment every touch still inside its hour — including fresh ones on proven routes — has its stored tier stripped. Before commit f3ac2a9 the mirrors survived the reset and the cold check stayed correct; only the dashboard and the press refusal lost the fact, which is the safe direction. The route switch-off (oneHourSwitchOff) is different: there the fact itself changes (the tier was never granted), so ending the mirror is right. The capacity reset changes no fact. - Fix: do not end the mirrors at the reset. Leave the stored
:1hvalues to expire byEntryLifetime, as round 1 did, and accept that the keeper-side index (dashboard, press refusal) loses them — that disagreement is display-only. If the map must not hold dead entries, evict by liveness (t.live(now)) instead of a wholesale reset.
- What fails: the reset at
Non-blocking
- apply/apply.go:705 — the carry gate drops the cold margin at the hour boundary. The gate is
now - carriedAt < EntryLifetime(...)with nocoldMargin, while the verdict path (cacheIsCold) adds 1 minute. A request 60 to 61 minutes after the ping reads cold, where the margined rule would wait to 61. One minute, at the boundary only, and in the safe direction (the entry is dead by then). The:1hpath keeps the margin; only the carry path loses it. - apply/apply.go (ConfirmRealTouch) — an accepted bypassed request does not end a
:1hmirror. A bypassed request writes no clock (the cold block is inside!bypass), so the record stays<pingAt>:1h;ConfirmRealTouchstrips only the^carry. The keeper's touch ends atRecord, the stored hour runs on. Warmth overstated, never a cut. Narrow: bypass plus a 1-hour ping. Same shape as round 1.
What I checked
- Last review: round 1, 6b395fa, 2026-11-24T14:24:22Z.
- New commits read: 2 — f3ac2a9 "fix(apply): carry the 1-hour ping under an unconfirmed real request; substitute tier from the body's marks", 7fc2fa0 "test(apply): the carried clock value also fails open for an older reader". The PR was also rebased onto f4ee9f8; I diffed my reviewed head against the rebased ae6d155 and confirmed the PR's own files are identical — every other difference (apply.go
headTTL1h, campaign, pi-package) came from main. - Read in full: 2 reviews, 7 comments, 0 inline comments (from the three files).
- New items since my last review: the author's 7 reply comments (all at 2026-11-24T14:59) and the 2 commits. I checked each reply against the code, as below.
Round-1 findings, mine:
- Finding 1 (failed real request splits the two tier indexes): fixed, and the fix is sound. A real request now writes
<ms>^<pingMs>(aliasSeenState), carrying the ping that stood before it;ConfirmRealTouchends the carry inRecord, after the status gate, on the same line that ends the keeper's touch. I traced every failure path: 429/5xx/4xx stop at the status gate (both records stay), a timeout or cancel never reachesRecord(both stay), a 2xx with no usage reaches the confirm (right: an accepted request touched the entry). Chained unconfirmed requests keep the original ping time. The cold check bounds the carry by the ping's time and the verdict by the request's, so warmth never runs past the ping's hour plus the failed request's overshoot — the safe direction.EndTouchTierhandles both the:1hand the^shapes. The tests (TestAFailedRealRequestKeepsTheOneHourPing,TestAnAcceptedRealRequestEndsBothRecordsOfTheTier,TestARealRequestCarriesTheOneHourPingUntilConfirmed) cover each path. The^shape fails open for an older binary (verifiedParseInterrors, and the new test asserts it). - Finding 2 (substitute tier from the entry, not the body): fixed. The touch and the D-touch now take
apply.AllBreakpointsAskExtendedTTL(j.raw)— the markers of the body the question was built from, the same rule asfireandPingNow.TestASubstituteTouchTakesItsTierFromTheBodysMarkerscovers plain and 1-hour markers withe.ttl1hset.
Round-1 notes, mine and reviewer 1's:
- Second
modelparse: fixed (read once at apply.go:621, reused inCacheFacts). - Stale dash comment (reviewer 1): fixed.
RecordCacheTouchduplicate derivation (reviewer 1): fixed — it now delegates toRecordCacheTouchTier, one derivation.- Failed manual press (reviewer 1): the author rejected it with a reason; I checked the reason and accept it.
PingNowrefuses whileoneHourTouchLiveLockedholds (ErrAtOneHour, manual.go:110-113), so the delete at manual.go:149 only removes a touch that is an hour old (its mirror expires by the sameEntryLifetime, one minute of margin at most) or on a route switched off (whose mirroroneHourSwitchOffalready ended). EndTouchTiercheck-then-act race (reviewer 1): the author accepted it and named it in the PR body's Technical notes. Same class as the pre-existing monotone write inRecordCacheTouchAliasTier. Agree: a compare-and-set in the store is a larger change than this fix.- Wholesale reset (mine, non-blocking, "safe direction"): the author fixed it by ending the mirrors — this is the new finding 1 above. The fix chose sync over correctness; sync is right for a route switch-off (the fact changed) and wrong for a capacity reset (the fact stands).
New commits, reviewed as a first review:
- The carry's store format: three shapes (
<ms>,<ms>:1h,<ms>^<pingMs>), one writer per shape,parseSeenStatereads all three and returns the zero state (never cold) on anything unreadable. A value with both separators cannot be written; parsing it anyway is harmless. RecordCacheTouchAliasTier's monotone check reads a carry'sat(the request time), so an older ping cannot move the clock back. A plain 5-minute ping after a carry writes plain and drops the carry — the #1258 rule, test-covered.- The substitute test's fixture (a hand-built
pingJobon a live entry) matchesrecordSubstitutePing's field use; the imports resolve. - The PR body now documents the carry, the confirm and the failure paths, and keeps the data-dependence claim true: the
^suffix is a second timestamp in the existingcg:seen:record, metadata only, same key list. - The behavior change stays inside the one the owner approved on 2026-11-24 (the cold check counts the ping's hour); the carry only removes a case where it did not.
- I did not run the tests (live tests not approved).
|
Reply to round-2 blocking finding (capacity reset ends live mirrors). Fixed. The finding was right.
|
7fc2fa0 to
593ce07
Compare
|
Reply to the note on the carry margin (apply.go:705). Fixed. The carry gate now adds |
|
Reply to the note on the carry |
|
Reply to the note on a test for |
|
Reply to the note on a bypassed request and |
593ce07 to
94e757b
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.331 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 3 of 3 | 593ce079695e |
blocking |
Verdict: blocking
Findings
- apply/apply.go:1353 —
ConfirmRealTouchnow strips a 1-hour tier a LATER ping wrote, and the cold check then reads a warm 1-hour entry as cold for up to 54 minutes- What fails: one content alias shared by two thread keys — the documented header/headerless split (apply.go's own clock note: "the same conversation reaches us under two ids"; the keeper's inflight count is per thread, keeper.go:522-524, and "another thread's open request never pauses it", keeper.go:1510). Thread K1 ends a wait turn; the keeper plans its free 1-hour ping. The user returns with a headerless turn: apply runs under K2 at tB and writes the shared alias clock. The sweep then pings K1 (K2's open request does not stop it), the ping relabels to 1 hour, reads the prefix, and
record1'sj.touchwritestP:1hon the shared alias with tP > tB (the monotone write passes). K2's response arrives:Recorddeletes the touch under K2's key only (K1's stays), then callsConfirmRealTouch(keeper.go:886), which readstP:1h, seesv.oneHour, and rewrites it plaintP. The entry is at the 1-hour tier from tP — the ping is the last touch — but the record now says 5 minutes. Every request from tP+6m to tP+60m readsColdCachetrue on a warm entry, and a cold-only cut rewrites the prefix. That is the exact #1350 outcome, introduced by this commit: before it, the confirm ignored:1hrecords, so this path read warm, which is correct. - Proof: trace.
ConfirmRealTouchcannot tell a:1hthe confirmed request's own apply would have replaced (the bypassed case it was widened for, where the tier's time is BEFORE the request) from a:1ha ping wrote AFTER the request's apply (its time is later). The keeper's own claim in the reply — "a ping that finishes during the request is also ended by the keeper's own touch deletion" — holds only for the SAME thread: a ping cannot dispatch while its own thread's request is in flight (keeper.go:1510), and a ping dispatched before the request has a touch time before the request's apply, so the request'saliasSeenStateconverts it to a carry, which the confirm rightly strips. The cross-thread shape has no such protection. The new test (TestConfirmRealTouchEndsAnUnreplacedOneHourTier) has no concurrent ping, so it does not cover this. - Fix: pass the confirmed request's start to the confirm and strip a
:1honly when its time is at or before that start:ConfirmRealTouch(st, alias, startedAtMs)withv.oneHour && v.at <= startedAtMs. A tier older than the request is the bypassed case; a tier newer than the request is a later touch and must stand. Carries strip unconditionally (they are by construction at or before the carrying request).Recordalready holdsr.StartedAt.
- What fails: one content alias shared by two thread keys — the documented header/headerless split (apply.go's own clock note: "the same conversation reaches us under two ids"; the keeper's inflight count is per thread, keeper.go:522-524, and "another thread's open request never pauses it", keeper.go:1510). Thread K1 ends a wait turn; the keeper plans its free 1-hour ping. The user returns with a headerless turn: apply runs under K2 at tB and writes the shared alias clock. The sweep then pings K1 (K2's open request does not stop it), the ping relabels to 1 hour, reads the prefix, and
Non-blocking
- keepalive/onehour.go:206 — the all-live reset still drops live touches from the keeper's index. When all 20000 touches are live, the map starts over and the dashboard and the press refusal lose facts whose stored mirrors stay warm. Display only, as the comment says. Accepted shape.
- The eviction scan holds
k.muover up to 20000 entries, but only at capacity, the same cost class as the wholesale reset it replaces.
Earlier findings
- Reviewer 2, round-2 blocking (the capacity reset ended live mirrors) — fixed, verified.
makeRoomForTouchLockedevicts only touches that are not live, and no stored mirror ends at a capacity event anymore: the mirrors expire byEntryLifetime, which is the same clock the cold check gates on, so an evicted dead touch's mirror is dead too.EndTouchTiernow runs only fromoneHourSwitchOff, where the fact itself changes. The map stays bounded (evict-then-reset, then the insert). The test drives both halves with the real keeper and apply. - My round-2 note on the carry
prevAtguard — fixed. The carry now counts only when the alias clock is the latest clock (seen.at >= prevAt), the same guard as the:1hpath. A bypassed request ends the carry. - My round-2 note on the carry margin — fixed. The carry gate adds
coldMargin, so it ends where the verdict's margined rule ends. - My round-2 note on a test for
EndTouchTieron a carried record — fixed.TestEndTouchTierEndsACarriedPingToocovers the<ms>^<pingMs>shape. - Reviewer 2's round-2 note on a bypassed request and
ConfirmRealTouch— the widening fixes it, but it introduces finding 1 above. The safe-direction note was traded for an expensive-direction race; a time-bounded strip fixes both.
What I checked
- Last review: round 2, 7fc2fa0, 2026-11-24T15:35:11Z
- New commits read: 1 — 593ce07 "fix(keepalive): the capacity bound keeps the stored tier of a live touch; carry guard and margin". The branch was also rebased onto 49f3531: I diffed the round-2 patch against the current
49f35315..HEADpatch; the same 23 files, and every difference is this commit's content. The rebase changed nothing else. - Read in full: 4 reviews, 12 comments, 0 inline comments (from the three files in my folder).
- New items since my last review: reviewer 2's round-2 review (1 blocking, 2 non-blocking — the blocking one fixed and verified, both notes addressed, one via the change that is finding 1); the author's 5 replies at 16:12-16:13 (4 fix reports, each checked against the code; the capacity and margin and guard and EndTouchTier reports all hold); the 1 new commit; the rebase.
- The capacity fix.
makeRoomForTouchLocked: delete-during-range is safe in Go; the bound holds after evict-or-reset plus the insert;liveuses the sameEntryLifetimethe cold check gates on, so an evicted touch's mirror cannot still widen anything; the keeper's index loss is display and press-refusal only. - The carry guard and margin. Both traced against
cacheIsColdandlastTouchOneHour: the guard usesprevAtbefore the alias merge, matching the:1hpath; the margin makes the carry end at 61 minutes like the verdict. The new test's three cases (30 s past the hour warm, 70 s past cold, bypass at 8 minutes then cold at 16) match the arithmetic. - The confirm widening. I traced the same-thread ping-overlap shape (safe: the inflight guard and the carry conversion cover it) and the cross-thread shape (finding 1). I also checked that the strip of a carry is always right: a carry's ping time is by construction at or before the request that carries it.
- Reviewer 2's round-2 reasoning on the capacity reset (a capacity event is not a fact about an entry) — I checked it and agree; the fix follows it.
- Live tests were not run (not approved). The author reports mutation checks for each fix.
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 3 | 593ce079695e |
blocking |
Verdict: blocking
Findings
- apply/apply.go:1353 —
ConfirmRealTouchnow ends a 1-hour tier that a LATER touch wrote, so one thread's accepted request can strip another thread's live ping- What fails: threads A and B share one content-derived alias (a fork, a side request with the same head). A's request is forwarded at T_A and streams for minutes. B sits in a long wait; its free 1-hour ping starts at T_B > T_A and its touch writes
<T_B>:1h(the monotone check accepts it: T_B > T_A). A's response arrives at T_R;RecordcallsConfirmRealTouch, which reads the:1hand writes plain<T_B>. But B's ping was the LAST touch — the entry is at 1 hour until T_B+60m. The cold check now reads 5 minutes from T_B. B's next request, 6 to 59 minutes after its ping, reads cold, and a cold-only cut rewrites a warm 1-hour prefix — the exact outcome #1350 exists to prevent. Round 2's confirm (carry-only) was correct here: it no-oped on:1h. Commit 593ce07 added|| v.oneHour, which trades a safe-direction miss (a bypassed request leaving:1hto run its hour) for this expensive-direction hit. - Proof: trace.
ConfirmRealTouch(apply.go:1345-1357) strips whatever tier record stands, with no comparison against the confirmed request's own time. The author's reply says "a ping that finishes during the request is also ended by the keeper's own touch deletion" —resolveOneHourProbedeletesoneHourTouches[key]for the recording thread's key only (onehour.go:266), so it covers a same-thread ping, which cannot occur anyway (a thread's wait starts at its ownRecord, andRecordCacheTouchAliasTier's monotone check refuses a ping that started before the request's apply write). The cross-thread ping is the case that occurs, and nothing covers it. The keeper's map still holds B's touch while the store says plain — the "one fact, two indexes, ended at one event" invariant breaks. The carry branch shares the shape on round-2 code: a carry written by a later request's apply, stripped by an earlier request's confirm, wrong when the ping touched after the confirming request started. - Fix: give
ConfirmRealTouchthe confirmed request's start time (Recordhasr.StartedAt) and strip only records whose own touch is not later than it: a:1hwhoseatexceeds the request's start belongs to a later touch and must stand; same for a carry whoseatexceeds it. The bypass case keeps working — a bypassed request writes no clock, so any standing:1hpredates or outlives it, and a:1hwritten after a bypassed request started is exactly the later-touch case that must stand.
- What fails: threads A and B share one content-derived alias (a fork, a side request with the same head). A's request is forwarded at T_A and streams for minutes. B sits in a long wait; its free 1-hour ping starts at T_B > T_A and its touch writes
Non-blocking
- keepalive/onehour.go:210 — the all-live restart can orphan a mirror for a later route switch-off. A touch dropped by the wholesale restart is no longer in the map, so a later
oneHourSwitchOffcannot end its stored:1h. The mirror then reads warm on a downgraded route until the hour passes — missed savings only. This is the accepted trade-off of the round-2 fix (leave the mirrors alone at a capacity event), and the safe direction. - apply/apply.go:1354 — the bypass strip anchors the clock at the ping's time, not the bypassed request's. After
ConfirmRealTouchends an unreplaced:1h, the plain value keeps the ping's timestamp, so the 5-minute clock can read cold up to (request time − ping time) before the entry really dies. Bounded by the bypass-ping gap, needs the bypass-plus-1-hour-ping combination, and the margin absorbs a minute of it.
What I checked
- Last review: round 2, 7fc2fa0, 2026-11-24T15:36:02Z.
- New commits read: 1 — 593ce07 "fix(keepalive): the capacity bound keeps the stored tier of a live touch; carry guard and margin". The PR was also rebased onto 49f3531: I diffed 7fc2fa0 against the rebased af38a6b and confirmed the PR's own files are identical — every difference (CI workflows, pi-package) came from main.
- Read in full: 3 reviews, 12 comments, 0 inline comments (from the three files).
- New items since my last review: reviewer 1's round-2 review (approve, 2 non-blocking notes); the author's 5 reply comments at 2026-11-24T16:12-16:13; commit 593ce07. I checked each against the code, below.
Round-2 items, disposition:
- My finding (the capacity reset ended live mirrors): fixed, and fixed the right way.
makeRoomForTouchLocked(onehour.go:210) drops only touches that are not live, and ends no stored mirror in either branch — the mirrors expire byEntryLifetime, exactly the round-2 proposal.judgeOneHourcalls it under the lock at the only write site of the map.TestTheCapacityBoundDoesNotEndALiveTouchsTiercovers both branches (dead eviction keeps the live touch; the all-live restart keeps the stored tier, a return at +13 minutes reads warm). The map is bounded at the only place it grows. - My note (the carry gate dropped the cold margin): fixed. The gate now adds
coldMargin(apply.go:715), the same margin ascacheIsCold. The test's arithmetic checks out: 60m30s past the ping reads warm, 60m70s reads cold. - My note (a bypassed request left
:1hstanding): fixed, with a defect — finding 1 above. The|| v.oneHourstrip is right for the bypass case; it is wrong for a tier a later touch wrote. - Reviewer 1's note (the carry lacked the
prevAtguard): fixed. The carry now counts only when the alias clock is the latest clock (seen.at >= prevAt, apply.go:678-681). I verified the guard's premise: a bypassed request records the tracker clock throughTurnAt(apply.go:770) without writing the alias clock, soprevAtadvances past the carry'satand the bypass at 8 minutes correctly ends the carry (the test asserts cold at 16 minutes). Same-thread pings cannot interleave with a request (the wait starts atRecord, and the monotone check refuses a ping that predates the apply write), so the guard does not lose legitimate carries. - Reviewer 1's note (no test for
EndTouchTieron a carried record): fixed.TestEndTouchTierEndsACarriedPingToocovers the<ms>^<pingMs>shape: a non-matching ping changes nothing, the matching ping's end leaves a plain value.
New commit, reviewed as a first review:
makeRoomForTouchLockeddeletes from the map during range (safe in Go), runs underk.muat its only call site, andt.live(now)uses the touch's own provider and model throughEntryLifetime.- The new tests hold no lock across the apply call (
r.k.mu.Unlock()precedesr.request), and their fixtures resolve (Opts.Bypassexists, apply.go:72-equivalent in opts.go;MaxTurnKeysis 20000). - The carry guard cannot zero-divide or misread:
carriedAt > 0implies theatparse succeeded, and an unreadable value reads as the zero state, which is never cold. - I did not run the tests (live tests not approved).
|
Reply to round-3 blocking finding (
|
|
Reply to the note on the bypass strip anchor (apply.go:1354). Gone with the revert. Nothing strips a plain |
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 @amiddaid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 4 of 10 | 71671f1ad6bf |
approve |
Verdict: approve
Findings
None. The round-3 finding is fixed by the revert, the fix is the behavior I verified correct in round 2, and the new commit introduces no defect.
Non-blocking
- apply/apply.go:1353 — a three-way race on the carry branch remains, from round-2 code. Trace: A's request writes the alias clock at T_A; a ping on the same alias writes
:1hat T_ping > T_A; a second request C converts it to a carry@T_C^T_pingat T_C > T_ping; A's response arrives before C's andConfirmRealTouchstrips C's carry; C then fails (429, 5xx), so the ping's hour should stand but the store says plain. A return 6 to 59 minutes after the ping reads cold on a warm entry. It needs two threads sharing one content head, both with requests in flight, a ping landing between their apply writes, and the later request failing — a compound coincidence, strictly narrower than the two-actor race fixed this round. It is also the same non-atomic read-check-write class the repo has accepted and named (theEndTouchTierrace, round 1): a compare-and-swap in the store, or the time-bounded confirm reviewer 1 proposed in round 3, would close the whole family. Fine as a follow-up; not a reason to hold this PR. - The bypass gap is back and accepted: a bypassed request writes no alias clock, so a
:1hthat stood before it runs its hour. False warm only, no cut. Named in the PR body (Technical notes).
What I checked
- Last review: round 3, 593ce07, 2026-11-24T16:21:31Z.
- New commits read: 1 — 71671f1 "fix(apply): ConfirmRealTouch ends only a carry, never a later ping's tier". The PR was also rebased onto 1d20435: I diffed 593ce07 against the rebased 94e757b and confirmed the PR's own files are identical — every difference (CI, CLAUDE.md, scripts/dev) came from main.
- Read in full: 6 reviews, 16 comments, 0 inline comments (from the three files).
- New items since my last review: reviewer 1's round-3 review (blocking — the same
ConfirmRealTouchwidening I found, reached independently); the author's 4 replies at 2026-11-24T16:27; commit 71671f1; the rebase. I checked each against the code, below.
Round-3 findings, disposition:
- My finding 1 (
ConfirmRealTouchstripped a later ping's:1h): fixed by the revert, and the revert is the right call.ConfirmRealTouchis back to carry-only (apply.go:1353), which is byte-for-byte the round-2 behavior I verified correct for the cross-thread ping: the confirm no-ops on a:1h, so a later ping's tier stands and the cold check keeps the hour. The author declined the time-bounded strip ("a revert adds no new edge case") — a fair trade: the strip's only benefit was the bypass gap, which errs warm, and the revert removes the expensive-direction race instead. Reviewer 1 raised the same finding in round 3 (their finding 1); I checked their trace independently in round 3 and it matches mine, including the same fix options. - My non-blocking notes: the bypass strip anchor is gone with the revert (nothing strips a plain
:1hnow); the all-live restart orphan is accepted with a correct reason (a capacity event is not a fact about an entry; ending mirrors there would put the #1350 bug back — the same reasoning I gave in round 2); the eviction scan underk.muruns once per capacity event, the same cost class as the reset it replaced. - Reviewer 1's round-3 non-blocking notes (the all-live restart dropping the keeper's index, the eviction scan): both accepted by the author with reasons that match the code. The index loss is display and press-refusal only; the stored mirrors, which the cold check reads, stay warm by
EntryLifetime.
New commit, reviewed as a first review:
- The revert touches only
ConfirmRealTouch's condition and its comment; the doc comment now states the rule and the reason (a plain:1hmay belong to a later ping). The PR body states the same rule (line 78) and names the bypass gap as accepted (line 80). The removed test (TestConfirmRealTouchEndsAnUnreplacedOneHourTier) asserted the wrong rule; removing it is correct. - The replacement test,
TestConfirmRealTouchLeavesALaterPingsTier, models the round-3 scenario exactly: a request at +5 minutes, a later ping's:1hat +6 minutes, the confirm, the record unchanged, and a return at +13 minutes reading warm. I checked its arithmetic: the request's apply writes plain@5m, the ping's touch passes the monotone check (6m > 5m), the carry-only confirm no-ops, and the return converts the:1hinto a carry that keeps the hour. Restoring|| v.oneHourfails the test by construction. - The behavior change stays inside the one the owner approved on 2026-11-24; the revert restores behavior already reviewed in round 2. Data dependence is unchanged (one or two timestamps per
cg:seen:record, metadata only). - I did not run the tests (live tests not approved).
…e-lifetime source After a free 1-hour keep-alive ping the provider keeps the entry for an hour. The cold check still used 5 minutes, so 5 to 60 minutes later it said cold and the sweep rewrote a warm entry (#1350). - A keep-alive request that leaves the entry at the 1-hour tier now writes that tier in the cg:seen: clock ("<ms>:1h"). A real request or a 5-minute touch writes the plain value, so the tier lasts until the next touch. - The cold check counts the lifetime of the last touch's tier, from apply.LifetimeAtTier (one call into modelinfo.CacheLifetime). - The keeper takes the tier from the body it really sent. - Hardcoded 5-minute and 1-hour literals in keepalive, apply and the accountant wiring now read the modelinfo constants. The two duplicate constant pairs in modelinfo are one pair. Fixes #1350 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…or the 1-hour touch; dash default per provider Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…ing attribution Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…substitute tier from the body's marks Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…uch; carry guard and margin Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…tier Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
71671f1 to
bf1958f
Compare
|
The round-4 approvals still count at The head moved from |
A copy of the reader that v0.7.8 ships (#1357) must read each value this version writes (a tagged ping, a numbered and tagged carry) as 0, which is never cold. The shapes v0.7.8 writes must read the same in both readers. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Behavior change: the owner approved all 3 items.
|
…oxy (#1375) refactor(apply): decide the attribution lifetime in apply, not the proxy The proxy decided "billed at 1 hour OR last touch was a free 1-hour ping" for the miss attribution. That is a cache-lifetime rule. It now lives in apply.BilledLifetimeMs, which takes the two facts. Results do not change. Refs #1357 docs(apply): fix two stale comments on the attribution lifetime Follow-up to #1357 (owner: "merge + followup"): the proxy-boundary leak in proxy/dashcapture.go moves into apply.BilledLifetimeMs. No behavior change: the same result for all 4 input pairs. Approvals at 5111490 still count (COMMENTS ONLY). No laptop run: the v0.7.8 heavy CI and Part A on the release commit cover it. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
The fact "the last touch of this thread was a free 1-hour ping" had 2 records after #1357: the keeper's oneHourTouch map and the cg:seen store value. Three review rounds each found an event where they split. The store value is now the only record of the tier and the time. - apply.StandingOneHourPing and apply.LiveOneHourPing read it. The dashboard clock, the manual-ping refusal and the probe ask them. - The keeper keeps an index of thread -> alias, store and route. It holds no tier and no time. - A route switch-off ends the tier in the store (apply.EndTouchTier). - store.PeekValue reads a value without sliding its TTL, so a dashboard poll does not renew a clock record. No behavior change is intended. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
A copy of the reader that v0.7.8 ships (#1357) must read each value this version writes (a tagged ping, a numbered and tagged carry) as 0, which is never cold. The shapes v0.7.8 writes must read the same in both readers. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…proxy (#1370) refactor(accrec): move the savings tracker and the ping store out of proxy The savingsTracker becomes accrec.Recorder: begin, end, compute, the fail-open compute, the finish-time pricing rules (Price) and the restart state format and age rules. The ping store becomes accrec.PingStore. The proxy keeps the state file I/O, the log lines, the Usage type and the HTTP wiring, and calls them. No behaviour change. A replay test pins the booked figures of a fixed request set, taken on origin/main before the move. Refs #1303, #1309 refactor(accrec): keep the side-effect order of finish Price gains an AfterCompute hook. The host books the event and the metrics there, before the rescue counter and the ping-facts drop, as before the move. A test pins the order. docs(accrec): name the Recorder, PingStore and state format; pin the kept reason Round 1 notes of #1370. The several-rounds subtest now passes a non-empty NoResult and checks that Price keeps it. Refs #1303 (stays open: accEndNow and accBilledTTL move in a follow-up). No behavior change: a replay test books the same result hashes before and after the move and after the #1357 merge. Approvals at d901ba6 still count: the +/- lines of the PR diff against main equal the approved diff. Local tests waived (owner rule, 2026-11-24). Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
) refactor(keepalive): one record of the 1-hour touch, in the store The fact "the last touch of this thread was a free 1-hour ping" had 2 records after #1357: the keeper's oneHourTouch map and the cg:seen store value. Three review rounds each found an event where they split. The store value is now the only record of the tier and the time. - apply.StandingOneHourPing and apply.LiveOneHourPing read it. The dashboard clock, the manual-ping refusal and the probe ask them. - The keeper keeps an index of thread -> alias, store and route. It holds no tier and no time. - A route switch-off ends the tier in the store (apply.EndTouchTier). - store.PeekValue reads a value without sliding its TTL, so a dashboard poll does not renew a clock record. No behavior change is intended. fix(apply): a confirm ends only the carry its own request wrote A confirm stripped any carry under the alias. In a 3-way race it stripped a later request's carry: request A writes its clock, a ping writes :1h, request C turns it into a carry, A is accepted first and strips C's carry, then C fails. The ping's hour was lost and a return 6 to 59 minutes after the ping read cold. apply now reports the clock time its request wrote (Trace.TouchAtMs). The host passes it to Record (Record.TouchAtMs), and ConfirmRealTouch ends the carry only when the value's own time matches. A request that wrote no clock ends nothing. fix(apply): a route switch-off ends only a ping its own route wrote The switch-off ended the 1-hour tier of every indexed thread on the route, by alias. A later ping of another route, on the same alias, could be ended too. That reads a warm entry as cold. A 1-hour ping is now stamped with a hash of its route in the store value (<ms>:1h:<tag>, and <ms>^<pingMs>:<tag> under a carry). EndTouchTier ends a ping only when its tag matches. An older reader cannot parse the new shapes and reads 0, which is never cold. fix(apply): a confirm matches its request exactly, and the proxy wiring is tested Two requests that wrote a clock in the same millisecond could end each other's carry. A carry now holds the number of the request that wrote it (<ms>^<pingMs>#<seq>:<tag>). ConfirmRealTouch ends a carry only when the time and the number match. apply.Trace.TouchSeq and keepalive.Record.TouchSeq pass the number through the proxy. A new proxy test runs the real handler, apply and keeper over one store. It shows that serve hands the request's own clock to the keeper: an accepted response ends the carried ping, a failed one keeps it. test(apply): pin the v0.7.8 reader against every new store shape A copy of the reader that v0.7.8 ships (#1357) must read each value this version writes (a tagged ping, a numbered and tagged carry) as 0, which is never cold. The shapes v0.7.8 writes must read the same in both readers. test(proxy): wait for the keeper without polling Closing the test server waits for the handler, which records the touch. The timing guard allows no sleep poll in a test. fix(apply): the Responses route reports the clock it wrote bodyResponsesOpts wrote the alias clock but never set Trace.TouchAtMs and TouchSeq, so the keeper confirm ended nothing on that route. It now uses aliasSeenWrite and reports both. Both routes set the two fields only when a clock was really written. A new proxy test runs the Responses route end to end. The docs now say that a host that runs apply must pass both fields, that a route tag must come from RouteTag, that PeekValue slides the TTL on a store without the capability, and what the keeper pays to read the store under its lock. test(keepalive): the 3 readers at each store kind, and the v0.7.8 shapes Pin what the dashboard, the manual refusal and the cold check say with a Memory store, store.Nop and no store, and after the stored record expired. Pin the reading of the 3 shapes v0.7.8 writes, field by field. fix(keepalive): with no store the keeper answers as before When the store keeps nothing (store.Nop, or no store), there is no record to read. The index then also holds the ping time, so the cache clock, the manual-ping refusal and the probe answer as on main. With a real store the field is always 0 and the store is the only record. The case is found by type (store.Keeps), not by a missed Get: a miss in a real store means no fact. Refs #1365. Behavior change (users with store.ttl_seconds < 3600 and a 1-hour strategy: after the stored record expires inside the hour, the dash and the manual ping agree with the cold check; off: store.ttl_seconds >= 3600, default 10000) and the "1-hour touch" data-dependence row approved by the owner, its Decided-by person (David Amid, 2026-11-25, integrator session): "1380 yes". Store off keeps main behavior (keeper fallback, TestTheThreeReadersAtEachStoreKind). Approvals at dc75657 still count (clean merge of main). Local tests waived (owner rule). Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Behavior change (approved by the owner, 2026-11-24)
1-hour-on-waitand1-hour-always(the 1-hour ping paths).ColdCacheorTailOnlyCold) applied 5 minutes after a free 1-hour ping, on an entry that was still warm.Second change (display only): the dashboard cache clock for a thread that has no recorded cache write now takes its lifetime from the provider and the model table, not from a fixed 5 minutes.
ttl_s300).ttl_s1800). Anthropic threads still show 5 minutes.Also corrected (display and miss labels): after a free 1-hour ping, the dashboard's miss attribution now judges the next request against 1 hour, not 5 minutes. Before, it could label a miss with the wrong lifetime.
Fixes #1350
Summary
What changed
apply.EntryLifetime(CacheFacts)andapply.IsCold(CacheFacts, prevAtMs, nowMs)are the one place that turns facts into a lifetime and a verdict.CacheFactsholds metadata only: provider, model, the tier of the last touch, the billed tier, and a floor from the safety guards.cacheLifetime, so cacheTTL, the substitute windows, the probe, the 1-hour touch), the dashboard cache clock, the dashboard's per-thread default, and the miss attribution.applybecauseapply,keepalive,dashandproxyalready import it, and it imports none of them. The tier table stays ininternal/modelinfo.sessionTTL, the parent key, the alias key, and the 1-minute cold margin.oneHourTouchmap (by thread, for the dashboard and the manual ping) and thecg:seen:<alias>value<ms>:1h(for the cold check) hold the same fact.apply.EndTouchTier).EntryLifetime. The keeper stores no duration.<ms>^<pingMs>). The keeper'sRecordends that carry (apply.ConfirmRealTouch) at the same line that ends its own touch, and only for an accepted (2xx) request. So both records end at one event. A 429, a 5xx, a 4xx, a timeout, a cancel, or a missingRecordcall leaves both in place, and both end an hour after the ping.<ms>. A 5-minute ping after a 1-hour ping moves the entry back (fix(keepalive): count the cache clock an hour from a free 1-hour ping #1258). The clock stays monotone.EntryLifetimewith the row's provider and model (/api/cachestatethreads query now selectsr.provider).entryAgeMsandcacheAttributionTTLMsareapply.EntryAgeMsandapply.BilledLifetimeMs.kaArrival.refreshedOneHour).OneHourIdleFloor(now the 5-minute constant), the accountant facts inaccrec/(accrec.BaseTTL,accrec.OneHourTTL, read by the proxy),oneHourIf, the forecast's 1-hour tier. The duplicate constant pair inmodelinfois one pair.ManualHoldMax,oneHourProbeTTL, the 30-minute age caps,warmPendingMax, SQL gap buckets and histogram edges. None is a provider cache lifetime.kvcache/reusemodel_v1_gen.go(LifeS: 300.0, generated); ``campaign/andaccrec/` were audited: no other cache-lifetime literal.PrefixRewritten).Store format and downgrade
cg:seen:areapply(cold check, OpenAI path, the ping touch), the disk store's key list, and tests. All useparseSeen.<ms>:1has an integer, fails, and reads 0. That means "no previous touch", which is never cold. It then writes a plain value. So a downgrade fails open: it never cuts because of the new format. (Test:TestTheTierSuffixFailsOpenForAnOlderReader.)Sub-agents and hosts
TestASubAgentRequestDoesNotEndTheMainThreadsOneHourTier(apply, same session id) andTestASubAgentRequestKeepsTheMainThreadsOneHourTouch(keeper).Record.Storenil) writes no touch, so the cold check sees no ping at all. That was already true before this PR for the plain ping touch. The bifrost adapter does not run the keeper. A downstream host such as the Cortex plugin is out of this repo; it must passRecord.Storeto get the fix.Data dependence
Metadata only: one tier flag and one timestamp per thread, in the existing
cg:seen:record. No storage level changes. No row indocs/data-dependence.mdchanges (the key list is the same).How it was tested
macOS, Go 1.27.4.
keepalive/coldtouch_test.go: real keeper plus real apply. A free 1-hour ping, a return 13 minutes after the request: not cold, lifetime 1 hour. 59 minutes: warm. 62 minutes: cold. A plain 5-minute ping: cold after 6 minutes. Switching the route off ends the stored tier. A sub-agent request keeps the main thread's touch.apply/touchtier_test.go: the last touch wins; a real request ends the tier; OpenAI GPT-5.6 keeps 30 minutes;EntryLifetimefacts; sub-agent isolation; the downgrade fail-open;EndTouchTier.dash/cachestate_test.go: an OpenAI GPT-5.6 thread with no write shows 1800.proxy/attributionttl_test.goandapply/touchtier_test.go(TestBilledLifetimeMsAfterAFreeOneHourPing): after a free 1-hour ping the miss is judged against 1 hour.EndTouchTieron switch-off, 1 fails.CGO_ENABLED=1 go test -race -timeout 30mon./apply/... ./keepalive/... ./store/... ./internal/... ./components/... ./dash/... ./proxy/...: all pass at this head.make lint. No live run, no remote box.Technical notes
Capacity bound. The keeper's touch map drops touches that are not live first, and starts over only when all are live. It never ends a stored mirror: a bound is not a fact about an entry. Only a route switch-off ends mirrors.
The carry counts only while the alias clock is the latest clock, and ends at the hour plus the cold margin, like the verdict. An accepted request ends a carry only. It never strips a plain
:1h, because that tier may belong to a later ping (another thread's, on the same alias).Accepted gaps, all warm only (no cut):
:1hthat stood before it stays until it expires or a later touch replaces it.EntryLifetime.Known windows, all in the safe direction (warm: no cut, no rewrite):
EndTouchTierdoes a read, a check and a write with no store-level atomicity. A newer touch that lands between the read and the write can be overwritten by the older plain value. It needs a route switch-off at the same moment as a touch on one alias.RecordCacheTouchAliasTier's monotone write has the same shape and was there before.Record) holds the hour until it expires.EndTouchTier, so the two records agree.aliasSeenTierreturns the previous touch's time and tier before the real request overwrites it.lastTouchOneHouraccepts the tier only when the alias clock is the latest clock (not older than the thread tracker's).The widening is
max(ttl, LifetimeAtTier(..., true)). It sits next tosessionTTL, which stays "longest ever asked" for the request's own markers.A route switched off after the ping still shows the stored tier until the next touch. The window is one hour at most, and only for threads pinged before the switch-off.
The keeper's in-memory 1-hour touch (
OneHourTouches, read by the dashboard and the manual ping) and the stored tier are written at the same point (judgeOneHourand the ping's touch). They have the same life: a real request ends both.