Forgejo run retention on git.matou.nz — the /actions/runs listing has grown unanswerable #40

Closed
opened 2026-08-23 19:57:13 +00:00 by matou-build-agent · 3 comments

Split out of #28 (its part 3), which landed the harness half: the audit, the ratchet test and GOTCHAS 16.

The hazard

GET /api/v1/repos/Matou/<repo>/actions/runs?limit=N no longer answers inside 60 s on the big repos (8,900+ runs on Matou/idss; curl -m 60 → code 000 from two different machines). /actions/tasks?limit=100&page=N answers in under a second and is what the harness reads, so no tick is currently blocked on this — but the endpoint is unusable for a human, for any future tooling, and for the Forgejo web UI's own run pages, and run history only grows (the swarm mints ~150 runs/hour under a label storm).

Ask (server side, git.matou.nz)

  1. Set an Actions run/artifact retention policy on the instance — Forgejo's [actions] settings in app.ini (e.g. ARTIFACT_RETENTION_DAYS, and whatever run-record cleanup the running version offers), plus the cron.cleanup_actions job if this build has it.
  2. Or, failing a built-in, a periodic delete of runs older than N days so the listing recovers.
  3. Re-probe afterwards: curl -m 60 -o /dev/null -w '%{http_code} %{time_total}\n' -H "Authorization: token $FORGEJO_TOKEN" "$FORGEJO_API/actions/runs?limit=10" should return 200 well inside the timeout.

Why human

Every route to this is a ONE-WAY door under ADR 0174, so the session-runner agent stopped here deliberately:

  • It needs root/admin on the forge host (git.matou.nz app.ini + a Forgejo restart) — a credential and a security-posture door the agent does not hold and must not be given.
  • Deleting old run records is data destruction: irreversible, and it is the CI history of three repos. Which runs are expendable is a judgement call for the person who owns the instance.
  • A retention setting is instance-wide, so it lands on every repo on the forge, not just the factory's.

The harness needs nothing from this: it reads /actions/tasks, paged and timed, and tests/actions-endpoint-test.sh keeps it that way.

Split out of #28 (its part 3), which landed the harness half: the audit, the ratchet test and GOTCHAS 16. ## The hazard `GET /api/v1/repos/Matou/<repo>/actions/runs?limit=N` no longer answers inside 60 s on the big repos (8,900+ runs on `Matou/idss`; `curl -m 60` → code `000` from two different machines). `/actions/tasks?limit=100&page=N` answers in under a second and is what the harness reads, so no tick is currently blocked on this — but the endpoint is unusable for a human, for any future tooling, and for the Forgejo web UI's own run pages, and run history only grows (the swarm mints ~150 runs/hour under a label storm). ## Ask (server side, `git.matou.nz`) 1. Set an Actions run/artifact retention policy on the instance — Forgejo's `[actions]` settings in `app.ini` (e.g. `ARTIFACT_RETENTION_DAYS`, and whatever run-record cleanup the running version offers), plus the `cron.cleanup_actions` job if this build has it. 2. Or, failing a built-in, a periodic delete of runs older than N days so the listing recovers. 3. Re-probe afterwards: `curl -m 60 -o /dev/null -w '%{http_code} %{time_total}\n' -H "Authorization: token $FORGEJO_TOKEN" "$FORGEJO_API/actions/runs?limit=10"` should return `200` well inside the timeout. ## Why human Every route to this is a ONE-WAY door under ADR 0174, so the session-runner agent stopped here deliberately: - It needs **root/admin on the forge host** (`git.matou.nz` app.ini + a Forgejo restart) — a credential and a security-posture door the agent does not hold and must not be given. - Deleting old run records is **data destruction**: irreversible, and it is the CI history of three repos. Which runs are expendable is a judgement call for the person who owns the instance. - A retention setting is instance-wide, so it lands on every repo on the forge, not just the factory's. The harness needs nothing from this: it reads `/actions/tasks`, paged and timed, and `tests/actions-endpoint-test.sh` keeps it that way.
Author
Member

Re-diagnosed 2026-08-24 — this is not a retention problem

Probed on the forge host itself (Forgejo 15.0.5, postgres primary local, sync replica lag ~10 ms, action_run 53 MB / 16,344 rows, vacuumed today, all indexes present).

The database is not the bottleneck. Sampling pg_stat_activity during a 90 s runs?limit=10 request showed no action_run query at all — the same listing answers in 1–3 ms from psql. The time is spent in Go.

Root cause: a pagination guard. Both ListActionRuns and ListActionTasks call db.FindAndCount, which applies LIMIT only when page >= 1 (models/db/list.go). db.Find treats a missing page as page 1; FindAndCount does not. So any call that omits page selects the repo's entire run/task history and converts every row.

Measured (idss, 9,679 runs):

call result
runs?limit=10 (no page) 504 at 60 s via proxy; 90 s+ in-container
runs?limit=10&page=1 200 in 1.8 s
runs?limit=10&page=3 200 in 1.7 s
tasks?limit=60 (no page) 200 in 39.8 s
tasks?limit=50&page=1 200 in 0.2 s
web UI /Matou/idss/actions 200 in 1.6 s

Consequences

  • The harness was already immune — every read is tasks?limit=N&page=N (ratcheted by tests/actions-endpoint-test.sh). GOTCHAS 16 now states this cause.
  • The re-probe in this ticket's description omits page and would fail forever regardless of retention. Corrected re-probe:
    curl -m 60 -o /dev/null -w '%{http_code} %{time_total}\n' "$FORGEJO_API/actions/runs?limit=10&page=1" → expect 200 in a few seconds.
  • Retention is now storage hygiene rather than the fix. app.ini [actions] has only ENABLED = true: LOG_RETENTION_DAYS (default 365) and [cron.cleanup_actions] are unset. Forgejo 15 has no run-record retention and no API run delete (DELETE .../actions/runs/{id} is absent from this instance's swagger), so pruning records would be raw SQL across action_run/action_run_job/action_task/action_task_step — still a one-way door, but no longer urgent.

Still for a human (both low priority now): whether to set LOG_RETENTION_DAYS + enable cron.cleanup_actions (app.ini edit + Forgejo restart), and whether to report the FindAndCount page-0 inconsistency upstream.

An unpaged tasks?limit=60 call did hit the forge from the swarm host at 14:00Z today; it is not in the vendored harness, so it is a per-repo script or a hand probe — being traced separately.

## Re-diagnosed 2026-08-24 — this is not a retention problem Probed on the forge host itself (Forgejo 15.0.5, postgres primary local, sync replica lag ~10 ms, `action_run` 53 MB / 16,344 rows, vacuumed today, all indexes present). **The database is not the bottleneck.** Sampling `pg_stat_activity` during a 90 s `runs?limit=10` request showed no `action_run` query at all — the same listing answers in 1–3 ms from psql. The time is spent in Go. **Root cause: a pagination guard.** Both `ListActionRuns` and `ListActionTasks` call `db.FindAndCount`, which applies `LIMIT` only when `page >= 1` (`models/db/list.go`). `db.Find` treats a missing `page` as page 1; `FindAndCount` does not. So any call that omits `page` selects the repo's entire run/task history and converts every row. Measured (idss, 9,679 runs): | call | result | |---|---| | `runs?limit=10` (no page) | 504 at 60 s via proxy; 90 s+ in-container | | `runs?limit=10&page=1` | **200 in 1.8 s** | | `runs?limit=10&page=3` | 200 in 1.7 s | | `tasks?limit=60` (no page) | 200 in 39.8 s | | `tasks?limit=50&page=1` | 200 in 0.2 s | | web UI `/Matou/idss/actions` | 200 in 1.6 s | **Consequences** - The harness was already immune — every read is `tasks?limit=N&page=N` (ratcheted by `tests/actions-endpoint-test.sh`). GOTCHAS 16 now states this cause. - The re-probe in this ticket's description omits `page` and would fail forever regardless of retention. Corrected re-probe: `curl -m 60 -o /dev/null -w '%{http_code} %{time_total}\n' "$FORGEJO_API/actions/runs?limit=10&page=1"` → expect `200` in a few seconds. - Retention is now storage hygiene rather than the fix. `app.ini` `[actions]` has only `ENABLED = true`: `LOG_RETENTION_DAYS` (default 365) and `[cron.cleanup_actions]` are unset. Forgejo 15 has no run-**record** retention and no API run delete (`DELETE .../actions/runs/{id}` is absent from this instance's swagger), so pruning records would be raw SQL across `action_run`/`action_run_job`/`action_task`/`action_task_step` — still a one-way door, but no longer urgent. **Still for a human** (both low priority now): whether to set `LOG_RETENTION_DAYS` + enable `cron.cleanup_actions` (app.ini edit + Forgejo restart), and whether to report the `FindAndCount` page-0 inconsistency upstream. An unpaged `tasks?limit=60` call did hit the forge from the swarm host at 14:00Z today; it is not in the vendored harness, so it is a per-repo script or a hand probe — being traced separately.
Author
Member

Storage hygiene applied 2026-08-24 (Ben's go-ahead)

app.ini on the forge now carries (backup at app.ini.bak-2026-08-24 beside it):

[actions]
LOG_RETENTION_DAYS = 30

[cron.cleanup_actions]
ENABLED = true
RUN_AT_START = true
SCHEDULE = @midnight

Forgejo restarted clean. Verified:

  • CleanupLogs fired on start: removed 440 expired task logs (action_task now shows 440 log_expired, 19,164 kept)
  • artifact cleanup ran (0 — none in use); cron re-fires nightly at midnight
  • healthz 200 in 4.5 ms; external tasks?limit=1&page=1 read 200 in 0.9 s

Run-record pruning stays ruled out (raw SQL, no benefit — the listing slowness was the page-0 guard, see previous comment). The only open question left on this ticket is whether to report the FindAndCount page-0 inconsistency upstream to Forgejo — Ben's call; otherwise this is done and closable.

## Storage hygiene applied 2026-08-24 (Ben's go-ahead) `app.ini` on the forge now carries (backup at `app.ini.bak-2026-08-24` beside it): ```ini [actions] LOG_RETENTION_DAYS = 30 [cron.cleanup_actions] ENABLED = true RUN_AT_START = true SCHEDULE = @midnight ``` Forgejo restarted clean. Verified: - `CleanupLogs` fired on start: **removed 440 expired task logs** (`action_task` now shows 440 `log_expired`, 19,164 kept) - artifact cleanup ran (0 — none in use); cron re-fires nightly at midnight - healthz 200 in 4.5 ms; external `tasks?limit=1&page=1` read 200 in 0.9 s Run-record pruning stays ruled out (raw SQL, no benefit — the listing slowness was the page-0 guard, see previous comment). The only open question left on this ticket is whether to report the `FindAndCount` page-0 inconsistency upstream to Forgejo — Ben's call; otherwise this is done and closable.
Author
Member

Ben ruled 2026-08-24: no upstream report. Retention applied and verified, harness immune, re-probe corrected — closing.

Ben ruled 2026-08-24: no upstream report. Retention applied and verified, harness immune, re-probe corrected — closing.
Sign in to join this conversation.
No milestone
No project
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
Matou/dev-factory#40
No description provided.