codefloe/forgejo-codefloe
Watch
4
12
Fork
You've already forked forgejo-codefloe
0

feat(quota): give CI/CD usage its own tab, charted by day #101

Merged
pat-s merged 1 commit from feat/ci-usage-tab into v16.0/forgejo-codefloe 2026-08-30 13:28:20 +00:00
Owner

Follows #100, which landed the CI minutes ledger and put a CI card on the storage overview.

CI time is not storage, and that tab is gated on [quota] ENABLED, so the card was unreachable on an instance that caps no storage. This moves it out into a tab of its own and gives the numbers room to be read.

Rebased onto #105, so it sits on top of the whole of phase 2 rather than on #100 alone. The per-class breakdown #105 added to the card is carried into the new panel rather than dropped with it.

image

CI/CD usage tab

/user/settings/ci_usage and <org>/settings/ci_usage, gated only on [quota.ci] ENABLED. The card and its data loading come back out of templates/shared/quota_overview.tmpl and StorageOverview, so the storage overview is once again only about storage.

Four panels:

Limits — the rules that apply to CI time, each with a bar filled to used against limit. Now that #100 has landed time:ci:* subjects and [quota.ci.default] TOTAL, there is a real denominator to fill against.

Minutes by CI engine — one fold per producer, behind a chevron that turns on open, with the per-class breakdown inside. The <details> was already there in the card, but the storage overview's styling hides the disclosure marker, so nothing said the row opened.

Minutes by day — the period charted one column per day, stacked by the repositories that ran that day, with an axis tick on every day. Columns are scaled against the busiest day, printed above the plot. Hovering a segment names just that segment: the repository, its minutes, and the day. Days the period has not reached are a dotted baseline, so an empty tail reads as "not yet" rather than "nothing ran". Columns carry no track behind the bar; the limit bars above are what fills against a quota.

Minutes by repository — the five biggest, each with a bar and share, doubling as the chart's legend.

Units

Every duration reads in whole minutes as a plain number: "1797 minutes / 2400 minutes", not "29h 57m" and not "1,797". That is the unit the quota is written in and the one usage is communicated in.

Minutes are a display unit only. The ledger keeps exact wall-clock seconds, which is what accumulates without drift, and the API keeps reporting seconds as #93 specified, so machine consumers and phase 3's external reporters keep a lossless contract.

Every figure is rendered from those seconds rather than from a number that has already been rounded, because the two zeroes have to read differently: an account that has run nothing shows "0 minutes", while a run too short to round up to one still says "less than a minute". Ranking, shares and the "other" total are taken from the same seconds, so no decision is made on a figure that has lost the precision to make it.

The figure in the header and the rules beside it count work that is still running, so a long job is visible while it burns time. The breakdowns below are drawn from the ledger, which only has finished runs in it. Rather than leave the two to disagree by however long the jobs have been going, the page says how much of the total is still in flight, and only while there is any.

Colours

Series are coloured from viridis at five steps: #440154 #3B528B #21908C #5DC863 #FDE725, with #A8A8A8 for "other".

Checked with a colour-blindness validator over every pair rather than only adjacent ones, which is the right check because a stacked column can put any two series next to each other. Every pair clears both the colour-blind separation floor (worst 9.2 ΔE) and the normal-vision floor (worst 16.7 ΔE), on the light and the dark surface alike, "other" included. The neutral is deliberately light: a mid grey lands on viridis' teal and fails.

Series take palette slots in fixed order by name and are never cycled. The sixth repository onwards folds into the neutral, so the chart never shows a colour the legend cannot explain.

That invariant is held in seconds as well. A tail of runs that each round to no minutes still adds up to the legend's grey row, and a run that started and stopped inside the same second is dropped once, before either the chart or the legend sees it, so neither can show what the other does not.

The chart is plain server-rendered markup and CSS, no charting library and no new JS. Its styles live in web_src/css/codefloe/ci-usage-chart.css, reached through the fork's own @import list, so upstream's CSS is untouched.

Admin view

