Skip to content

Fix: dashboard overview crashes when an agent has no recorded cost - #31

Merged
vsn411 merged 1 commit into
secfoo-com:mainfrom
AmirNCI:fix/overview-unpriced-cost-crash
Oct 31, 2026
Merged

vsn411 merged 1 commit into
secfoo-com:mainfrom
AmirNCI:fix/overview-unpriced-cost-crash

Conversation

@AmirNCI

@AmirNCI AmirNCI commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What does this change, and why?

Found during the SECFOO-12 dashboard check: after PR #30, the dashboard
home page (/) returns 500 for anyone who has run a priced agent
(e.g. claude) and an agent that doesn't report cost (devin, droid,
cursor, agy).

File "src/secfoo/web/routes/overview.py", line 56, in overview
    sum(row.cost_usd for row in cost_by_agent)
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

PR #30 correctly made cost_summary() return cost_usd=None for an
all-unpriced group instead of 0, but the overview page still summed
with plain sum(). This switches it to sum_optional(), which the
secfoo cost CLI Total row already uses. Same result as before when
nothing is priced (None → "-").

Fixing that exposed a second crash in the same "AI spend by agent"
table: overview.html added input_tokens + output_tokens for any
priced row, but a run can have a cost with no token counts (my local
store has one), giving None + None. It now shows "-" when no token
count is known.

Testing

  • pytest tests passes (813 passed)
  • ruff check passes on the changed source file
  • Added test_overview_totals_cost_when_one_agent_is_unpriced
    (fails on main with the TypeError above, passes with this fix)
  • Checked against my real ~/.secfoo store: / went from 500 to 200

Since cost_summary() stopped collapsing unknown cost to $0 (PR secfoo-com#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]>
@karthickmk2001

Copy link
Copy Markdown
Collaborator

Could a maintainer review this when you get a chance? On main, the dashboard (/) returns a 500 error whenever an agent has runs with no recorded cost, and this PR fixes that. It has no merge conflicts and has been open since 17 Oct.

#34 (SECFOO-69 UI improvements) depends on this fix for the dashboard, so it would help to merge this one first. Thanks!

@karthickmk2001 karthickmk2001 changed the title fix: dashboard overview crashes when an agent has no recorded cost Fix: dashboard overview crashes when an agent has no recorded cost Oct 27, 2026
@vsn411
vsn411 merged commit a553cf7 into secfoo-com:main Oct 31, 2026
2 checks passed
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.

3 participants