Skip to content

feat(plugin): one prefix, status line, terminal views and user docs - #478

Merged
amiddavid merged 27 commits into
mainfrom
feat/plugin-v2
Oct 12, 2026
Merged

amiddavid merged 27 commits into
mainfrom
feat/plugin-v2

Conversation

@OsherElhadad

@OsherElhadad OsherElhadad commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #470, reports to #472. This PR includes #441's commit (its cost engine, moved into this plugin) and supersedes #441.

One plugin, one prefix

Everything is /context-guru:*. There is no second plugin.

Command The question
/context-guru:status How am I doing, what next? (the existing status skill, now with a bottom line, today vs yesterday, top three actions)
/context-guru:savings How much did it save?
/context-guru:cache Is my cache about to cost me?
/context-guru:waste What do I carry and never use?
/context-guru:session What happened in this session?
/context-guru:doctor Is it set up right?

The four insights* commands moved onto these and stay for one release as thin redirects that say so and run the new command. /context-guru:statusline still installs the status line. #441's five cost-* skills are gone.

Each screen: bottom line first, one small visual, details for tables. Dollars only, plain Unicode (readable on light and dark). ✓ Saved and ≈ Estimated are separate blocks.

Terminal views

/context-guru:watch (live caches), timeline, chart, heatmap and fill draw in the terminal with the same rules: dollars first, ✓ Saved and ≈ Estimated apart, colour off when piped, --ascii for plain ASCII.

#```
saved ≈$2.15 session · ≈$6.35 today · ★ ≈$212.40 lifetime
cache ◐ █░░░░░ 0:42 │ ctx ███░░░░░ 41% │ ▸ cache gone in 42s: a pause now costs ≈$1.20 to rewrite

- Two lines by default, one with `--layout=minimal`; labelled `cache` and `ctx` bars, percent only.
- Cache bar drains toward expiry (green, yellow, red); `↻` when the proxy plans a ping.
- `⚠ rewrite near` on the context bar from 85%; at most one hint.
- The installer writes `refreshInterval: 5` (checked in the Claude Code 2.1.296 binary, minimum 1); a value you tune is kept.
- Lifetime and today totals never block a render: cached value, detached refresher.

## Docs
User guide under `docs/plugin/` (overview and install, one page per command, status line with every state, terminal views, configuration and FAQ) and a README section. A test keeps the example blocks equal to the goldens.

## Codex
Same names as skills (`context-guru-status`, `-savings`, `-cache`, `-waste`, `-session`), same scripts (a test keeps the copies identical). Codex has no command-driven status line; gaps are tabulated in `docs/plugin-v2.md`.

## Evidence
- `go test ./context-guru-plugin/` passes, including goldens for every command and every status line state (warm, ping, expiring, rewrite-near, cold, narrow, first run); Codex plugin tests pass.
- Recordings of every screen, dark and light, in `docs/plugin-v2/` (`.cast` for asciinema, `.svg`). Data is a pseudonymised reconstruction on a throwaway proxy.
- Rebased on main after #445 and #477; the only conflict was `dash/api.go`, resolved by keeping both sides.

## Status line render time
Every layout returns within 0.4 s wall time, Python start-up included, in all four cases. The render has a budget (0.36 s from import, plus 25-70 ms of interpreter start-up): each read is sized from what is left of it, `/api/stats?lean=1` is the only read the default layouts wait for, and the cache state is read in parallel with it under the same deadline. The other reads (day and lifetime totals, series, spend, requests) come from the disk cache; with a stale copy they never wait, and a detached refresher (one per 30 s lock window) fills the cache. Only a read with nothing cached yet may wait, at most 0.15 s. A timeout still shows the last numbers with `⏳` and never `cg ✕ proxy offline`. TestStatuslineFinishesInHalfASecondOnASlowProxy fails if a default layout takes more than 0.5 s against a server that sleeps 5 s.

Measured on this host (loaded: production and benchmark labs share it), 50 runs per cell, wall ms p50 / p95 / max. Harness: `statusline_timing` style, fresh temp dir per cold/slow/down run. "slow" is a server that sleeps 5 s on every request.