/admin/users/{id} gets the same four panels, read-only, with the period total in the header. Upstream exposes admin quota over the API only, so this has no upstream equivalent to mirror.

Three gaps in the ledger

All fixed here rather than left for later:

  • Deleting an owner orphaned its ledger rows. quota_ci_usage and quota_ci_record are now dropped with the owner, in the existing DeleteBeans calls. #92 lists this under Risks. Both paths are covered: organizations never reach services/user/delete.go, they go through org_model.DeleteOrganization, and they are the owners that accumulate the most CI time.
  • The ledger had no index for the way it is read. v10 gave quota_ci_record single-column indexes on owner_id and on period, but every read of the detail rows asks for both at once. v11 adds the composite. The aggregate table needs nothing: its UNIQUE(usage_scope) already starts (owner_id, period).
  • The migration had no test. v10_test.go asserts both tables and both unique indexes exist, and that re-running the sync is a no-op. v11_test.go does the same for the new index, starting from the schema v10 leaves behind.

Model

One addition: PeriodBreakdown, which projects a period's records to (repo_id, stopped, seconds). The chart and the repository list are both computed from that single query, and every repository it names is resolved in one more, shared by both panels. Bucketing is done in Go rather than SQL because truncating a timestamp to a day differs across the three supported databases, and a period holds at most one month of one owner's records.

TopRepos goes: the storage card was its only caller, and its GROUP BY ... LIMIT 5 bounded the rows returned rather than the rows scanned, so what changed with PeriodBreakdown is the transfer, not the work the database does. v11's composite index is what makes that scan an index range over exactly the matching rows.

The new index is declared on the model as well as in the migration. Startup runs the migrations and then syncs the models, and that sync reconciles each table's indexes against its model rather than adding to them, so an index only the migration knows about is dropped again before the instance has finished starting. v11_test.go asserts that too.

Upstream merge surface

Seven upstream files, all small:

file change
routers/web/web.go two routes and one ctxDataSet entry
routers/web/admin/users.go one data-loading call
services/user/delete.go two beans
models/organization/org.go two beans and one import
templates/admin/user/view.tmpl one template include
templates/user/settings/navbar.tmpl, templates/org/settings/navbar.tmpl one tab each

templates/shared/quota_overview.tmpl and routers/web/shared/storage_overview.go go back to what upstream has, minus #100's own additions, which is a net reduction in surface.

Tests

  • integration tests for the tab on the user and the org, the admin panel, one chart column per day of the period, and that the tab is reachable with [quota] ENABLED off
  • a test that every colour in the chart is one the legend names, over a fixture with more repositories than the palette has slots and a tail that rounds to nothing
  • a test that the page reports minutes and only minutes, as a plain number with no thousands separator, including the sub-minute case
  • a test that an account which has run nothing reads as "0 minutes" and not as a very short run, on the tab and in the admin header
  • a test that a period whose every run rounds to nothing still draws its chart, and that a repository which spent no measurable time takes no colour in the legend
  • a test that a rule allowing nothing prints "0 minutes" and fills its bar rather than reading as untouched
  • a test that the dotted baseline follows the ledger's clock, which a mocked one moves
  • a test that a running job is called out on the page, and is not when there is none
  • a test that deleting an organization takes its ledger rows with it
  • a test that the storage overview no longer carries CI time
  • the migration tests above

Every test added or changed during review was also checked against the unfixed code — the defect put back, the test confirmed to fail — so none of them passes for the wrong reason. Two did not, at first: one asserted on a fixture where the tail absorbed the case it was meant to catch, and one synced a struct whose name mapped to a different table than the one it was asserting on.

Verification

go test -tags sqlite,sqlite_unlock_notify ./models/codefloe/... ./services/codefloe/... ./models/quota/... ./modules/setting ./services/user ./services/org ./models/organization ./services/actions ./services/cron
GITEA_ROOT="$PWD" GITEA_CONF=tests/sqlite.ini go test -tags sqlite,sqlite_unlock_notify ./models/codefloe_migrations
make test-sqlite#'TestQuota|TestAPIQuota|TestActionsQuota|TestWebQuota|TestOrg|TestAPIOrg|TestAdmin'
make lint-backend tidy-check swagger-check lint-swagger fmt-check swagger-validate lint-css

