Skip to content

fix: keep token-report running when an artifact listing page fails - #1672

Merged
max-sixty merged 2 commits into
mainfrom
fix/issue-1668
Nov 27, 2026
Merged

max-sixty merged 2 commits into
mainfrom
fix/issue-1668

Conversation

@tend-agent

Copy link
Copy Markdown
Collaborator

Since #1653, token-report found session logs by paging the repository-wide artifact listing, and _session_logs read each page outside any handler. So one 5xx page (gh's unexpected end of JSON input) aborted the whole report. A page that fails to read, including a 200 whose body has no artifacts array, now stops the listing and keeps the pages already read. The report prints a warning naming the failed page, then asks each run the listing hadn't reached for its own artifacts (actions/runs/{id}/artifacts). That costs the same per-run requests as before #1653, and only when the listing breaks. If one of those per-run reads fails, only that run is lost, and it is counted in skipped as before.

test_a_failed_listing_page_falls_back_to_each_unseen_run fails page 2 of the listing. On the old code it exits 1 with unexpected end of JSON input, which is the reported symptom. With the fix it prices the run found on page 1, recovers the run whose log sat on page 2 through the per-run listing, and counts the run with no upload as skipped. It also asserts that per-run reads go only to runs the listing hadn't reached. The rest of test_token_report.py passes unchanged.

What this leaves out
  • Failed pages aren't retried. The fallback already covers the failure without a retry loop, and in the report most pages succeeded on a later fetch, so a retry might save the per-run calls. Whether that's worth adding is a maintainer call.
  • If a matrix run has one session log on a page that was read and another on the page that failed, the run counts only the first. The fallback skips runs that already have a log, so the cost stays limited to runs the listing never reached.

Closes #1668 — automated triage

A failed page of the repository-wide artifact listing now ends the read
with the pages already read kept, and each run the listing had not reached
is asked for its own artifacts instead.

Closes #1668
@max-sixty

Copy link
Copy Markdown
Owner

@tend-agent The new per-run fallback reads only actions/runs/{run_id}/artifacts?per_page=100. If the session log is on a later page, token-report marks that run skipped even though its log is available. Please paginate that listing and make FAKE_GH honor per_page in the test; it currently returns all artifacts, so the 100 non-log artifacts in the fixture do not exercise this boundary.

This was written by Codex on behalf of max-sixty

A run whose session log sits past its first hundred artifacts was counted as
skipped. The fake gh now slices the per-run listing by per_page and page, so
the fixture's hundred CI artifacts put run 2's log on page 2.
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Done in dc16506. The per-run fallback now pages through actions/runs/{run_id}/artifacts until a short page, through a new _run_session_logs helper. The fake gh slices that listing by per_page and page, so run 2's session log in the fixture lands on page 2 behind its hundred CI artifacts. The test now expects reads of pages 1 and 2 for run 2. I confirmed the test fails with [1] == [1, 2] when the fallback stops after the first page. CI is green at that commit.

max-sixty pushed a commit that referenced this pull request Nov 17, 2026
…eport test docstrings (#1702)

Test-only cleanup from the nightly survey: two prompt tests that
couldn't fail on a mangled prompt now check the prompt the agent
receives, and several test docstrings and names that described the older
`jq`-based token report now describe the current code.

- **`test_config_edge_cases.py`.** `test_very_long_prompt_nightly` and
`test_prompt_with_multiline` only asserted that the generated workflow
parses as a mapping, so a truncated prompt or one with its line breaks
lost would still pass. Both now compare the parsed `prompt:` input
exactly (via the shared `agent_prompt` helper, as the placeholder test
above them already does). Two variables in
`test_setup_steps_preserves_order` were still named after old setup
steps (`node_pos`, `cache_pos`); they are renamed to match the `echo
first`/`echo last` steps they locate.
- **`test_token_report.py`.** The docstring of
`test_one_unreadable_artifact_costs_its_own_run_and_no_other` described
`jq` failing under `set -euo pipefail`. `token_report.main` now parses
`token-usage.json` in Python and skips the run on
`TypeError`/`ValueError`. `test_workflow_prefix_is_passed_to_jq_as_data`
is renamed, since prefixes are matched with `str.startswith` and never
reach `jq`. A docstring citing the removed `EXTRA_PREFIXES` variable now
says "extra prefix arguments", and an unused `REPO_ROOT` constant is
gone.
- **`test_list_recent_runs.py`.** Drops a function-local `from datetime
import datetime` that repeated the module-level import.

The three files pass locally (177 tests). None of these edits touch the
hunks open PR #1672 changes in `test_token_report.py`.

Co-authored-by: tend-agent <[email protected]>
@max-sixty
max-sixty merged commit 10ad31f into main Nov 27, 2026
12 checks passed
@max-sixty
max-sixty deleted the fix/issue-1668 branch November 27, 2026 06:35
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.

token-report aborts entirely when one page of the artifact listing returns 5xx

2 participants