Repository navigation
feat(delivery): carry per-run token counts onto the task file - #196
Conversation
Add the four token counts ClaudeResult already parses (input, output, cache-read, cache-creation) to AgentResultInfo and Result, populate them in claude/agent-step.go, copy them in agent_runner.go, and publish them as the metrics_*_tokens frontmatter keys plus a per-run metrics_runs history list (the flat keys are last-write-wins). A run with no usage summary publishes no token key, matching the existing turn-count absence rule.
# Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
The token-count plumbing is sound on the happy path, but two correctness gaps remain: metrics_runs is truncated for multi-delivery (multi-phase) Jobs, and token usage is discarded on the failed-run path and for partial-usage results. Selector-mode adjudication ran; intent unavailable (gh not permitted); precommit skipped in selector mode because CI covers lint+test.
…ry tokens on the failed path Review findings on #196: - metrics_runs was truncated for multi-phase Jobs: each delivery rebuilt the frontmatter from the Job-start content, so a second delivery dropped the first's entry. The list is now accumulated on the deliverer, seeded once from the Job-start content. - Token usage was discarded on the failed-run path and for partial-usage results. runCounts now reads usage before the error check (the runner carries it on the error path) and treats a summary with any token count as present even when no turn count was reported; the failed Result carries the counts.
superseded by new automated review
There was a problem hiding this comment.
Reviewed the token-count plumbing (ClaudeResult → Result → AgentResultInfo → Kafka frontmatter + metrics_runs history) against master. The change is additive, nil-safe, and the deliverer serializes runHistory under its existing mutex, so the per-deliverer mutable state is not racy and there is no re-delivery path that would double-count within the library. All 25 mechanical-funnel findings were verified against the worktree and are false positives/exempt: the go-composition hits are receiver method calls plus a pure stdlib fmt.Sprintf (explicitly ruled out by the rule), the go-enum-type hits are frontmatter map keys not enums, the go-k8s-binary 'secret' hits are int64 token COUNTS not credentials, and the go-testing bare-call hits are counterfeiter GenerateReturns, which returns nothing. No blocking defect found; three non-blocking nits and one Should-Fix test gap are noted.
Task: 8c45c38f-abf5-43f2-9f05-00c1ea1d57ca
Adds the four token counts
ClaudeResultalready parses (input, output, cache-read, cache-creation) toAgentResultInfoandResult, populates them inclaude/agent-step.go, copies them inagent_runner.go, and publishes them as themetrics_*_tokensfrontmatter keys plus a per-runmetrics_runshistory list.metrics_runsrecords every run (counts +completed_at) for a per-window budget to sum.Unblocks
bborbe/agent-task-executor'stokenCeilingadmission check (follow-up).Verified:
make precommitgreen (golangci-lint 0 issues, gosec clean via #nosec G101 on the key-name constants, tests pass, helm render OK).