Repository navigation
fix(dash): session-state follow-ups from #770 - #775
Conversation
Five follow-ups from the session-state change (#770), none blocking: 1. The janitor's "could not archive, so delete" branch now has a test (TestEvictFallbackDeletesSessionAndAliasState), mutation-checked. 2. Deleting or archiving a session now removes the state rows under its content-derived alias too (cg:seen:, cg:ttl: are keyed by the alias), so they no longer outlive the session until the 30-day retention. An alias another live session still uses — by its session_alias column or by a headerless session whose own id IS the alias — is kept. 3. DropOldestSessions picks its victims once and removes exactly that set. The delete used to re-run the ordering subquery itself, so a request landing between the pick and the delete could change the order, and the state cleanup then acted on a set other than the one deleted. 4. DeleteSessionState checks rows.Err(): a scan that fails midway now returns the error instead of silently deleting less. 5. docs/data-dependence.md: extract_llm_sweep removed from "Rows to confirm"; both confirmations are recorded on #770. Data dependence: no change (this deletes more, it stores nothing new). Behavior change: none that a user sees, apart from fewer leftover rows. Written by GLM (rits/zai-org/glm-5-3) through Claude Code Assisted-By: GLM 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 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.312 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 0ad62817ca25 |
blocking |
Verdict: blocking
Findings
-
dash/store.go:958 — the in-use guard covers only the alias direction, not the victim's own id
- What fails: a seesaw-id conversation (header on some turns, absent on others) has rows under two ids. The header rows carry
session_alias; the headerless rows have the alias AS theirsession_id. When the headerless turns stop and the header turns continue, the headerless session becomes the oldest. The janitor evicts or archives it.deleteSessionState(victim)then runs with no in-use check and removescg:seen:andcg:ttl:under the alias. The live header session reads those keys on every turn, so its next turn reads them as absent, decides the cache is cold, and pays a cache-write of the whole suffix — the exact mechanism the code comments price at −$708 (apply/apply.go:577-593). It self-heals after one turn. - Proof: apply/apply.go:600-627 reads
aliasSeenandsessionTTLunder the alias on every turn, and loads them from disk first; proxy/dashcapture.go:587-611 and dash/capture.go:505-511 record the alias on header turns, so those state rows stay fresh while the headerless session's request rows age. The new guard (deleteAliasState, dash/store.go:438-457) protects state under an alias read by others, but the three call sites that delete a victim's own state — dash/store.go:958-960, dash/archive.go:344, dash/janitor.go:381 — never check whether the victim's id is still in use as another session's alias. The guard query already answers this: after the victims' rows go,SELECT COUNT(*) WHERE session_alias = ?counts the live header session's rows, because they carry the victim id as their alias. - Fix: before
deleteSessionState(id), run the same in-use check on the victim's own id (count rows withsession_alias = idafter the delete). Keep the state when another session carries it, asdeleteAliasStatealready does.
- What fails: a seesaw-id conversation (header on some turns, absent on others) has rows under two ids. The header rows carry
-
dash/store.go:1040 — the tenant row-quota path still deletes sessions with no state cleanup
- What fails: a deployment with
MaxRowsPerTenantset and no cold storage trims an over-quota tenant throughDropOldestSessionsOfTenant. That path deletes request rows only. The session's state rows survive under its own id and under its aliases until the 30-day state retention. This is the exact leak #772 describes ("state outlived the session until retention"), on the one delete path the follow-up did not touch. It predates this PR, but the PR's own contract —deleteSessionState's comment: "removes the session's rows from the session_state table, when a session is archived or deleted here" — is false on this path. - Proof: dash/janitor.go:202-204 routes
remote == niltoDropOldestSessionsOfTenant; dash/store.go:1028-1053 contains nodeleteSessionStateorsessionAliasescall. The PR adds the cleanup to the other three delete paths (dash/store.go:940-965, dash/archive.go:337-344, dash/janitor.go:374-381). - Fix: read the aliases before the delete and call
deleteSessionStateper dropped session, asDropOldestSessionsdoes. The loop's one-session-per-pass shape makes this a two-line change per pass.
- What fails: a deployment with
Non-blocking
- No index on
requests.session_alias.deleteAliasState's count (session_alias = ? OR session_id = ?, dash/store.go:443) can useidx_requests_sessionfor thesession_idarm only. Thesession_aliasarm is a full table scan, once per alias, on the writer goroutine, during eviction passes. An index onsession_alias(or one count for the whole batch) would remove the scan. DropOldestSessionsbinds one placeholder per victim (dash/store.go:953). The disk rule computesdrop = sessions / 10(dash/janitor.go:287). Above roughly 327,000 sessions the IN list passes SQLite's 32,766-variable limit, and eviction then fails on every pass. Extreme scale today, but a cap on the batch size makes it unreachable.sessionAliasesswallows errors silently (dash/store.go:469-471, 476). A failed query or scan returns nil with no log, and the alias state stays until retention.deleteAliasStatelogs the same situation; this should too.
What I checked
- The full diff, and the code around each change:
DropOldestSessions,deleteSessionState,deleteAliasState,sessionAliases,ArchiveSessionFull,evictSessions,DeleteSessionState. - The alias model end to end: how
SessionAliasis recorded (proxy/dashcapture.go:603-612, dash/capture.go:498-512), how it is derived (apply/apply.go:553-627, session/session.go:151), and who reads state under it. store.DeleteSessionStateagainstStatePrefixes,globalPrefixesandboundaryOK, and the fake driver instore/disk_delstate_test.goagainst those rules (BilledPrefix is first; both fake keys pass the boundary check; the pointer receiver onNextis needed and correct).- The four new tests against the helpers they use (
openTestDB,putState,archiveRecorder,failPut,oldestLocalSessions), and the victim selection each one implies. - All four session-delete paths in the dashboard, including the tenant-quota path the PR does not touch.
- The PR description for the behavior-change and data-dependence statements (both present).
- I did not run builds or tests: live runs 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.312 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 0ad62817ca25 |
blocking |
Verdict: blocking
Findings
-
dash/store.go:443 — the alias in-use check is one full table scan per alias, and the disk rule can run thousands of them on the writer goroutine
- What fails: the filesystem passes the high watermark →
relieveDiskPressuresetsdrop = sessions / 10(dash/janitor.go:287) →DropOldestSessions(drop)picks that many victims →sessionAliasesreturns up to one distinct alias per victim →deleteAliasStaterunsSELECT COUNT(*) FROM requests WHERE session_alias = ? OR session_id = ?once per alias. No index starts withsession_alias(dash/schema.go:273-304), and theORstops SQLite from usingidx_requests_session, so every call is a full scan ofrequests. The repo's own measurement puts a full scan of this table at 2.0 s over 1.58 M rows (dash/store.go:903-907). A database with ~50 k sessions therefore spends ~5 000 × 2 s ≈ 2.8 hours inside one janitor pass.janitorPassruns on the single writer goroutine (dash/capture.go:547), so during that time no batch is written and the capture channel drops every event it receives. The same per-candidate scan also runs inevictSessions(dash/janitor.go:376-381) when cold storage is configured — that path's rclone work is bounded by a 60 s context, butdeleteAliasStatetakes no context and is not bounded by it. - Proof: the query at dash/store.go:443; the index list in dash/schema.go:273-304 (no
session_aliasindex);drop := int(sessions / 10)at dash/janitor.go:287;case <-prune.C: r.janitorPass()on the writer goroutine at dash/capture.go:547; the measured 2.0 s / 1.58 M-row scan at dash/store.go:903-907. - Fix: answer all in-use checks with one query —
SELECT session_alias FROM requests WHERE session_alias IN (…) GROUP BY session_aliasover the alias list, then delete the ones absent from the answer. Or add an index onsession_aliasthroughadditiveDDL, likeidx_requests_project(dash/schema.go:664).
- What fails: the filesystem passes the high watermark →
-
dash/store.go:1028 —
DropOldestSessionsOfTenantstill deletes whole sessions without deleting their state, the exact defect this PR fixes in the other two delete paths- What fails: a tenant over its row quota with no cold storage →
trimTenantToQuotacallsDropOldestSessionsOfTenant→ the loop at dash/store.go:1040-1050 runs onlyDELETE FROM requests. It never callsdeleteSessionState, so the session's own state rows and the state under its aliases stay for the full 30-day state retention.deleteSessionState's own doc names this the defect: "without removing it a deleted session's state outlived it until retention (#772)". The retention prune does not clean it either (dash/store.go:422-424,TestPruneKeepsSessionState). The PR closed this hole inDropOldestSessions,evictSessionsandArchiveSessionFull, and left the fourth destructive path open. - Proof: dash/store.go:1040-1050 — no
deleteSessionStateorsessionAliasescall anywhere in the function;git show a834c746:dash/store.goconfirms the base is the same, so this is a pre-existing hole, but the PR is the follow-up whose purpose is to close exactly this class. - Fix: before each delete, read the session id the subquery will remove (one
SELECT session_id … LIMIT 1, same shape as the delete's own subquery) plussessionAliases(id), then calldeleteSessionState(id, aliases…)after the delete — the same shape asDropOldestSessions.
- What fails: a tenant over its row quota with no cold storage →
Non-blocking
- dash/store.go:953 — bind-variable ceiling.
DropOldestSessionsnow binds one placeholder per victim (placeholders(len(victims))); modernc.org/sqlite caps a statement at 32 766 variables.drop = sessions / 10, so above ~327 k sessions the delete fails with "too many SQL variables" and the disk rule stops for that pass. The old code bound one variable (LIMIT ?). Chunk the IN list if that scale is real. - dash/store.go:967 — a failed pick now reads as an empty table.
oldestSessionIDsswallows its error and returns nil;DropOldestSessionsthen returns(0, nil), andrelieveDiskPressurelogs "nothing left to evict". The old code deleted anyway, because its delete re-ran the subquery. The new direction is safer, but the error is masked — returning it would tell the operator why the disk rule did nothing. - dash/sessionstate_test.go:215 —
stateRowsForcounts withLIKE '%<id>%'. An id that is a substring of another id over-counts. The current test ids are safe; a future id pair likesess-old/sess-old-2would not be. - dash/store.go:443 — the untested half of the in-use check. The tests cover "another session's rows carry the alias". No test covers "a live session's own id IS the alias" (the
session_id = ?half, the headerless-turn case the comment at dash/store.go:434-437 names). - docs/data-dependence.md:216 — the row still says "A row lives 30 days after its last write". An eviction or an archive can now end an alias-keyed row earlier. One sentence would cover it.
What I checked
- The full diff
a834c746..HEAD, and the code around every hunk. DropOldestSessionsend to end: pick, probe seam, alias read, delete, state cleanup. Traced the old subquery-based delete against the new picked-set delete, and confirmed the regression test indash/droprace_test.gofails on the old code (the probe re-dates the victim, so the old delete removedsess-livewhile the state cleanup acted onsess-victim).deleteAliasStateandsessionAliasesagainst the schema: thesession_aliascolumn (dash/schema.go:103), which indexes exist, the<> session_idand<> ''exclusions, and the headerless-turn case.- All three destructive delete paths that now clean state (
DropOldestSessions,evictSessions' fallback branch,ArchiveSessionFull), plus the two paths that share aliases across candidates — the delete ordering keeps a shared alias until its last user goes, in both the batched and the per-candidate form. - The fourth destructive path (
DropOldestSessionsOfTenant) against the base commit — finding 2. store.DeleteSessionState: the newrows.Err()check, its fail direction (keeps rows, retention bounds them), and the fake-driver test — tracedStatePrefixesorder,boundaryOKon both fake keys, and thedatabase/sqlpath (QueryerContext, non-EOFNexterror surfacing throughrows.Err()).- All callers of every changed function (
DeleteSessionState,deleteSessionState,DropOldestSessions,ArchiveSessionFull) — nothing outsidedashandstorecalls them. - Concurrency: the janitor and the inserts share one writer goroutine, so the count-then-delete window in
deleteAliasStatehas no in-process writer; the store's own flush goroutine writes onlysession_state, notrequests. - The three new tests traced statement by statement against the schema and the helpers (
putStatewrites 2 rows per id; victim ordering byMAX(ts); the archive-failure path throughevictOldestSessions). - The
docs/data-dependence.mdedit: it only movesextract_llm_sweepout of "Rows to confirm"; the storage levels are unchanged. - I did not run builds or tests — live tests are not approved for this review.
Both round-1 reviews on #775 were blocking; this answers them. 1. A victim's own id gets the same in-use guard as its aliases. A headerless session (its session_id IS an alias) evicted while the header session sharing that alias is live used to lose cg:seen: and cg:ttl: that the live session still reads. Now both halves are checked before any state key goes: rows carrying it as session_alias, or a live session whose own id IS it. 2. DropOldestSessionsOfTenant deletes state with the rows, through the same guard. The tenant row-quota trim was the one session-delete path that left state behind. 3. The in-use check is no longer one full-table scan per alias on the writer goroutine. idx_requests_session_alias is added on open (old databases get it too, like idx_requests_project), and one pass answers all its in-use checks with TWO queries over the whole key list, not one query per key. 4. Every IN (...) list is bound in batches of 500 ids: the disk rule can ask for a tenth of all sessions at once, past SQLite's 32,766-variable statement limit. 5. A failed victim pick or alias read now returns its error instead of reading as "nothing left to evict", and stateRowsFor-style checks match exact keys. docs/data-dependence.md says an eviction or an archive can end a state row before its 30 days. Data dependence: no change (this deletes more, it stores nothing new). Behavior change: none that a user sees, apart from fewer leftover rows. Written by GLM (rits/zai-org/glm-5-3) through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]>
|
Round-2 answers to both reviews, in commit Blocking1. The victim's own id had no in-use guard (Reviewer 1, dash/store.go:958). Fixed.
So a headerless victim whose id is a live header session's alias keeps New test 2. Fixed. Each pass now picks the victim by id first ( New test 3. One full-table scan per alias on the writer goroutine (Reviewer 2, dash/store.go:443). Both halves done:
New test Non-blocking (all done)
VerificationOn the eval box, against
|
Main moved ahead through #773 (the mod's Ping-button change), which conflicted with this branch in one place: docs/data-dependence.md, where #773 grew the keep-alive row next to the row this branch edits. The resolution keeps both: main's keep-alive row (the sentence about the cache-state answer carrying the next planned ping) and this branch's session-state row (an eviction or an archive can end a row before its 30 days). Nothing else was changed; every other file merged cleanly. No behavior change: the merge only combines docs text and already-merged main code. Written by GLM (rits/zai-org/glm-5-3) through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]>
|
Merged What the merge resolved: one file,
Nothing else was hand-resolved. Every other file from #773 merged cleanly, unmodified. No behavior changed. The merge only combines docs text with main's already-merged #773 code; this branch's code is untouched by it. Verification after the merge (eval box, fresh copy):
CI on |
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.312 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 434b2322b553 |
blocking |
Verdict: blocking
Both round-1 findings (mine and Reviewer 1's) are fixed, and every non-blocking point too. The fix commit left one new gap in the fail-safe direction of the rewritten guard, below.
Findings
- dash/store.go:471 —
inUseIDsdoes not checkrows.Err(), so a scan that fails midway deletes state a live session still reads- What fails:
inUseIDsreads its answer withfor rows.Next() { … }and thenrows.Close()— norows.Err()check (dash/store.go:471-477). If the driver fails the scan midway (an I/O or BUSY-class error; the janitor'sreadCtxiscontext.Background, so cancellation is not a cause), the loop ends early and every key the scan did not reach reads as not in use.deleteSessionStatethen callsstore.DeleteSessionStateon those keys, which removescg:seen:andcg:ttl:under an id a live session reads every turn. That session's next turn reads the cache as cold and pays a cache-write of the whole suffix — the exact cost the guard exists to prevent. This is the unsafe direction, and it breaks the function's own contract: "An unreadable answer says every key is in use — keeping rows is the safe side" (dash/store.go:444-446). TheQueryerror path honors that contract (dash/store.go:460-469); only the scan-error path does not. - Proof: the loop at dash/store.go:471-477 has no
rows.Err(), against two checks this same PR added for the same failure class:sessionAliases(dash/store.go:504-507, same commit) andstore.DeleteSessionState(store/disk.go:195-200, whose comment says "a scan that fails midway… the caller must hear about the failure rather than take the partial delete for the whole one"). In those two the partial answer deletes too little; here it deletes too much. The trigger is rare, but the PR's own bar treats this class as a defect. - Fix: after the
rows.Next()loop, checkrows.Err(); on error, mark every key in use (the existingQuery-error branch), log once, and return — three lines.
- What fails:
Non-blocking
- dash/store.go:966 — stale comment.
DropOldestSessions's doc still says "One statement, so one transaction." The delete is now chunked into up to⌈victims / 500⌉statements (dash/store.go:992-1000). A failed chunk also returns before the state cleanup, so earlier chunks' victims keep their state until retention — the safe direction, but the comment no longer describes the code. - The age-rule archiver runs on its own goroutine (dash/capture.go:263-270), so
ArchiveSessionFull's delete and the writer's inserts can interleave with the janitor's in-use count. The window is the same one-turn, self-healing class the design doc already documents for restarts, and state is best-effort by contract. Not new in this PR; noting it because my round-1 "no in-process writer" reasoning covered the janitor, not the archiver.
Earlier findings — status
- Reviewer 1, finding 1 (the victim's own id had no in-use guard): fixed.
deleteSessionState(sessions, aliases)now puts the victims' own ids and their aliases in one key list and keeps any key a request row still uses, in either direction (dash/store.go:427-440,inUseIDsat 447-481). I tracedTestEvictionKeepsStateOfAHeaderlessVictimend to end: victimshdr-aliasandv-old, keys[hdr-alias, v-old, live-alias]; after the delete,hdr-live's rows carryhdr-aliasassession_aliasandlive-alias's rows carry it assession_id, so both stay;v-oldgoes. The assertions match that trace exactly. - Reviewer 1, finding 2 and my finding 2 (
DropOldestSessionsOfTenantleft state behind): fixed. Each pass now picks the victim by id, reads its aliases, deletes by id, and calls the guardeddeleteSessionState(dash/store.go:1098-1121). The pick-then-delete-by-id shape also closes the re-pick mismatch on this path.TestTenantQuotaTrimDeletesSessionStatedrives it throughtrimTenantToQuotawith no remote — the exact route from the finding. - My finding 1 (one full-table scan per alias on the writer goroutine): fixed, both halves.
idx_requests_session_aliasis created inadditiveDDL2, which runs afteraddColumns(dash/schema.go:950-982), so old databases get it too —TestOpenAddsSessionAliasIndexverifies the reopen.inUseIDsanswers all in-use checks with two chunkedIN (…)queries instead of one COUNT per key;deleteAliasStateis gone. Both queries are index lookups now. - All non-blocking points: fixed.
sqlChunk = 500caps every bound list, withTestDropOldestSessionsChunksTheVictimListexercising three batches plus a partial one (I checkedchunkStringskeeps the partial chunk).oldestSessionIDsandsessionAliasesreturn their errors;DropOldestSessionsandDropOldestSessionsOfTenantpropagate them, the archive paths log and continue.stateRowsForcounts exact keys. The data-dependence row now says an eviction or an archive can end a row early. - The merge
434b2322: brings in #773 and resolves one conflict indocs/data-dependence.md. I verified every #773 file in the merge is byte-identical to85919a8f(empty diff), and the docs resolution keeps both rows — main's keep-alive sentence and this branch's session-state sentence. No code changed in the merge.
What I checked
- Last review: round 1,
0ad62817ca25aa28dcb3cd327d27201e3941e120, 2026-10-29T18:50:46Z - New commits read: 2 —
dc3a888afix(dash): state cleanup on every session-delete path (#775 review);434b2322merge: origin/main into chore/session-state-followups - Read in full: 2 reviews, 2 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt) - New items since my last review: the author's round-2 answer comment (checked every claim against the code — all hold except the one gap above); the merge comment (verified as above); commit
dc3a888a(full diff plus the code around every hunk); the #773 content that entered through the merge (confirmed identical to main, so it is not this PR's change) - The rewritten
deleteSessionState/inUseIDs/sessionAliasesagainst the alias model: whatputStatewrites, which rows carry which id, and the seesaw-id cases in both directions. DropOldestSessionsOfTenant,DropOldestSessions,evictSessionsandArchiveSessionFullend to end at the new head, including the chunked deletes and the error paths.- The DDL phase order in dash/schema.go (additiveDDL → addColumns → additiveDDL2), confirming the new index is safe on databases that predate the
session_aliascolumn. - All five new/changed tests traced statement by statement: the chunk test, the headerless-victim test, the tenant-quota test, the index test, and the exact-key
stateRowsFor. - Concurrency:
NewRecorder's goroutines (writer, countLoop, archiveLoop) against the guard's count-then-delete window — the archiver is the one concurrent requests-row writer, noted under Non-blocking. - I did not run builds or tests — live tests are not approved for this review. The author's eval-box tables are their claims; I verified what the code can show.
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.312 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 434b2322b553 |
blocking |
Verdict: blocking
Both round-1 blocking findings are fixed and I verified the fixes line by line. One small gap remains in the new code, below.
Findings
- dash/store.go:471 —
inUseIDsignores a scan that fails midway, and then fails toward deleting live state- What fails: the in-use check opens its query, then iterates
rows.Next()with norows.Err()check and skips keys whoseScanfails (dash/store.go:471-477). A driver error during the iteration ends the loop early, so keys that ARE in use read as unused.deleteSessionStatethen deletes the state under them, and a live session reads cold on its next turn — the same consequence as round-1 finding 1. This breaks the function's own contract: "An unreadable answer says every key is in use — keeping rows is the safe side" (dash/store.go:444-446). The code honors that only when the query fails to OPEN (line 460), not when it fails midway. The PR fixed exactly this failure class instore.DeleteSessionStatein this same diff (therows.Err()check, store/disk.go:195-200), so the standard is the author's own. - Proof: dash/store.go:471-477 — the loop closes
rowswithout readingrows.Err(); a mid-scan error is indistinguishable from a complete answer. Likelihood is low (local SQLite, indexed IN query), and this path runs under disk pressure, where I/O errors are least exotic. - Fix: after the loop,
if err := rows.Err(); err != nil— log once, mark every key in use, and return, exactly like the query-open branch.
- What fails: the in-use check opens its query, then iterates
Earlier findings
- Mine 1 (victim's own id had no in-use guard): fixed.
deleteSessionState(sessions, aliases)(dash/store.go:427-440) now checks the whole key list throughinUseIDs, which covers both directions: rows carrying the key assession_alias, and a live session whose own id IS the key. I tracedTestEvictionKeepsStateOfAHeaderlessVictimstatement by statement: victimshdr-alias(headerless) andv-old;hdr-live's rows carryhdr-aliasas their alias andlive-aliasis a live session's own id, so both keys stay whilev-old's state goes. The scenario I described in round 1 now keeps its state on all four delete paths. - Mine 2 (tenant row-quota path had no state cleanup): fixed.
DropOldestSessionsOfTenant(dash/store.go:1088-1121) now picks the victim by id, reads its aliases before the delete, deletes by id, and calls the guardeddeleteSessionState. This also removes the re-picking subquery there, so the #772 pick-versus-delete mismatch cannot happen on this path either.TestTenantQuotaTrimDeletesSessionStatedrives it throughtrimTenantToQuotawithremote == nil, the route I flagged. - Reviewer 2, finding 1 (one full scan per alias on the writer goroutine): fixed, and I agree.
idx_requests_session_aliasis added inadditiveDDL2(dash/schema.go:665-670), whichmigrateruns on both the fresh and the already-at-version path, afteraddColumns(dash/schema.go:947-984) — so an old database gets it, whichTestOpenAddsSessionAliasIndexpins.deleteAliasStateand its per-alias count are gone;inUseIDsanswers the whole list with two chunked queries. - Reviewer 2, finding 2: same as my finding 2. Fixed.
- Non-blocking points (both reviews): all addressed. Chunked
INlists (sqlChunk/chunkStrings, dash/store.go:1030-1045, withTestDropOldestSessionsChunksTheVictimList);oldestSessionIDsandsessionAliasesnow return errors and callers propagate or log them;stateRowsForcounts exact keys; the untestedsession_idarm of the in-use check now has a test;docs/data-dependence.mdsays an eviction or an archive can end a state row early. I verified each in the code.
Non-blocking
sqlChunkis a package-level var the chunk test mutates (dash/droprace_test.go:27-29). Safe today because no dash test callst.Parallel()(I checked). A future parallel test would race it. A parameter or at.Setenv-style guard would make that impossible.- First open after upgrade builds
idx_requests_session_aliasover the wholerequeststable — a few seconds on a 1.58 M-row database, once, at startup. Inherent to adding any index; noting it so the one-time startup pause is not a surprise.
What I checked
- Last review: round 1, 0ad6281, 2026-10-29T18:50:04Z
- New commits read: 2 —
dc3a888a(fix(dash): state cleanup on every session-delete path),434b2322(merge of origin/main).85919a8f(#773) arrived through the merge; it is main's already-merged code, not this PR's change. - Read in full: 2 reviews, 2 comments, 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 (posted after mine): read in full; its findings overlap mine and its scan-cost finding I re-verified against the new code.
- The author's round-2 answer comment: checked every claim against
dc3a888a— the fix shapes, the tests, the index placement, the DDL phase ordering. - The merge note comment: verified the merge by diff —
git diff 85919a8f..HEAD --stattouches only this PR's 9 files, and thedocs/data-dependence.mdrow carries both main's keep-alive sentence and this branch's eviction sentence. No other file was hand-resolved. - Commit
dc3a888a: read the full diff and the code around each hunk —deleteSessionState,inUseIDs,sessionAliases,chunkStrings,DropOldestSessions,DropOldestSessionsOfTenant, the archive and janitor call sites, the schema change, and the five new or changed tests, each traced against the helpers and victim ordering they imply.
- Concurrency and defaults:
NewRecorder(Options{})opens an in-memory database with no remote; the janitor's quota rule is off with no quota set and the 7-day default retention does not touch the test's 48-hour rows; the recorder's writer goroutine receives nothing in that test. - I did not run builds or tests: live runs are not approved for this review. The author's eval-box runs are quoted in the round-2 answer; I read them but verified nothing by execution.
Both round-2 reviews blocked on one finding: inUseIDs closed its rows without checking rows.Err(), and skipped a failed Scan silently. A scan that fails midway ends the loop early, so the keys it did not reach read as unused, and deleteSessionState then deleted state a live session still reads — the unsafe direction, and the one the function's own contract forbids. Both failure modes now take the same path as a query that fails to open: log once, mark every key in use, return. Two fake-driver tests cover them; each fails at 434b232 and catches its own mutation. Also: DropOldestSessions' comment no longer says "one statement, so one transaction" — the delete is chunked, and a failed chunk returns before the state cleanup, so earlier chunks' victims keep their state until retention (the safe direction). Left as is, said on the PR: the age-rule archiver runs on its own goroutine, so its delete can interleave with the janitor's in-use count. That window is old, self-healing within one turn, and state cleanup is best-effort by contract. Data dependence: no change (this deletes less on a failure, it stores nothing new). Behavior change: none that a user sees. Written by GLM (rits/zai-org/glm-5-3) through Claude Code Assisted-By: GLM Signed-off-by: DAVID AMID <[email protected]>
|
Round-3 answers to both reviews, in commit The finding:
|
| Run | Result |
|---|---|
gofmt -l dash store, go vet ./dash/... ./store/... |
clean |
Both new tests, -count=1 |
pass |
The full session-state / drop / janitor / quota / archive suite, -count=1 |
pass |
Both new tests at 434b2322 |
fail by assertion (one state delete ran on each failure mode) |
| 2 mutations (rows.Err() guard removed, Scan guard removed) | both caught, each by its own test |
go test -race -count=1 ./store/... ./dash/... |
pass (33.1 s / 580.5 s) |
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.312 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 3 | ee7778745e07 |
approve |
Verdict: approve
The round-2 finding is fixed, on all three failure modes, with a test per mode. Nothing new is broken. No findings.
Earlier findings — status
- Round-2 finding (mine, and Reviewer 1's identical one):
inUseIDsignored a scan that fails midway. Fixed. One sharedgiveUpclosure now holds the contract for every way the answer can break: the query fails to open (dash/store.go:472-475), a row fails toScan(dash/store.go:481-485), and the scan ends early (dash/store.go:491-495). Each path closes the rows, logs once, marks every key in use, and returns. The unsafe direction — a partial answer reading a live session's key as unused — is gone. The doc comment states all three modes now (dash/store.go:445-446). - The stale "one statement, so one transaction" comment: fixed.
DropOldestSessions's doc now says the delete runs in chunks, one transaction each, and that a failed chunk returns before the state cleanup so earlier chunks' victims keep their state until retention (dash/store.go:985-988). That matches the code. - The archiver-goroutine note: left as is, and I accept the reason. The window predates this PR, self-heals within one turn, and state cleanup is best-effort by contract —
deleteSessionState's own doc and the data-dependence row both say state is rebuilt from traffic. Closing it would serialize the archiver behind the writer for a one-turn cache re-write. The trade is right.
What I checked in the new commit
dash/inusefail_test.go, both tests traced againstdatabase/sqlsemantics.TestUnreadableInUseAnswerKeepsAllState: the fake yields one clean row ("k-live"), then a non-EOFNexterror;rows.Err()returns it,giveUpfires, zero state deletes. At434b2322the partial answer{k-live}letsk-gonethrough tostore.DeleteSessionState, whose fakesession_statelisting returnscg:bin:k-gonewith a clean end so the round-1 scan guard does not stop it — one DELETE runs, and the test fails by assertion.TestUnscannableInUseRowKeepsAllState: astruct{}{}value failsScaninto*string, followed by a cleanio.EOFend, so only the Scan guard can catch it —rows.Err()is nil by design. At434b2322the row is skipped silently and one DELETE runs. Both mutation proofs in the author's comment are coherent with this trace. The honest note about the out-of-contractdriver.Valueis correct: no in-contract value fails that Scan, so this is the only way to reach the guard, and it is defense in depth.giveUpitself: it marks every key in use, including keys earlier chunks already answered — conservative, the safe side.warnedmakes the log once per call.rows.Close()runs on every exit path. No double close, no leaked rows.- The sibling scans, same failure class, safe direction:
sessionAliases(dash/store.go:517-527) andoldestSessionIDs(dash/store.go:1024-1036) still skip a failedScansilently, but a missed alias or victim there means a key is kept until retention — the direction that cannot cost a warm cache its state. No gap. - Reviewer 1's round-2 non-blocking notes, checked myself: no dash test calls
t.Parallel()(grep is empty), so thesqlChunkvar the chunk test mutates cannot race today; the one-timeidx_requests_session_aliasbuild on a 1.58 M-row database is a startup cost inherent to adding any index. Both fine to leave. - Call sites of the guard: all four unchanged and consistent at the new head —
DropOldestSessions(dash/store.go:1023),DropOldestSessionsOfTenant(dash/store.go:1143),evictSessions(dash/janitor.go:386),ArchiveSessionFull(dash/archive.go:349).
What I checked
- Last review: round 2,
434b2322b5537e9421ea0ff23fcba46904375bfc, 2026-10-29T19:50:32Z - New commits read: 1 —
ee777874fix(dash): an unreadable in-use answer keeps all state (#775 round 2) - Read in full: 4 reviews, 3 comments, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt) - New items since my last review, and what I did about each: Reviewer 1's round-2 review at 19:51:27Z (same finding as mine, posted after mine; its two non-blocking notes I re-checked myself, above); the author's round-3 answer comment at 20:15:04Z (every claim checked against the code — all hold); commit
ee777874(full diff plus the code around both hunks) - I did not run builds or tests — live tests are not approved for this review. The author's eval-box tables are their claims; I verified what the code can show.
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.312 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 3 of 3 | ee7778745e07 |
approve |
Verdict: approve
Findings
None. My round-2 finding is fixed correctly, and I found nothing new in ee777874.
Earlier findings — status
- My round-2 finding (and reviewer 2's round-2 finding, the same one):
inUseIDsignored a scan that fails midway. Fixed. All three failure modes now share onegiveUppath (dash/store.go:456-465): the query fails to open, a row fails to scan, or the scan ends early. Each logs once and marks every key in use, then returns. I read the finalinUseIDsend to end — the unsafe direction is gone on every path, androws.Close()runs on all of them. The doc comment now states the contract for all three modes, so code and comment agree. - Reviewer 2's non-blocking stale comment ("one statement, so one transaction"): fixed.
DropOldestSessions' doc now describes the chunked delete and says a failed chunk returns before the state cleanup — the safe direction (dash/store.go:985-990). That matches the code I read in round 2. - The archiver-goroutine interleave: left as is, and I accept the reason. The author's argument: the window is narrow, the loss self-heals within one turn, state cleanup is best-effort by contract, and closing it would serialize the archiver behind the writer. I checked the reasoning against the code: the only rows that can vanish mid-count belong to a session the archiver is itself removing, and a live session's rows are never deleted, so the count still sees them. The worst case is one extra cold read for a session whose own archive pass would have kept the key — bounded, and not worth the machinery. Accepted.
What I checked in ee777874
- The full diff (2 files) and the code around each hunk.
- The
giveUprewrite (dash/store.go:447-492): the closure shares thewarnedflag across all failure modes, marks every key in use, and each error path closesrowsand returns. No path can now deliver a partial answer that reads a live key as unused. - Both new tests, traced on the fixed and the broken code.
TestUnreadableInUseAnswerKeepsAllState: the fake yieldsk-live, then fails the scan;rows.Err()firesgiveUp, both keys read in use, zero deletes. At434b2322the same run marks onlyk-live, sostore.DeleteSessionStatecollectscg:bin:k-gonefrom the fake's cleansession_statelisting and runs one DELETE — the test fails, as the author claims.TestUnscannableInUseRowKeepsAllState:struct{}{}is outside thedriver.Valuecontract, soScaninto a string fails while the rows end cleanly — only the Scan guard can catch it; on the broken code the row is skipped and the delete runs. The pointer receiver onNextis needed for the same reason as instore/disk_delstate_test.go. TheFROM session_statebranch ending cleanly is deliberate and correct: without it, the round-1 scan guard instore.DeleteSessionStatewould stop the broken path and the test would pass for the wrong reason. - The commit message's claims against the code: the comment fix, the two tests, the "left as is" decision — all verified above.
What I checked
- Last review: round 2, 434b232, 2026-10-29T19:51:27Z
- New commits read: 1 —
ee777874fix(dash): an unreadable in-use answer keeps all state (#775 round 2) - Read in full: 4 reviews, 3 comments, 0 inline comments (from the three saved files)
- New items since my last review, and what I did about each:
- Reviewer 2's round-2 review (posted just before mine): read in full. Its finding is the same as mine; its two non-blocking notes are the stale comment (fixed in
ee777874) and the archiver interleave (the author's "left as is", which I checked and accept above). - The author's round-3 answer comment: every claim checked against
ee777874— the fix shape, both tests' failure modes and their behavior at434b2322, the mutation proofs' logic as readable from the code, and the honest note about the out-of-contractdriver.Value. - Commit
ee777874: full diff, plus the final state ofinUseIDs,deleteSessionState, and theDropOldestSessionsdoc.
- Reviewer 2's round-2 review (posted just before mine): read in full. Its finding is the same as mine; its two non-blocking notes are the stale comment (fixed in
- I did not run builds or tests: live runs are not approved for this review. The author's eval-box tables are their claims; I verified what the code can show.
Summary
Five small follow-ups from #770 (session state in the dashboard database). Written by GLM (rits/zai-org/glm-5-3) through Claude Code. Closes #772.
Data dependence: no change (this deletes more, it stores nothing new). Behavior change: none that a user sees, apart from fewer leftover rows.
What changed
evictSessionswas the one delete path without one. Covered byTestEvictFallbackDeletesSessionAndAliasState, mutation-checked.cg:seen:andcg:ttl:are keyed by the content-hash alias, not the session id, so they outlived a deleted or archived session until the 30-day retention. The dashboard now reads the session'ssession_aliascolumn before the rows go, and deletes the state under that alias through the samestore.DeleteSessionStateboundary check. An alias that another live session still uses is kept: the check counts rows that carry the alias, and rows of a headerless session whose own id IS the alias.DropOldestSessionsdeletes exactly the set it picked. TheDELETEused to re-run the ordering subquery itself, so a request landing between the pick and the delete could change the order, and the state cleanup then acted on a set other than the one deleted. The victims are now picked once and removed by id, in chunked statements. One deliberate deviation from the issue's decision text: the pick stays outside the delete's transactions (each chunk is a single statement, so one transaction), because a read-then-write transaction on this shared pool can fail to upgrade its WAL snapshot when the session-state flush commits in between — the same reasonArchiveSessionFullreads its events outside its delete.DeleteSessionStatechecksrows.Err(). A scan that fails midway now returns the error (the dashboard logs it once per op) instead of silently deleting less.docs/data-dependence.md:extract_llm_sweepremoved from "Rows to confirm". Both confirmations are recorded on feat(store): keep session state through a restart and a long pause (#769) #770.A new test seam,
DB.dropProbe, lets a test land a request between the pick and the delete in point 3. It is nil in production.What changed in round 2 (
dc3a888a, answers to the blocking reviews)Both round-1 reviews were blocking. All findings are fixed:
session_idIS an alias) evicted while the header session sharing that alias is live no longer loses the state that live session reads. One guard now covers both directions: rows carrying the key assession_alias, and a live session whose own id IS the key.DropOldestSessionsOfTenantwas the one session-delete path without state cleanup. It now picks its victim by id, reads the aliases, and calls the same guarded cleanup.idx_requests_session_aliasindex is added on every open (old databases get it too), and one pass answers all its in-use checks with two queries over the whole key list — not one full-table scan per alias on the writer goroutine.IN (…)list is bound in batches of 500 ids, past SQLite's 32,766-variable statement limit.docs/data-dependence.mdsays an eviction or an archive can end a state row before its 30 days.What changed in round 3 (
ee777874, answer to the round-2 reviews)Both round-2 reviews blocked on one finding: the in-use check ignored a scan that fails midway.
inUseIDsnow checksrows.Err()after the scan loop and treats a failedScanthe same way as a query that fails to open: log once, mark every key in use, return. A partial answer can no longer read a live session's key as unused — the unsafe direction is gone. Two fake-driver tests cover the two failure modes; each fails at the previous head and catches its own mutation.DropOldestSessions' comment matches the code again: the delete is chunked, and a failed chunk returns before the state cleanup, so earlier chunks' victims keep their state until retention — the safe direction.How it was tested
All runs on the eval box (
go1.26.4,/usr/local/go/bin/go), worktree synced by tar.gofmt -l dash storego vet ./dash/... ./store/...go test ./dash— the 3 new tests + 5 neighboring session-state tests,-count=1go test ./store—TestDeleteSessionStateReportsScanError,-count=1origin/maincopyTestDropOldestSessionsDeletesExactlyThePickedSetonorigin/maindropProbeseam does not exist there, so the interleaving cannot be expressed; the mutation run below proves the test catches the regressionDELETErestored, alias-state delete removed,rows.Err()check removed)0ad62817(the round-1 head)434b2322(the merge head)rows.Err()guard removed, Scan guard removed)go test -race -count=1 ./store/... ./dash/...go test -race -count=1 ./proxy/...(rounds 1 and 2, merge-verified)Closes #772
🤖 Generated with Claude Code