run view --log-failed: one missing job log no longer fails the whole command (CLS-963) #300

Merged
stephen merged 3 commits from stephen/cls-963-log-failed into main 2026-10-29 21:14:43 +00:00
Owner

CLS-963: fj run view <run> --log-failed printed error: Loki fallback needs workflow task metadata for job index N and no log, so a real lint failure read as infrastructure and ci-fix recommended a rerun.

Cause (in fj, not the gateway): fetch_run_logs_with_sources asked Forgejo for each selected job's log in turn and, on the first job that answered resource does not exist (a job with no task yet, like 120671 in run 4719), threw away the jobs that had loaded and fell back to Loki for the whole run. Loki needs the run's task list, which the gateway path did not supply, so the command failed with the metadata error. The same job log fetched directly returned fine.

Now each job is settled on its own:

  • a job whose log loaded keeps it;
  • a job whose log is confirmed missing falls back to Loki for that job only, and if there is no task metadata for it, or Loki has nothing, it prints log unavailable for this job: <reason> in its own lines instead of failing the command;
  • a job whose read fails (transport, a server error, a failed task-list read, a failed Loki query) is not "missing": its lines say log retrieval failed for this job: <error>, the other jobs still print, and the command exits non-zero after printing (ensure_logs_complete). --json carries the same in errors. If nothing at all could be retrieved, the failure is still the command's error, as before;
  • TaskSource::load now returns a Result, so a failed task-list read can no longer pass as an empty list.
    source reads forgejo-api, loki, forgejo-api+loki, or none.

Failure paths

  • One job missing, others fine: one_missing_job_log_does_not_discard_the_others.
  • Missing job recovered from Loki for that job only: a_missing_job_log_falls_back_to_loki_for_that_job_only.
  • No metadata for any job: no_task_metadata_reports_each_job_as_unavailable.
  • Task-list read fails (500) after a native 404: a_failed_task_list_read_keeps_loaded_logs_and_records_the_failure, and with nothing retrieved at all a_failed_task_list_read_with_no_logs_at_all_fails_the_run.
  • Loki query fails: a_failing_loki_query_keeps_the_logs_that_loaded, and when it is the only source a_failing_loki_query_still_fails_the_run.
  • Retries, concurrency, timeouts: unchanged.

Fix scope: invariant is that one job's missing or failed log never hides the others, and a failed retrieval never exits as a complete read. Callers checked: run view --log/--log-failed and run log, text and --json.

Known edge cases (follow-up): CLS-1022 collects two. A missing task-list entry on Forgejo 16 (where /actions/tasks ignores its run filter and can be capped) still prints log unavailable and exits 0, and the older-server path (fetch_run_logs_from_tasks) still returns on the first failed Loki query.

Tests: cargo test --bin fj workflow_logs passes (31), run locally. cargo clippy -D warnings fails on src/cli/pr_line_comment.rs:65 (chunks_exact_to_as_chunks), which is on main and unrelated to this change. Not run: the CLI against a live gateway; that needs a deployed build.

