feat(miner): extract and persist real coding-agent token usage - #5658
Conversation
Both driver implementations now report a real tokensUsed count instead of always leaving it 0: the Agent SDK driver reads usage.input_tokens/ output_tokens off the SDK's own result message, and the CLI-subprocess driver ports src/selfhost/ai.ts's extractCliUsage to scan CLI JSON/JSONL stdout for the same signal. iterate-loop.ts sums this per-iteration total into finalMeterTotals.tokens (previously hardcoded 0), and attempt-cli.js surfaces it as totalTokensUsed and persists it on the attempt_outcome_summary ledger event alongside the existing cost/provider fields. Closes #5653
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
loopover-ui | 1fbf677 | Commit Preview URL Branch Preview URL |
Jul 13 2026, 09:40 PM |
|
Warning 🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨 ⏸️ LoopOver review result - manual review recommendedReview updated: 2026-07-13 22:17:23 UTC
⏸️ Suggested Action - Manual Review
Review summary Nits — 7 non-blocking
Review context
Contributor next steps
Signal definitions
[BETA] Chat with GittensoryAsk Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.
Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands 🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.
|
… type attempt-cli.js's runtime finalResult object already carries this field (the previous commit) but the hand-maintained .d.ts was missed.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5658 +/- ##
=======================================
Coverage 95.03% 95.03%
=======================================
Files 577 577
Lines 45920 45946 +26
Branches 14695 14708 +13
=======================================
+ Hits 43639 43665 +26
Misses 1528 1528
Partials 753 753
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Summary
input_tokens/output_tokensoff the SDK's own result message (usagefield) instead of never reporting tokenssrc/selfhost/ai.ts'sextractCliUsageto scan CLI JSON/JSONL stdout for input/output/total token keys (top-level and nestedusage/token_usage/etc.), same convention already used there for costiterate-loop.tssums each iteration's realtokensUsedintofinalMeterTotals.tokens(previously hardcoded to0)attempt-cli.jssurfaces the accumulated total astotalTokensUsedon the attempt result and persists it on theattempt_outcome_summaryledger event, alongside the existingcostUsd/providerfields feeding the Grafana miner-usage dashboardAbsent (not zero) is preserved as the "no signal reported" case throughout, mirroring
costUsd's existing honest-absence convention.Closes #5653
Test plan
packages/gittensory-enginenode:test suite (537/537 pass)miner-attempt-runner/miner-attempt-cli(136/136 pass)npm run test:cigreennpm run test:coverage(unsharded) — 100% branch coverage on every new/changed line, verified directly against lcov.infonpm run typecheck,npm run build:miner,npm run test:miner-pack,npm audit --audit-level=moderateall clean