Skip to content

Read the token report's session logs from one artifact listing - #1653

Merged
max-sixty merged 2 commits into
mainfrom
token-report-artifacts
Nov 5, 2026
Merged

max-sixty merged 2 commits into
mainfrom
token-report-artifacts

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

tend runtime token-report, which each consumer's nightly sweep runs, made one gh run download per run in its window, and every Tend workflow on the account shares that account's 5,000-request hourly allowance. On max-sixty/leaf on 2 Nov the report spent 3,977 of those requests in three minutes and starved the account's other Tend workflows for most of an hour (#1642). #1644 dropped runs that skipped every job. This drops the requests for runs that uploaded no session log, which is most of what remains.

The report now pages the repository's artifact listing once, newest first, back to the run fetch's creation bound. It downloads each session-log artifact of a run it covers by artifact id, so a run without one costs nothing. Most runs in a busy window upload none: landing checks, mention relays, CI-failure verdicts and mentions not addressed to the bot.

Measured on max-sixty/leaf over the 24 hours to 2026-11-05 17:48 UTC: 832 runs in the window after skipped ones, 328 of them with a session log (329 artifacts). The per-run requests go from 832 + 329 = 1,161 to 13 listing pages + 329 = 342. On the same one-hour window against leaf, the old and new code gave byte-identical JSON and summaries, at 103 and 59 requests.

  • _common.gh takes a stdout file, so the zip download still goes through the one gh call site.
  • A token-usage.json holding a value that isn't an object now costs only its own run. Its TypeError used to escape the per-run handler and end the report.
  • A failed listing page now fails the report outright, where the old path counted each failed per-run download as a missing upload and under-reported without saying so. Of 27 calls at 100 per page, 7 failed with HTTP 500 in a burst, and none of the 30 since.

Known, and unchanged here:

  • The missing-upload footnote says those runs "ended before the upload or had torn uploads". On leaf, nearly all of the roughly 500 a day it counts never ran an agent, which hides any real torn upload.
  • tend-land completed 413 runs in a day on leaf, so a long window plus the 24-hour creation cushion could pass the 1,000-run listing ceiling. The report warns when that happens.

Refs #1642

This was written by Claude Code on behalf of max-sixty

`tend runtime token-report` ran `gh run download` for every run in its
window. That call lists the run's artifacts, one REST request, and then
downloads each session log, one more. Most runs in a busy window upload
no session log (landing checks, mention relays, CI-failure verdicts,
mentions not for the bot), so most of the report's requests found
nothing. Every Tend workflow on the account shares the same 5,000/hour
allowance.

The report now pages the repository's artifact listing, newest first,
back to the run fetch's creation bound, and downloads each session log
of a run it covers by artifact id. A run without a session log costs
nothing. The listing costs one page per hundred artifacts the
repository uploaded since that bound, whichever workflow uploaded them.

Measured on max-sixty/leaf for the 24 hours to 2026-11-05 17:48 UTC:
1,180 completed tend runs, 348 of them skipped, which leaves 832 the
report covers. 328 of those uploaded a session log (329 artifacts). The
per-run part costs 832 + 329 = 1,161 requests before and 13 pages + 329
= 342 after. Both figures exclude the workflow and run listings, about
40 requests, which this change leaves alone. Old and new code on the
same one-hour anchor against leaf produced byte-identical JSON and
summaries, at 103 and 59 requests.

`_common.gh` takes a `stdout` file for a body that isn't text, so the
zip still goes through the one `gh` call site. A token-usage.json that
holds a non-object value now costs only its own run: its `TypeError`
used to escape the per-run handler and end the report.

Refs #1642
@max-sixty
max-sixty merged commit 6130ea8 into main Nov 5, 2026
13 checks passed
@max-sixty
max-sixty deleted the token-report-artifacts branch November 5, 2026 20:55
@max-sixty max-sixty mentioned this pull request Nov 9, 2026
max-sixty added a commit that referenced this pull request Nov 9, 2026
Release 0.3.24, shipping #1648's per-issue triage concurrency, so a
consumer's triage sessions for different issues run at once instead of
in one lane. Also ships #1652's CI handoff to tend-land when the
review's CI wait is off, the token report's API savings (#1644, #1653),
and the fixes and tool bumps listed in the changelog.

Validation: full `wt test` and all pre-commit hooks passed on the
release commit. The Codex subscription smoke passed on `d1f7c5ef` after
`CODEX_AUTH_JSON` in the `tend` environment was refreshed with an
access-only login; it runs again on the exact release commit before the
tag.

> _This was written by Claude Code on behalf of max-sixty_
max-sixty added a commit to max-sixty/leaf that referenced this pull request Nov 9, 2026
Regenerates Leaf's Tend workflows with [tend
0.3.24](https://github.com/max-sixty/tend/releases/tag/0.3.24).

The change that matters here is `tend-triage`'s concurrency
([max-sixty/tend#1648](max-sixty/tend#1648)).
Every triage run shared one workflow-level `tend-triage` group, so cause
issues waited in a single lane behind the daily batch; this morning 20
issue runs sat queued behind it. Each triage job now holds a group for
its own issue only (`tend-triage-<issue>`), so different issues run at
once, and `max_parallel: 10` still bounds one dispatched batch.

The release also tells every session when the review's CI wait is off,
so a session that pushes to a bot PR leaves its CI to tend-land
([max-sixty/tend#1652](max-sixty/tend#1652)),
and the nightly token report makes far fewer API requests
([max-sixty/tend#1653](max-sixty/tend#1653)).

> _This was written by Claude Code on behalf of max-sixty_
max-sixty pushed a commit that referenced this pull request Nov 27, 2026
…1672)

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.

<details><summary>What this leaves out</summary>

- 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.

</details>

Closes #1668 — automated triage

---------

Co-authored-by: tend-agent <[email protected]>
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.

2 participants