All pass. Two notes on running them:

  • lint-backend needs the toolchain version pinned in go.mod rather than a newer system Go, which is what makes it runnable at all. It is also the target that catches lint-editorconfig, which the shorter lint-go does not.
  • The migration tests need GITEA_ROOT and GITEA_CONF, the way the Makefile passes them. Without those they fail with "no database host defined", which looks like an environment they cannot run in and is not.
Follows #100, which landed the CI minutes ledger and put a CI card on the storage overview. CI time is not storage, and that tab is gated on `[quota] ENABLED`, so the card was unreachable on an instance that caps no storage. This moves it out into a tab of its own and gives the numbers room to be read. Rebased onto #105, so it sits on top of the whole of phase 2 rather than on #100 alone. The per-class breakdown #105 added to the card is carried into the new panel rather than dropped with it. ![image](/attachments/073d0718-1034-4d5b-a0fa-7aa868250607) ## CI/CD usage tab `/user/settings/ci_usage` and `<org>/settings/ci_usage`, gated only on `[quota.ci] ENABLED`. The card and its data loading come back out of `templates/shared/quota_overview.tmpl` and `StorageOverview`, so the storage overview is once again only about storage. Four panels: **Limits** — the rules that apply to CI time, each with a bar filled to used against limit. Now that #100 has landed `time:ci:*` subjects and `[quota.ci.default] TOTAL`, there is a real denominator to fill against. **Minutes by CI engine** — one fold per producer, behind a chevron that turns on open, with the per-class breakdown inside. The `<details>` was already there in the card, but the storage overview's styling hides the disclosure marker, so nothing said the row opened. **Minutes by day** — the period charted one column per day, stacked by the repositories that ran that day, with an axis tick on every day. Columns are scaled against the busiest day, printed above the plot. Hovering a segment names just that segment: the repository, its minutes, and the day. Days the period has not reached are a dotted baseline, so an empty tail reads as "not yet" rather than "nothing ran". Columns carry no track behind the bar; the limit bars above are what fills against a quota. **Minutes by repository** — the five biggest, each with a bar and share, doubling as the chart's legend. ## Units Every duration reads in whole minutes as a plain number: "1797 minutes / 2400 minutes", not "29h 57m" and not "1,797". That is the unit the quota is written in and the one usage is communicated in. Minutes are a display unit only. The ledger keeps exact wall-clock seconds, which is what accumulates without drift, and the API keeps reporting seconds as #93 specified, so machine consumers and phase 3's external reporters keep a lossless contract. Every figure is rendered from those seconds rather than from a number that has already been rounded, because the two zeroes have to read differently: an account that has run nothing shows "0 minutes", while a run too short to round up to one still says "less than a minute". Ranking, shares and the "other" total are taken from the same seconds, so no decision is made on a figure that has lost the precision to make it. The figure in the header and the rules beside it count work that is still running, so a long job is visible while it burns time. The breakdowns below are drawn from the ledger, which only has finished runs in it. Rather than leave the two to disagree by however long the jobs have been going, the page says how much of the total is still in flight, and only while there is any. ## Colours Series are coloured from **viridis** at five steps: `#440154 #3B528B #21908C #5DC863 #FDE725`, with `#A8A8A8` for "other". Checked with a colour-blindness validator over *every* pair rather than only adjacent ones, which is the right check because a stacked column can put any two series next to each other. Every pair clears both the colour-blind separation floor (worst 9.2 ΔE) and the normal-vision floor (worst 16.7 ΔE), on the light and the dark surface alike, "other" included. The neutral is deliberately light: a mid grey lands on viridis' teal and fails. Series take palette slots in fixed order by name and are never cycled. The sixth repository onwards folds into the neutral, so the chart never shows a colour the legend cannot explain. That invariant is held in seconds as well. A tail of runs that each round to no minutes still adds up to the legend's grey row, and a run that started and stopped inside the same second is dropped once, before either the chart or the legend sees it, so neither can show what the other does not. The chart is plain server-rendered markup and CSS, no charting library and no new JS. Its styles live in `web_src/css/codefloe/ci-usage-chart.css`, reached through the fork's own `@import` list, so upstream's CSS is untouched. ## Admin view `/admin/users/{id}` gets the same four panels, read-only, with the period total in the header. Upstream exposes admin quota over the API only, so this has no upstream equivalent to mirror. ## Three gaps in the ledger All fixed here rather than left for later: - **Deleting an owner orphaned its ledger rows.** `quota_ci_usage` and `quota_ci_record` are now dropped with the owner, in the existing `DeleteBeans` calls. #92 lists this under Risks. Both paths are covered: organizations never reach `services/user/delete.go`, they go through `org_model.DeleteOrganization`, and they are the owners that accumulate the most CI time. - **The ledger had no index for the way it is read.** v10 gave `quota_ci_record` single-column indexes on `owner_id` and on `period`, but every read of the detail rows asks for both at once. v11 adds the composite. The aggregate table needs nothing: its `UNIQUE(usage_scope)` already starts `(owner_id, period)`. - **The migration had no test.** `v10_test.go` asserts both tables and both unique indexes exist, and that re-running the sync is a no-op. `v11_test.go` does the same for the new index, starting from the schema v10 leaves behind. ## Model One addition: `PeriodBreakdown`, which projects a period's records to `(repo_id, stopped, seconds)`. The chart and the repository list are both computed from that single query, and every repository it names is resolved in one more, shared by both panels. Bucketing is done in Go rather than SQL because truncating a timestamp to a day differs across the three supported databases, and a period holds at most one month of one owner's records. `TopRepos` goes: the storage card was its only caller, and its `GROUP BY ... LIMIT 5` bounded the rows returned rather than the rows scanned, so what changed with `PeriodBreakdown` is the transfer, not the work the database does. v11's composite index is what makes that scan an index range over exactly the matching rows. The new index is declared on the model as well as in the migration. Startup runs the migrations and then syncs the models, and that sync reconciles each table's indexes against its model rather than adding to them, so an index only the migration knows about is dropped again before the instance has finished starting. `v11_test.go` asserts that too. ## Upstream merge surface Seven upstream files, all small: | file | change | | --- | --- | | `routers/web/web.go` | two routes and one `ctxDataSet` entry | | `routers/web/admin/users.go` | one data-loading call | | `services/user/delete.go` | two beans | | `models/organization/org.go` | two beans and one import | | `templates/admin/user/view.tmpl` | one template include | | `templates/user/settings/navbar.tmpl`, `templates/org/settings/navbar.tmpl` | one tab each | `templates/shared/quota_overview.tmpl` and `routers/web/shared/storage_overview.go` go back to what upstream has, minus #100's own additions, which is a net reduction in surface. ## Tests - integration tests for the tab on the user and the org, the admin panel, one chart column per day of the period, and that the tab is reachable with `[quota] ENABLED` off - a test that every colour in the chart is one the legend names, over a fixture with more repositories than the palette has slots and a tail that rounds to nothing - a test that the page reports minutes and only minutes, as a plain number with no thousands separator, including the sub-minute case - a test that an account which has run nothing reads as "0 minutes" and not as a very short run, on the tab and in the admin header - a test that a period whose every run rounds to nothing still draws its chart, and that a repository which spent no measurable time takes no colour in the legend - a test that a rule allowing nothing prints "0 minutes" and fills its bar rather than reading as untouched - a test that the dotted baseline follows the ledger's clock, which a mocked one moves - a test that a running job is called out on the page, and is not when there is none - a test that deleting an organization takes its ledger rows with it - a test that the storage overview no longer carries CI time - the migration tests above Every test added or changed during review was also checked against the unfixed code — the defect put back, the test confirmed to fail — so none of them passes for the wrong reason. Two did not, at first: one asserted on a fixture where the tail absorbed the case it was meant to catch, and one synced a struct whose name mapped to a different table than the one it was asserting on. ## Verification ``` go test -tags sqlite,sqlite_unlock_notify ./models/codefloe/... ./services/codefloe/... ./models/quota/... ./modules/setting ./services/user ./services/org ./models/organization ./services/actions ./services/cron GITEA_ROOT="$PWD" GITEA_CONF=tests/sqlite.ini go test -tags sqlite,sqlite_unlock_notify ./models/codefloe_migrations make test-sqlite#'TestQuota|TestAPIQuota|TestActionsQuota|TestWebQuota|TestOrg|TestAPIOrg|TestAdmin' make lint-backend tidy-check swagger-check lint-swagger fmt-check swagger-validate lint-css ``` All pass. Two notes on running them: - `lint-backend` needs the `toolchain` version pinned in `go.mod` rather than a newer system Go, which is what makes it runnable at all. It is also the target that catches `lint-editorconfig`, which the shorter `lint-go` does not. - The migration tests need `GITEA_ROOT` and `GITEA_CONF`, the way the Makefile passes them. Without those they fail with "no database host defined", which looks like an environment they cannot run in and is not.
image.png
469 KiB
pat-s force-pushed feat/ci-usage-tab from 860173b093
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m2s
testing / backend-checks (pull_request) Failing after 3m47s
testing / test-unit (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
to 74c19a05eb
Some checks failed
testing / test-unit (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 1m24s
testing / backend-checks (pull_request) Failing after 4m20s
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
2026-08-28 18:58:44 +00:00
Compare
pat-s force-pushed feat/ci-usage-tab from 74c19a05eb
Some checks failed
testing / test-unit (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-pgsql (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 1m24s
testing / backend-checks (pull_request) Failing after 4m20s
testing / test-sqlite (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
to 24788e0fdd
Some checks failed
testing / test-unit (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 57s
testing / backend-checks (pull_request) Failing after 4m55s
testing / test-pgsql (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
2026-08-30 06:56:27 +00:00
Compare
pat-s force-pushed feat/ci-usage-tab from 24788e0fdd
Some checks failed
testing / test-unit (pull_request) Has been skipped
testing / test-sqlite (pull_request) Has been skipped
testing / frontend-checks (pull_request) Successful in 57s
testing / backend-checks (pull_request) Failing after 4m55s
testing / test-pgsql (pull_request) Has been skipped
testing / test-mysql (pull_request) Has been skipped
testing / test-e2e (pull_request) Has been skipped
testing / test-remote-cacher (redis) (pull_request) Has been skipped
testing / test-remote-cacher (garnet) (pull_request) Has been skipped
testing / test-remote-cacher (valkey) (pull_request) Has been skipped
to f76deb4839
All checks were successful
testing / backend-checks (pull_request) Successful in 6m27s
testing / frontend-checks (pull_request) Successful in 57s
testing / test-remote-cacher (garnet) (pull_request) Successful in 5m48s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m12s
testing / test-e2e (pull_request) Successful in 27m14s
testing / test-unit (pull_request) Successful in 10m37s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m33s
testing / test-mysql (pull_request) Successful in 30m31s
testing / test-pgsql (pull_request) Successful in 48m52s
testing / test-sqlite (pull_request) Successful in 45m51s
2026-08-30 07:04:53 +00:00
Compare
Author
Owner

Reviewed at f76deb4839. Ten findings, each verified against the branch.

Correctness

1. Zero minutes renders as "less than a minute" — templates/shared/codefloe_ci_minutes.tmpl:7

{{- if .}}...{{else}}under_a_minute{{end -}} — 0 is falsy in Go templates, so there is no way to print "0 minutes".
A user with no CI records sees "less than a minute / Unlimited"; same for the admin header total and any rule whose limit is 0.
Needs an explicit {{if lt . 1}}-style split that distinguishes 0 from 0<x<1.

2. Deleting an organization still orphans the ledger — services/user/delete.go:107 / models/organization/org.go:408

The quota_ci_model.Usage/Record beans were added only to the user path.
services/org/org.go calls org_model.DeleteOrganization directly and never reaches services/user/delete.go, so an org's quota_ci_usage/quota_ci_record rows survive forever.
DeleteRecordsBefore prunes records by retention, but aggregates are never pruned at all.
Since orgs are the owners that actually accumulate CI time, this is the bigger half of the gap the PR sets out to close.

3. The chart paints colours the legend cannot explain — routers/web/shared/codefloe_ci_usage.go:352

The "other repositories" legend row is gated on if other > 0, where other sums already-rounded minutes.
The chart's label() (line 397) independently maps any repo missing from colors to the grey otherColor, using raw seconds.
Six-plus repositories where the tail rounds to 0 minutes gives grey segments in the chart and no grey row in the legend, which breaks the invariant the description states.

4. Repository shares divide by a total that includes in-flight work — routers/web/shared/codefloe_ci_usage.go:348

percentOf(named[i].Minutes, minutesOf(total)) with total = info.Used.Total.
GetInfo's own comment says that figure "includes an estimate for work that is still running", while PeriodBreakdown reads only finished quota_ci_record rows.
Shares silently under-sum whenever a job is in flight.
classTotals works around exactly this mismatch for the class breakdown; the repository panel did not get the same treatment.

5. A rule with a limit of 0 draws an empty bar — routers/web/shared/codefloe_ci_usage.go:201, via percentOf's whole <= 0 guard at line 289

A rule that denies CI outright gets Percent == 0, so it renders as unused rather than as maxed out.

6. The chart panel disappears on sub-minute periods — templates/shared/codefloe_ci_usage.tmpl:16

{{if .CIUsageChart.PeakMinutes}} gates on rounded minutes, so a period of only short runs loses the chart while the repository panel below still lists those same repositories.
Same root cause as finding 1: rounded minutes used as a truthiness test.

7. Rounded corners land on the wrong end of the column — web_src/css/codefloe/ci-usage-chart.css:70

.ci-usage-chart-stack is flex-direction: column-reverse, so the first DOM child renders at the bottom.
:first-child should be :last-child.
Invisible on the codefloe themes (--border-radius: 0), visible on upstream ones.

8. time.Now() instead of the timeutil clock — routers/web/shared/codefloe_ci_usage.go:429

The rest of the ledger goes through timeutil, so Future and the dotted-baseline behaviour are wrong under a mocked clock and cannot be covered by a test.

Efficiency

9. PeriodBreakdown is an unbounded SELECT — models/codefloe/quota_ci/quota_ci.go:395

It replaces a GROUP BY ... LIMIT 5 with every record in the period, now run on the settings tab and on every /admin/users/{id} view.
The doc comment's justification ("at most one month of one owner's records") is fine for a personal account and thin for a busy org.

10. 2N point queries per render — routers/web/shared/codefloe_ci_usage.go:310 and :397

Every distinct repository is resolved via GetRepositoryByID in ciUsageRepos even though only five are named, then resolved again by the chart through its own names cache.
One batched lookup shared by both would do.

Checked and fine

Permissions are sound: the org route sits inside the owner-gated settings group, the user route uses ctx.Doer.ID, and the handler re-checks setting.QuotaCI.Enabled rather than trusting the nav gate.
The sortedCopy helper v10_test.go uses is already defined in v9_test.go in the same package.
The quota_ci unit tests and the new integration tests pass.
The migration tests fail in my environment for a pre-existing reason (no DB host configured) and fail identically on v8 and v9.

I would treat findings 1, 2 and 3 as blocking: 2 because it is the risk the PR claims to close, 1 and 3 because they contradict behaviour the description promises.

Reviewed at `f76deb4839`. Ten findings, each verified against the branch. ## Correctness **1. Zero minutes renders as "less than a minute"** — `templates/shared/codefloe_ci_minutes.tmpl:7` `{{- if .}}...{{else}}under_a_minute{{end -}}` — `0` is falsy in Go templates, so there is no way to print "0 minutes". A user with no CI records sees "less than a minute / Unlimited"; same for the admin header total and any rule whose limit is 0. Needs an explicit `{{if lt . 1}}`-style split that distinguishes 0 from 0<x<1. **2. Deleting an organization still orphans the ledger** — `services/user/delete.go:107` / `models/organization/org.go:408` The `quota_ci_model.Usage`/`Record` beans were added only to the user path. `services/org/org.go` calls `org_model.DeleteOrganization` directly and never reaches `services/user/delete.go`, so an org's `quota_ci_usage`/`quota_ci_record` rows survive forever. `DeleteRecordsBefore` prunes records by retention, but aggregates are never pruned at all. Since orgs are the owners that actually accumulate CI time, this is the bigger half of the gap the PR sets out to close. **3. The chart paints colours the legend cannot explain** — `routers/web/shared/codefloe_ci_usage.go:352` The "other repositories" legend row is gated on `if other > 0`, where `other` sums already-rounded minutes. The chart's `label()` (line 397) independently maps any repo missing from `colors` to the grey `otherColor`, using raw seconds. Six-plus repositories where the tail rounds to 0 minutes gives grey segments in the chart and no grey row in the legend, which breaks the invariant the description states. **4. Repository shares divide by a total that includes in-flight work** — `routers/web/shared/codefloe_ci_usage.go:348` `percentOf(named[i].Minutes, minutesOf(total))` with `total = info.Used.Total`. `GetInfo`'s own comment says that figure "includes an estimate for work that is still running", while `PeriodBreakdown` reads only finished `quota_ci_record` rows. Shares silently under-sum whenever a job is in flight. `classTotals` works around exactly this mismatch for the class breakdown; the repository panel did not get the same treatment. **5. A rule with a limit of 0 draws an empty bar** — `routers/web/shared/codefloe_ci_usage.go:201`, via `percentOf`'s `whole <= 0` guard at line 289 A rule that denies CI outright gets `Percent == 0`, so it renders as unused rather than as maxed out. **6. The chart panel disappears on sub-minute periods** — `templates/shared/codefloe_ci_usage.tmpl:16` `{{if .CIUsageChart.PeakMinutes}}` gates on rounded minutes, so a period of only short runs loses the chart while the repository panel below still lists those same repositories. Same root cause as finding 1: rounded minutes used as a truthiness test. **7. Rounded corners land on the wrong end of the column** — `web_src/css/codefloe/ci-usage-chart.css:70` `.ci-usage-chart-stack` is `flex-direction: column-reverse`, so the first DOM child renders at the bottom. `:first-child` should be `:last-child`. Invisible on the codefloe themes (`--border-radius: 0`), visible on upstream ones. **8. `time.Now()` instead of the timeutil clock** — `routers/web/shared/codefloe_ci_usage.go:429` The rest of the ledger goes through timeutil, so `Future` and the dotted-baseline behaviour are wrong under a mocked clock and cannot be covered by a test. ## Efficiency **9. `PeriodBreakdown` is an unbounded SELECT** — `models/codefloe/quota_ci/quota_ci.go:395` It replaces a `GROUP BY ... LIMIT 5` with every record in the period, now run on the settings tab and on every `/admin/users/{id}` view. The doc comment's justification ("at most one month of one owner's records") is fine for a personal account and thin for a busy org. **10. 2N point queries per render** — `routers/web/shared/codefloe_ci_usage.go:310` and `:397` Every distinct repository is resolved via `GetRepositoryByID` in `ciUsageRepos` even though only five are named, then resolved again by the chart through its own `names` cache. One batched lookup shared by both would do. ## Checked and fine Permissions are sound: the org route sits inside the owner-gated settings group, the user route uses `ctx.Doer.ID`, and the handler re-checks `setting.QuotaCI.Enabled` rather than trusting the nav gate. The `sortedCopy` helper `v10_test.go` uses is already defined in `v9_test.go` in the same package. The quota_ci unit tests and the new integration tests pass. The migration tests fail in my environment for a pre-existing reason (no DB host configured) and fail identically on v8 and v9. I would treat findings 1, 2 and 3 as blocking: 2 because it is the risk the PR claims to close, 1 and 3 because they contradict behaviour the description promises.
pat-s force-pushed feat/ci-usage-tab from f76deb4839
All checks were successful
testing / backend-checks (pull_request) Successful in 6m27s
testing / frontend-checks (pull_request) Successful in 57s
testing / test-remote-cacher (garnet) (pull_request) Successful in 5m48s
testing / test-remote-cacher (valkey) (pull_request) Successful in 5m12s
testing / test-e2e (pull_request) Successful in 27m14s
testing / test-unit (pull_request) Successful in 10m37s
testing / test-remote-cacher (redis) (pull_request) Successful in 5m33s
testing / test-mysql (pull_request) Successful in 30m31s
testing / test-pgsql (pull_request) Successful in 48m52s
testing / test-sqlite (pull_request) Successful in 45m51s
to 6648e7392b
Some checks failed
testing / test-e2e (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / backend-checks (pull_request) Successful in 7m35s
testing / frontend-checks (pull_request) Successful in 1m48s
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
2026-08-30 08:57:07 +00:00
Compare
pat-s force-pushed feat/ci-usage-tab from 6648e7392b
Some checks failed
testing / test-e2e (pull_request) Has been cancelled
testing / test-unit (pull_request) Has been cancelled
testing / backend-checks (pull_request) Successful in 7m35s
testing / frontend-checks (pull_request) Successful in 1m48s
testing / test-remote-cacher (redis) (pull_request) Has been cancelled
testing / test-remote-cacher (valkey) (pull_request) Has been cancelled
testing / test-remote-cacher (garnet) (pull_request) Has been cancelled
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
testing / test-mysql (pull_request) Has been cancelled
to 6b6d66fb80
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m1s
testing / backend-checks (pull_request) Successful in 5m4s
testing / test-unit (pull_request) Successful in 9m21s
testing / test-remote-cacher (garnet) (pull_request) Successful in 4m0s
testing / test-remote-cacher (redis) (pull_request) Successful in 4m3s
testing / test-remote-cacher (valkey) (pull_request) Successful in 4m3s
testing / test-e2e (pull_request) Successful in 24m56s
testing / test-mysql (pull_request) Successful in 28m59s
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
2026-08-30 09:16:49 +00:00
Compare
pat-s force-pushed feat/ci-usage-tab from 6b6d66fb80
Some checks failed
testing / frontend-checks (pull_request) Successful in 1m1s
testing / backend-checks (pull_request) Successful in 5m4s
testing / test-unit (pull_request) Successful in 9m21s
testing / test-remote-cacher (garnet) (pull_request) Successful in 4m0s
testing / test-remote-cacher (redis) (pull_request) Successful in 4m3s
testing / test-remote-cacher (valkey) (pull_request) Successful in 4m3s
testing / test-e2e (pull_request) Successful in 24m56s
testing / test-mysql (pull_request) Successful in 28m59s
testing / test-pgsql (pull_request) Has been cancelled
testing / test-sqlite (pull_request) Has been cancelled
to 54ad33766a
All checks were successful
testing / frontend-checks (pull_request) Successful in 1m1s
testing / backend-checks (pull_request) Successful in 5m9s
testing / test-unit (pull_request) Successful in 10m9s
testing / test-remote-cacher (valkey) (pull_request) Successful in 4m40s
testing / test-e2e (pull_request) Successful in 26m46s
testing / test-remote-cacher (redis) (pull_request) Successful in 4m14s
testing / test-remote-cacher (garnet) (pull_request) Successful in 4m42s
testing / test-sqlite (pull_request) Successful in 46m18s
testing / test-pgsql (pull_request) Successful in 49m12s
testing / test-mysql (pull_request) Successful in 31m25s
issue-labels / backporting (pull_request_target) Has been skipped
milestone / set (pull_request_target) Has been skipped
2026-08-30 10:05:38 +00:00
Compare
pat-s merged commit 0d7203b377 into v16.0/forgejo-codefloe 2026-08-30 13:28:20 +00:00
pat-s deleted branch feat/ci-usage-tab 2026-08-30 13:28:20 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
codefloe/forgejo-codefloe!101
No description provided.