Repository navigation
feat(assistant): record cost and outcome of discovery runs and Matter activations - #6321
Conversation
… activations Every discovery run (broad heartbeat, quick discovery) and every Matter activation now appends one row to a local run-cost ledger: kind, start, end, outcome, and the model usage its Sessions accrued in that window. Usage is read from the canonical Usage ledger by Session and time window, the technique hosted-execution settlement already uses, so no new metering path is added and discovery cost stays apart from the user's Session cost. A run that finishes and hands over nothing is recorded as no_report, and an unreadable or partial Usage window is recorded as incomplete rather than as zero. The ledger is written after the run, swallows its own failures, and nothing reads it back to limit, delay or reroute a run. A summary (daily totals per kind, activations per Matter, recent runs) is exposed in the assistant status. Refs #6309, #6247 Generated-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>
me2seeks
left a comment
There was a problem hiding this comment.
Found one reproducible outcome-accounting bug. The 32 focused cost/quick tests pass on Node 24.18.1, but adding a retryable network failure to the existing Matter cost fixture records interrupted instead of retried.
…rrupted A retryable terminal failure makes completion() call retryExecution(), which clears the activation on purpose and sets the outcome to retried. Execution then fell through to the classification that reads a missing activation as the user interrupting the run, and overwrote retried with interrupted. Every automatic retry was therefore counted as a user interruption. Skip that classification once a retry has decided the outcome. Add tests for a retryable (network) failure and a non-retryable one, so the fix cannot over-correct. Refs #6309 Generated-by: Claude Opus 5.5 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks @me2seeks, reproduced and fixed in b03705e. Root cause as you described: I added your scenario as a test: a retryable |
me2seeks
left a comment
There was a problem hiding this comment.
Reviewed the updated head. The retry outcome is now preserved and covered by retryable and non-retryable regression cases. Verified the previous finding is fixed; local assistant tests pass (93 + 89 + 88), hosted CI is green, and the review thread is resolved.
Summary
Decision 4 on #6247 is to add cost visibility before any limit. This records what each discovery run and each Matter activation cost and how it ended, and limits nothing.
no_report, so reported and silent runs can be told apart (RFC(assistant): tool boundaries, delegation ownership and heartbeat cost of the discovery session #6247 item 6).Fixes #6309
Refs #6247
Verification
Node 24.21.0, on
origin/main@da614305c:tscbuild of core, storage, mcp, runtime, runtime-hostnpm run typecheckinpackages/runtime-hostbiome checkon the 12 changed filesnpm run check:asf-headersnpm run test:assistantinpackages/runtime-hostusageandexecution-compositiondist testsThe one failure,
assistant Host fallback registers a task workspace usable by ordinary Session creation and binding, fails the same way onorigin/main@da614305cwithout this change, so it is not introduced here. I did not investigate its cause. The full workspace test suite and the desktop build were not run.New tests cover: a run that reports is recorded with both workers' cost and kept apart from the conversation; a quick run that reports nothing is recorded as
no_reportwith its model cost; an unreadable Usage ledger is recorded as unknown cost, not zero cost and not a stalled run.Review focus
finallyblocks in the Matter controller and the two discovery controllers. A recording failure must not change a run's outcome; that is what the swallow-and-continue in the ledger guarantees.readSessionUsageWindowincanonical-usage-reader.tsmarks a window incomplete when the Usage ledger has partial, missing, unreadable or unrepaired rows.AI use
Select exactly one:
Tool(s) and scope: Claude Code (Claude Opus 5.5) drafted the implementation and tests from the #6309 acceptance list. I reviewed the diff and ran the checks above. The commit carries a
Generated-bytrailer.Checklist
Does this PR entail a change in behavior?
🤖 Generated with Claude Code