Repository navigation
Conversation
…issed `session.step.ended` and `session.step.failed` carry no model, so the model comes from the `stepMeta` entry `session.step.started` writes. When that entry is missing (the plugin subscribed after the step started, or the execution ended and its sweep cleared the entry before the step ended), `api_request`, `api_error`, the token, cost and message metrics all report model and provider `unknown`. The model now falls back to the in-flight model request of the session (`activeLlm`), then to the session's last known model, kept on the session identity from each step start and from `session.get` for a session the plugin looks up, and only then to `unknown`. Co-Authored-By: Claude Opus 5.5 <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.
Problem
session.step.endedandsession.step.failedcarry no model, sohandleStepEnded/handleStepFailedtake it from thestepMetaentry thatsession.step.startedwrites. When that entry is missing, every signal of the step reports model and providerunknown: theapi_request/api_errorlog,token.usage,cost.usage,message.countandmodel.usage.We see this in practice:
api_requestrecords withmodel="unknown"and real token counts, which a backend reading these logs can't price or attribute to a model. The entry goes missing when:ensureSessionhandles for sessions), orsweepExecutiondeletes the session'sstepMetaentries, so asession.step.ended/failedarriving after it finds nothing.Change
stepModelresolves the model in this order:stepMeta(unchanged),activeLlm, written bymodel.requestandsession.step.started),SessionIdentity.model: written on every step start, and fromsession.getwhencontextForSessionlooks a session up (a resumed session),unknown, only when none of them names one.finalizeSessionkeeps the identity, so 3 also covers a step that ends after its execution was swept. A model switched mid-run could in theory be attributed to the previous model for such a step; that is still closer thanunknown.Tests
tests/handlers/step.test.ts(step model fallback): missed start, a step ending after its execution was interrupted and finalized, an in-flight model request on a failed step, andunknownwhen nothing names the model.tests/state.test.ts:contextForSessionkeeps a looked-up session's model.🤖 Generated with Claude Code
https://claude.ai/code/session_01LjxP4wYYiGM6J8Bazqkuc5