Conversation
Pairs with 3dl-dev/legion#339. Legion's API substrate now posts `inference-usage` tagged messages to the work campfire after each Router.Infer call, carrying the actual InputTokens / OutputTokens. Adds `accumulateInferenceUsage` handler called from the watch loop alongside the existing `accumulateToolUsage` path. Attribution is by item_id via workItemToScenario (terminal-tool messages use finding-id tags — legion does not know finding IDs, so we attribute via item_id instead). forge_calls is NOT incremented — that count remains owned by terminal tools. Dedup uses the existing seenToolUsageMsgs set keyed by message ID. Before: every per-scenario record had tokens_in=0, tokens_out=0 After (UT-02 single-scenario run): tokens_in=16211, tokens_out=938 attributed correctly from 5 legion inference-usage posts. mallcoppro-3 (academy token attribution = 0, third request) Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an
accumulateInferenceUsagehandler that readsinference-usage-tagged messages posted by legion's API substrate (3dl-dev/legion#339) and attributes theirtokens_in/tokens_outto the matching scenario.Why
Per-scenario token counts have been zero for a long time. The existing
emitToolUsagepath inmallcop-investigate-tools/tools_f1g.goreadsMALLCOP_SESSION_TOKENS_IN/OUTenv vars that nothing populates — by design, those were a forward-compat placeholder. Legion now posts the actualInputTokens/OutputTokensdirectly after eachRouter.Infer, and this handler ingests them.Behavior
item_idviaworkItemToScenario(terminal-tool messages use finding-id tags, but legion does not know finding IDs).ts.toolUsageTokensIn/ts.toolUsageTokensOutonly. Does NOT increment forge_calls — that count remains owned by terminal tools.seenToolUsageMsgsset.Test plan
go test ./cmd/mallcop-academy/...— all existing tests passtokens_in=16211,tokens_out=938(was 0 before)forge_calls=2unchanged (terminal-tool count untouched)Depends on
mallcoppro-3
🤖 Generated with Claude Code