Skip to content

fix: don't report unpriced AI spend as $0, give the api agent its own no-key status - #30

Merged
vsn411 merged 1 commit into
mainfrom
fix/cost-tracking-and-api-status
Oct 15, 2026
Merged

vsn411 merged 1 commit into
mainfrom
fix/cost-tracking-and-api-status

Conversation

@Varunpoojari

@Varunpoojari Varunpoojari commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes SECFOO-34 and SECFOO-35.

SECFOO-34 — secfoo cost showed unknown tokens/cost as 0 / $0.00

cost_summary()'s SQL wrapped every SUM() in COALESCE(...,0), so a group (or the CLI's Total row) where no run reports cost/tokens rendered as 0 instead of -. SQLite's SUM() already returns NULL exactly when every value in the group is NULL -- that's the "unknown" signal, and the COALESCE was throwing it away.

  • Dropped the COALESCE in repository.py's cost_summary().
  • CostRow.input_tokens / output_tokens / cost_usd are now int | None / float | None.
  • Added cost.sum_optional() for the CLI cost command's Total row, which had the same bug one level up.
  • web/routes/overview.py's dashboard template already guarded this correctly per-row (priced = row.unpriced_runs < row.runs), so no change needed there.

SECFOO-35 — api agent with no key reported binary_not_found

The api agent has no CLI binary -- is_available() checks for an API key, not a binary on PATH -- but on failure it reused the base adapter's binary_not_found status, which means "the CLI isn't installed." That's not what's wrong here.

  • Added a distinct not_configured status to agents/base.py's Status literal.
  • api.py now returns not_configured (same stderr message) instead of binary_not_found.
  • Wired the new status into the CLI's _STATUS_STYLE and the dashboard's _STATUS_BADGE_CLASS maps.

Testing

Added test_cost_command_total_is_dash_when_every_run_is_unpriced, updated the existing unpriced-group assertion and test_run_without_a_key_explains_what_to_set. Full suite: 808 passed (only the 4 pre-existing mermaid-vendor failures noted on SECFOO-5, unrelated to this change -- local env has no ~/.secfoo/vendor/mermaid.min.js).

… no-key status

SECFOO-34: cost_summary() wrapped every SUM() in COALESCE(...,0), so a
group (or the secfoo cost command's Total row) where no run reports
cost/tokens rendered as 0 instead of "-". SQLite's SUM() already returns
NULL exactly when every value in the group is NULL -- that's the "unknown"
signal, and the COALESCE was throwing it away. Dropped it, made CostRow's
numeric fields Optional, and added cost.sum_optional() for the CLI Total
row, which had the same bug one level up.

SECFOO-35: the api agent has no CLI binary -- is_available() checks for
an API key, not a binary on PATH -- but reused the base adapter's
binary_not_found status on failure, which means "the CLI isn't
installed." Added a distinct not_configured status instead, wired into
the CLI and dashboard status->style maps.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019mBtLHW8WjEnRgDGAbzXLF
@vsn411
vsn411 merged commit b6f50f9 into main Oct 15, 2026
2 checks passed
@Melwinjoel20 Melwinjoel20 mentioned this pull request Oct 16, 2026
4 tasks done
vsn411 pushed a commit that referenced this pull request Oct 31, 2026
Since cost_summary() stopped collapsing unknown cost to $0 (PR #30),
an agent whose runs are all unpriced (devin, droid, cursor, agy) comes
back with cost_usd=None. The overview page added every agent's cost
with a plain sum(), so one priced run plus one unpriced agent raised
TypeError and "/" returned 500. Use sum_optional(), as the `secfoo
cost` Total row already does.

The "AI spend by agent" table had the same problem with tokens: a run
can have a cost but no token counts, and the template added None +
None. Show "-" when no token count is known.

Co-Authored-By: Claude Opus 5.5 <[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