Repository navigation
fix(dash): seed seen models, per-model tier and 2xx recency on restart - #996
Conversation
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.321 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 347f66d9f3c3 |
blocking |
Verdict: blocking
Findings
- dash/capture.go:860 — seedModels counts failed rows, so a model used only by failed requests is no longer a cold start after a restart
- What fails: a thread has 2xx rows on model B and only failed rows on model A. The proxy restarts. The next request on model A is a miss. It reads
unknown(orttl_expiry), notcold_start. No cache entry was ever written on A, socold_startis the true verdict. The live path agrees: it labels this requestfirst_on_model→cold_start. - Proof:
seedModels(capture.go:859-860) has no status filter, so it seedsseenModel["t1\x00A"] = truefrom the failed rows.AttributeCachegivescold_startonly when!seenModel(event.go:1057), so the seeded flag removes it. The live path corrects this case with thefailedKeymarker (prefixcause.go:116-122), but that marker lives inlastFacts, which a restart clears — so the correction cannot fire. The comment at capture.go:856 claims "ObservePrefix still reads first_on_model after a failed one"; after a restart that claim does not hold. Before this PR,seenModelwas not seeded at all, so the restart path readcold_startand matched the live label by accident. - Fix: filter
seedModelsto 2xx rows (status >= 200 AND status < 300), as the recency seed now does. Add a test: rows on model A all failed, restart, next request on A readscold_start.
- What fails: a thread has 2xx rows on model B and only failed rows on model A. The proxy restarts. The next request on model A is a miss. It reads
Non-blocking
seedModelscan return more than 1,000 tenant+model keys on a busy multi-tenant proxy.observe()then clears the wholeseenModelmap on the next request (capture.go:655-657), wiping the seed for every model. The cap is pre-existing; the seed only raises the odds of hitting it.- No test covers two smaller new rules: a failed 1h write must not seed the tier, and a keep-alive ping must not seed
seenModel. The SQL does both correctly. - This PR changes attribution labels across restarts (that is its purpose). Repo rules say the PR must name the behavior change at the top and have a human's approval. I did not read the PR body in round 1, so I cannot confirm it is named there.
What I checked
- Read the full diff (5 files) and the code around each change:
dash/capture.go(Recorder fields,pruneSessionsLocked,SeedSessions,seedModels,seedOneHourTiers),dash/prefixcause.go(ObservePrefix), and the newdash/restartseed_test.go. - Traced the key rules end to end:
- The 2xx filter in the recency seed: a failed row no longer re-dates a thread; the thread falls back to its latest 2xx row. Matches
TestRestartSeedRecencyIgnoresAFailedRequestand the live rule (ObservePrefix commits only 2xx). - The per-model tier key:
seedTierkeys arethread.Key(session, thread) + "\x00" + modelon both the write side (capture.go:901) and the read side (prefixcause.go:97,108).thread.Key(internal/thread/thread.go:49) uses the same separator, so the keys agree. - The fork path:
perModelappendscur.Modelin both the own-thread and the parent lookup, so a fork on model B cannot read the parent's model-A tier. The!same && !hadAnyguard keeps live facts above the seed. write1h >= writewithwrite > 0in the seed matchesFactsOf(prefixcause.go:50).- The
ROW_NUMBERwindow function matches the style already used in dash/keepalive.go and kvcache.go; modernc.org/sqlite supports it.idisINTEGER PRIMARY KEY AUTOINCREMENT(schema.go:59), so theORDER BY ts DESC, id DESCtiebreak is valid.idx_requests_tscovers the ts-bounded scans. seedTierpruning by age uses the write time, which is inside the 2-hour seed window; the wholesale 20,000-entry reset still covers it.
- The 2xx filter in the recency seed: a failed row no longer re-dates a thread; the thread falls back to its latest 2xx row. Matches
- Checked the callers:
SeedSessionsruns once at startup (cmd/context-guru-proxy/main.go:427);ObservePrefixis called from proxy/dashcapture.go:713 withcommit = 2xx, and the new test helperturnOnmirrors that call. - Checked the updated tests (cachecost_test.go, thread_test.go, grace_test.go): each restart row that must seed now carries
Status: 200, consistent with the new filter. - Data dependence: unchanged. All three seeds read the
requeststable (ids, timestamps, token counts, status) — metadata only, same as before. - I did not run builds or tests; live tests are not approved for this review.
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.321 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 347f66d9f3c3 |
approve |
Verdict: approve
Findings
None. I traced every changed path and found no wrong behavior introduced by this commit.
Non-blocking
- dash/prefixcause.go:112 — a request on another model after the restart drops the seeded tier. The mask is
seededTier && !same && !hadAny.hadAnyis thread-wide, so one post-restart request on model B erases the seeded 1h tier of model A. Trace: 1h write on A at T0, restart, one request on B, then a miss on A at T0+20 min. Result:model_changedwith a 5-minute TTL. Without a restart the live rule keepslastFacts[key+"\x00"+A]and readsunknownwith the 1h TTL. This hole predates the PR (the old thread-level seed had the same mask) and the PR narrows it, so I do not block. Recommend a follow-up issue. - dash/capture.go:848 — the seed can be wiped at once on a busy proxy.
SeedSessionsnow fillsseenModelfrom the database.observe()clears the whole map when it passes 1000 entries. A proxy with more than 1000 distinct tenant+model pairs in the 2-hour window gets its seed discarded by the first request after the restart, so the fix silently does nothing there. The PR lists the wipe as out of scope. Note the new interaction in that issue. - dash/capture.go:760 — the comment "One indexed group-by at startup" is stale.
SeedSessionsnow runs three queries (recency, tiers, models). Words only.
What I checked
- Read
CLAUDE.mdanddocs/design.md. The change is dash-only, metadata-only (status, timestamps, model ids, token counts). The PR states this and names the behavior change at the top, as the repo rules require. - Read the full diff and the code around each change:
dash/capture.go,dash/prefixcause.go, and the caller inproxy/dashcapture.go(observe at line 666,ObservePrefixat line 713 withcommit = 2xx). - Key shapes verified:
seedTierkeys arethread.Key(session, thread) + "\x00" + model, the same keyObservePrefix'sperModelbuilds;seedModelskeys aretenant_id + "\x00" + model, the same keyobserve()builds; the fork lookup mirrors thelastFactsfork fallback. - Traced each new test in
dash/restartseed_test.goby hand againstObservePrefixandAttributeCache. Each one fails without its piece, as claimed: the per-model key (a thread-level key would leak A's 1h tier to B), the fork lookup, the seen-model seed, and the 2xx recency filter. - Checked that all other tests that call
SeedSessions(cachecost_test.go,thread_test.go,prefixcause_test.go,grace_test.go) store rows with a 2xx status where the seed must find them. The three updated tests are exactly the ones that neededStatus: 200. - Checked the prune paths:
seedTierages by its own write time, which is always older than the matchinglastFactstimestamp, so the seed never outlives the facts it stands in for. The wholesale reset clears it with the others. - Checked the SQL: the window function needs SQLite 3.25+; the driver is
modernc.org/sqlitev1.56.0, which bundles a newer SQLite. Thetsfilters can useidx_requests_tsandidx_requests_tenant. - The 2xx-only recency seed diverges from the live path, where
observe()runs before the status is known and re-dateslastSeenon a failed request. The seed direction is the more correct one (a failed request wrote no entry), and the PR documents it. I found no reader that needs any-status recency. - Live tests were not approved, so I did not run them. I verified the test code by reading it, not by execution.
SeedSessions now also: - seeds seenModel from the models in the seed window, so the first request on a known model is no longer a cold_start; - seeds the billed tier per thread and model, and a fork reads its parent's tier; - takes recency from the latest 2xx row, as SeedGraceSessions does. Closes #994 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
347f66d to
de3e0b1
Compare
|
Round 1 replies. New head is the one this comment follows. Reviewer 1, blocking (seedModels counts failed rows). Fixed. Reviewer 1, non-blocking.
Reviewer 2, non-blocking.
|
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.321 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | de3e0b106932 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed and verified. The new commit introduces no defect I can show.
Round-1 findings
- Fixed —
seedModelscounts failed rows (mine, blocking).- The query now filters
status >= 200 AND status < 300(capture.go:860). The comment no longer claims live parity through thefailedKeymarker; it states the true reason.TestRestartSeedsNoModelFromFailedRowscovers it. I traced the test: with the filter, model A stays unseeded and the request readscold_start; without it,seenModel[A]is true and the verdict falls through tounknown. The test distinguishes.
- The query now filters
The other reviewer's round-1 findings
- prefixcause.go:112, one request on model B drops model A's seeded tier — rejected by the author, and I accept the reason. I checked the mask myself:
seededTier = seededTier && !same && !hadAny, andhadAnyis thread-wide. Keeping the tier past a request on another model needs a seeded per-model write time and prompt size, which is the fulllastFactsseed the PR deliberately does not build. The hole predates the PR and is named under Out of scope with a follow-up issue. Not a blocker. - capture.go:848, the 1000-entry
seenModelwipe — out of scope, accepted. The cap is older and unchanged. The new interaction (a seed larger than 1000 keys is wiped by the first request) is named under Out of scope in the PR body. - capture.go:760, stale "one indexed group-by" comment — fixed. The comment now says "Three queries at startup".
Non-blocking
- One residual label divergence remains by design: a thread with a 2xx row on model A and a later failed row on A reads
first_on_model(cold_start) on the live path, but not after a restart, because the failed marker lives inlastFactsand is not seeded. The restart direction is the more accurate one (the 2xx write's entry may still exist). Same class as the out-of-scope item above; noting it for the follow-up issue.
What I checked
- Last review: round 1, 347f66d, 2026-11-09T19:44:05Z
- New commits read: 1 (
de3e0b1fix(dash): seed seen models, per-model tier and 2xx recency on restart — the squashed PR commit with the round-1 fixes folded in) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (19:47:26Z, approve, 3 non-blocking items) — read in full; checked each item against the code and the author's reply.
- The author's round-1 reply comment (20:10:35Z) — read in full; verified every claim it makes (see below).
- Commit
de3e0b1— read the full diff since347f66d9(2 files: capture.go, restartseed_test.go) and the final state of each changed hunk.
- Verified the fix:
seedModels(capture.go:858-874) now filters to 2xx, and the corrected comment matches the code. - Traced each new test by hand against
observe(),ObservePrefixandAttributeCache:TestRestartSeedsNoModelFromFailedRows— fails without the 2xx filter, as claimed.TestRestartSeedsNoModelFromAPing— the ping row gets status 200 from the helper's default, so only thekeepalive = 0filter keeps model A unseeded; the test covers that filter.TestRestartFailedOneHourWriteSeedsNoTier— without the status filter inseedOneHourTiers, the failed 1h write would seed the tier and the 20-minute miss would readunknown, notttl_expiry. The test distinguishes.
- Verified the author's other replies against the PR body (read in full via the API): the behavior-change block is at the top with who, old and new behavior, and the switch; data dependence is stated as metadata only; the 1000-entry wipe and the model-B tier drop are named under Out of scope.
- Confirmed the full PR diff (base
8c12384e..de3e0b1) is exactly my round-1 diff plus the round-2 delta; nothing else moved. - I did not run builds or tests; live tests are not approved for this review.
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.321 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | de3e0b106932 |
approve |
Verdict: approve
Findings
None. The fix for reviewer 1's blocking finding is correct, and the new tests cover it.
Earlier findings
- Reviewer 1, finding 1 (seedModels counted failed rows) — fixed. I checked it myself.
seedModelsnow filtersstatus >= 200 AND status < 300(capture.go:867). I traced why the filter is the right rule, not just a patch: live, a failed request still setsseenModel, butObservePrefix'sfailedKeymarker then labels the next request on that modelfirst_on_model→cold_start(prefixcause.go:116-122, event.go:1057). A restart clears that marker, so an any-status seed would have readunknown. The 2xx seed gives the same verdict as the live path. I also traced the other row kinds: a ping never marksseenModellive (keepalive = 0in the query, pings never callobserve()), and a status-0 row sets the marker live, socold_startis the matching seed verdict there too. - Reviewer 1, non-blocking (1000-entry wipe): not fixed, named under Out of scope in the PR body, with the new interaction spelled out. Accepted. The cap is older than this PR.
- Reviewer 1, non-blocking (missing tests): fixed.
TestRestartFailedOneHourWriteSeedsNoTierandTestRestartSeedsNoModelFromAPingadded. I traced both below. - Reviewer 1, non-blocking (behavior-change block): confirmed. I read the PR body; the behavior-change block is at the top.
- My round-1 non-blocking (prefixcause.go:112 mask): rejected by the author, and I accept the reason. The reason: returning only
prevOneHour = truewould not match the in-memory result, because themodel_changedpath also needs the per-model write time (for the gap) and the previous prompt size. That matches the code — the switch'shadAnybranches returnprevOneHour = falseandgapMs = -1(prefixcause.go:139-141), so a mask change alone fixes nothing. It predates the PR and is now named under Out of scope as a follow-up. - My round-1 non-blocking (stale "one indexed group-by" comment): fixed ("Three queries at startup").
- My round-1 non-blocking (seed wiped at 1000 entries): not fixed, same Out-of-scope entry as reviewer 1's. Accepted.
What I checked
- Last review: round 1,
347f66d9f3c3cfa28176fcf87411909a6570ca70, 2026-11-09T19:47:26Z. - New commits read: 1. The branch was rewritten:
de3e0b10replaces347f66d9(same title, amended content). I readgit diff 347f66d9..HEADin full. The delta is two files: theseedModels2xx filter plus comment indash/capture.go, and three new tests indash/restartseed_test.go. I also re-read the full diff against the base to confirm nothing else moved. - 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:
- Reviewer 1's round-1 review (blocking on
seedModels). Checked the fix and the reasoning myself, as above. - The author's round-1 replies comment (2026-11-09T20:10:35Z). Verified each claim: the filter, the two new tests, the comment fix, and the two Out-of-scope entries in the PR body.
- The rewritten head
de3e0b10. Reviewed its delta as a first review, below.
- Reviewer 1's round-1 review (blocking on
- The three new tests, traced by hand:
TestRestartSeedsNoModelFromFailedRows: model A has only a 500 row, so the seed skips it and the request readscold_start. Under the round-1 query it readunknown, so the test fails without the filter.TestRestartSeedsNoModelFromAPing: model A has only a ping row, excluded bykeepalive = 0. Readscold_start, matching the live rule that pings never mark a model seen.TestRestartFailedOneHourWriteSeedsNoTier: the thread's 1h write is a 500, soseedOneHourTiersskips it and the tier stays 5 minutes. The miss at 20 minutes readsttl_expiry. Without the 2xx filter in that query the tier would read 1h and the test would fail.
- The
seedModelscomment's new claim (the live path labels a failed-only modelfirst_on_model"through a marker that a restart clears") is accurate against prefixcause.go:116-122. - Live tests were not approved, so I did not run them. I verified the tests by reading them, not by execution.
|
Behavior change approved by a human developer. The repo owner (@amiddavid) approved the behavior change of #996 in the authoring session on 2026-11-10, in these words: "I approve". |
…1014) TestDashboardAddsNoRequestLatencyWithContentCapture failed on loaded CI runners (on #930, #971, #996, #1010) because one pass of 40 paired samples was too noisy for the 45 ms budget. It now measures the guard in up to 3 rounds, and passes as soon as one round is in budget; a real slowdown fails all 3. Closes #1013. Behavior change: none. Test only (proxy/dash_test.go). Data dependence: none. Known limit (older than this PR): under heavy load, a 50 ms delay in capture.finish does not fail the test; filed as its own issue. Reviews: 2 offload reviews (GLM), round 2, both approve at 2fbb429. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Behavior change — needs a human developer's yes
--dashboardon. Only the first requests after the restart.cold_start. New:hit, or the real miss reason. A model never seen in the window still readscold_start./modelswitch gave the new model the old model's tier, and a fork read 5 minutes. New: per thread and model, and a fork reads its parent's tier.cold_start(no entry exists).ttl_expiryis no longer hidden).Closes #994
Summary
Recorder.SeedSessionsnow fixes three restart gaps. Data dependence: metadata only (model ids, timestamps, status, token counts). No row indocs/data-dependence.mdchanges.What changed
seenModelis seeded fromSELECT DISTINCT tenant_id, modelin the window: non-ping rows with a 2xx status. A model with only failed rows stays unseeded, so it readscold_startas in the live path.seedTieris keyed by thread + model and holds the write time.ObservePrefixreads it for the request's own model, and for the parent thread when the thread is a fork. The age prune and the wholesale reset treat it likelastFacts.ROW_NUMBER() OVER (PARTITION BY session_id, thread_id, model). The rule is theFactsOfrule: 2xx, non-ping,cache_write > 0,cache_write_1h >= cache_write.status 2xxto both halves.SinceLastMs, thekaRefreshedAtage cut andObserveThreadFrommeasure from a request that wrote the entry. The grace uses its own clock (graceSeen), unchanged. No reader needs any-status recency.Status: 200.How it was tested
dash/restartseed_test.go: known model readshitand notcold_start; unknown model readscold_start;/modelswitch does not leak the tier; fork inherits the 1h tier; failed request after the last write readsttl_expiry. Each fails without its piece.go test -race ./dash/...passes (split^Test[A-J]and^Test[K-Z]).go test -race ./proxy/...passes.go vetandgofmtare clean.SCAN r+SEARCH r2 USING INDEX idx_requests_session. New tier query:SCAN requests USING INDEX idx_requests_session+TEMP B-TREEfor the window. New model query:SCAN requests USING INDEX idx_requests_tenant+TEMP B-TREE FOR DISTINCT.Out of scope
seenModelwipe at 1000 entries (observe()). It is older and unchanged. New interaction: a proxy with more than 1000 tenant+model keys in the window loses the seed on its first request.model_changed(5 minutes), not the in-memoryunknown(1h). Fixing it needs a seeded per-model write time and prompt size. This was true before the PR. Follow-up issue.Assisted-By: Claude (Anthropic AI) [email protected]