Skip to content

feat(stats): per-group missing-money counts and security log totals - #193

Merged
fylorn merged 1 commit into
mainfrom
feat/stats-counts
Sep 25, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/stats-counts

Conversation

@fylorn

@fylorn fylorn commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Two protocol gaps the redesigned desktop UI had to paper over.

/summary/buckets/by: every group says how much of its money is missing

CostBucketGroup gains two fields, with exactly the semantics CostBucket and CostGroup already use (the same NO_PRICE / NO_USAGE SQL conditions):

field type meaning
unpriced_requests number requests in this bucket and group whose model is not in the price table (usage is known; a price would fix it) — see Summary::unpriced_requests
no_usage_requests number requests in this bucket and group that got no usage from the upstream — see Summary::no_usage_requests

Filled for every dim (model, provider, client). A group whose cost is 0 can now be told apart as "no price", "no usage" or genuinely free (e.g. a free-billing upstream), and the groups of one bucket add up to that bucket's own counts in /summary/buckets.

GET /security/events: the total for the window, by outcome

SecurityEventsPage gains:

field type meaning
total number every event matching the request's guard and from_ms/to_ms window — not just this page
by_outcome SecurityOutcomeCounts how many of total were recorded / replaced / cut / blocked; all four keys always present (0 when none); they add up to total

New type SecurityOutcomeCounts { recorded: number, replaced: number, cut: number, blocked: number } (one field per SecurityOutcome variant).

  • The page query and the count query share one WHERE clause (SECURITY_FILTER in tw-store/src/db.rs), so the header number and what paging can reach are the same set.
  • before is a paging cursor, not a filter: every page of the same window reports the same total / by_outcome.
  • more is unchanged. The count only reads security_events (the join to requests never adds or drops an event). No schema change.
  • Db::security_events now returns the whole tw_api::SecurityEventsPage; the handler passes it through.

No new endpoints, no new message codes, no changes to the first-layer crates (tw-dialect, tw-guard, tw-breaker).

Tests

  • tw-store: every_group_in_a_bucket_says_how_much_of_its_money_is_missing (all three dims across two buckets, including a free-billing group and an empty window; groups sum to the plain bucket); the two cost-state definition tests now also cover cost_buckets_by.
  • tw-store: the_total_counts_the_whole_window_not_just_the_page (9 events, pages of 4; total stays 9 on every page), the_total_is_what_paging_to_the_end_yields_under_every_filter (guard and time filters, including an empty filtered set), an_empty_window_counts_zero_of_everything.
  • tw-control: the log test now checks total / by_outcome on the first page, the next page and a filtered query; the_log_counts_past_one_page_and_an_empty_window_counts_zero (150 events with the default page of 100; the exact JSON for an empty window); new tests/summary.rs checks the /summary/buckets/by JSON for all three dims and an empty window.

cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass locally.

🤖 Generated with Claude Code

/summary/buckets/by: every CostBucketGroup now carries unpriced_requests
and no_usage_requests, counted with the same NO_PRICE / NO_USAGE
conditions as CostBucket and CostGroup, for every dim (model, provider,
client). A group whose cost is 0 can now be told apart as "no price",
"no usage" or genuinely free, and the groups of a bucket add up to that
bucket's own counts.

GET /security/events: SecurityEventsPage gains `total` (every event that
matches the guard and time window, not just this page) and `by_outcome`
(SecurityOutcomeCounts: recorded / replaced / cut / blocked, all four
always present; they add up to `total`). The page and the count share
one WHERE clause (SECURITY_FILTER); `before` is a cursor, not a filter,
so every page of the same window reports the same total. `more` stays.

Db::security_events now returns the whole tw_api::SecurityEventsPage.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 56587c3 into main Sep 25, 2026
4 checks passed
@fylorn
fylorn deleted the feat/stats-counts branch September 25, 2026 03:21
@fylorn fylorn mentioned this pull request Sep 25, 2026
fylorn added a commit that referenced this pull request Sep 25, 2026
v0.48.0 was published before the template landed, so its page holds
only GitHub's generated list. release-notes/0.48.0.md summarizes it
from #191-#198 so the page can be rewritten from the template:

- upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16
  (core 0.47.0, protocol 20) does not connect to it and a server used
  with that app stays on 0.47.0; the request store's schema 20, which
  empties the request history on the first start (and again on the way
  back); the /in-flight shape, RequestStarted.session and the removed
  ChatgptUsage fields;
- session and route on the start event, requests a rule decided
  without an upstream, the replayable /in-flight snapshot and the new
  /live fields, and /summary/routes (#197);
- per-group unpriced and no-usage counts, and security log totals
  (#193);
- the signed-in account on a ChatGPT account upstream (#195);
- releases published from one job, the server guide and the crate
  metadata (#191), and the test port fix (#192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn added a commit that referenced this pull request Sep 25, 2026
v0.48.0 was published before the template landed, so its page holds
only GitHub's generated list. release-notes/0.48.0.md summarizes it
from #191-#198 so the page can be rewritten from the template:

- upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16
  (core 0.47.0, protocol 20) does not connect to it and a server used
  with that app stays on 0.47.0; the request store's schema 20, which
  empties the request history on the first start (and again on the way
  back); the /in-flight shape, RequestStarted.session and the removed
  ChatgptUsage fields;
- session and route on the start event, requests a rule decided
  without an upstream, the replayable /in-flight snapshot and the new
  /live fields, and /summary/routes (#197);
- per-group unpriced and no-usage counts, and security log totals
  (#193);
- the signed-in account on a ChatGPT account upstream (#195);
- releases published from one job, the server guide and the crate
  metadata (#191), and the test port fix (#192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fylorn added a commit that referenced this pull request Sep 25, 2026
…summary (#196)

* ci(release): write the release page from a template, with an English summary

#191 made the publish job write the release once, with GitHub's
generated list of pull requests as its only text and the tag as its
title. A release is now titled "ThinkWatch Core <version>", and its text
has, in order:

- an English summary from release-notes/<version>.md, when that file
  exists;
- a table of the files for each platform;
- the commands that install this version on a Linux server and switch
  an existing installation to it (install.sh --version, twcore upgrade
  --version --restart);
- how to verify a download against its .sha256;
- GitHub's generated list of pull requests.

scripts/release_notes.py builds the text; the publish job fetches the
generated list itself (releases/generate-notes) and hands the finished
text to action-gh-release, which no longer generates anything. The
"only once" rule from #191 stays: a release that already exists keeps
its text. A rehearsal (workflow_dispatch) now writes the text into the
run summary, using the version in Cargo.toml.

scripts/release_notes_test.py checks that the table links exactly the
files in release.yml's FILES list, that the install and upgrade options
exist, and that every file in release-notes/ renders; the Linux CI job
runs it before compiling.

release-notes/0.47.0.md summarizes 0.47.0 from #183-#190; the live
v0.47.0 release page now carries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* release-notes: summarize 0.48.0

v0.48.0 was published before the template landed, so its page holds
only GitHub's generated list. release-notes/0.48.0.md summarizes it
from #191-#198 so the page can be rewritten from the template:

- upgrade notes: CONTROL_API_VERSION 21, so ThinkWatch Lite 2026.9.16
  (core 0.47.0, protocol 20) does not connect to it and a server used
  with that app stays on 0.47.0; the request store's schema 20, which
  empties the request history on the first start (and again on the way
  back); the /in-flight shape, RequestStarted.session and the removed
  ChatgptUsage fields;
- session and route on the start event, requests a rule decided
  without an upstream, the replayable /in-flight snapshot and the new
  /live fields, and /summary/routes (#197);
- per-group unpriced and no-usage counts, and security log totals
  (#193);
- the signed-in account on a ChatGPT account upstream (#195);
- releases published from one job, the server guide and the crate
  metadata (#191), and the test port fix (#192).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* release-notes(0.48.0): say where the key is kept without naming the keychain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant