Repository navigation
fix(dash): price the Inventory tab on the requests that carried each declaration - #531
Conversation
OsherElhadad
left a comment
There was a problem hiding this comment.
Review: APPROVE at edb9d74. (Posted as a comment: GitHub does not let the author account approve.)
Verified:
- Same pricing as /api/adapt/tools.
carriedCostis the old per-request loop moved, not rewritten. It keeps the same tier rule, including the 5m write at the write rate (bd15bf4) and the 1h write at 2x input, plus the same latest-before set pick by tool count and the same bounds. Each of these mutations fails a test:- an off-by-one shard step (11 failures)
ntoolsoverwritten instead of summed when a set straddles two slices- billing an item in a session that used it
- dropping the 5m write rate
- dropping the lower bound
- Rowid slices.
step = (hi-lo)/16 + 1makes 16 half-open ranges that cover[lo, hi]exactly once; gaps and deletes are harmless. Rows inserted after the MIN/MAX read are left for the next refresh. A set that straddles two slices is merged (tool count summed, items appended, earliestfirst). - Interning. It is per call (local
ids/keys), so nothing outlives a request.keyOfis read-only in Inventory, and AdaptTools guards itsmetamap with a mutex. - Per-session "unused". An item used in one session and not in another is billed only on the second session's carrying requests, which is what the tab has always meant. The two endpoints agree only on items that were never used, as the PR says.
- Concurrency and memory.
/api/toolsstays behind the response cache (single-flight per scope key, stale-while-revalidate) and the heavy-route bound. The extra memory is small against the service's memory limit, and one fleet-view compute serves every concurrent reader of that key. Accepted. - Checks.
gofmtandgo vetare clean. The dashTool|Adapt|Golden|Inventory|Suggest|Decltests pass, including under-race. One run under host IO load failed TestAdaptToolsSkipsWhatIsAlreadyRemoved; it passed 3 runs alone and 2 full group reruns, and the same group passes on the base. The commit is signed off with no AI attribution, and the PR text has no figures.
Non-blocking:
carriedSets(16 slices) runs besidescanDecls(its own concurrent pass), so one cold fleet view runs roughly twice as many SQLite readers at once as before. Different scopes are not globally bounded; that predates this PR for/api/tools. Consider taking the dashboard's heavy slot (acquireKVCache) around the compute, or sharing one slice pass.- The headline range covers mapped requests only. Requests that match no stored set are in neither bound.
/api/adapt/toolswarns about them, but the Inventory tile does not. A short "N requests not matched" fromcarriedwould keep the range honest. usedBySessionkeys usage by baresession_id, so in a fleet view two accounts with the same session id would share "used". This predates the PR and is unlikely with UUIDs, but non-Claude-Code agents may reuse ids.
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at 367302e. (Posted as a comment: GitHub does not let the author account approve.)
carriedSetsnow runs one pass at a time across the process.- A narrow scope reads in one query, which removes the per-slice connections behind the SQLITE_BUSY flake. The sharded path is still covered by TestInventoryTablePassEqualsPerSessionProbe.
- The headline now states how many requests matched no declaration set.
gofmtandgo vetare clean, andgo test -race ./dash -run 'Tool|Adapt|Inventory|Decl'passes. Both commits are signed off with no AI attribution.
Non-blocking: carriedSlot <- struct{}{} does not watch the request context. A tenant view queues behind a cold fleet pass, and a client that has gone keeps waiting for the slot. A select on d.readCtx() or the request's Done() would release it.
Approved.
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-review: APPROVE at 277b1c8. The carriedSlot wait now selects on d.readCtx().Done(). That context is the request's when the DB comes from a.db(r) (WithContext), so an abandoned request stops waiting. A shared background refresh keeps waiting, which is correct. Signed off. The approval stands.
OsherElhadad
left a comment
There was a problem hiding this comment.
Note on 277b1c8: the change is right, but no test pins it. 277b1c8 touches only dash/adapttools.go, and no test references carriedSlot. Please add one: hold carriedSlot, call the carried pricing with a DB whose context is already cancelled (WithContext), and assert it returns context.Canceled promptly (within, say, 1 s) without taking the slot. That test would fail on the old blocking send. Approval stands once it's in.
bd15bf4 to
a5e3295
Compare
e925f27 to
d592326
Compare
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-confirm: APPROVE at d592326 (rebased onto #528's 9496607; was e925f27). git range-diff d6b3147c..e925f27d 9496607d..d592326a shows 21 of 22 commits identical. The only changed patch is 352d2b7 → 5cdab08, and its sole difference is context lines in cmd/context-guru-proxy/main.go from the squashed base; no code change. CI is green. This approval covers d592326.
fd300e3 to
9b489bf
Compare
…declaration The tools report billed a declaration on every request of a session that declared it, at the session's first model. Sessions hold several declaration sets (subagents, servers added mid-session) and often two models, so it overstated what was carried. It now uses the same per-request pricing as /api/adapt/tools (carriedCost), with low/high bounds for requests that recorded no declaration set, and the headline states the range. The pricing pass reads tool_declarations in concurrent rowid slices like scanDecls and runs beside the inventory read. Signed-off-by: Osher-Elhadad <[email protected]>
…matched no declaration set Signed-off-by: Osher-Elhadad <[email protected]>
…en connections Each slice is a new connection running the connection pragmas, which on a small database with a background writer waited out the busy timeout. The sharded path stays for broad scopes and is covered by the existing table-pass equivalence test. Signed-off-by: Osher-Elhadad <[email protected]>
… is gone Signed-off-by: Osher-Elhadad <[email protected]>
… slot Signed-off-by: Osher-Elhadad <[email protected]>
…text Signed-off-by: Osher-Elhadad <[email protected]>
d592326 to
4dcef47
Compare
OsherElhadad
left a comment
There was a problem hiding this comment.
Re-confirm: APPROVE at 4dcef47 (rebased onto main after #523 merged). git range-diff d6b3147c..d592326a origin/main..4dcef47d shows the PR's 6 own commits identical (=). The 16 #523 commits drop out because they are on main now. CI is green (build-test, purego, trivy, DCO). This approval covers 4dcef47.
Follow-up to #523. The dashboard's Inventory tab (
GET /api/tools, and the suggestions onGET /api/toolfilter) now prices "unused" declarations the same way/api/adapt/toolsdoes.What changes
decl_digest) are matched by tool count. Each row and the totals carryunused_usd_low/unused_usd_highbounds, and the headline tile states the range when it matters.carriedin the report says how many requests were matched exactly, by tool count, or ambiguously.carriedCost) now serves both/api/adapt/toolsand the Inventory tab. It readstool_declarationsin concurrent rowid slices likescanDecls, keeps the sets compact (interned keys), and runs beside the inventory read.Checked
/api/adapt/toolsto floating-point precision.Not done