Repository navigation
Perf: Move the savings accountant off the request path - #1073
Conversation
accBegin and accEnd parsed and hashed the request body on the request goroutine, before the request went upstream. On a 670 KB body this cost 5.7 ms idle and 26 ms mean under load (issue #1059). accBegin now only notes the meta and the client body. accEnd starts one goroutine that opens the record and ends it. finish waits for that goroutine (accWait) before it prices the request, so a record is complete before it is priced. A panic in the job is recovered and the row is stored with no saving. Adds a guard test on a 24-tool-result body without -race. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 1 of 2 | 50b8a42cc781 |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no data loss, no broken fail-open path, and no missing test.
Non-blocking
-
proxy/accountant_wire.go:46 — the comment claims an ordering the code does not enforce.
- The comment says "a thread's next request arrives after the previous one was priced".
finishruns inserve's defer, after the response bytes are flushed to the client (proxy/proxy.go:2614-2617). The client can send the next request before that defer runs, so the next request can be processed, and even priced, first. - With the record now opened in the job goroutine, the begin/end order of two requests of one thread rests on scheduling, not on synchronization. The window is narrow: the job must be delayed past a full client round trip. The accountant library tolerates this by design (optimistic
Versionreplace,Result.Recomputed, R53 ininternal/engine/compute.goandstate.go), and concurrent same-thread requests could already interleave before this PR. - Fix: weaken the comment to say the order is usual, not guaranteed.
- The comment says "a thread's next request arrives after the previous one was priced".
-
proxy/proxy.go:1512 — stale comment. It says "The savings tracker begins HERE".
accBeginnow only notes the body;BeginRequestruns inaccEnd's job. Fix the wording. -
proxy/dashcapture.go:940 — stale comment. It says "accBegin never opened a record". Now the reason is that
accEndnever noted a request, or the job never ran. Fix the wording. -
proxy/accountant_async_test.go:66 — the test's premise is broader than what it measures. "What the request pays" measures
accBegin+accEndonly. The request goroutine also paysaccWaitinfinish, which waits for the whole job. That cost sits after the response is flushed, so it does not touch the first byte upstream (issue #1059's goal). The comment "what the request goroutine pays must be a small part" reads as if no other part exists. Say "what the request pays before the first byte goes upstream".
What I checked
- Read
CLAUDE.mdanddocs/design.mdin full. Read the full diff of all six files, and the code around each change. - The async handoff.
accEndbuilds a private capturewand copiesmeta,clientandops. The job goroutine writes onlyw's fields.accWaitreadswonly afterdoneis closed, so the channel close gives the happens-before edge. The request goroutine writesc.accJob,c.accOpen,c.accMeta,c.accClientandc.accPreDeferonly beforeaccEndor afteraccWait(proxy/accountant_wire.go:33-75, proxy/proxy.go:1524-1669).finishandaccEndrun on the same handler goroutine. I found no shared field without an ordering edge, so no data race. - Shared state.
savingsTracker.clientsis async.Map;PingStoreandsiblingStorehold mutexes (proxy/accountant_ping.go, proxy/accountant_shared.go). The job'spings.peekandsiblings.sharedWarmare safe against the keeper and other requests. - Body bytes. The job reads
origand the forwardedbody. AfteraccEndthe request goroutine only reads them (serve, the recorder, the prefix asker). Thegostatement gives the job visibility of all earlier writes. I found no in-place writer afteraccEnd. - Fail-open. A panic in the job is recovered in
accRunand costs the figure only (proxy/accountant_wire.go:82-91). This is stronger than before: the request is already on its way, and the old pre-forward recover is no longer reachable from accountant work.TestAccountantPanicOffThePathCostsTheSavingOnlypins it. - The drop path. A panic between
accBeginandaccEndstill callsaccDrop(proxy/proxy.go:1424), andaccOpen = falsemakes a lateraccEnda no-op (proxy/accountant_wire.go:49, proxy/dashcapture.go:925).accDropruns only beforeaccEndin production, so no job is left booked for a dropped request.TestAccDropForgetsTheClientHashcovers it. finishordering.accWaitis the first statement of the accountant block (proxy/dashcapture.go:775), before every read ofaccReq,accThread,accPingWindowandaccNoResult.finishruns before the--recorddefer sends the row, so a row still carries the priced result;TestUpstreamIsReachedBeforeTheAccountantFinishespins both halves. The/compactfinish(proxy/proxy.go:960) never pairs withaccBegin, so itsaccWaitis a no-op.- Figure stability.
meta.Atiscp.start, fixed at request start, soEndRequest,ComputeandsharedWarmsee the same times as before; only the wall-clock moment the library calls run moved.RequestIDis still taken ataccBegin, so ids stay in request order. - Library tolerance. Read
rossoctl/[email protected](internal/engine/state.go,compute.go).BeginRequesttouches no thread state;EndRequestandComputeuse optimisticVersionreplacement and markRecomputedwhen another request of the thread intervened. The new interleaving window falls inside what the library already handles. - Tests. Every test that read accountant results right after
accEndnow callsaccWait(accountant_ping_test.go:352, accountant_state_test.go:161, accountant_wire_test.go:307). All helpers the new file uses exist (accHandlerYAML,waitForRows,manyToolResultsRequest,benchBody,accTap.all). The new tests cover the four new behaviors: no wait, bounded pre-forward cost, panic isolation, row completeness. - Rules. No request-path behavior changes for users; only the timing of the accounting moved. No data-dependence change: the accountant still works from hashes and counts only. No sidecar code, no library/proxy boundary change.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 1 of 2 | 50b8a42cc781 |
approve |
Verdict: approve
Findings
None. The change is sound. The proof paths I checked:
- Fail-open holds.
accRunkeeps the recover from the oldaccBegin(proxy/accountant_wire.go:82-91). A panic in the job costs the saving only. The request is already on its way.TestAccountantPanicOffThePathCostsTheSavingOnlypins this. - No shared mutable state between the job and the request goroutine.
accEndbuilds a privatecapturewand copiessavings,provider,pings,accClient,accPreDeferinto it before the goroutine starts (proxy/accountant_wire.go:52-60). The job writes onlywfields.accWaitreads them after<-job.done, so the channel close gives the happens-before edge. The stores the job touches are mutex-guarded:PingStore(proxy/accountant_ping.go:20),siblingStore(proxy/accountant_shared.go:24), and the library'sTrackers("safe for concurrent use", engine/state.go:56).servenever mutates thebodybytes in place, so the job's concurrent parse ofclientandforwardedraces with reads only. - Every reader of
accReq,accThread,accPingWindow,accNoResultruns afteraccWait. I grepped all uses. They sit infinish(proxy/dashcapture.go:775-807), which callsc.accWait()first.accBilledTTLand the ping-window drop therefore see the finished record. The/compactpath (proxy/proxy.go:960) never callsaccBegin, so itsaccWaitis a no-op. - The drop path is correct.
accDropnow also clearsaccOpen, so anaccEndafter a drop is a no-op. The pre-forward recover (proxy/proxy.go:1417-1426) fires only beforeaccEnd, so no job is in flight when it runs.TestAccDropForgetsTheClientHashandTestAccBeginRecoversAndDropscover both. - Cross-request ordering. The next request of a thread can now begin before the previous one is priced, because
finishruns inserve's defer while the client may already send the next turn. The library handles this: each request holds its own state copy,Computedetects a version change and recomputes (Result.Recomputed, engine R53). So the figure degrades to "recomputed", never to a wrong sum. - Ping facts. The job's
peekandfinish'sdropkeep the window check from before (proxy/accountant_ping.go:67-76), so a newer ping still survives. The read moved from the request goroutine to the job, but the order inside the work (begin, then peek) is unchanged. - Reversibility and the wire are untouched. The accountant is a side figure. The forwarded body, the expand loop and the store are not on any path this PR changes.
Non-blocking
- proxy/accountant_wire.go:53-60 — a panic between
c.accJob = jobandgo func()leavesdoneunclosed.finish'saccWaitthen blocks forever, and the request loses its row and itscg.requestline. The only realistic trigger is an allocation failure in theopscopy, so the probability is near zero. The old code was worse: any panic inaccEnd's work reached the pre-forward recover and cost the rewrite. A cheap hardening: start the goroutine before you publishc.accJob, or letaccDropclearc.accJob. - proxy/dashcapture.go:773-774 — the comment is stale. It says "the client hash begin kept for end".
accBeginno longer keeps a hash; the job'sbegindoes, and the job's own paths remove it. Thedefer c.savings.drop(c.accReq)is now a belt-and-braces no-op in practice. - proxy/accountant_wire.go:46-47 — the doc comment overstates the ordering. "A thread's next request arrives after the previous one was priced" is not guaranteed:
finishruns inserve's defer, and the client can send the next request after the last response byte. The library tolerates the interleaving (R53), so the claim should say "the library recomputes" rather than promise an order. - proxy/accountant_async_test.go:143-163 — thin timing margin. The row becomes visible about
accountantDelay(2 s) afteraccEnd.waitForRowspolls 400 x 5 ms, also about 2 s. The pass margin comes mostly from the two SQLitePRAGMAqueries thatRecorder.Stats()runs per poll (dash/store.go:881). A smalleraccountantDelay(say 1 s) or a longer poll budget would remove the dependence on that incidental overhead. - PR body — no data-dependence statement. CLAUDE.md asks every PR that changes a feature to state its data dependence. This PR changes none (hashes and counts only, nothing new stored), so one line saying so is enough. The behavior change is named at the top, as the rule requires.
What I checked
- The full diff of all six files, line by line, plus the surrounding code:
proxy/accountant_wire.go,proxy/dashcapture.go(capture struct,finish,accDrop),proxy/proxy.go(the pre-forward closure at 1417-1670, bothfinishcall sites,serve's defer),proxy/accountant_savings.go,proxy/accountant_ping.go,proxy/accountant_shared.go. - The accountant library at the pinned version (v0.1.1-0.20261108152158-5181d50c1f98):
Trackers.BeginRequest,EndRequest,Compute, the R53 optimistic lock,Snapshotlocking. - Every use of
accBegin,accEnd,accWait,accDrop,accJob,accOpen,accMeta,accClient,accPreDefer,accThread,accPingWindow,accReq,accNoResultin non-test and test code. - The test helpers the new tests use (
accHandlerYAML,waitForRows,manyToolResultsRequest,accTap), and the timing margins of the two wall-clock tests. - The PR description (author's, not other reviews): the behavior change is named at the top; the owner's yes is still pending, which the PR itself states.
- No builds or tests were run; live tests are not approved for this review.
- Say the order of two requests of one thread is usual, not guaranteed. - Update comments that still described the old accBegin. - Publish the accountant job last in accEnd. - Give the handler test more time to see its row. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
|
Round 1 answers. Fixed in the new commit:
Assisted-By: Claude (Anthropic AI) [email protected] |
|
Integrator note. The owner approved the behavior change on 2026-11-11 ("1073 yes"), and called this the most critical PR of v0.7.3. It is next in line once these are fixed:
Then message the integrator session with the head. |
The savings record now ends in a background job, so the inject test must wait for it. The async test compares the upstream time with the moment the accountant ended, not with a fixed limit. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 2 of 2 | 5bb6aaa68ed9 |
approve |
Verdict: approve
Findings
None. The fixes are correct, and the new commits add no defect.
Earlier findings
All round-1 findings were non-blocking. None was rejected. Status:
- Ordering comment (reviewer 1, #1; mine, #3): fixed.
accEnd's doc now says the order of two requests of one thread is "usual, not guaranteed", and names the library'sResult.Recomputed(proxy/accountant_wire.go:46-49). This matches what the library does. - Stale comments (reviewer 1, #2 and #3): fixed. proxy/proxy.go:1531-1533 now says
accBeginonly notes the body andaccEndopens the record on another goroutine. proxy/dashcapture.go:941 now says "accEnd never noted a request, or the job opened none". - Ratio test comment (reviewer 1, #4): fixed. It now says "before the first byte goes upstream" (proxy/accountant_async_test.go:57-58).
accJobpublish order (mine, #1): fixed.c.accJob = jobmoved to the line before thegostatement (proxy/accountant_wire.go:59-61). Theopscopy and both allocations now run before the publish. Nothing that can fail sits between the publish and thego, sodonecannot be left unclosed by an enqueue panic.finishcomment (mine, #2): fixed. proxy/dashcapture.go:773-775 now says the job is joined first and describes the job'sbeginas the hash holder.- Thin test timing margin (mine, #4): fixed twice over. The row poll now runs up to 10 s (proxy/accountant_async_test.go:170-172), and 5bb6aaa removed the fixed limit entirely. See below.
- PR data-dependence statement (mine, #5): fixed. The PR body has a "Data dependence" section: "None changes. The accountant still works from hashes and counts only."
The new commits
e29be51 — review fixes. Comment fixes and the accJob publish move, verified above. No behavior change.
31a5f00 — merge of origin/main. The integrator asked for this merge. I checked it against an automatic merge: git merge-tree --write-tree e29be518 8b311f10 produces a tree identical to the merge commit's tree. So the merge has no hand resolution. The three main commits it brings (#1029, #1065, #1066) each carry their own approvals, named in their commit messages. The PR diff at the new base contains only the accountant change: proxy/proxy.go contributes 6 comment lines and nothing else. The interaction points are clean: #1029's agent usage reading feeds the same usage value finish prices, and #1066's refresh-clock changes sit outside the accountant block.
5bb6aaa — test speed independence. This answers the integrator's two CI failures at e29be51:
accountant_async_test.go:161failed with "the upstream saw the request 1.209 s after it was sent". The old check compared the upstream time withsentunder a fixed 1 s limit, so a slow pre-forward path on CI failed it without any waiting on the accountant. The new check comparesreachedwithaccountantDone, the moment the accountant's work ended (proxy/accountant_async_test.go:163-168). Runner speed delays both sides equally, so it cancels out. I traced both directions: with the async design,reachedsits one forward-hop afteraccEndwhiledonesitsaccountantDelay(2 s) after it, so the check passes with a wide margin however slow the runner is. With the old synchronousaccEnd, the work (and the 2 s sleep) completes before the forward, soreached >= doneand the test still fails. The regression guard is intact.accountant_inject_test.go:62failed with "the savings record never ended". The record now ends in the background job, so the test polls up to 5 s for it before it reads the record (proxy/accountant_inject_test.go:61-68). Correct fix; the assertions after the poll are unchanged.
Non-blocking
- proxy/accountant_async_test.go:176 and proxy/accountant_inject_test.go:82 —
tap.all()[0]can race the Tap. The recorder incrementsWrittenbefore it callsTap(dash/capture.go:549-559), both on the writer goroutine. A poll that observesWritten >= 1in the sub-microsecond window between the two can see an emptytap.all()and panic on[0]. The window is tiny and the pattern predates this PR (waitForRowsthentap.all()[0]), so I do not hold the PR for it. Alencheck before indexing, or Tap before the counter, would close it. - CI at the new head is still pending. At review time, trivy and DCO pass; build-test, purego, record and analyze are pending. I could not run the tests myself (live tests are not approved for this review). Both failures the integrator named are fixed by code reading, but green CI is the integrator's final check before merge.
What I checked
- Last review: round 1, 50b8a42, 2026-11-11T08:00:05Z.
- New commits read: 6 —
e29be518fix(proxy): Address review of the async accountant;31a5f003merge of origin/main;8b311f10feat(dash) #1065 (from main);62289d9afix(keepalive) #1066 (from main);d865b250feat(agent) #1029 (from main);5bb6aaa6test(proxy): Stop two accountant tests depending on runner speed. - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about them:
- The author's round-1 answers (08:08:32Z): checked each of the six items against the code. All fixed as stated.
- The integrator note (09:02:58Z): merge conflict — verified the merge exists and is automatic (merge-tree comparison, identical trees). CI failures at e29be51 — read both failing tests and the fixes in 5bb6aaa, traced the pass and fail directions of the new check. New review round — this review. The owner's approval of the behavior change is recorded in that note ("1073 yes").
- Commits e29be51, 31a5f00, 5bb6aaa: read the full diffs and the changed files around them (
proxy/accountant_wire.go,proxy/accountant_async_test.go,proxy/accountant_inject_test.go,proxy/dashcapture.go,proxy/proxy.go). - The PR diff at the new base
8b311f10..HEAD: 8 files, +274/−23. It contains only the accountant change; the agent refactor and the other main work stay in the base. - The recorder's write path (dash/capture.go:515-563) for the Tap-versus-
Writtenordering. - The PR body's Data dependence section.
- CI status at the head via
gh pr checks: pending, noted above.
- No builds or tests were run; live tests are not approved for this review.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 2 of 2 | 5bb6aaa68ed9 |
approve |
Verdict: approve
Findings
None. Both new commits are correct. Every round-1 finding is fixed.
Earlier findings
Mine, round 1:
- Ordering comment (accountant_wire.go:46) — fixed. The comment now says the order is usual, not guaranteed, and names
Result.Recomputed. This matches what I proved in round 1 from the library's R53. - Stale comment proxy.go:1512 — fixed. It now says
accBeginonly notes,accEndopens the record on another goroutine. - Stale comment dashcapture.go:940 — fixed. "accEnd never noted a request, or the job opened none".
- Test premise wording — fixed. The comment now says "before the first byte goes upstream (accBegin and accEnd; finish waits for the job later, after the response)".
Reviewer 2, round 1 (I checked each myself):
- A panic between
c.accJob = jobandgoleavesdoneunclosed — fixed.accEndnow publishesc.accJobimmediately before thegostatement, with nothing between (proxy/accountant_wire.go:58-63). The goroutine's first statement isdefer close(job.done), sodonecloses even ifaccRunpanics. I agree with the fix. - Stale
finishcomment — fixed (dashcapture.go:773-775). Same as my item 3. - Ordering comment — fixed. Same as my item 1.
- Thin timing margin in the handler test — fixed twice.
e29be518extended the poll to 10 s;5bb6aaa6went further and replaced the fixed limit with a comparison against the moment the accountant ended. CI ate29be518confirmed the margin was real ("the upstream saw the request 1.209 s after it was sent"). - PR body data-dependence line — fixed. The body now has a "Data dependence" section: "None changes. The accountant still works from hashes and counts only."
The integrator's note (a person's request):
- Merge main — done.
31a5f003mergesorigin/main(d865b250#1029,62289d9a#1066,8b311f10#1065). I verified the merge:git diff e29be518..31a5f003on all seven PR files is empty, so the merge changed none of this PR's code;git diff 8b311f10..HEAD -- proxy/proxy.gois the comment fix only. GitHub reports the PR mergeable. The three main commits carry their own two-review approvals, named in their commit messages. - CI failures at
e29be518— fixed in code, CI pending. Both failures came from tests that assumed the record ends before the response returns:accountant_inject_test.go:61-64now pollsgotfor up to 5 s before it reads the record. Correct: the record ends in the job, after the response.TestUpstreamIsReachedBeforeTheAccountantFinishesnow fails only when the upstream was reached at or after the accountant finished (reached >= done, accountant_async_test.go:165-168). A slow runner delaysreachedanddonetogether, so the assertion no longer depends on runner speed. I traced both the healthy path and a synchronous regression: a synchronousaccEndstill fails the test, so the guard stays meaningful.- CI at the head
5bb6aaa6is pending (build-test, purego, record). I could not run tests; live tests are not approved. The fixes are correct by reading.
- New review round — this review.
Non-blocking
- proxy/accountant_async_test.go:170-176 —
Written >= 1does not yet prove the tap holds the event. The writer goroutine runsr.written.Addbeforer.opts.Tap(e)(dash/capture.go:549-558). If the writer is preempted in that window, the test seesWritten >= 1andtap.all()[0]panics on an empty slice. The window is a few statements wide, so the risk is near zero. The same shape exists inwaitForRows(proxy/dash_test.go:166-176), so this is a pre-existing pattern, not a regression. Fix if desired: polllen(tap.all()) > 0instead ofStats().Written. - proxy/accountant_async_test.go:165 — the new comparison still has a runner-speed edge. A healthy runner whose pre-forward work takes more than
accountantDelay(2 s) reaches the upstream after the accountant ended and fails the test. The budget doubled against the old 1 s limit and CI passed at 1.2 s before, so the residual risk is small. A largeraccountantDelaywould remove it.
What I checked
- Last review: round 1, 50b8a42, 2026-11-11T07:59:57Z.
- New commits read: 6 —
e29be518fix(proxy): Address review of the async accountant;d865b250feat(agent) #1029 (from main, via the merge);62289d9afix(keepalive) #1066 (from main);8b311f10feat(dash) #1065 (from main, the new base);31a5f003merge of origin/main;5bb6aaa6test(proxy): Stop two accountant tests depending on runner speed. - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review: reviewer 2's round-1 review (approve, 5 non-blocking; I verified each fix above); the author's round-1 answers (6 items, all verified in the diff); the integrator note (3 items, all handled above); commits
e29be518,31a5f003,5bb6aaa6. - Read the full diff
50b8a42c..HEADon the PR's own files, and the base..head diff8b311f10..HEAD: accountant_wire.go, dashcapture.go, proxy.go, and the five test files. The PR-own proxy.go change is the comment fix only. - Verified the merge left every PR file untouched and that base..head contains only this PR's changes, so the merge adds no unreviewed code of this PR's authorship.
- Re-read the changed regions at head:
accEnd(publish-last),finish(accWait first), both changed tests. Checkeddash.Recorder.Stats().Writtenexists (dash/capture.go:424,467) and the tap wiring (dash.Options.Tap, called after the insert, dash/capture.go:557). - The PR body states the behavior change at the top, the owner's approval (integrator note), and the data dependence.
- No builds or tests were run; live tests are not approved. CI at head is pending; the two test fixes are correct by reading.
|
Integrator note: #1054 is now on main (43802c5). It adds the nil-by-default timing hooks |
|
Integrator recheck at 5bb6aaa: round-2 approvals are at this head, thank you. Two things are left:
If the merge needs a hand resolution in code, it needs one more GLM round on the new head. The owner pre-approved extra rounds. |
The conflict was in proxy/accountant_wire.go. Main (#1054) times accEnd on the request goroutine. accEnd is now the launcher, so it keeps that timing. accEndNow runs off the request path and is not timed. The two accountant tests now also wait for the tap, because the recorder counts a row just before it calls the tap. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 3 of 3 | ad1e7b8a4d8b |
approve |
Verdict: approve
Findings
None. The merge's hand resolution is correct, and it follows the integrator's instruction.
The new commits
27c0c40 (#1067) and 43802c5 (#1054) — from main. Both sit in the new base. Each carries its own two-review approvals, named in its commit messages. Neither changes this PR's files in the PR diff: git diff 43802c5a..HEAD holds only the eight accountant files. I read #1054 where it meets this PR, in full at head: the timing hooks in proxy/accountant_wire.go and proxy/dashcapture.go, and the spend guard in proxy/dash_test.go. #1067 touches apply/ and dash/ only.
ad1e7b8 — the merge, with the hand resolution. git merge-tree --write-tree 5bb6aaa6 43802c5a confirms only proxy/accountant_wire.go conflicted; every other file auto-merged. The resolution:
accBeginkeeps main'sdefer c.timed("accBegin")()and now measures the no-op note.accEndkeepsdefer c.timed("accEnd")()and now measures the launch only: the private capture, the ops copy, and the goroutine start (proxy/accountant_wire.go:30,51).accEndNow, the work on the job goroutine, carries no span. Correct: it is off the request path. No timed call exists on the job's private capture — I grepped everytimed(in the package; the job's path (accRun→accEndNow→accBilled/envelopeOpsFor/entryFacts/savings.end) has none, so no span from the job can pollute the guard's figures.accWaitsits insidefinish's span (defer c.timed("finish")()at proxy/dashcapture.go:591 wraps all offinish,c.accWait()inside it). Correct: the join is real work on the request goroutine, and the guard should see it. This is what the integrator asked for: "keep the hooks around the work that is still on the request goroutine."- The guard's
parentmap (accBilledTTL→accCompute→finish, proxy/dash_test.go:560) still matches reality: no span was added, removed, or renamed. The merge kept main'sdash_test.gobyte-identical (git diff 43802c5a..HEAD -- proxy/dash_test.gois empty), which is right, because the span set kept its shape. - Nil-safety holds:
timedreturnsnoopSpanfor a nil capture (proxy/dashcapture.go:56-60), so the hook before the nil check inaccBeginandaccEndis safe, the same pattern main used.
The merge also carries two test fixes, named in its message:
TestUpstreamIsReachedBeforeTheAccountantFinishesnow pollslen(tap.all())directly, notrec.Stats().Written(proxy/accountant_async_test.go:170-175).TestSavingsRecordEndsWithTheInjectedForwardedBodyadds a tap-wait loop afterwaitForRows(proxy/accountant_inject_test.go:82-85).
Both close the race from my round-2 note 1 and reviewer 2's: the recorder counts a row before it calls the tap (dash/capture.go:549-558), so Written >= 1 did not prove the tap held the event. The fix is correct.
Earlier findings
- All round-1 and round-2 items, mine and reviewer 2's: fixed and still fixed. The merge kept every comment fix (the "usual, not guaranteed" ordering comment, both stale-comment fixes, the test-premise wording, the publish-last
accJob, the PR body's data-dependence line). - My round-2 note 1 (tap race): fixed by the merge, above.
- My round-2 note 2 (the
accountantDonecomparison fails on a runner slower than 2 s pre-forward): still open, minor. CI has passed on both heads since; the risk is small. A largeraccountantDelaywould remove it.
The integrator's sign-off request: the merge commit ad1e7b8a carries Signed-off-by. The DCO check passes.
Non-blocking
- proxy/dash_test.go:637-643 — the capture check "leaves the accountant out" only partly now. The check skips
accBegin,accEnd,accBilledTTLandaccCompute, but the accountant's join remainder now sits insidefinish's span, which it does not skip. Counting it is semantically right:accWaitis real request-goroutine work. But the 25 ms budget (dash_test.go:640) now absorbs an amount that varies with the job's remaining work atfinishtime. Therecordjob passed./proxy/...under-raceat this head (ok proxy 444.440s), so the budget held. A passing run does not print itst.Logfmedian, so the margin is unknown to me. If this check flakes later, giveaccWaitits own span and add it to the skip list, or raise the budget with a fresh measurement.
What I checked
- Last review: round 2, 5bb6aaa, 2026-11-11T09:16:23Z.
- New commits read: 3 —
27c0c406fix(dash): count the fixed_restore copy in the saved figure (#1067, from main);43802c5atest(proxy): time the dashboard's own work on the request goroutine (#1054, from main);ad1e7b8amerge of origin/main with the hand resolution. - Read in full: 4 reviews, 4 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about them: reviewer 2's round-2 review (approve; I read it and agree with its verification, including its merge-tree check); the integrator comment at 09:16:35Z (#1054 is on main; keep the hooks on request-goroutine work; the guard's parent map must follow the span nesting — all three followed, see above); the integrator comment at 09:32:59Z (merge main again, sign the merge, one more round for a hand resolution — all three done); the three commits.
- The hand resolution: read the full
git diff 43802c5a..HEADonproxy/accountant_wire.go,proxy/dashcapture.go,proxy/limitheaders.go, and the three test files; readtimed/timedSpan/spendHook(dashcapture.go:37-61),finish's span (line 591) withaccWaitinside it, the whole spend guard (dash_test.go:496-648) includingdashboardSpends, theparentmap, both budgets, and the helpersfakeUpstreamUsageanddashHandler; grepped everytimed(call in the package to confirm the job goroutine has none. - The merge mechanics:
git merge-tree --write-tree 5bb6aaa6 43802c5a(one conflict,proxy/accountant_wire.go);git diff 43802c5a..HEAD --stat(the eight PR files only);git diff 43802c5a..HEAD -- proxy/dash_test.go(empty). - CI at the head, read only: purego pass; record (
go test -race -tags cg_record ./proxy/...) pass,ok proxy 444.440s, downloaded and read its job log; build-test (make cover, also-race) still pending at review time. Therecordjob already runs the same proxy tests under-race, so the resolution is exercised. No tests were run by me; live tests are not approved.
finish joins the accountant's job (accWait). That wait is the accountant's cost, which the max-content latency test leaves out. Its work ran inside accEnd before, and accEnd was left out. It now runs in accWait, so accWait is left out too, and its time is taken out of finish. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 4 of 4 | dc8a9407b799 |
approve |
Verdict: approve
Findings
None. The new commit is correct, and the merge resolution follows the integrator's instruction.
The new commits
ad1e7b8 — merge of origin/main, with a hand resolution. I ran git merge-tree --write-tree 5bb6aaa6 43802c5a myself. It reports one conflict, in proxy/accountant_wire.go, the file the integrator named. I read the resolved file in full at HEAD:
accBeginkeeps main'sdefer c.timed("accBegin")()and measures the no-op note only (proxy/accountant_wire.go:30).accEndkeepsdefer c.timed("accEnd")()and measures the launch only: the private capture, the ops copy, the goroutine start (line 51). This is what the integrator asked: hooks stay on the work that is still on the request goroutine.- The job goroutine's path (
accRun→accEndNow→accBilled→envelopeOpsFor→entryFacts→savings.end) carries notimedcall. I grepped everytimed(andtimedSpan(in the package. No span from the job can pollute the guard's figures. accBilledTTLis called from one place only, proxy/dashcapture.go:842, inside theaccComputespan thatfinishopens at line 827 and closes at line 852. The guard'sparentmap (accBilledTTL→accCompute→finish) matches reality.- The merge commit carries
Signed-off-by, as the integrator asked. DCO passes at HEAD.
The merge also brings the two tap-race fixes both reviewers raised in round 2: accountant_async_test.go now polls len(tap.all()), and accountant_inject_test.go waits for the tap after waitForRows. Both are correct: the recorder counts a row before it calls the tap, so polling the tap closes the window.
27c0c40 (#1067) and 43802c5 (#1054) — from main. Both sit in the new base. Each carries its own two-review approvals, named in its commit messages. I read their full diffs as they entered this branch. The PR diff at the new base holds only the accountant change: 9 files, and git diff 43802c5a..HEAD -- proxy/dash_test.go is the 4-line delta of dc8a940 and nothing else.
dc8a940 — accWait as its own span. This answers reviewer 1's round-3 note. I verified each part:
accWaitnow opensdefer c.timed("accWait")()before its nil check (proxy/accountant_wire.go:70).timedreturnsnoopSpanfor a nil capture, so the hook before the nil check is safe, the same pattern asaccBeginandaccEnd.- The guard's
parentmap gains"accWait": "finish"(proxy/dash_test.go:560). The nesting is real:accWaitis called only fromfinish(proxy/dashcapture.go:824), insidefinish's span, so the join's time is taken out offinishand counted once, under its own name. - The max-content check adds
accWaitto its skip list (proxy/dash_test.go:643). So that check now leaves out the whole accountant:accBegin,accEnd,accWait,accBilledTTL,accCompute. The main check skips none of them, so it still counts all dashboard work, the join included. This matches the two checks' documented split: the join is the accountant's cost (#1059), not capture work. - The commit message's claim checks out: before this PR, the accountant's work ran inside
accEndon the request goroutine, andaccEndwas already on the skip list. The work now runs in the job, and the join runs inaccWait. SkippingaccWaitkeeps the same coverage.
Earlier findings
- My round-1 and round-2 items: all fixed before, all still fixed at HEAD. I re-read the resolved
proxy/accountant_wire.go: the "usual, not guaranteed" ordering comment (lines 47-49), the publish-lastaccJob(lines 59-61), and the accEnd/accWait structure are intact. The PR body still opens with the behavior-change section and carries the Data dependence section. - My round-2 note on the tap race: fixed by the merge's test fixes, above.
- Reviewer 1's round-3 note 1 (accWait inside finish's span, not skipped by the capture check): fixed by dc8a940, above. I checked it myself; the fix is the right one.
- Reviewer 1's round-3 round-2 note 2 (the
accountantDonecomparison fails on a runner slower than 2 s pre-forward): still open, minor, unchanged by the new commits. CI passed at the two heads before this one, so the risk stays small.
Non-blocking
- proxy/dash_test.go:496 — the doc comment's list of timed calls is now short. It names "the accountant's accBegin and accEnd, finish".
accBilledTTL,accComputeand nowaccWaitare also timed, and the comment does not name them (the nesting note at line 500 covers only accBilledTTL and accCompute). The maintenance rule below the comment is the load-bearing one, so this cannot mislead a careful reader. AddingaccWaitto the nesting note would close it. - CI at HEAD is pending. CodeQL, analyze, DCO and trivy pass; build-test, purego and record are pending at review time. The two new commits touch only test accounting and a one-line span, and the merge's resolution is exercised by the proxy suite, so I expect green. Green CI stays the integrator's final check before merge.
What I checked
- Last review: round 2, 5bb6aaa, 2026-11-11T09:16:16Z.
- New commits read: 4 —
27c0c406fix(dash): count the fixed_restore copy in the saved figure (#1067, from main via the merge);43802c5atest(proxy): time the dashboard's own work on the request goroutine (#1054, from main via the merge);ad1e7b8amerge of origin/main with the hand resolution;dc8a9407fix(proxy): Time the wait for the accountant as its own span. - Read in full: 5 reviews, 4 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about them:
- Reviewer 1's round-2 review (09:16:23Z): read; its round-1 fix checks agree with mine.
- Integrator comment 09:16:35Z (keep the hooks on request-goroutine work; the parent map must follow the span nesting): verified both in the merge resolution and in dc8a940, above.
- Integrator comment 09:32:59Z (merge main again; sign the merge; one more round for a hand resolution): merge done at ad1e7b8, Signed-off-by present, DCO pass; this review is the round it asked for.
- Reviewer 1's round-3 review (10:02:40Z): read in full; re-ran its merge-tree check myself and confirmed its span-nesting claims by reading the code.
- Commits 27c0c40, 43802c5, ad1e7b8, dc8a940: read the full
git diff 5bb6aaa6..HEAD(all files) andgit show dc8a9407; readproxy/accountant_wire.goandproxy/dashcapture.goin full around every change.
- The span set at HEAD: grepped every
timed(,timedSpan(andspendHookuse in the package; confirmedaccWaitandaccBilledTTLeach have exactly one production call site, both insidefinish's span, matching the guard'sparentmap. - The PR diff at the base:
git diff 43802c5a..HEAD --stat(9 accountant files);git diff 43802c5a..HEAD -- proxy/dash_test.go(the dc8a940 delta only). - The PR body: behavior-change section at the top and a Data dependence section, both still present.
- CI at HEAD via
gh pr checks: 4 pass, 3 pending, noted above. - No builds or tests were run; live tests are not approved for this review.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 4 of 4 | dc8a9407b799 |
approve |
Verdict: approve
Findings
None. The commit is correct, and it fixes my round-3 note as proposed.
The new commit
dc8a940 — fix(proxy): Time the wait for the accountant as its own span. Three lines: accWait gains defer c.timed("accWait")() (proxy/accountant_wire.go:70), the guard's parent map gains "accWait": "finish" (proxy/dash_test.go:560), and the capture check's skip list gains "accWait" (proxy/dash_test.go:643). What I verified:
- The span reaches the guard.
timedgoes throughtimedSpan, which loadsspendHook(proxy/dashcapture.go:46-61). The hook indashboardSpendstherefore sees anaccWaitcall. - The nesting is always true. The only non-test call site of
accWaitis proxy/dashcapture.go:824, insidefinish, whose span starts at line 591. So"accWait": "finish"never misparents. A secondaccWaitcall, and the/compactpath, findaccJobnil and measure about zero (proxy/accountant_wire.go:71-76). - Nil-safety. The hook sits before the nil check, the same pattern as
accBeginandaccEnd. A nil capture returnsnoopSpan(proxy/dashcapture.go:56-61). - The main check keeps its figure. The hook counts
accWait's duration in the sum and subtracts the same amount fromfinish. SoTestDashboardAddsNoRequestLatencyWithContentCapture, which skips nothing, totals the same as before this commit. A runaway join on a small body still fails it. - The exclusion is right for the capture check. The join is the accountant's cost: the same work the check has always left out, first inside
accEnd, now insideaccWait's join. It runs inserve's defer, after the response is flushed, so it adds no client-visible latency. The accountant's growth with body size stays tracked byTestRequestPathCostDoesNotGrowWithBodySize. The commit message states this rationale, and I agree with it. - No production cost.
spendHookis nil in production, so the span costs one atomic load (proxy/dashcapture.go:37-41). No user behavior change. - Hygiene. The commit carries
Signed-off-byand theAssisted-By:line. DCO passes.
Earlier findings
- My round-3 non-blocking note 1 (the capture check's 25 ms budget absorbs the
accWaitjoin, with an unknown margin): fixed, exactly as the note proposed — a span of its own, plus the skip list and the parent map entry. - My round-2 note 2 (the
accountantDonecomparison fails on a runner slower than 2 s pre-forward): still open, minor. Unchanged by this commit. CI has passed on every head since. - All round-1 and round-2 items, mine and reviewer 2's: fixed and still fixed. Nothing in this commit touches them.
Non-blocking
- proxy/dash_test.go:516 — the comment is now stale. It says the capture check "leaves the accountant out (accBegin, accEnd, accBilledTTL and accCompute)". The check now also leaves out
accWait, and the comment does not name it. Fix: addaccWaitto the list. The example at line 520 ("accBilledTTL in accCompute in finish") could also nameaccWaitinfinish, but that is optional.
What I checked
- Last review: round 3, ad1e7b8, 2026-11-11T10:02:40Z.
- New commits read: 1 —
dc8a9407fix(proxy): Time the wait for the accountant as its own span. - Read in full: 5 reviews, 4 comments, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about them: the commit
dc8a9407only. No new comments exist — the last comment stays at 09:32:59Z, before my round-3 review. Reviewer 2 has posted no round-3 review. The round-3 reviews now in the file are mine (already known) and nothing else new. - The commit: read the full
git diff ad1e7b8a..HEAD; readaccWaitat head (proxy/accountant_wire.go:68-81),timed/timedSpan/spendHook(proxy/dashcapture.go:37-61),finish's span at line 591 with theaccWaitcall at line 824, and the whole guard inproxy/dash_test.go(the comment block,dashboardSpends, both budgets, both checks). Grepped every non-testaccWaitandtimed("finish")call site to confirm the nesting claim. - The PR scope at the new head:
git diff 43802c5a..HEAD --stat— 9 files, +282/−26. The only change past the round-3 head is the 3 lines of this commit, inproxy/accountant_wire.goandproxy/dash_test.go. - CI at the head, read only: purego pass (3m25s), CodeQL, analyze, trivy and DCO pass; build-test and record pending at review time. The prior head
ad1e7b8apassed the same proxy tests under-race(record:ok proxy 444.440s), and this commit's delta is one timed call and one skip-list entry, which purego already compiled and ran green. No tests were run by me; live tests are not approved.
…ts (#1112) The agentmodel tests (from #1074) now wait for the detached summary call before they count the upstream's calls, with a time limit. Since #1073 the summary call runs off the request path, so a fixed check raced it and failed now and then in CI (TestOpenAISummaryCallTargetIsUnchanged, TestMalformedAgentModelTargetKeepsTheHostDefault). Test only. Behavior change: none. Data dependence: none. Fixes #1110. Reviews: 2 offload review rounds (Claude backend). Round 2: both approve at 0b3a6a0, which is the PR head. Signed-off-by: Vitaly Zabershinsky <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
…tests (#1132) The agentmodel tests wait for the detached summary calls before they count them. Since #1073 the summary call runs off the request path, and #1112's drain waits only for summaries already in flight, so "none started yet" passed as "none in flight". Each test that counts summary calls now waits through testutil.WaitForState (#1122) for the wanted call, with a 30 s bound, after first waiting for any summary an earlier test left running. The want-0 tests keep one read after the drain. The failures were not reproduced locally (0 in 7,000 runs before and after), so the race is inferred from the code. CI failed on these tests 3 times on 2026-11-12, on PRs that did not touch them. Behavior change: none (one test file). Data dependence: none. Fixes #1110. Reviews: 2 offload review rounds (GLM). Round 2: both approve at 3ad22bd, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Behavior change (needs a human yes before merge)
The accountant work now runs on its own goroutine. `finish` waits for it before it prices the request. So a row still has its saving when it is written. The cost moves from before the upstream call to `finish`, which runs after the response. If the work is slow, `finish` can wait for it.
Problem
`accBegin` and `accEnd` parsed and hashed the request body on the request goroutine. The request went upstream only after they finished. On a 670 KB body (24 tool results) this cost 5.7 ms idle and 26 ms mean under load. Closes #1059.
Change
The accountant library is not changed.
Tests
New tests are in `proxy/accountant_async_test.go`. Each failed before the change.
Three existing tests changed because `accBegin` no longer does work: `TestAccBeginRecoversAndDrops`, `TestAccDropForgetsTheClientHash` and the ping test.
Results: `go test ./proxy/` passed. A `-race` run of the accountant, ping, savings and dashboard tests reported no data races. I did not re-measure the issue's timings on the eval box.
Data dependence
None changes. The accountant still works from hashes and counts only. Nothing new is stored.
Assisted-By: Claude (Anthropic AI) [email protected]