Repository navigation
feat(mod): on a subscription show the next message as a share of the 5-hour limit - #1135
Conversation
…5-hour limit With learned 5-hour weights that pass their checks, the band and the pane show the next message as a share of the 5-hour limit, warm and cold: `next message ≈0.1% of 5h · ≈1.5% if cold`. A cold cache shows `○ cache cold · next message ≈1.5% of 5h`. Below 80 columns the row reads `next 5h ≈0.1% · ≈1.5% cold`, so it fits 60 columns. - cg.py cachestate reads GET /api/me/fivehour-weights on a subscription, at most once a minute, through the on-disk cache. A failed read uses the last copy only while it is under 15 minutes old. - The cold share uses the write weight of the entry's tier (ttl_s 300 or 3600), else the write tier the fit learned. - Without weights, or with a fit below its gate, the band keeps the one token figure. Dollar mode does not change. Fixes #1095 Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
|
Go tests on the eval box, head 464803d:
|
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.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 464803dacf14 |
blocking |
Verdict: blocking
Findings
- docs/data-dependence.md:252 — the generated page was edited by hand; the row file was not
- What fails: the PR edits
docs/data-dependence.md(the generated page) directly. It does not edit the row filedocs/data-dependence/features/fivehour-weights.md, and it does not rungo run ./cmd/gen-datadep. The row file still holds the old text, without the band sentences and without the "band: David Amid, #1095 (2026-11-11)" decision record. The nextmake datadep(Makefile:50) rebuilds the page from the row files (internal/datadep/datadep.go,cmd/gen-datadep/main.go) and silently drops the whole change. - Proof:
git diff fa25367e..HEAD --stat -- docs/data-dependence.md docs/data-dependence/shows one file changed,docs/data-dependence.md, 1 insertion 1 deletion. Thefeatures/directory is untouched. CLAUDE.md says: edit the feature's row file, then run the generator; "Never edit that page by hand." - Fix: move the new sentences (and the band decision record) into
docs/data-dependence/features/fivehour-weights.md, then rungo run ./cmd/gen-datadepon a box with Go. Keep the generated diff that results.
- What fails: the PR edits
Non-blocking
context-guru-plugin/hooks/model.ts:105— with weights present and the proxy's price missing (next_warm_usd/next_cold_usdabsent,prefix_tokens≥ 1),nextPricenow returns kindsharewith both figures undefined. The pane then drawsif the cache is warm unknown/if it is cold unknownplus the weights line, where it drew onenext message unknownbefore. The band draws nothing, as before. Fail open holds; only the pane's edge-case words change.context-guru-plugin/hooks/model.ts:110— theww === undefinedguard is dead: the gate infiveHourWeightsguarantees at least one learned write weight, sowriteWeightalways finds one. Harmless defence.
What I checked
- Read the full diff (11 files, +550/−27) and the code around every change.
cg.py(both copies):share_weightsandfivehour_weightstraced againstcgcache.py(take_slot,backoff,record_failure,age_of,write_atomic) andApi.get(returns None on 404 or bad JSON, so an old proxy backs off, it does not crash).add_weightsfails open on its own try/except, and runs only when the mod sends--window-start-ms(subscription only,register.tsx:90-91). Thecached is None or take_slot(...)single-flight pattern matches the existingpane_get.- The two
cg.pycopies are byte-identical (TestCGScriptsAreVendoredIntoCodexcoverscg.py). - The endpoint:
dash/fivehourweights.goanddash/fivehourfit.go— route, field names (ok,weights,learned,requests), tier keys (cache_read,cache_write_5m,cache_write_1h),{}for an API key. All match whatshare_weightsreads. - Gate parity: the Python gate and the TS gate in
fiveHourWeightsrequire the same things (ok, learned positive read weight, at least one learned positive write weight). A fit that passes one passes the other. model.ts:nextPricewithout weights keeps the old tokens behaviour exactly;writeWeightmatches the documented tier rule;writeTiercomes from the merged main entry (mainEntrycopiesttl_sfrom the main thread);signaturenow includesv.weights, andanchoralready includesttl_s.register.tsx: band and pane render paths for warm, cold, narrow (60 columns) and wide; width arithmetic for the longest row (◆ next 5h ≈0.1% · ≈2.7% cold ↻ ping 59:59 … hide dash ↗= 56 cells at 60 columns, inside thecols - 4budget the tests assert).- Tests read in full:
register.test.tsx(new band/pane cases, the five fallback cases, the API-key case, the late-weights redraw) andtest_cg_weights.py(gate, one-minute TTL, 15-minute fail-open, back-off,add_weights), plus the Go wrapperTestCGFiveHourWeightsPythonTests(requireToolexists inplugin_test.go; the script inserts its own directory intosys.path, so-Iis safe). No test was run: live tests are not approved. - Data dependence: the PR states it at the top (metadata only, no level change), and the row's "Decided by" (David Amid) matches the approval named in the PR body. The process defect is finding 1.
TestDocsExamplesAreTheGoldens: thedocs/plugin/statusline.mdchange touches prose bullets only, no golden block.
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.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 464803dacf14 |
blocking |
Verdict: blocking
Findings
- docs/data-dependence.md:252 — the generated page was edited by hand. Its row file was not. The datadep test fails.
- What fails:
internal/datadep.TestGeneratedPageIsUpToDatebuilds the page from the row files and compares it with the checked-in page. The PR changed the "Learned 5-hour weights" row indocs/data-dependence.mdonly.docs/data-dependence/features/fivehour-weights.mdstill carries the old text. So the built page and the checked-in page differ, and the test fails on this head. - Proof:
git diff fa25367..HEAD -- docs/data-dependence/is empty (no row file changed).git diff fa25367..HEAD -- docs/data-dependence.mdchanges the row text of that one line.internal/datadep/datadep_test.go:12(TestGeneratedPageIsUpToDate) fails when the two differ. CLAUDE.md says: edit the row file, then rungo run ./cmd/gen-datadep; never edit the page by hand. The PR body says "Go is not installed locally, so the Go tests did not run yet", so this failure was not seen. - Also: the next person who runs the generator loses this PR's documentation change, because the generator writes the old row-file text back.
- Fix: move the new sentences ("Since #1095 the Claude Code plugin's band and pane also use them … band: David Amid, #1095 (2026-11-11).") into the body of
docs/data-dependence/features/fivehour-weights.md. Then rungo run ./cmd/gen-datadepand commit the page it builds.
- What fails:
Non-blocking
- scripts/cg.py:331 (fivehour_weights) — after a failed read, the served copy can be up to 15 minutes old. The fit inside it can be up to 15 minutes older still, because the endpoint caches a fit for 15 minutes. So the band can draw weights about 30 minutes old on the failure path. The docs state the copy-age rule honestly, and the weights move slowly. No change asked.
- hooks/model.ts:72 (writeWeight) — an entry on the 5-minute tier, when the fit has no 5-minute weight (prices missing, only the 1-hour write learned), uses the 1-hour weight. That overestimates the cold share. This needs prices missing and a partial fit at the same time. Fail-safe direction. No change asked.
- hooks/model.ts:105 (nextPrice) — with weights and an unpriced state (
next_warm_usdandnext_cold_usdabsent), the pane now shows twounknownlines plus the weights line. Before, it showed oneunknownline. The PR names this in its technical notes. Cosmetic.
What I checked
- The full diff (11 files) and the code around each change:
scripts/cg.py(both copies),hooks/model.ts,hooks/register.tsx,hooks/register.test.tsx,types/index.d.ts,scripts/test_cg_weights.py,cg_cachestate_test.go, the three docs files. - The two
cg.pycopies are identical (diffclean), soTestCGScriptsAreVendoredIntoCodexholds. - The endpoint contract:
dash/fivehourweights.goanddash/fivehourfit.go. The answer fields (ok,weights,learned,requests) and the tier names (input,cache_read,cache_write_5m,cache_write_1h,output) match whatshare_weightsandfiveHourWeightsread. The fit cache is 15 minutes, as the comments claim. - The gate is checked twice, in Python (
share_weights) and in TypeScript (fiveHourWeights), with the same rules:oktrue, a learned positive read weight, at least one learned positive write weight. I traced each field type (bool, string, NaN, 0, negative) through both gates. They agree. - Fail open:
add_weightscatches everything and leaves the field out; the band then keeps the token figure.fivehour_weightsserves the last copy only under 15 minutes, else nothing. The mod re-checks the gate, so a bad cached document cannot break the band. - The on-disk cache:
cgcache.read_json,age_of,take_slot,backoff,record_failure. The one-read-a-minute, single-flight and back-off rules matchcachestate_cachedandpane_get. The file name carries the port, so sessions share one copy. - The request budget: the weights read piggybacks on the existing cachestate poll. At most one network read per minute, timeout 3 s, backed off after failures. The mod sends
--window-start-msonly on a subscription, so an API key never triggers the read. - Row 1 width at 60 columns: I recomputed the lengths for the share row with the longest ping hint (
↻ ping 59:59, 56 chars withhideanddash ↗) and withping off. The tests cover the worst case. The ping hint cannot exceed 59:59, because a ping must fire before the entry expires and the TTL is at most 3600 s. - The new tests: band and pane, warm and cold, 140 and 60 columns, the tier choice (1-hour entry, unknown tier), tiny and large shares, five fallback cases, dollars with weights present, and the late-arrival redraw. The Python tests cover the gate, the TTL, the 15-minute limit, the back-off and fail open. The Go test runs them in CI with
python3 -I, and the script inserts its own directory intosys.path, so isolated mode works. - The PR body: it names the behavior change at the top, with the owner's approval and the undo path, and states the data dependence. Both are required by CLAUDE.md and RELEASING.md.
- I did not run tests. Live tests were not approved, and Go is not installed here.
Round 1 of #1135: - The cold share uses only a write weight the fit learned for the entry's tier. When the fit did not learn it, the cold figure stays in tokens (90.0k wr). Owner's decision, 2026-11-12. - With weights but no price for either state, the pane shows one "next message unknown" line, as without weights. - The band text for the learned 5-hour weights row moves into its row file, docs/data-dependence/features/fivehour-weights.md. The page is built again with go run ./cmd/gen-datadep. Assisted-By: Claude Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 answers. All fixes are in commit 14d1ef0. Both reviewers (blocking): the generated page was edited by handFixed. The band text is now in the row file, Owner decision (David Amid, 2026-11-12): learned write weights onlyThe PR's first version used the 1-hour write weight on a 1-hour entry even when the fit had not learned it. That weight is the API price scaled to the account's spend, a guess. The owner chose: use only learned weights.
Non-blocking notes
Tests
|
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.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 14d1ef0c4406 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed, and the new commit adds no defect I can show.
Round-1 findings, both reviewers
- The generated data-dependence page was edited by hand (mine and reviewer 2's blocking finding). Fixed.
- The band text now lives in
docs/data-dependence/features/fivehour-weights.md:10, and the page was rebuilt. - I rebuilt the row line from the row file the way
internal/datadepdoes it (front matter plus the body, joined to one line, pipes escaped). The result matchesdocs/data-dependence.md:252byte for byte. The cumulative diff against the base touches one row line in the page and one line in the row file, nothing else. SoTestGeneratedPageIsUpToDatehas nothing left to catch. The author also reports it passing on the eval box.
- The band text now lives in
My round-1 non-blocking notes
- The pane's two
unknownlines. Fixed.nextPricenow falls through to the token kind when the weights give no figure for either state (model.ts:114), so the pane shows onenext message unknownline. I traced every combination (warm or cold cache, priced or unpriced, write weight learned or not): the fall-through fires only when both figures are undefined, which is exactly when the oldpricedcheck was false. The result matches the no-weights path. A new test covers it (register.test.tsx:475). - A 5-minute entry using the 1-hour weight. Resolved by a stronger rule. The owner decided the band uses only learned weights (
writeWeight,model.ts:74). An entry whose write tier the fit did not learn keeps its cold figure in tokens (90.0k wr), with noof 5h. This removes the guess I flagged.docs/plugin/statusline.mdand the PR description state the rule, and the commit message records the owner's decision of 2026-11-12.
Reviewer 2's round-1 notes (checked myself)
- The dead
ww === undefinedguard. Agree with reviewer 2 that it was dead, and it is live now: with the learned-only rule,writeWeightreturns undefined for an unlearned tier. - A copy up to about 30 minutes old on the failure path. The author kept it. Both reviewers asked for no change, and the docs state the rule. Accept.
The new commit (14d1ef0), reviewed as a first review
writeWeight(model.ts:74):learned1his true only whenwrite1his a positive number (the gate atmodel.ts:64), so the learned path can never return undefined. With the tier unknown, the gate's "at least one learned write" keeps the fallback defined. Correct.nextPrice(model.ts:105): the fall-through and thecoldIsTokensflag. I traced the band and the pane for warm, cold, narrow and wide. A token cold figure carries noof 5hin either surface (register.tsx:341,register.tsx:512), and the colors match the no-weights path. Correct.- The tests: the tier test now covers a 1-hour entry with and without the learned 1-hour weight, in band and pane, and asserts
wr of 5hnever appears. The 60-column fit test now learns the 1-hour weight, so it still measures the longest form (↻ ping 59:59plushideanddash ↗, inside the 56-cell budget). The no-price test drops all three price fields and checks the oneunknownline. cg.pyis untouched in this commit; the Python gate still passes unlearned weights through, and the mod's learned-only decision applies on the TypeScript side. The two copies stay identical.- Docs:
statusline.mdand the PR body both state the learned-only rule; the data-dependence row file and the page agree.
What I checked
- Last review: round 1, 464803d, 2026-11-12T14:49:55Z.
- New commits read: 1 (
14d1ef0c"fix(mod): only learned write weights; data-dependence row file"). - Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files; the inline file is empty).
- New items since my last review: the commit 14d1ef0 (reviewed above); the author's round-1 answer at 15:40 (each point checked above); the eval-box test report at 14:41 (predates my last review; it ran
./context-guru-plugin/..., which does not coverinternal/datadep, so it does not contradict my round-1 finding); reviewer 2's round-1 review, read now as this round allows (checked above). - I did not run tests. Live tests are not approved, and Go is not installed here.
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.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 14d1ef0c4406 |
approve |
Verdict: approve
Findings
None. Both round-1 blocking findings are fixed, and the fix commit introduces no new defect.
Earlier findings
- Mine, finding 1 (data-dependence page edited by hand): fixed. The band text and the "band: David Amid, #1095" decision record now live in
docs/data-dependence/features/fivehour-weights.md, and the page is the generator's output. I checked it myself without Go: the page's reason cell for that row is byte-identical to the row file's body (a local comparison script prints MATCH), the page diff touches that one row only, and the row file's front matter is unchanged. The author also rango test ./internal/datadep/ ./components/all/on the eval box;TestGeneratedPageIsUpToDate(internal/datadep/datadep_test.go:12) guards it from now on. - Mine, non-blocking (pane drew two
unknownlines with weights and no price): fixed.nextPricenow falls through to the token kind when both figures are undefined (model.ts:113), and the new testwith learned weights but no price for either state the pane shows one unknown line, not twopins it. - Mine, non-blocking (dead
ww === undefinedguard): resolved by design. With the learned-only rule,writeWeightreturns undefined for an unlearned tier, so the guard is live. - Reviewer 1, finding 1: fixed, same fix as my finding 1. Agree with reviewer 1; I verified the fix the same way.
- Reviewer 1, non-blocking (5-minute entry using the 1-hour weight overestimated the cold share): fixed by the learned-only rule, with the owner's decision named in the commit and the PR body.
- Reviewer 1, non-blocking (copy up to ~30 minutes old on the failure path): kept, as reviewer 1 suggested. The docs state the rule. Agreed.
The new commit (14d1ef0)
- The learned-only rule is sound and consistent.
writeWeight(model.ts:74-77) returns a weight only for a tier the fit learned; with the tier unknown it uses the learned tier, and the gate infiveHourWeightsguarantees one of the two is learned, so the unknown-tier path always finds a weight. The scaled-API-price weight (learned false) is never shown as a share. This matches the owner's decision named in the commit message, the PR body, anddocs/plugin/statusline.md. - The mixed figure is drawn correctly.
coldIsTokensgates everyof 5hsuffix: the band's warm-branch cold suffix (register.tsx:359), the band's cold-cache branch (register.tsx:367), and the pane's cold line (register.tsx:512, 540). The warm line keeps its unit, because the read weight is always learned when the gate passed. The token cold figure keeps the warning color, as the old token figure did. - The fall-through keeps the old no-price behavior. With weights but no price for either state,
nextPricereaches thepricedcheck with both prices absent, returns the token kind without a figure, and the pane shows onenext message unknownline, as before the PR. - Tests cover the rule. The changed tier test covers the 1-hour entry with and without the learned 1-hour weight, in band and pane, plus the unknown tier; the 60-column fit test now learns the 1-hour weight so it still exercises the longest form (
◆ next 5h ≈0.1% · ≈2.7% cold ↻ ping 59:5x, 56 of 56 cells). The new no-price test drops all three price fields from both the document and the main thread, so it really reaches the fall-through.
Non-blocking
context-guru-plugin/hooks/register.tsx:367— the cold-cache band branch with an unlearned tier (○ cache cold · next message 90.0k wr, noof 5h) has no test. The mixed figure is pinned on the warm band and the pane only. A regression there would print90.0k wr of 5h.context-guru-plugin/hooks/register.tsx:356— a very small edge: a warm cache with the warm state unpriced and the tier unlearned, below 80 columns, readsnext 5h 90.0k wr cold: the5hlabel with no share figure under it. It needs an old proxy (nonext_warm_usd) together with a partial fit, so I do not ask for a change.
What I checked
- Last review: round 1, 464803d, 2026-11-12T14:49:29Z
- New commits read: 1 —
14d1ef0cfix(mod): only learned write weights; data-dependence row file - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline file is empty) - New items since my last review, and what I did about each:
- Reviewer 1's round-1 review (posted 26 s after mine, so unread in round 1): read in full. Its blocking finding is mine; its non-blocking 5m/1h note is fixed by the learned-only rule. No finding of theirs is unanswered.
- The author's eval-box comment (Go tests pass on 464803d, including the new Python-test wrapper and the vendoring test): noted; I did not re-run anything, live tests are not approved.
- The author's round-1 answers (15:40:27Z): each claim checked against the code — the row-file fix, the learned-only rule, the pane fall-through, the now-live guard, the kept 30-minute rule. All claims hold.
- Commit 14d1ef0: full diff read, plus the code around every change (
model.ts40-120,register.tsx330-370 and 505-545, the changed tests, both data-dependence files,statusline.md).
- The generated page against its row file, without Go: the reason cell and the row body are byte-identical, the page diff is one row, the row file's front matter is unchanged.
- The PR body: it now states the learned-only rule with the owner's decision and date, as
statusline.mddoes. docs/dashboard.mdand the goldens: the commit does not touch them, and thestatusline.mdchange is prose only, soTestDocsExamplesAreTheGoldensis safe.- I did not run tests. Live tests are not approved, and Go is not installed on this machine.
Plugin versions for v0.7.4: - Claude Code plugin 0.7.3 -> 0.7.4 (#1096, #1135, #1174, #1177, #1199, #1216). - Codex plugin 0.2.12 -> 0.2.13 (#1115, #1135). - Pi package 0.1.1 -> 0.1.2 (#1113). - Bob plugin 0.1.1 -> 0.1.2 (#1093, #1111, #1118, #1124, #1126, #1127). The owner's Bob hold (#1221) covers release tests only. - OpenCode: PINNED_VERSION v0.7.3 -> v0.7.4 in opencode-plugin/index.js, its README, docs/how-to/install-opencode-plugin.md and 3 tests. Behavior change: the version numbers; the OpenCode plugin's first start downloads proxy v0.7.4. Release bumps are approved by the owner ("I approve version bumps"). Data dependence: none. Reviews: 2 offload review rounds (GLM): both approve at ab79001. After it: 1422093, a merge of main with no hand resolution (remerge-diff 0; approval-still-valid: SAME CHANGE). Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Behavior change
next message 90.0k rd(warm, green) or○ cache cold · next message 90.0k wr(cold, amber).next message ≈0.1% of 5h · ≈1.5% if cold. A cold cache shows○ cache cold · next message ≈1.5% of 5h. Without weights, the old token figure stays.Summary
The band now shows what a cold cache costs on a subscription. A cold message uses about 15 times more of the 5-hour limit than a warm one. The token figure could not show that.
Fixes #1095
What changed
cg.py cachestatereadsGET /api/me/fivehour-weightson a subscription (when the mod sends the window start). It addsfivehour_weightsto the document only when the fit passed its gate.model.tsadds thesharekind tonextPrice.ttl_s3600 = 1-hour, 300 = 5-minute). The band uses only a weight the fit learned (owner's decision, 2026-11-12). When the fit did not learn the entry's tier, the cold figure stays in tokens (90.0k wr). When the tier is not known, it is the write tier the fit learned (5-minute when it learned both).≈1.5%below 10%,≈12%from 10%,<0.1%for a tiny share.ok, a learned read weight, and one learned write weight, each a positive number. Any failure gives the token figure.register.tsxdraws the share as it draws dollars: warm in green, cold dim, cold-only in amber. Below 80 columns row 1 readsnext 5h ≈0.1% · ≈1.4% cold. It fits 60 columns with the longest next-ping hint (↻ ping 59:59). The pane shows both shares, the prefix size, andat learned 5-hour weights (1,234 requests).docs/plugin/statusline.md(the Subscription bullets under row 1),docs/dashboard.md(who reads the weights),docs/data-dependence.md(the Learned 5-hour weights row).cg.pyis updated (TestCGScriptsAreVendoredIntoCodex).Data dependence
Metadata only. No change of level. The band reads the cached prefix's token count and the fitted weights: numbers and flags. The plugin keeps the endpoint's answer in its local cache directory. It reads no request text.
How it was tested
claude plugin test context-guru-plugin: 121 pass, 1 fail. The fail isno data: the band is left to the engine, which also fails onorigin/main.ok: false, no learned read weight, no learned write weight, a bad number), dollar mode with weights present, and a redraw when weights arrive on a later poll.python3 -I scripts/test_cg_weights.py: 9 pass. It covers the gate, the one-minute cache, the 15-minute limit after a failed read, the back-off, and fail open.TestCGFiveHourWeightsPythonTests, runs that Python file in CI. Go is not installed locally, so the Go tests did not run yet.Technical notes
next_cold_usd) to be present, and the warm share needsnext_warm_usd, as the token figure did. Without it that figure does not show.🤖 Generated with Claude Code