Repository navigation
refactor(accrec): move the savings tracker and the ping store out of proxy - #1370
Conversation
…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 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
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. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 0569091dd0cb |
approve |
Verdict: approve
Findings
None. The move keeps behavior. I traced each path old against new (details under "What I checked").
Non-blocking
- Test debt before merge. The PR body says
go test -race ./proxy/...is owed.scripts/dev/local-tests.sh 1370is also still needed at the final head (CLAUDE.md, "A PR is ready when"). Run both before the hand-off. docs/design.md:20— theaccrec/row does not name the new contents. The row lists the glue rules. The package now also holds the request recorder (Begin/End/Price) and the state-file format. One added clause would fix it.accrec/state.go:685— the error text says "proxy version". The message moved into the library, where any host reads it. Say "state file version" instead.accrec/recorder_test.go:531— the subtest name promises more than it checks. "Several rounds book nothing and keep the earlier reason" passesNoResult: "", so no earlier reason exists to keep. Pass a non-emptyNoResultor rename it.accrec/pingstore.go:79—Takeis Peek then Drop, not one atomic step. A ping stored between the two calls is dropped by theDrop(key, "")of the missed Peek. Pre-existing: the old proxytakehad the same shape. No change in this PR.
What I checked
- Read the full diff of all 13 files, and the code around each change in
accrec/,proxy/andthread/. - Side-effect order of
finish(the PR's main claim). I compared the baseproxy/dashcapture.gofinish block againstaccrec.Recorder.Priceline by line. Old order:ShouldComputegate,accBilledTTL,computeSafe, event + metrics on success,ComputePanickedon panic, rescue counter, ping-facts drop — all only when compute runs. New order inPrice: same gate (early return keeps the ping facts and skips the rescue counter, as before),BeforeCompute(=accBilledTTL),ComputeSafe,AfterCompute(= event + metrics) only on success,ComputePanickedon panic, rescue counter, ping-facts drop.c.accNoResult = out.NoResultlands the same values:whywhen gated, the earlier reason when priced,ComputePanickedon panic. The order test inTestPricepins this. - Nil-safety and fail-open.
c.savings.Priceruns only whenc.accReq != nil, andaccReqis set only on a path that requiresc.savings != nil(accBegin/accEnd/accRun), so the promoted-method call cannot meet a nil savings tracker.recordThinking,drop,RescueFactsMissingkeep their nil checks.ComputeSafekeeps the recover-and-log of the oldcomputeSafe. A nil*PingStorepassed as thePingSinkstill works: its methods are nil-safe, as the oldpingSinkwrapper was. - State save and restore parity.
savenow callsSnapshotState, which marshals the sameStateFile(version 2, snapshot, thinking).restorekeeps the same log lines and the same decisions in the same order: read error,ThinkingMaxAgegate, thinking counts restored even when the snapshot is refused or too old,StateMaxAgegate,Trackers.Restoreerror. The proxy constants alias the accrec ones, so no value changed. - Ping store. The exported
Put/Peek/Take/Drop/Pricedare the old unexported methods, byte for byte in logic, bound still 4096 with the same eviction.proxy.PingSavingspasses the store itself as the sink; the interface change is behavior-neutral (checkedNotePricedand the manual-ping rule inaccrec/ping.go). ThreadOfinproxy/accountant_wire.go. Same mapping as the old inline code (thread.Result.InheritsFromreturns(string, bool); verified inthread/thread.go:103).- Compile-level checks by grep (live builds are not approved for this review): no leftover use of the removed
put/peek/take/drop/notePriced/pingSink/pingStoreMaxin non-test proxy code;s.clients,s.billed1h,s.thinking,s.onEndview fields still have all their users;proxyappusesproxy.NewPingStore, which still exists; the replay test's helpers (msg,body,rewriteOp,accFacts,mustMsg) all exist inproxy/accountant_savings_test.go; no import cycle (accrecimports onlyaccountant,accwire,thinkcount,components). - Rules. Business logic (compute gate, pricing, state rules, ping facts) moved out of the host into
accrec— the direction CLAUDE.md asks for. The PR names its data dependence (unchanged, metadata only) and claims no behavior change; my trace confirms both. New tests use no sleeps, sotimingguardis safe.
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 | 0569091dd0cb |
approve |
Verdict: approve
Findings
None. The PR moves code, it does not change behavior. I checked each move against the base
commit line by line. Details under "What I checked".
Non-blocking
docs/design.md:20— theaccrec/row does not name the three pieces this PR adds: the
Recorder, thePingStoreand the state-file format. The row still reads true ("the
accountant's glue rules, shared by every host"), but a reader looking for where the restart
state lives will not find it from the table.accrec/state.go:31—RestoreState's version-mismatch error says "state file has proxy
version". The rule now lives in a library shared by every host, so "proxy" is the wrong word
in a log an operator reads. The string also matches the old one, so changing it is cosmetic
only.accrec/pingstore.go:79—TakeisPeekthenDropunder two lock holds. APutbetween
them is dropped by the empty window even though no request read it. The race existed before
the move, andTakenow has no production caller (the request path usesPeekat open and
Dropwith the read window at price). Test-only, so I leave it as a note.accrec/recorder.go:361—PriceIn.Pingsis the concrete*PingStore, whilePingSavings
takes thePingSinkinterface. A host with its own sink cannot reusePrice. No host needs
that today; worth an interface only when one does.
What I checked
- Read the full diff (
1d20435f..0569091d, 13 files) anddocs/design.md. - The move is verbatim. I compared every moved function against the base commit
(git show 1d20435f:proxy/...):begin/end/compute/computeSafe/drop/
recordThinking/noteRescueFactsMissing(accountant_savings.go), all sixPingStore
methods and the 4096 bound (accountant_ping.go), and the save/restore logic
(accountant_state.go). Only receiver and field names changed. The state-file JSON tags and
StateVersion = 2are unchanged, so old files still restore. - The finish order is kept. I diffed the old
finishblock (dashcapture.go) against
Recorder.Priceplus theBeforeCompute/AfterComputehooks step by step:accBilledTTL
before compute, event and metrics only when priced, rescue counter (kaPings > 0 && pingWindow == "") and ping-facts drop after them,accNoResultset the same way on each
branch (rejected, deferral, rounds, panic). Commit 2 fixed the one order change commit 1 had
introduced (event booked after the drop); the head is correct. - Fail-open paths survive.
ComputeSafekeeps its recover;PingSavingskeeps its recover;
accRunkeeps its recover andDrop. Nil-safe receivers are kept: a nil*PingStorepassed
as thePingSinkinterface is a typed nil, andNotePriced/Putstay no-ops — the same
semantics the oldpingSinkwrapper had. - Keys match.
Pricedrops withPingKey(Session, Thread); the capture passes
c.accThread, whichaccEndNowsets fromThreadOf(th.ID,...).ID— the same mapped id
entryFactsread with.ThreadOfis the old inline parent logic, unchanged. - External wiring still compiles by alias.
proxyappusesproxy.NewPingStore,
proxy.PingSavingsandOptions.Pings; all three are now aliases or thin wrappers over
accrec.promexport.goreadsPriced()on the same store. - Tests cover the new code.
TestPrice(six subtests, including the side-effect order and
the panic path),TestPingStore*,TestStateRoundTripAndRefusals,
TestReplayBooksTheSameFigures(pins the booked figures across the move),
TestFinishSpendsThePingFactsOnlyWhenItPricesin the proxy. The moved tests were kept, not
dropped. - Hard boundaries.
accrecimports no host package; the proxy keeps only file I/O, log
lines, theUsagetype and wiring. This is the direction CLAUDE.md asks for (the Cortex
test). No data-dependence change: the state file holds the same metadata, and the
accountant-savingsrow stays true. - I did not run tests or builds; this review is from reading the code only.
…kept reason Round 1 notes of #1370. The several-rounds subtest now passes a non-empty NoResult and checks that Price keeps it. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 notes, fixed in the new head.
Kept as they are:
Tests: build and vet are clean, with and without |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.331 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | d901ba6b35e5 |
approve |
Verdict: approve
Findings
None. The new commit changes one test and one doc line. No code path changes.
Earlier findings, this round's state
- design.md
accrec/row (mine, and reviewer 1's) — fixed. The row now names theRecorder(Begin/End/Price), thePingStoreand the state-file format (docs/design.md:20). - "Several rounds" subtest (mine) — fixed. It now passes
NoResult: "earlier_reason"and assertsPricekeeps it (accrec/recorder_test.go:127). I traced it:ShouldCompute(200, 2, "earlier_reason")returns(false, "earlier_reason"), so the assertion pins the kept reason. The author's mutation (empty reason from several rounds) failed the test, which confirms it checks something. - "proxy version" error text (mine, and reviewer 1's) — rejected by the author. Reason: the string matches the old one, and changing an operator-facing message is a separate decision. I accept the reason. The string is identical to the base commit's, so no behavior changed.
Takeas Peek then Drop (mine, and reviewer 1's) — rejected by the author. Reason: old code moved as it was, no production caller. I checked:grepfor.Take(overaccrec,proxy,proxyapp,cmd,adapters,dashfinds no non-test caller. I accept.PriceIn.Pingsconcrete type (reviewer 1's) — rejected by the author. Reason: no host needs another sink yet. I checkedPriceInusers: onlyproxy/dashcapture.gopassesc.pings. I accept. Agree with reviewer 1, finding 4; nothing to add.- Owed test runs (mine) — still open. See Non-blocking.
Non-blocking
- Test debt before merge. The author's comment says build and vet are clean, but the unit tests were not run at the new head, and
go test -race ./proxy/...andscripts/dev/local-tests.sh 1370are still owed. CLAUDE.md requires the heavy tests at the final head before the hand-off. The new head changed a test file, so the earlier runs (had they existed) would not cover it.
What I checked
- Last review: round 1, 0569091, 2026-11-24T17:59:09Z.
- New commits read: 1 (
d901ba6b"docs(accrec): name the Recorder, PingStore and state format; pin the kept reason"). - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files in my folder).
- New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (18:00:15Z, approve, no findings): read in full. Their four non-blocking notes overlap my round-1 notes on three points; the fourth (
PriceIn.Pingsconcrete type) I checked myself above. - Author's comment (18:02:16Z): read in full. Two fixes, three rejections with reasons — each checked above.
- Commit
d901ba6b: read the full diff.accrec/recorder_test.go— one subtest now passes and checks a non-emptyNoResult; traced the assertion throughShouldCompute.docs/design.md— one row extended; the wording matches what the PR adds.
- Reviewer 1's round-1 review (18:00:15Z, approve, no findings): read in full. Their four non-blocking notes overlap my round-1 notes on three points; the fourth (
- The rest of the PR is unchanged since my round-1 review of
0569091d, which traced the side-effect order offinish, the fail-open paths, the state save/restore parity and the ping-store move. I did not re-run tests or builds; this review is from reading the code only.
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 | d901ba6b35e5 |
approve |
Verdict: approve
Findings
None. The new commit changes one test and one docs row. Both are correct.
Non-blocking
- Tests still owed before the hand-off. The author's comment says build and vet are clean,
but the unit tests were not run (load average above 300). CLAUDE.md also asks for
scripts/dev/local-tests.sh 1370at the final head. Run both before the PR is handed to the
integrator. Same point reviewer 2 raised in round 1; it still stands.
What I checked
- Last review: round 1,
0569091dd0cb69761e3a0473cb16583f797ab32c, 2026-11-24T18:00:15Z. - New commits read: 1 (
d901ba6b"docs(accrec): name the Recorder, PingStore and state
format; pin the kept reason"). - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files).
- New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (approve, 5 non-blocking notes). Read in full. Our notes
overlap on three points (design.md row, "proxy version" text,Takerace); I checked each
again myself below. No new finding to agree with or dispute. - The author's comment "Round 1 notes, fixed in the new head." Checked every claim in the
commit (below). - Commit
d901ba6b. Reviewed in full; see below.
- Reviewer 2's round-1 review (approve, 5 non-blocking notes). Read in full. Our notes
- Earlier findings, each resolved:
- design.md
accrec/row (mine, and reviewer 2's): fixed. The row now names the
Recorder(Begin/End/Price), thePingStoreand the state-file format
(SnapshotState/RestoreState). I checked the names against the code; they match. - Several-rounds subtest checked less than its name said (reviewer 2's): fixed. The
subtest now passesNoResult: "earlier_reason"and assertsPricekeeps it. I traced
ShouldCompute(200, 2, "earlier_reason"): not rejected, notDeferralUnplaced, rounds 2,
so it returns(false, noResult)— the earlier reason is kept and nothing is priced. The
assertion matches the trace, and the author's mutation (empty reason for several rounds)
fails it, as the comment says. - "proxy version" error text (mine, and reviewer 2's): rejected by the author, reason
accepted. The string is byte-identical to the one before the move. Changing a message an
operator reads is a visible change, and this PR claims none. A separate change can reword
it. PingStore.TakePeek-then-Drop race (mine, and reviewer 2's): rejected, reason
accepted. The code is the old proxy code moved as it was, andTakehas no production
caller (the request path usesPeekthenDropwith the read window).PriceIn.Pingsconcrete type (mine): rejected, reason accepted. No host needs another
sink today; an interface can come when one does.- Test debt before merge (reviewer 2's): not done yet, kept under Non-blocking above.
- design.md
- The new commit touches nothing else.
git diff 0569091d..d901ba6bchanges only
accrec/recorder_test.go(2 lines) anddocs/design.md(1 line). The rest of the PR is the
code I verified line by line in round 1; my round-1 trace of the move and of the finish
order still stands at this head. - I did not run tests or builds; this review is from reading the code only.
Signed-off-by: DAVID AMID <[email protected]>
|
Output of |
|
Approval check by hand: the approvals of
This PR's own changed lines did not change: The replay test |
Add two bullets to RELEASING.md section 3, by owner decision ("add both"):
write issue numbers in a PR body as "Refs #N" only, and freeze every
merge for a PR stuck in a merge-of-main loop.
Refs #1303, #1370, #1331
Assisted-By: Claude Opus 5.5
Signed-off-by: DAVID AMID <[email protected]>
…eze) (#1405) docs(release): tell the PR owner after every merge Add a bullet to RELEASING.md section 3: after every merge, send the PR owner one message in the same step. Owner decision (David Amid, 2026-11-25): "put the rule into the realsing.md file so other integrators on other machines would know it". Refs #1394, #1388 docs(release): add Refs-only and full-freeze merge rules Add two bullets to RELEASING.md section 3, by owner decision ("add both"): write issue numbers in a PR body as "Refs #N" only, and freeze every merge for a PR stuck in a merge-of-main loop. Refs #1303, #1370, #1331 Docs only. The owner approved the text and the merge with no review round, in the integrator session, 2026-11-25: "1405 merge". Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Refs #1303, #1309. Does not close #1303 (see "Left in the proxy").
Summary
The
savingsTrackermoves out ofproxy/intoaccrec.Recorder. The ping store moves toaccrec.PingStore. The proxy keeps the state file, the log lines, the metrics and the HTTP wiring.What changed
accrec.Recorder:Begin,End,Compute,ComputeSafe(fail open),Drop, thinking counts, the rescue-facts-missing counter, and the per-thread stores (trackers, siblings, billed tiers).accrec.Recorder.Price: the finish-time rules. It takes usage, status, rounds, the earlier no-result reason and the thread. It returns a result or a fallback reason (rejected_status,deferral_unplaced,compute_panicked). It also counts a request that followed pings and found no ping facts, and spends the ping facts it read.accrec.Recorder.SnapshotStateandRestoreState: the state format (StateFile, version 2) and the age rules.RestoreStatereturns what happened. The proxy logs it with the same lines as before.accrec.ThreadOf: thread id and parent mapping.accrec.PingStore: bounded map (4096), Put, Peek, Take, Drop, Priced.proxy/accountant_savings.go: a thin host type. It embeds the Recorder and keeps theUsageconversion.proxy/accountant_state.go: file I/O only (temp file, sync, rename, dedupe of unchanged writes, the periodic save).proxy/dashcapture.go: only the accountant block offinish(it callsPrice). Nothing else.Left in the proxy
capturejob flow (accBegin,accEnd,accWait,accRun): it is a goroutine and request state, not a decision.accEndNowandaccBilledTTL: PR fix(apply): count a free 1-hour ping in the cold check, from one cache-lifetime source #1357 edits lines in both. I left them as they are (accBilledTTLruns through theBeforeComputehook ofPrice). A later PR moves them after fix(apply): count a free 1-hour ping in the cold check, from one cache-lifetime source #1357 merges.dashEmitter.KeepAlivePingrow build: it is adash.Event, so it is display.Behaviour
None. The figures are the same. The side-effect order in
finishis the same: compute, event and metrics, rescue counter, ping-facts drop (Pricehas anAfterComputehook for the second step).Test edits (all mechanical, no assertion changed)
accountant_ping_test.go:put/take/drop/peekbecamePut/Take/Drop/Peek, andlen(st.m)becamest.Len(). The two tests of the store itself (TestPingStoreTakeDeletes...,TestPingStoreIsBounded) moved toaccrec/pingstore_test.go.accountant_wire_test.go:s.trackers = nilbecames.Trackers = nil(2 lines). The field is now the Recorder's.Data dependence
Same as before. The Recorder keeps hashes, sizes and token counts. It keeps no message text. No change at any storage level (off, metadata only, everything).
docs/data-dependence.mdneeds no edit.How it was tested
macOS, Go 1.27.4. Load average was about 380 during all runs.
go build ./...,go vet ./...,gofmt -l .: clean. Same with-tags cg_record.go test ./accrec ./proxy: pass.go test ./proxyapp ./cmd/cg-cache-campaign ./cmd/cg-selarm: pass, exceptTestNoHooksKeepsTheBinaryDefaults(known failure on origin/main).go test -race ./accrec: pass.go test -race ./proxy/.... I did not run it, because the load was above 50.proxy/accountant_replay_test.goreplays 6 requests on 2 threads, with a replayed change, a client edit and a save and restore between them. It compares a hash of each bookedResult. I took the hashes onorigin/mainbefore the move. The test passes on the moved code with the same hashes.accrec/recorder_test.go,accrec/pingstore_test.go.Price.TestPricefailed ("the ping facts the request read must be spent").TestPricechecks thatAfterComputeruns before the rescue counter and the ping-facts drop. Swapping the order fails it.StateMaxAge-time.Minute.TestStateRoundTripAndRefusalsfailed.Technical notes
Recorder.Trackers,ClientsandOnEndare exported so a host test can break or watch them.thinking,billed1handclientsas views of the Recorder's pieces, so existing host code and tests read them unchanged.