Repository navigation
fix(action): restore token aggregation broken by result-event filter - #266
Merged
Merged
Conversation
#249 switched the token-usage jq filter to `select(.type == "result")`, an event type that claude-code-action's session JSONL does not emit. Every `token-usage.json` since the merge has reported zero tokens — confirmed across all 61 runs in the past 24h on this repo. Restore the per-assistant-event aggregation from #188 and compute cost from token totals × Claude Opus 4 list prices, since `total_cost_usd` isn't available in this JSONL format. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Owner
|
but there is a cost field at the end of the logs! can we search for and use that? |
…file Switches the token-usage aggregation to read `$RUNNER_TEMP/claude-execution-output.json` (exposed via `steps.claude.outputs.execution_file`) instead of summing per-turn assistant events from the session JSONL. The SDK writes a `type: "result"` entry at the end of that array with `total_cost_usd`, `num_turns`, and per-session usage totals — so cost is now accurate regardless of the model in use, and the hard-coded Opus 4 rate table goes away. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Collaborator
Author
|
Good catch — you are right. The Pushed 250ebe9 which switches to that source: cost comes straight from |
max-sixty
added a commit
that referenced
this pull request
Apr 14, 2026
Bumps generator version to 0.0.12 and syncs lockfile. 50 commits since 0.0.11: notifications cost cut + freshness gate (#251, #254), token-report per-run table and cost estimate (#249, #250), review-reviewers outcome-focused Haiku analysis (#255), config workflow_extra/jobs pass-through (#227), canonical author_association tiers across skills (#261, #263), action token aggregation fix (#266), plus numerous review/mention/ci-runner fixes. Co-Authored-By: Claude <[email protected]>
Merged
max-sixty
added a commit
that referenced
this pull request
Apr 14, 2026
Bumps generator version to 0.0.12 and syncs lockfile. 50 commits since 0.0.11. Highlights: - feat: notifications cost cut + freshness gate (#251, #254) - feat: token-report per-run table + cost estimate (#249, #250) - feat: review-reviewers outcome-focused Haiku analysis (#255) - feat: config `workflow_extra` / `jobs` pass-through (#227) - skills: canonical `author_association` tiers (#261, #263) - fix: action token aggregation (#266), plus numerous review/mention/ci-runner fixes > _This was written by Claude Code on behalf of Maximilian_ Co-authored-by: Claude <[email protected]>
max-sixty
pushed a commit
that referenced
this pull request
Sep 21, 2026
…t marked for removal (#1361) `claude_step` copied the raw stream-json into the session-log artifact as `claude-stream.json`, gated to `max-sixty/tend`. Its comment named the condition for removing it — "Drop once #302 is resolved" — and #302 was resolved on 2026-05-12 by the result-event summing in #266, which is what the module docstring's path 1 now describes: sum `usage.*` and `num_turns` across every `result` event, take `total_cost_usd` from the last. Nothing reads the copy. `claude-stream.json` is written in one place and read in none — not by `token_report.py`, and not by `/tend-ci-runner:read-session-logs` or `install-tend:debug-tend-run`, which both parse the session JSONL instead. The stream itself is unaffected: `STREAM_JSON` still feeds `claude_usage`, and `launch_agent.py` still exports it out of the sandbox for that. What goes is the extra artifact copy and the repo gate that guarded it, which was the only reason `GITHUB_REPOSITORY` meant anything on the Claude path beyond the record's own `repo` field. No regression test — this removes an unexercised diagnostic side effect rather than changing behavior, and the surviving path is already covered by `shared/steps/test_token_usage.py`. Refs #302. --------- Co-authored-by: tend-agent <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every
token-usage.jsonsince #249 reports zero tokens. Confirmed across all 61 tend CI runs in the past 24 h on this repo (12tend-review, 19tend-mention, 22review-reviewers, 6tend-notifications, 1tend-nightly, 1tend-weekly).Sample artifact (run 24330280717,
tend-review):{"input_tokens":0,"output_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"turns":0,"model":"opus","cost_usd":0}Root cause
#249 added a
select(.type == "result")filter that targets the SDK's per-session result event — which carriestotal_cost_usd,num_turns, and a session-levelusageobject. That event is real, but it isn't written to the per-turn session JSONL under/home/runner/.claude/projects/;claude-code-actionwrites it (along with the rest of the SDK message stream) to$RUNNER_TEMP/claude-execution-output.jsonand exposes that path as theexecution_fileaction output. Reading from/home/runner/.claude/projects/therefore matched zero entries and every numeric field fell back to 0.This was masked yesterday because the 24 h analysis window straddled the #249 merge time (2026-04-11 20:28 UTC) — most artifacts in that window pre-dated the regression. Today's window is fully post-#249, so every run reports zeros.
Fix
Read
${{ steps.claude.outputs.execution_file }}and pulltotal_cost_usd,num_turns, andusage.*directly from theresultentry. Cost is now whatever the SDK reports (no hard-coded model rate table), so Sonnet/Haiku adopters and 1-hour cache usage are accounted for correctly.Verified with a synthetic execution-file array containing a real
resultentry from run 24330280717: produces34 input / 4954 output / 1035105 cache_read / 39191 cache_creation, 24 turns, $0.89— matches thetotal_cost_usdprinted in that run's job log (0.886... rounded to 2dp).