Skip to content

fix(apply): count a free 1-hour ping in the cold check, from one cache-lifetime source - #1357

Merged
amiddavid merged 9 commits into
mainfrom
feat/cold-1h-ping
Nov 24, 2026
Merged

amiddavid merged 9 commits into
mainfrom
feat/cold-1h-ping

Conversation

@amiddavid

@amiddavid amiddavid commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior change (approved by the owner, 2026-11-24)

  • Who it affects: users of 1-hour-on-wait and 1-hour-always (the 1-hour ping paths).
  • Old: a cold-only cut (the sweep's held answer, cold collapse, anything gated on ColdCache or TailOnlyCold) applied 5 minutes after a free 1-hour ping, on an entry that was still warm.
  • New: the cut waits until the entry really expires (1 hour after the ping), or until a real cold request.
  • How to turn it off: use a strategy that is not a 1-hour one.

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.

  • Who: OpenAI GPT-5.6+ threads that only read the automatic cache.
  • Old: the clock showed 5 minutes (ttl_s 300).
  • New: it shows 30 minutes (ttl_s 1800). Anthropic threads still show 5 minutes.
  • How to turn it off: no switch. It is a display value only. No request changes.

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

  • After a free 1-hour ping, the cold check used a 5-minute lifetime. The provider keeps the entry for 1 hour.
  • 5 to 60 minutes later the check said "cold". The sweep then applied a held answer and rewrote a warm prefix. Each rewrite wrote 65k to 384k tokens again.
  • Now the cold check counts the lifetime of the tier the last touch left the entry at.

What changed

  • One decision. apply.EntryLifetime(CacheFacts) and apply.IsCold(CacheFacts, prevAtMs, nowMs) are the one place that turns facts into a lifetime and a verdict. CacheFacts holds metadata only: provider, model, the tier of the last touch, the billed tier, and a floor from the safety guards.
    • Callers: the cold check, the keeper (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.
    • It lives in apply because apply, keepalive, dash and proxy already import it, and it imports none of them. The tier table stays in internal/modelinfo.
    • The floor keeps every old guard: the monotone sessionTTL, the parent key, the alias key, and the 1-minute cold margin.
  • One tier fact, two indexes (the keeper's map is the source for the dashboard and the manual ping; the stored value mirrors it for the cold check). The keeper's oneHourTouch map (by thread, for the dashboard and the manual ping) and the cg:seen:<alias> value <ms>:1h (for the cold check) hold the same fact.
    • They are written at the same ping.
    • A real request ends both.
    • Switching the route off ends both (apply.EndTouchTier).
    • Both expire by EntryLifetime. The keeper stores no duration.
  • A failed request does not end the tier. A real request writes its own clock before the forward, so its value carries the ping before it (<ms>^<pingMs>). The keeper's Record ends 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 missing Record call leaves both in place, and both end an hour after the ping.
  • The tier lasts until the next accepted touch. A real request, or a 5-minute touch, writes the plain <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.
  • The keeper takes the tier from the body it sent (every breakpoint asks 1 hour). A substitute question uses the entry's own tier.
  • Dashboard.
    • The cache clock and the per-thread default call EntryLifetime with the row's provider and model (/api/cachestate threads query now selects r.provider).
    • entryAgeMs and cacheAttributionTTLMs are apply.EntryAgeMs and apply.BilledLifetimeMs.
    • The proxy only passes the fact "the last touch was a live free 1-hour ping" (kaArrival.refreshedOneHour).
  • Literals replaced (same values): the keeper's D-touch lifetimes, the probe limits, OneHourIdleFloor (now the 5-minute constant), the accountant facts in accrec/ (accrec.BaseTTL, accrec.OneHourTTL, read by the proxy), oneHourIf, the forecast's 1-hour tier. The duplicate constant pair in modelinfo is one pair.
  • Not changed, on purpose: timeouts, ManualHoldMax, oneHourProbeTTL, the 30-minute age caps, warmPendingMax, SQL gap buckets and histogram edges. None is a provider cache lifetime.
  • Follow-ups, named: kvcache/reusemodel_v1_gen.go (LifeS: 300.0, generated); ``campaign/andaccrec/` were audited: no other cache-lifetime literal.
  • The 1-hour probe. No cold cut applies in the hour after a free ping, so the probe no longer sees its own cut as a silent downgrade. A client rewrite is already ignored (PrefixRewritten).

Store format and downgrade

  • The only readers of cg:seen: are apply (cold check, OpenAI path, the ping touch), the disk store's key list, and tests. All use parseSeen.
  • An older binary on the same store parses <ms>:1h as 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.)
  • A plain 5-minute value stays a plain integer.

Sub-agents and hosts

  • A sub-agent has its own prefix, so its own alias clock. Its real request does not end the main thread's 1-hour tier. Tests: TestASubAgentRequestDoesNotEndTheMainThreadsOneHourTier (apply, same session id) and TestASubAgentRequestKeepsTheMainThreadsOneHourTouch (keeper).
  • A host with no store (Record.Store nil) 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 pass Record.Store to 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 in docs/data-dependence.md changes (the key list is the same).

How it was tested

macOS, Go 1.27.4.

  • New tests (fail on the old code):
    • 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; EntryLifetime facts; 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.go and apply/touchtier_test.go (TestBilledLifetimeMsAfterAFreeOneHourPing): after a free 1-hour ping the miss is judged against 1 hour.
  • Mutation checks: without the tier widening in the cold check, 3 tests fail. With the keeper passing "5 minutes" for a free 1-hour ping, 2 fail. Without EndTouchTier on switch-off, 1 fails.
  • CGO_ENABLED=1 go test -race -timeout 30m on ./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):

    • A bypassed request writes no alias clock, so a :1h that stood before it stays until it expires or a later touch replaces it.
    • When all touches are live, the keeper's map starts over. A mirror whose touch was dropped is not ended by a later route switch-off. It expires by EntryLifetime.
  • Known windows, all in the safe direction (warm: no cut, no rewrite):

    • EndTouchTier does 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.
    • A carried ping that no accepted request ever confirms (the host never calls Record) holds the hour until it expires.
    • A press that fails (manual ping) deletes only a keeper touch that was not live (an hour old, or on a route switched off). Its mirror already ended by time or by EndTouchTier, so the two records agree.
  • aliasSeenTier returns the previous touch's time and tier before the real request overwrites it. lastTouchOneHour accepts 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 to sessionTTL, 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 (judgeOneHour and the ping's touch). They have the same life: a real request ends both.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — RecordCacheTouch still 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 on TouchAliasFor says the two "cannot drift", but two copies of one derivation is how they drift. RecordCacheTouch could be RecordCacheTouchAliasTier(st, TouchAliasFor(tenant, body, provider), nowMs, false) with no behavior change (TouchAliasFor returns "" exactly where the old guards returned).
  • apply/apply.go:1410 — EndTouchTier can move the clock backwards in a narrow race. It does Get, check ms == 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 plain atMs. Result: a stale prevAt, 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. Note RecordCacheTouchAliasTier'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 uses billedTTL(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 oneHourTouches entry before it dispatches. On a 429, 5xx, 4xx or no-usage answer it returns before job.touch, so the stored cg: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). aliasSeenTier reads the tier before the plain write, so the request's own write cannot hide it. lastTouchOneHour counts the tier only when the alias clock is the latest clock; I traced the bypass path (no aliasSeenTier call) and the sub-agent path (its own alias), and the aliasAt >= prevAt guard covers both. EntryLifetime takes max(Floor, table), and sessionTTL still persists the request's own ask before the check, so the new verdict is never colder than the old one.
  • The store format. parseSeen fails open: an older binary reads <ms>:1h as 0, which is never cold, then writes a plain value. I grepped every reader of cg:seen:; only apply (and tests) parse values. The data-dependence claim holds: same key, metadata only.
  • The keeper. fire sets sentOneHour from the body it really sends, before dispatch, and passes the same j copy to record1. judgeOneHour and record1's j.touch use the same start, so EndTouchTier's ms == atMs match holds. On a 2xx free switch, noteOutcome never returns outcomeFailed, so the two writes cannot diverge. oneHourSwitchOff ends the stored tier outside the lock. PingNow sets sentOneHour before dispatch. recordSubstitutePing reads the entry's tier under the lock. Record's noteTouchLocked ttl 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, BilledLifetimeMs and the dash billedTTL/touchTTLSeconds all reduce to EntryLifetime with the same facts as before. An empty provider from old rows behaves exactly as the old constants (300/3600), so no dash regression.
  • The proxy. attributionTTLMs widens to 1 hour only from the billed tier or a live free ping (OneHourTouchLive, which also checks the route). arriveAt runs at arrival, before Record clears 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 reports go test -race green on macOS, Go 1.27.4.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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.BodyOpts already wrote the plain clock at T+6m (aliasSeenTier, apply/apply.go:673), so the stored :1h tier ends there. But Record returns at the status gate (keeper.go:870) before resolveOneHourProbe (keeper.go:876) deletes the keeper's touch. The next request at T+13m reads prevAt = T+6m, tier gone, lifetime 5m: cacheIsCold says 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. aliasSeenTier runs in BodyOpts before the forward, whatever the upstream status will be. Record's gate if status < 200 || status >= 300 { return } sits before resolveOneHourProbe, which is the only Record path that deletes oneHourTouches. 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 Record for a thread whose oneHourTouchLiveLocked holds, 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 in aliasSeenTier cannot be undone, so the keeper must write the correction.
  2. 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.ttl1h is 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 — PingNow states it in manual.go:144-147, and the cold check's tier model in this PR is built on it. But recordSubstitutePing passes oneHour = e.ttl1h || e.pol.HeadTTL1h to j.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.ttl1h is assigned only at onehour.go:191 (the A path, ping relabelled, client markers untouched). The HeadTTL1h half 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>), as fire and PingNow now do. The error direction is safe (missed savings, no rewrite), so this can also ride a follow-up if the owner prefers.

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.
  • oneHourTouches is reset wholesale at MaxTurnKeys (onehour.go:185-187). Those threads' stored :1h mirrors then never get EndTouchTier on 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.
  • EndTouchTier matches on ms == atMs. A mirror overwritten by a later touch is correctly left alone; verified the write paths (record1, PingNow) use the same start the map stores.

What I checked

  • The full diff (23 files) and the code around each change: apply's cold-check block, the cg: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.provider column, column/scan order in cacheThreadsQuery, billedTTL, applyOneHour).
  • The alias derivations agree: TouchAliasFor matches RecordCacheTouch (bare content hash), and the host-passed TouchAlias wins where tool deferral would shift it (#902).
  • The downgrade story: an old binary parses <ms>:1h as 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.Minute hits 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.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to blocking finding 1 (failed real request). Fixed in 9cfdd1b. The finding was right.

  • Cause: two records of one fact. apply writes the plain clock before the forward. The keeper's touch stays when Record returns at the status gate.
  • Fix, so the class goes away: a real request now writes <ms>^<pingMs>. It carries the ping that stood before it. apply.ConfirmRealTouch ends the carry. The keeper calls it on the same line that ends its own touch (resolveOneHourProbe), and only for an accepted request. Both records now end at one event.
  • Why every non-2xx path is covered:
    • 429, 5xx, 4xx: Record returns at the status gate, before that line. Both records stay.
    • Timeout, client cancel, no Record call: that line is never reached. Both records stay.
    • A 2xx with no usage: Record reaches the line. The request was accepted and touched the entry, so both end.
    • In all "stay" cases both records end an hour after the ping.
  • The cold check counts the carried hour while now - ping is under the 1-hour lifetime from EntryLifetime.
  • Tests (real keeper, real apply): TestAFailedRealRequestKeepsTheOneHourPing (429, 500, 400, no Record call: ping, failed request at +6 min, return at +13 min reads warm). TestAnAcceptedRealRequestEndsBothRecordsOfTheTier (a 200 ends both). TestARealRequestCarriesTheOneHourPingUntilConfirmed (apply).
  • Mutation: with the carry removed, 2 tests fail. With the confirm removed from Record, 1 test fails.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to blocking finding 2 (substitute tier). Fixed in 9cfdd1b. The finding was right.

  • The substitute touch now takes its tier from the markers of the body it was built from: apply.AllBreakpointsAskExtendedTTL(j.raw). The D-touch lifetime in recordSubstitutePing uses the same value.
  • A plain-marker read moves a 1-hour entry back to 5 minutes, so the touch no longer claims the hour. A body with 1-hour markers (a 1-hour-always thread) still writes :1h.
  • Test: TestASubstituteTouchTakesItsTierFromTheBodysMarkers (plain markers give a plain value, even with e.ttl1h set; 1-hour markers give :1h).
  • Mutation: with the old e.ttl1h rule back, the test fails.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on RecordCacheTouch (apply.go:1365). Fixed in 9cfdd1b. RecordCacheTouch now calls RecordCacheTouchTier, which uses TouchAliasFor. One derivation remains.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

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+).

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on the second model parse (apply.go:702). Fixed in 9cfdd1b. The cold block reads model once, before CacheLifetime, and reuses it for CacheFacts.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on a failed manual press (manual.go:149). Not changed. The two records already agree on this path.

  • PingNow deletes the keeper's touch only after oneHourTouchLiveLocked returned false. A live touch is refused with ErrAtOneHour before that line.
  • A touch that is not live is one an hour old, or on a route that is switched off.
    • Hour old: the stored mirror expires by the same EntryLifetime, so it does not widen anything.
    • Route off: oneHourSwitchOff already ended the mirror (EndTouchTier, test TestSwitchingTheRouteOffEndsTheStoredTierToo).
  • So a failed press leaves no :1h that the keeper has dropped for a live reason. Existing test: TestAManualPressClearsAnExpiredOneHourTouch.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on the wholesale reset (onehour.go:185). Fixed in 9cfdd1b. Before the map starts over at MaxTurnKeys, the keeper collects the dropped touches. After it releases the lock, it ends each stored mirror (EndTouchTier), as the route switch-off does.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on the EndTouchTier race. Accepted, and named in the PR body, Technical notes. No fix.

  • The read, check and write have no store-level atomicity. A newer touch that lands in between can be overwritten by the older plain value.
  • It needs a route switch-off at the same moment as a touch on one alias. The result is a stale clock, which is the same class as the monotone write in RecordCacheTouchAliasTier (there before this PR).
  • A fix needs a compare-and-set in the store, which is a larger change than this critical fix.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. ConfirmRealTouch strips the carry, and the keeper calls it on the line after resolveOneHourProbe — the same 2xx Record that 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 missing Record never 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 on now - 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, as fire and PingNow do. EndTouchTier also 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 single model parse, the reset, the EndTouchTier match).
  • My note on RecordCacheTouch's duplicate derivation — fixed. It now delegates to RecordCacheTouchTier, which uses TouchAliasFor. 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 EndTouchTier race — 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. PingNow refuses with ErrAtOneHour while 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 same EntryLifetime gate, and the carry branch uses the same gate) or one on a route switched off (EndTouchTier already ended the mirror). No live disagreement remains. Accepted.

Non-blocking

  • apply/apply.go:706 — the carry branch ignores the prevAt guard that lastTouchOneHour has. A bypassed request advances the tracker clock (TurnAt) but writes no alias clock, so the store can still hold the ping's :1h while prevAt is 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. A seen.at >= prevAt style guard on the carry would close it.
  • No direct test for EndTouchTier on a carried record. The route-switch-off and reset tests end plain :1h records; 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..HEAD patch; 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 :1h and 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. TestAFailedRealRequestKeepsTheOneHourPing fails 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 real recordSubstitutePing with e.ttl1h forced true and plain markers, which is the case the old rule got wrong. runTouches confirms every request, so the round-1 expectations keep their meaning.
  • The rebase base. f4ee9f8 brings main's #1356 (headTTL1h in apply.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 amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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 calls EndTouchTier on 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, reads prevAt = 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 oneHourTouches only 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 :1h values to expire by EntryLifetime, 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.

Non-blocking

  • apply/apply.go:705 — the carry gate drops the cold margin at the hour boundary. The gate is now - carriedAt < EntryLifetime(...) with no coldMargin, 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 :1h path keeps the margin; only the carry path loses it.
  • apply/apply.go (ConfirmRealTouch) — an accepted bypassed request does not end a :1h mirror. A bypassed request writes no clock (the cold block is inside !bypass), so the record stays <pingAt>:1h; ConfirmRealTouch strips only the ^ carry. The keeper's touch ends at Record, 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; ConfirmRealTouch ends the carry in Record, 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 reaches Record (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. EndTouchTier handles both the :1h and the ^ shapes. The tests (TestAFailedRealRequestKeepsTheOneHourPing, TestAnAcceptedRealRequestEndsBothRecordsOfTheTier, TestARealRequestCarriesTheOneHourPingUntilConfirmed) cover each path. The ^ shape fails open for an older binary (verified ParseInt errors, 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 as fire and PingNow. TestASubstituteTouchTakesItsTierFromTheBodysMarkers covers plain and 1-hour markers with e.ttl1h set.

Round-1 notes, mine and reviewer 1's:

  • Second model parse: fixed (read once at apply.go:621, reused in CacheFacts).
  • Stale dash comment (reviewer 1): fixed.
  • RecordCacheTouch duplicate derivation (reviewer 1): fixed — it now delegates to RecordCacheTouchTier, one derivation.
  • Failed manual press (reviewer 1): the author rejected it with a reason; I checked the reason and accept it. PingNow refuses while oneHourTouchLiveLocked holds (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 same EntryLifetime, one minute of margin at most) or on a route switched off (whose mirror oneHourSwitchOff already ended).
  • EndTouchTier check-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 in RecordCacheTouchAliasTier. 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, parseSeenState reads 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's at (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 pingJob on a live entry) matches recordSubstitutePing'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 existing cg: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).

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to round-2 blocking finding (capacity reset ends live mirrors). Fixed. The finding was right.

  • A capacity bound is not a fact about an entry. The reset no longer ends any stored mirror. They expire by apply.EntryLifetime.
  • The map now evicts by liveness first (makeRoomForTouchLocked drops only touches that are not live). If every touch is live, it starts over, and still ends no mirror. Only the keeper's own index (dashboard, press refusal) loses a touch then. That is display only.
  • EndTouchTier stays on the route switch-off, where the fact does change.
  • Test: TestTheCapacityBoundDoesNotEndALiveTouchsTier. It fills the map with dead touches, checks that the live one stays, then forces the all-live reset and checks that a return at +13 minutes reads warm.
  • Mutation: ending the mirrors at the reset fails the test. Evicting live touches fails the test.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on the carry margin (apply.go:705). Fixed. The carry gate now adds coldMargin, the same margin as cacheIsCold. Test: TestTheCarriedPingHasTheColdMarginAndTheLatestClockGuard (30 seconds past the hour reads warm, 70 seconds past reads cold). Mutation: without the margin the test fails.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on the carry prevAt guard (apply.go:706). Fixed. The carry counts only when the alias clock is the latest clock (seen.at >= prevAt), the same guard as the :1h path. A bypassed request moves the tracker clock without writing the alias clock, so it now ends the carry. Same test as above (a bypass at 8 minutes, a return at 16 minutes reads cold). Mutation: without the guard the test fails.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on a test for EndTouchTier on a carried record. Fixed. TestEndTouchTierEndsACarriedPingToo covers the <ms>^<pingMs> shape: another ping's end changes nothing, the matching ping's end leaves a plain value. Mutation: ignoring the carry in EndTouchTier fails the test.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on a bypassed request and ConfirmRealTouch. Fixed, and it was cheap. ConfirmRealTouch now ends both a carry and a 1-hour tier that no apply write replaced (a bypassed request writes no clock). This matches the keeper, whose touch ends at the same line for any accepted request. A ping that finishes during the request is also ended by the keeper's own touch deletion, so the two records still agree. Test: TestConfirmRealTouchEndsAnUnreplacedOneHourTier. Mutation: restricting the confirm to a carry fails the test.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. apply/apply.go:1353 — ConfirmRealTouch now 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's j.touch writes tP:1h on the shared alias with tP > tB (the monotone write passes). K2's response arrives: Record deletes the touch under K2's key only (K1's stays), then calls ConfirmRealTouch (keeper.go:886), which reads tP:1h, sees v.oneHour, and rewrites it plain tP. 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 reads ColdCache true 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 :1h records, so this path read warm, which is correct.
    • Proof: trace. ConfirmRealTouch cannot tell a :1h the 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 :1h a 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's aliasSeenState converts 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 :1h only when its time is at or before that start: ConfirmRealTouch(st, alias, startedAtMs) with v.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). Record already holds r.StartedAt.

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.mu over 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. makeRoomForTouchLocked evicts only touches that are not live, and no stored mirror ends at a capacity event anymore: the mirrors expire by EntryLifetime, which is the same clock the cold check gates on, so an evicted dead touch's mirror is dead too. EndTouchTier now runs only from oneHourSwitchOff, 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 prevAt guard — fixed. The carry now counts only when the alias clock is the latest clock (seen.at >= prevAt), the same guard as the :1h path. 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 EndTouchTier on a carried record — fixed. TestEndTouchTierEndsACarriedPingToo covers 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..HEAD patch; 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; live uses the same EntryLifetime the 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 cacheIsCold and lastTouchOneHour: the guard uses prevAt before the alias merge, matching the :1h path; 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 amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. apply/apply.go:1353 — ConfirmRealTouch now 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; Record calls ConfirmRealTouch, which reads the :1h and 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 :1h to 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" — resolveOneHourProbe deletes oneHourTouches[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 own Record, and RecordCacheTouchAliasTier'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 ConfirmRealTouch the confirmed request's start time (Record has r.StartedAt) and strip only records whose own touch is not later than it: a :1h whose at exceeds the request's start belongs to a later touch and must stand; same for a carry whose at exceeds it. The bypass case keeps working — a bypassed request writes no clock, so any standing :1h predates or outlives it, and a :1h written after a bypassed request started is exactly the later-touch case that must stand.

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 oneHourSwitchOff cannot 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 ConfirmRealTouch ends 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 by EntryLifetime, exactly the round-2 proposal. judgeOneHour calls it under the lock at the only write site of the map. TestTheCapacityBoundDoesNotEndALiveTouchsTier covers 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 as cacheIsCold. The test's arithmetic checks out: 60m30s past the ping reads warm, 60m70s reads cold.
  • My note (a bypassed request left :1h standing): fixed, with a defect — finding 1 above. The || v.oneHour strip is right for the bypass case; it is wrong for a tier a later touch wrote.
  • Reviewer 1's note (the carry lacked the prevAt guard): 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 through TurnAt (apply.go:770) without writing the alias clock, so prevAt advances past the carry's at and 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 at Record, 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 EndTouchTier on a carried record): fixed. TestEndTouchTierEndsACarriedPingToo covers 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:

  • makeRoomForTouchLocked deletes from the map during range (safe in Go), runs under k.mu at its only call site, and t.live(now) uses the touch's own provider and model through EntryLifetime.
  • The new tests hold no lock across the apply call (r.k.mu.Unlock() precedes r.request), and their fixtures resolve (Opts.Bypass exists, apply.go:72-equivalent in opts.go; MaxTurnKeys is 20000).
  • The carry guard cannot zero-divide or misread: carriedAt > 0 implies the at parse succeeded, and an unreadable value reads as the zero state, which is never cold.
  • I did not run the tests (live tests not approved).

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to round-3 blocking finding (ConfirmRealTouch strips a later ping's tier). Fixed. The finding was right, and I agree with the revert.

  • ConfirmRealTouch ends only a carry (^), as before the widening. It never strips a plain :1h, because that tier may belong to a later ping, for example another thread's ping on the same alias.
  • No time-bounded strip. A revert adds no new edge case.
  • Test: TestConfirmRealTouchLeavesALaterPingsTier. A request starts at +5 minutes, a later ping writes :1h at +6 minutes, the request is confirmed, the :1h stays, and a return at +13 minutes reads warm.
  • Mutation: restoring || v.oneHour fails the test.
  • I removed the old test TestConfirmRealTouchEndsAnUnreplacedOneHourTier, which asserted the wrong rule.

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Reply to the note on the bypass strip anchor (apply.go:1354). Gone with the revert. Nothing strips a plain :1h now, so no plain value keeps the ping's time. The bypass gap itself (a bypassed request writes no alias clock, so a :1h that stood before it stays) errs warm only: no cut. It is named as an accepted gap in the PR body, Technical notes.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :1h at T_ping > T_A; a second request C converts it to a carry @T_C^T_ping at T_C > T_ping; A's response arrives before C's and ConfirmRealTouch strips 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 (the EndTouchTier race, 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 :1h that 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 ConfirmRealTouch widening 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 (ConfirmRealTouch stripped a later ping's :1h): fixed by the revert, and the revert is the right call. ConfirmRealTouch is 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 :1h now); 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 under k.mu runs 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 :1h may 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 :1h at +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 :1h into a carry that keeps the hour. Restoring || v.oneHour fails 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]>
…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]>
…uch; carry guard and margin

Assisted-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

The round-4 approvals still count at bf1958f6.

The head moved from 71671f1a to bf1958f6 only by a clean rebase onto main, which brought in #1366 (e54d499a). scripts/release/approval-still-valid.sh finds the same patch-id. So the PR's own change is the same.

approved: 71671f1ad6bf (base 1d20435fe193) patch-id aa3a5bd8ead5
head:     bf1958f6aad5 (base e54d499a9341) patch-id aa3a5bd8ead5
--- git range-diff
 1:  da73715b =  1:  a3b0f19b fix(apply): count a free 1-hour ping in the cold check, from one cache-lifetime source
 2:  299dcc34 =  2:  2302647a refactor(apply): entry age and billed lifetime live in apply, not proxy
 3:  d18063c6 =  3:  f4e814c6 refactor(apply): one CacheFacts decision for the entry lifetime; mirror the 1-hour touch; dash default per provider
 4:  a73874ae =  4:  85869da5 docs(design): name EntryLifetime as the one decision
 5:  0dd45e30 =  5:  f97bea63 refactor(accrec): cache lifetimes from the one table; test the free-ping attribution
 6:  54a3088e =  6:  814baddc fix(apply): carry the 1-hour ping under an unconfirmed real request; substitute tier from the body's marks
 7:  80812f4e =  7:  b725dc38 test(apply): the carried clock value also fails open for an older reader
 8:  94e757b2 =  8:  2990380e fix(keepalive): the capacity bound keeps the stored tier of a live touch; carry guard and margin
 9:  71671f1a =  9:  bf1958f6 fix(apply): ConfirmRealTouch ends only a carry, never a later ping's tier
SAME CHANGE: only the base moved. The approval of 71671f1ad6bf still counts. Say so on the PR.

amiddavid added a commit that referenced this pull request Nov 24, 2026
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]>
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Behavior change: the owner approved all 3 items.

  • Who: the owner, David Amid.
  • Where: in the integrator session ("1357 yes"), 2026-11-24. Item 1 was also approved earlier, in the PR-owner session.
  • What:
    1. A cold-only cut now waits for real expiry after a free 1-hour ping.
    2. The dashboard clock takes its lifetime from the provider and model table, so a GPT-5.6+ thread shows 30 minutes.
    3. After a free 1-hour ping, the miss labels judge the next request against 1 hour.

@amiddavid
amiddavid merged commit f83f2df into main Nov 24, 2026
10 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 24, 2026
amiddavid added a commit that referenced this pull request Nov 24, 2026
…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]>
amiddavid added a commit that referenced this pull request Nov 24, 2026
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]>
amiddavid added a commit that referenced this pull request Nov 24, 2026
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]>
amiddavid added a commit that referenced this pull request Nov 24, 2026
…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]>
amiddavid added a commit that referenced this pull request Nov 25, 2026
)

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

fix(apply): the cold check ignores a free 1-hour ping, so the sweep rewrites a warm cache

1 participant