CLS-963: `fj run view <run> --log-failed` printed `error: Loki fallback needs workflow task metadata for job index N` and no log, so a real lint failure read as infrastructure and ci-fix recommended a rerun. Cause (in `fj`, not the gateway): `fetch_run_logs_with_sources` asked Forgejo for each selected job's log in turn and, on the first job that answered `resource does not exist` (a job with no task yet, like 120671 in run 4719), threw away the jobs that had loaded and fell back to Loki for the whole run. Loki needs the run's task list, which the gateway path did not supply, so the command failed with the metadata error. The same job log fetched directly returned fine. Now each job is settled on its own: - a job whose log loaded keeps it; - a job whose log is confirmed missing falls back to Loki for that job only, and if there is no task metadata for it, or Loki has nothing, it prints `log unavailable for this job: <reason>` in its own lines instead of failing the command; - a job whose read fails (transport, a server error, a failed task-list read, a failed Loki query) is not "missing": its lines say `log retrieval failed for this job: <error>`, the other jobs still print, and the command exits non-zero after printing (`ensure_logs_complete`). `--json` carries the same in `errors`. If nothing at all could be retrieved, the failure is still the command's error, as before; - `TaskSource::load` now returns a `Result`, so a failed task-list read can no longer pass as an empty list. `source` reads `forgejo-api`, `loki`, `forgejo-api+loki`, or `none`. Failure paths - One job missing, others fine: `one_missing_job_log_does_not_discard_the_others`. - Missing job recovered from Loki for that job only: `a_missing_job_log_falls_back_to_loki_for_that_job_only`. - No metadata for any job: `no_task_metadata_reports_each_job_as_unavailable`. - Task-list read fails (500) after a native 404: `a_failed_task_list_read_keeps_loaded_logs_and_records_the_failure`, and with nothing retrieved at all `a_failed_task_list_read_with_no_logs_at_all_fails_the_run`. - Loki query fails: `a_failing_loki_query_keeps_the_logs_that_loaded`, and when it is the only source `a_failing_loki_query_still_fails_the_run`. - Retries, concurrency, timeouts: unchanged. Fix scope: invariant is that one job's missing or failed log never hides the others, and a failed retrieval never exits as a complete read. Callers checked: `run view --log/--log-failed` and `run log`, text and `--json`. Known edge cases (follow-up): CLS-1022 collects two. A missing task-list entry on Forgejo 16 (where `/actions/tasks` ignores its `run` filter and can be capped) still prints `log unavailable` and exits 0, and the older-server path (`fetch_run_logs_from_tasks`) still returns on the first failed Loki query. Tests: `cargo test --bin fj workflow_logs` passes (31), run locally. `cargo clippy -D warnings` fails on `src/cli/pr_line_comment.rs:65` (`chunks_exact_to_as_chunks`), which is on `main` and unrelated to this change. Not run: the CLI against a live gateway; that needs a deployed build.
Each job's log is settled on its own. A job that answers 'resource does not
exist' keeps the logs of the jobs that loaded, falls back to Loki for that job
only, and otherwise reports 'log unavailable' in its own lines instead of
failing the command on missing task metadata.
Keep the logs that loaded when one job's retrieval fails, and fail after printing (CLS-963)
All checks were successful
ci / check (pull_request) Successful in 17m0s
ci / coverage (pull_request) Successful in 3m27s
ci / live-e2e (pull_request) Successful in 4m27s
40d7176cc4
gerri approved these changes 2026-10-29 20:53:36 +00:00
gerri left a comment

Automated Codex review (read-only) of head 40d7176cc4.

No new blocking findings.

  • Low (edge case), src/api/workflow_logs.rs:1061,1213: The completeness and partial-failure invariants retain the two accepted deferrals in CLS-1022: capped task metadata can produce log unavailable with exit 0, and the older-server adapter discards loaded logs after a later Loki failure. Both affect run view and run log, including JSON. Follow-up fix: establish metadata completeness and settle older-server jobs independently. No new evidence warrants reopening either as blocking.

BLOCKING: 0

Reviewed head 40d7176cc4 at 2026-10-29T20:53:35Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 40d7176cc4b2114dcfd437fc71938838a34f2664. No new blocking findings. - **Low** (edge case), `src/api/workflow_logs.rs:1061,1213`: The completeness and partial-failure invariants retain the two accepted deferrals in CLS-1022: capped task metadata can produce `log unavailable` with exit 0, and the older-server adapter discards loaded logs after a later Loki failure. Both affect `run view` and `run log`, including JSON. Follow-up fix: establish metadata completeness and settle older-server jobs independently. No new evidence warrants reopening either as blocking. BLOCKING: 0 --- Reviewed head 40d7176cc4b2114dcfd437fc71938838a34f2664 at 2026-10-29T20:53:35Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.