run logs: read a job's task by id, page the task list, keep loaded logs on the older-server path (CLS-1022) #301

Merged
stephen merged 4 commits from stephen/cls-1022-run-logs-edge-cases into main 2026-10-31 20:04:57 +00:00
Owner

The two edge cases deferred from #300 (CLS-963).

  1. A missing task-list entry read as "log unavailable" (exit 0). GET /actions/tasks ignores its run filter on Forgejo 16 and answers with repository tasks, so the run's task could be absent from a capped or shifted list while its logs exist in Loki. Now:
    • A job that names its task (task_id) is matched to that task by id, not by its position in the list. A task that is not in the list is a retrieval error for that job (the others still print, and the command fails after printing), not "log unavailable".
    • list_run_tasks pages (limit=50, page=N) until the wanted ids are found, the walk has passed them (the list is newest first), or the list is exhausted (total_count reached, or a page with nothing new). A short page is not taken as the end, since a server may clamp the page size. A list cut off by the 40 page cap, by a page that fails after the first, or by a page that repeats while the count says more, comes back marked incomplete with what was found: resolved tasks still read, unresolved ones fail with the reason. A first page that fails is an error.
    • A fallback job with no task_id is matched by position in the run's whole list, so any such job makes the walk exhaustive; with an incomplete list it fails instead of guessing.
  2. The older-server path (fetch_run_logs_from_tasks, explicitly configured Loki) returned on the first failed Loki query. It now settles each task on its own like the native path: failures are kept in errors (the command fails after printing), a confirmed-missing log reads as unavailable, and it only returns an error when nothing at all loaded.

I probed the live endpoint read-only first: it honours limit and page, returns total_count, and orders newest first.

Failure paths

  • Page 2+ failing, cap reached, repeated page, unnamed job with an incomplete list: each covered through the real list_run_tasks against wiremock, and through fetch_run_logs_with_sources for the per-job outcome.
  • Retries and idempotency: read-only GETs.
  • Partial failure: per job, as above.
  • Cost: a server that sends no total_count costs one extra confirming request (the integration mocks now expect 1 to 2 task requests). Forgejo 16 sends the count; the native path still never loads the list when Forgejo serves the logs (existing test).

Fix scope

  • Invariant: an unresolved task is never read as an absent one. Paths checked: native fallback (named and unnamed jobs), older-server path, run view --log and run logs through fetch_run_logs.
  • Tests: 12 new in workflow_logs.rs plus the four integration mocks that count task requests. cargo test passes; clippy shows nothing in the touched files (it flags chunks_exact in src/cli/pr_line_comment.rs, which is not part of this change).

Known edge cases (follow-up)

  • The task list is read newest first up to 2000 tasks back; a run older than that on a very busy repository reports the list incomplete rather than reading it. Walking from the run's id range instead needs a server-side filter that does not exist yet.
  • Self-review used its three rounds; the last edge fix (a repeated page with a larger total) was not re-reviewed.

Closes CLS-1022.

The two edge cases deferred from #300 (CLS-963). 1. A missing task-list entry read as "log unavailable" (exit 0). `GET /actions/tasks` ignores its `run` filter on Forgejo 16 and answers with repository tasks, so the run's task could be absent from a capped or shifted list while its logs exist in Loki. Now: - A job that names its task (`task_id`) is matched to that task by id, not by its position in the list. A task that is not in the list is a retrieval error for that job (the others still print, and the command fails after printing), not "log unavailable". - `list_run_tasks` pages (`limit=50`, `page=N`) until the wanted ids are found, the walk has passed them (the list is newest first), or the list is exhausted (`total_count` reached, or a page with nothing new). A short page is not taken as the end, since a server may clamp the page size. A list cut off by the 40 page cap, by a page that fails after the first, or by a page that repeats while the count says more, comes back marked incomplete with what was found: resolved tasks still read, unresolved ones fail with the reason. A first page that fails is an error. - A fallback job with no `task_id` is matched by position in the run's whole list, so any such job makes the walk exhaustive; with an incomplete list it fails instead of guessing. 2. The older-server path (`fetch_run_logs_from_tasks`, explicitly configured Loki) returned on the first failed Loki query. It now settles each task on its own like the native path: failures are kept in `errors` (the command fails after printing), a confirmed-missing log reads as unavailable, and it only returns an error when nothing at all loaded. I probed the live endpoint read-only first: it honours `limit` and `page`, returns `total_count`, and orders newest first. Failure paths - Page 2+ failing, cap reached, repeated page, unnamed job with an incomplete list: each covered through the real `list_run_tasks` against wiremock, and through `fetch_run_logs_with_sources` for the per-job outcome. - Retries and idempotency: read-only GETs. - Partial failure: per job, as above. - Cost: a server that sends no `total_count` costs one extra confirming request (the integration mocks now expect 1 to 2 task requests). Forgejo 16 sends the count; the native path still never loads the list when Forgejo serves the logs (existing test). Fix scope - Invariant: an unresolved task is never read as an absent one. Paths checked: native fallback (named and unnamed jobs), older-server path, `run view --log` and `run logs` through `fetch_run_logs`. - Tests: 12 new in `workflow_logs.rs` plus the four integration mocks that count task requests. `cargo test` passes; clippy shows nothing in the touched files (it flags `chunks_exact` in `src/cli/pr_line_comment.rs`, which is not part of this change). Known edge cases (follow-up) - The task list is read newest first up to 2000 tasks back; a run older than that on a very busy repository reports the list incomplete rather than reading it. Walking from the run's id range instead needs a server-side filter that does not exist yet. - Self-review used its three rounds; the last edge fix (a repeated page with a larger total) was not re-reviewed. Closes CLS-1022.
gerri approved these changes 2026-10-31 19:35:54 +00:00
gerri left a comment

Automated Codex review (read-only) of head 7dbbe28faf.

  • Low (edge case), src/api/workflow_logs.rs:1027. Invariant: incomplete reads must not certify completeness (standards 8 and 15). seen.len() includes tasks deleted between requests, so comparing it with the latest total_count can terminate the walk early. For example, with two tasks per page, read [30,29], then delete task 30. Page 2 returns [27], skipping task 28 because offsets shifted. The new total is 3, matching seen.len(), so this incomplete list is marked complete. Newly paginated positional fallback can consequently assign task 27 to task 28's job; the older-server adapter can silently omit task 28. Both CLI entry points inherit this behavior. Detect changing counts and mark the result incomplete, or restart against a stable list before certifying positional matches. Add a real-adapter deletion-between-pages test.

The documented 2000-task cap remains an accepted follow-up.

BLOCKING: 0

Reviewed head 7dbbe28faf at 2026-10-31T19:35:53Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 7dbbe28faf649e066cd69871aeb668dd87e31494. - **Low** (edge case), `src/api/workflow_logs.rs:1027`. Invariant: incomplete reads must not certify completeness (standards 8 and 15). `seen.len()` includes tasks deleted between requests, so comparing it with the latest `total_count` can terminate the walk early. For example, with two tasks per page, read `[30,29]`, then delete task 30. Page 2 returns `[27]`, skipping task 28 because offsets shifted. The new total is 3, matching `seen.len()`, so this incomplete list is marked complete. Newly paginated positional fallback can consequently assign task 27 to task 28's job; the older-server adapter can silently omit task 28. Both CLI entry points inherit this behavior. Detect changing counts and mark the result incomplete, or restart against a stable list before certifying positional matches. Add a real-adapter deletion-between-pages test. The documented 2000-task cap remains an accepted follow-up. BLOCKING: 0 --- Reviewed head 7dbbe28faf649e066cd69871aeb668dd87e31494 at 2026-10-31T19:35:53Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.