| layout | healthy, warm cache | healthy, cold cache | slow proxy | proxy down |
|---|---|---|---|---|
| minimal | 53 / 59 / 64 | 89 / 97 / 97 | 389 / 398 / 399 | 92 / 98 / 106 |
| balanced | 51 / 60 / 66 | 89 / 104 / 133 | 390 / 397 / 401 | 94 / 105 / 110 |
| detailed | 57 / 66 / 70 | 93 / 103 / 110 | 389 / 395 / 398 | 91 / 101 / 104 |
| spark | 55 / 64 / 64 | 90 / 102 / 108 | 389 / 393 / 396 | 92 / 104 / 127 |
| strip | 54 / 58 / 61 | 89 / 97 / 103 | 391 / 399 / 406 | 89 / 111 / 125 |
| heat | 55 / 60 / 67 | 90 / 99 / 101 | 391 / 410 / 425 | 92 / 111 / 116 |
| fill | 54 / 57 / 61 | 85 / 94 / 94 | 390 / 408 / 427 | 81 / 92 / 120 |
| watch | 55 / 59 / 63 | 91 / 101 / 104 | 391 / 412 / 416 | 91 / 97 / 99 |

`origin/main` (after #403), same harness and host:

| layout | healthy, warm cache | healthy, cold cache | slow proxy | proxy down |
|---|---|---|---|---|
| minimal | 42 / 59 / 63 | 80 / 89 / 93 | 682 / 691 / 692 | 76 / 90 / 91 |
| balanced | 44 / 53 / 54 | 80 / 91 / 99 | 679 / 729 / 751 | 75 / 82 / 86 |
| detailed | 45 / 52 / 60 | 79 / 89 / 98 | 678 / 703 / 713 | 83 / 126 / 146 |

So no regression from #403 on the slow path (680 ms down to 390 ms). Healthy renders are about 10 ms slower than main's, from the extra elements (agents, spend) the layouts compute.

@OsherElhadad

OsherElhadad commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Design review, round 1: plugin and status line. Reviewed the recordings (light and dark) against the three questions: how much am I saving, is my cache about to cost me, what should I do. Reviewer persona: a busy first-time user who has never heard of caching.

Rubric

Item Result
Three questions answered FAIL: question 3 is missing on the status line and /cg:session
At most 2 lines (status line) PASS
Bottom line first (commands) PASS
Dollars first PASS, except /cg:session
No prose paragraphs PASS
No raw token counts FAIL (status line)
Realised vs estimated separate PASS in /cg:savings; FAIL in /cg (see 4)
No jargon FAIL (see 5)
Readable light and dark PASS for the recordings; colour only exists in the status line, so there is little to break
Namespace consistent FAIL (see 8)

Findings

  1. BLOCKING, status line, line 2: shows 366.2k/1.0M for context fill. That is a raw token count; the brief says none unless asked. Show the percent only (37%), or dollars at risk.
  2. BLOCKING, status line, line 2: the two bars are unlabelled. A new user cannot tell which one is the cache timer and which is context fill. Add a 2-3 letter label to each (cache, ctx), or one glyph each, and keep it when the bar is narrow.
  3. BLOCKING, status line: no answer to "what should I do". The hint slot is empty in the recording. Show one hint in a recorded state where it fires (cache about to lapse, context near full) so we can judge it.
  4. BLOCKING, /cg, first line and "Do next": the saved figure is small and the "within reach" figure is far larger, in one sentence. A reader will add them or assume the product leaves most of the money on the table. Put the realised number alone in the bottom line, and put the opportunity in its own labelled "Estimated, not realised" block as /cg:savings already does.
  5. BLOCKING, jargon in /cg item 1-2, /cg:cache miss table: "pauses outlived the cache", "prefix change", "cold start", "new thread", "history rewrite", "idle expiry". A first-time user does not know these. Use plain words ("You paused too long", "Settings changed mid-session") and say what to do.
  6. BLOCKING, /cg:session: the first line is five facts and raw counts (turns, hours, cache misses) with no verdict. The strip is cryptic and covers the last 4 hours while the line above covers the whole session, so the two disagree. No action is offered. Give a verdict and a dollar figure first, make the strip and the line cover the same window, and end with one action.
  7. POLISH, /cg:doctor: the fix points to /context-guru:statusline while everything else is /cg:*. Use one namespace, or say why not.
  8. POLISH, /cg:waste: "client tool" is unexplained, and the five rows sum to well under the headline total. Add "top 5 of N" so the sum is not misread.
  9. POLISH, /cg:cache: bar is 2:56 of 5:00 here and a 6-cell bar on the status line. Fine, but say once what the 5:00 is (how long your prompt stays cheap to reuse).
  10. POLISH, all commands: output is plain, no colour, by design. Acceptable, but state realised/estimated with a symbol as well as a word so it survives monochrome.

Next: the author fixes 1-6; I re-judge the recordings after the new ones are pushed.

@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Round 1 review addressed (findings 1-7 and polish 8-11) in the latest commit; recordings in docs/plugin-v2/ re-recorded, including the expiring and cold states where the hint fires.

@OsherElhadad

OsherElhadad commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Design review, round 2: PASS.

Re-judged the new recordings (status line in warm, expiring and cold states; all remaining commands). Findings 1-6 and 8-11 are resolved: percent only with labelled cache and ctx bars, a hint that fires in the expiring and cold states and fits on the second line, realised and estimated split with check and approx marks, plain-word causes, a dollar verdict plus one action in /cg:session.

Rubric: all items pass (three questions, two lines, bottom line first, dollars first, no prose paragraphs, no raw token counts, realised vs estimated separate, jargon, light and dark, namespace explained).

Remaining POLISH, non-blocking:

  1. ctx is still a short form; spell it context if width allows.
  2. /cg:doctor still points at /context-guru:statusline; the explanation helps, a /cg: alias would be cleaner.

Re-checked after the squash: the status line (warm, expiring, cold) and the six remaining commands are unchanged and still pass; the cache screen is clean without its trailing line. Saved/Estimated badge words are consistent with the dashboard.

@OsherElhadad

OsherElhadad commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review of 6615248 (on top of #441).

Verified: go test ./context-guru-plugin/ ./cg-plugin/ pass (777 s and 15 s under load); go vet clean. Attribution clean. No hosts, ids or secrets in the diff; test transcripts use obviously synthetic ids.

Findings (none blocking)

  1. A docs section and command that were not ready for public release have been removed from this PR (resolved).
  2. settings.py: is_ours_statusline now matches the old value or the new value with refreshInterval 5 only. If a user edits refreshInterval, remove will leave the status line in place instead of restoring the previous one. Acceptable, but add a test for the edited case or document it.
  3. statusline.py keeps its cache and lock files at predictable names in the shared temp dir, and opens the lock file with plain open(lock, "w"), which follows a symlink. This pattern is pre-existing on main (not introduced here), but refreshInterval 5 makes it run much more often; use a per-user directory (XDG_RUNTIME_DIR or uid-suffixed) with O_NOFOLLOW in a follow-up.
  4. feat(plugin): five cost commands (today, unused, cold, compact, trends) #441's five cost skills are deleted in favour of /cg:*; make sure the marketplace entry and the docs no longer name the old skill ids (I did not find stale references).
  5. Merge order: contains feat(plugin): five cost commands (today, unused, cold, compact, trends) #441.

Approving. Labelled ready-to-merge.

@OsherElhadad OsherElhadad added the ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval label Oct 12, 2026
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Re-review of a8b9477 (squashed, force-pushed): no cache-campaign command, docs, goldens, recordings or CG_DASH_COOKIE remain in the diff, so the public-contract point is resolved. A user-tuned refreshInterval is now kept on reinstall and the status line is still recognised as ours on remove (the check allows only type, command, refreshInterval). vet clean; context-guru-plugin (701 s) and cg-plugin tests pass. The shared-temp cache and lock files remain as a follow-up. Keeping ready-to-merge; merge #441 first.

Adds GET /api/spend/explain (dollars by token type, full-prefix rewrites
classified from token columns, live cache state, Context Guru ledger) and
GET /api/tools/last-used, and scripts/cgcost.py with five skills: cost-today,
cost-unused, cost-cold, cost-compact, cost-trends. Refs #436.

Signed-off-by: Osher-Elhadad <[email protected]>
Commands, all /context-guru:*: status is now the home screen (bottom line, today vs
yesterday, top three actions); new savings, cache, waste, session, doctor. The
insights* and cost-* commands stay for one release as thin redirects. The cost engine
from #441 stays in this plugin; Codex gets the same names as skills.

Status line: saved session/today/lifetime, a cache bar that drains to expiry with a
ping marker, a context bar with a rewrite-near warning, one hint, refreshInterval 5.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad OsherElhadad changed the title feat(plugin): two-line status line with cache countdown, and the /cg commands feat(plugin): one prefix, status line v2, new commands (and terminal views) Oct 12, 2026
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Rebased on the rebased #441 (main after #445/#477; no conflicts beyond #441's dash/api.go). One plugin, one prefix: the cg plugin is folded into context-guru as /context-guru:status (home), savings, cache, waste, session, doctor. insights* and cost-* stay for one release as thin redirects. Codex has the same names. docs/plugin-v2.md is now in the mkdocs nav; mkdocs build --strict and the plugin tests pass locally. statusline.py changes and terminal views will land here as further commits.

Osher-Elhadad added 3 commits October 12, 2026 11:34
Count the cache down in seconds (amber, then red, then up as "cold 1:20")
and give each running sub-agent its own clock. /api/cachestate gains the
response end time and a per-thread list, and the main clock and context
bar now follow the main thread instead of whichever agent spoke last.

Drop the /compact suggestion from the cold-cache hint, warn when a model
switch will rewrite the cache, explain a tool-set miss, say "proxy
offline" in words, and add spend, $/h and session age to the detailed
layout plus a remembered --set-layout toggle.

Signed-off-by: Osher-Elhadad <[email protected]>
…k, 80-column renders

Hints no longer change wording as the clock ticks, say what a pause or
model change costs in dollars, and fit an 80-column terminal. Several
sub-agents show a count and the soonest expiry instead of an unlabelled
list of clocks. Latency over a second is shown in seconds.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Re-review of 11f465d (single prefix, on top of #441 98359cd). Both branches are mergeable against current main. The cg plugin is gone and all new commands sit under /context-guru:*; the insights and cost skills are thin redirects (same script, one line telling the user where it moved), the script files are executable and identical in the Codex copy, mkdocs nav has plugin-v2.md. No campaign files or words, no hosts, ids or paths in the diff; attribution clean. go test ./context-guru-plugin (560 s under load): one failure, TestUserScopeThenProjectKeepsTwoPorts (port_changed_since_plan, a port-allocation race on a busy host); it passes alone twice on this branch and on origin/main. User-edited refreshInterval handling is as agreed earlier. Two notes: the redirect skills pass $ARGUMENTS through to the shell command, as the insights skills did before, so keep allowed-tools restricted to the script; and #480 is stacked on the previous #478 head and has to be rebased onto this one. Approved; ready-to-merge stays (merge #441 first).

Osher-Elhadad added 4 commits October 12, 2026 11:59
…README section

One page per command, the status line with every state, configuration and
troubleshooting; screenshots are the goldens rendered, and a test keeps the example
blocks equal to the goldens.

Signed-off-by: Osher-Elhadad <[email protected]>
…ed order and render cost

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad OsherElhadad changed the title feat(plugin): one prefix, status line v2, new commands (and terminal views) feat(plugin): one prefix, status line, terminal views and user docs Oct 12, 2026
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Final design pass on the whole PR at head cd5df33: commands, status line, five terminal views, README section and docs/plugin. Persona: busy first-time user. I read the README section, all of docs/plugin, the status line and views docs, and checked that every image referenced exists. Not PASS yet: three BLOCKING wording contradictions, all quick text fixes.

Checks

Item Result
README: what it is, install, six commands with example first lines PASS
docs/plugin reads clearly for a new user (install, commands, moved commands, update, uninstall) PASS
Images referenced in the docs exist and match the text PASS
Old /cg: names gone from output and docs PASS
Three questions, bottom line first, dollars first, no raw tokens in default views PASS
One vocabulary across commands, status line, views and dashboard FAIL (1, 2)
Docs do not contradict the product FAIL (3)

Findings

  1. BLOCKING, "Estimated" means two things. In docs/plugin/statusline.md the table says saved ≈$0.31 session is an "Estimated saving". Everywhere else (status, savings, views, index.md, configuration.md) the same figure is ✓ Saved and ≈ Estimated is spend you could still avoid. A reader who learns "Estimated = avoidable spend" will misread the status line. Say in the status line table "Saved (modelled against the same requests without the proxy)" and keep the word Estimated for avoidable spend only. The leading ≈ can stay as a mark that the figure is modelled.
  2. BLOCKING, "observed" vs "Measured". Command and view output label billed numbers "(observed)" (cache, chart, waste, terminal-views), while the dashboard in the same release uses "Measured". Pick one word for all four surfaces. Measured is the plainer word and is already on the dashboard.
  3. BLOCKING, docs/plugin/index.md says command output is "plain Unicode, no colour codes... Colour appears only in the status line", but terminal-views.md documents coloured heat ramps, --theme and NO_COLOR. Fix the sentence: the six commands are plain, the five views use colour and fall back to plain when output is not a terminal or NO_COLOR is set.
  4. POLISH, statusline.md, ctx row: "against the window actually served" is jargon; say "of the model's context limit".
  5. POLISH, README example for the six commands uses mixed periods (7 days for savings, "this session" for the session line); fine, but the /context-guru:session example hides that it covers only recent activity in a long session. Add "in the last 4 hours" to the example so it matches the real output.
  6. POLISH, README mentions the five views only on the docs site; add one line with their names so a README reader knows they exist.

Pass needs 1 to 3.

Osher-Elhadad added 2 commits October 12, 2026 12:36
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Final design pass, re-check at head 25cfee3: PASS.

The three blockers are fixed. The status line now shows saved $0.31 session · ... with no estimate mark, and the docs table calls it Saved (modelled against the same requests without the proxy); Estimated is used for avoidable spend only. "(observed)" labels are replaced by Measured across the commands, views and docs, matching the dashboard. The colour sentence now says the six commands are plain and the five views use colour with a plain fallback.

Whole-PR checks: README and docs/plugin read clearly for a first-time user, images exist and match the text, one vocabulary (Saved / Estimated / Measured) across commands, status line, views and dashboard, no contradictions found.

Remaining POLISH (non-blocking): the ctx row's "window actually served" wording; the README session example should say "in the last 4 hours"; the README could name the five views.

Osher-Elhadad added 7 commits October 12, 2026 12:47
…derers can import them without cg

Signed-off-by: Osher-Elhadad <[email protected]>
…at, fill, watch)

One-line versions of the terminal views, selectable with --layout or
--set-layout, drawn with tvlib and fed by the same cached, non-blocking
reads as the other layouts. Goldens at 60, 80 and 120 columns.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Design review: five new status line layouts (spark, strip, heat, fill, watch), commit da62833. Judged from the .cast output (text and escape codes) at 80 columns as a first-time user; the layouts are opt-in via --layout, so the default screens already passed are unaffected.

Layout 5-second result Fits 80 cols, 2 lines Verdict
spark partly: "saved $24.30 today" then a bar graph labelled "14 days"; a reader cannot tell whether $24.30 is today or the 14 days yes (42) POLISH
strip partly: "last 20" markers with no legend; "last 20" and "today" mix two scopes in one line yes (56) BLOCKING (1)
heat no yes (48) BLOCKING (2)
fill yes: bar, percent and time to full; no dollars on the line yes (68; 110 at 120 cols) PASS with polish
watch no: "a1 ████ 4:22 a2 █░░░ 0:52" does not say what a1 and a2 are yes (26) BLOCKING (3)

Findings

  1. BLOCKING, strip: the ✖ and ■ markers have no key on the line, and the label mixes "last 20" (requests) with "$5.56 lost to misses today". Rename to one scope ("last 20 requests: ✖ = miss") and say what the dollars cover ("$5.56 lost today"), or drop the dollars.
  2. BLOCKING, heat: the cells are spaces with a background colour only (\e[48;5;…m ). With NO_COLOR, on a colour-blind display, in a copied or echoed line, or in a theme where the background shades look alike, the heat strip is invisible: the line reads "misses 0h 24h $5.56 lost". Use shade characters (░▒▓█) as well as colour. Also: 14 coloured cells then blank space against a 0h to 24h axis, so the strip does not span the axis it labels; and the dollar total is for the day while the cells are miss counts per hour, as noted, so the line shows two different measures with one label. Label it ("misses per hour, $5.56 lost today").
  3. BLOCKING, watch: a1 and a2 are unexplained. Use the existing wording from the default layout (agents 2 · soonest ◐ 0:52) or spell out "agent 1". Also the line has no saved or cost figure, so it answers none of the money questions.
  4. POLISH, spark: put the scope in the label ("saved $24.30 today · last 14 days ▁▁█…").
  5. POLISH, fill: first line has no dollars. Add the price of a miss now ("a miss now costs $X") in the 120-column form where there is room.
  6. POLISH, all five: line 2 is the cache clock only; none carries a hint slot. Fine for these glance layouts, but say so in the docs so users do not expect a hint.

Pass needs 1 to 3.

Osher-Elhadad added 2 commits October 12, 2026 13:24
Signed-off-by: Osher-Elhadad <[email protected]>
…heat readable without colour

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Status line layouts, re-check at 960a76b: PASS.

Strip now has one scope, a key for the miss marker, and "lost today". Heat uses shade glyphs plus colour, shows future hours as "·" so it spans its 0h to 24h axis, and reads without colour. Watch names the clocks ("agent caches (2)") and carries the saved figure on the same line as the cache clock. Spark states its scopes ("today · last 14 days"); fill at 120 columns adds the price of a miss. All lines are 79 characters or shorter.

Remaining POLISH: heat's "$5.56 lost" should say "today" like strip does, so its day scope is explicit.

@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Review of da62833 (and cd5df33, the head main asked about). Not approved yet; the ready-to-merge label is removed until the two blockers below are fixed.

Checked at cd5df33 and da62833: full go test ./context-guru-plugin/ passes at both (398 s and 374 s under load); mkdocs build --strict passes; go vet clean; no "campaign" in the plugin, docs/plugin, docs/plugin-v2.md or the Codex plugin; no AI or Co-Authored-By trailers in the range; no hosts, ids or paths in the diff.

BLOCKING

  1. Wall-time budget of the default layouts (new criterion). I ran the real script end to end, Python start-up included, in a fresh temp/cache dir against a local server that can sleep, for minimal, balanced and detailed (harness: m2/reviewer/statusline_timing.py). Cold 0.09 s, warm 0.05 to 0.06 s, proxy down 0.09 s (prints cg ✕ proxy offline), all fine. Slow proxy (every endpoint sleeps 3 s): 0.69 s cold (cg: stats loading…) and 0.66 to 0.67 s with a primed but stale cache (the stale line plus ⏳), in all three layouts. That exceeds 0.5 s because the shared fetch deadline is HTTP_TIMEOUT_SECONDS 0.6 plus 0.2 (statusline.py ~l.71 and ~l.1233). Reads on the render path are all lean=1 (/api/stats?lean=1 with and without since, /api/cachestate), so the lean rule holds. The fix has to bring the slow cases under 0.5 s with Python start-up included (budget the deadline from process start, not from the fetch), and keep fix(dash,plugin): stop statusline cg! on slow stats, dedupe cache refresh #403's protections: stale on timeout, no false cg!, single flight.
  2. The 14-day sparkline (spark layout) is wrong in every time zone east of UTC. _spark_row indexes the day buckets with ts // DAY_MS (UTC days) and compares them with last = now // DAY_MS, while the server buckets start at the local midnight passed as since. I fed 14 buckets with values 1..14 at local midnights: in UTC the line is _..,,::-==++##; in Asia/Kolkata it is ..,,::-==++### (every day shifted by one, the last value repeated); in America/Los_Angeles and Pacific/Auckland it happened to come out right at the pinned clock. The goldens pin TZ=UTC, so no test sees it. Index the buckets by position (sort by ts, take the 13 before the last, then today) and add golden tests under TZ=Asia/Kolkata and TZ=America/Los_Angeles.

SHOULD FIX
3. _growth in statusline.py duplicates the helper that now lives in tvlib (commit 4275e8a moved it for exactly this reason). Import it lazily from tvlib instead, or add a test that the two agree on the same rows.
4. The heat layout sums cache_misses counts per hour and the strip/heat tail adds rewrite_usd from /api/spend/explain from midnight - 1 h; state in the docs that the dollar figure is the rewrite cost (an estimate of loss), and add a test where that read fails (the layout should still draw).
5. The new layouts add background reads (/api/series, /api/spend/explain, /api/requests) that are not on the default layouts' path; that is right, but add the same wall-time harness for the five new layouts against a sleeping server so they obey the same 0.5 s rule.

Re-review when 1 and 2 are fixed.

@OsherElhadad OsherElhadad removed the ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval label Oct 12, 2026
Osher-Elhadad added 4 commits October 12, 2026 13:34
…nd heat follow local time

The render budget is measured from process start and sizes every read; a
read with a cached copy never waits (stale copy plus detached refresh), a
slow proxy shows the last numbers with the stale marker. The 14-day
sparkline sums the proxy's UTC-aligned hourly buckets into the user's
local days. Goldens under three time zones and a slow-proxy test.

Signed-off-by: Osher-Elhadad <[email protected]>
@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Final re-review at 2f4b916 (code at ec131b8, docs-only commit on top). Both blockers are resolved. Render time: my end-to-end harness (Python start-up included, fresh cache dir, a server that sleeps 3 s) gives minimal, balanced and detailed at 0.38 to 0.41 s with a slow proxy, cold or with a stale cache, including a run with six busy loops competing for CPU (worst 0.413 s); warm 0.05 to 0.06 s, cold 0.09 s, proxy down 0.09 s with 'cg ✕ proxy offline'. Only lean=1 stats and cachestate are read on the render path. The new TestStatuslineFinishesInHalfASecondOnASlowProxy and the #403 tests pass. Sparkline: my earlier diagnosis was wrong, the proxy's series buckets are epoch-aligned, so the hourly-sum-into-local-days approach is correct, and the goldens under Asia/Kolkata, Europe/Berlin and America/Los_Angeles agree with UTC. Full go test ./context-guru-plugin passes (374 s), mkdocs build --strict passes at 2f4b916, CI is green (build-test, build, purego, trivy, DCO), no campaign words, no AI attribution. The docs tables match my measurements. Approved; ready-to-merge.

@OsherElhadad OsherElhadad added the ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval label Oct 12, 2026
@amiddavid

Copy link
Copy Markdown
Collaborator

Status-line timing test on real data: no regression of #403

Result: #478 does not bring back the false "proxy down" that #403 fixed. I tested it against copies of a real local dashboard DB (262 MB, 12.4k requests), with a darwin build of this branch and of main. I used 1, 4 and 8 concurrent sessions, each re-rendering every 1–5 s, so the detached refreshers fired.

2 notes on this PR's own code (neither blocks it)

1. A small race in the refresher lock (statusline.py, _bg_json)

  • The lock is taken with os.stat(lock).st_mtime, then a separate open(lock, 'w'). That is check-then-write, not atomic.
  • In a synchronized cold start (8 sessions within 0.3 s), 2 detached refreshers started for the same key.
  • The impact is small: both call the same endpoint, and the server's single-flight still runs the query only once. So the cost is one extra HTTP GET.
  • Fix: create the lock with os.open(lock, os.O_CREAT | os.O_EXCL | os.O_WRONLY), and treat FileExistsError as "someone else is refreshing". Then clear a stale lock by its age.

2. The render budget is tighter than main's

@OsherElhadad

Copy link
Copy Markdown
Collaborator Author

Thanks for testing on real data. Both notes are handled in 738b525.

Note 1, the refresher lock. Fixed in context-guru-plugin/scripts/statusline.py, _take_refresh_slot (line 757), used by _bg_json (line 801). The check-then-write is gone. The lock file is now created with os.open(..., O_CREAT | O_EXCL | O_WRONLY), and FileExistsError means "someone else is refreshing". One difference from what you suggested: the lock file's name carries the 30-second window number (<cache file>.lock.<n>), so a lock left behind by a crashed refresher belongs to an earlier window and stops mattering. That avoids the stat-then-unlink step, which has its own small race when two renders both see a stale lock. The previous window's file and the old unnumbered lock name are removed best effort. Test: TestStatuslineRefreshLockIsAtomic starts 16 simultaneous cold calls on one key and gets exactly 1 refresher, 0 more in the same window, and 1 again when the only lock is from an earlier window.

Note 2, "loading" with a usable cache. I checked every path. A fetch that times out already shows the cached numbers with ⏳. There was one path that did not: if the fetch thread has not reported by the time the budget ends (a loaded host can starve it), the line said "loading" even with a cache on disk. That path now reads the cached body and shows it with ⏳ (_stale_stats, line 506). Test: TestStatuslineNeverSaysLoadingWithACache. It printed cg: stats loading… before the fix and prints the cached $2.50 with ⏳ after.

Numbers, 20 renders each, 2.1 s apart so every render fetches, stats call stalled for 5 s, on this loaded host:

The budget is unchanged (0.36 s; the render stays under 0.5 s). We'll re-check after #492 lands.

@amiddavid
amiddavid merged commit a9ee930 into main Oct 12, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Oct 12, 2026
amiddavid added a commit that referenced this pull request Oct 13, 2026
User decision on this PR's review: remove the daily_rollup design
entirely for this release. Ship only the bounded session and day
scopes; lifetime (since=0) goes back to answering exactly like the
full handler, no rollup, no backfill, no watermark. A bounded lifetime
is its own project, tracked as #510 rather than shipped
half-verified here.

- Removed: the daily_rollup table and index (schema.go), its backfill
  (dailyrollupbackfill.go, deleted), its write-time accumulation and
  watermark (store.go), and its wiring into backgroundMigrations
  (capture.go).
- OverviewLean: session and day-window scope still run the single
  bounded aggregate from the previous commit. True lifetime
  (session=="" && since==0 && until==0) now calls Overview() plus both
  read-time-priced credits unconditionally — byte-identical to main's
  own lean handler, confirmed via the regenerated stats_lean golden
  file (the only remaining differences are fields lean never computed
  even before #498: self_removed_*, tier_costs, total_reduced_usd).
- Review M3: CachesplitSizeSpread (dash/cachehistory.go) ran a
  deployment-wide, unindexed scan on every session-scoped lean call.
  Added a TTL cache (5 minutes) behind a *DB-held pointer, so
  DB.WithContext's shallow copy stays lock-free and every handle
  shares one cache. TestCachesplitSizeSpreadQueryItselfIsAWholeTableScan
  documents why the cache exists; TestCachesplitSizeSpreadIsCached
  proves it intercepts repeat calls (verified it fails with the cache
  disabled, passes with it restored).
- Review M4: cg_latency_ms_avg stays in the lean SELECT — the released
  v0.4.2 status line (before #478) reads it and renders "proxy: 0ms"
  if it is ever absent.
- DeclFilterSavings now included for day-window scope too, not just
  session (TestOverviewLeanDeclFilterSavingsIncludedForDayScope).
- The EXPLAIN-plan test now rejects "SCAN ... USING INDEX", not just a
  bare table scan — an index-assisted scan still visits every matching
  row, unbounded by session or time. Lifetime is deliberately excluded
  from it, with a comment pointing at the follow-up issue.
- Kept: the #501 tenant-scoping fix in cachesplitHistoricalQuery.

go test -race -count=1 on ./dash/... and ./proxy/... both pass.

Assisted-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: DAVID AMID <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Program PR approved by the reviewer, CI green; needs maintainer approval

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants