Uh oh!
There was an error while loading. Please reload this page.
fix agent name showing 'unknown' issue - #73
Conversation
📝 WalkthroughWalkthroughIn ChangesSession Totals Initialization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~5 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
dialupdisaster
commented
Jun 24, 2026
Thanks for jumping on this. The Why I’m hesitant about the current approach:
I think a cleaner fix in the current codebase would be:
That would fix the agent-name bug without fabricating partial totals for resumed sessions. If you want, I think that would still be a very nice contribution and a cleaner follow-up on top of the run-by-user-message tracing work in #74. |
chingjustwe
commented
Jun 25, 2026
make sense, let me do it. |
chingjustwe
commented
Jun 25, 2026
I found below code in #74 already fixed the "unknown" agent name bug: conststartTime=Date.now()constexistingTotals=sessionTotals.get(input.sessionID)constnextTotals: SessionTotals={startMs: existingTotals?.startMs??startTime,tokens: existingTotals?.tokens??0,cost: existingTotals?.cost??0,messages: existingTotals?.messages??0,
agent,agentType: existingTotals?.agentType??"primary",}setBoundedMap(sessionTotals,input.sessionID,nextTotals)I'm OK to close this PR and Issue #72 |
Description
Fix Issue: #72
When a user sends a message to an existing session (no
session.createdevent), thesessionTotalsmap has no entry for that session. Thechat.messagehook only mutated an existing entry but did not create one. This causedgetSessionAgentMetato fall back to "unknown" for all subsequent metric counters, trace span attributes, and log event attributes.This fix creates a
sessionTotalsentry in thechat.messagehook when one does not exist, usinginput.agentas the agent name. Sincechat.messagefires before any code that readssessionTotals, this ensures the correct agent is always available.Type of change
Checklist
bun run lintpasses with no errorsbun run check:jsdoc-coveragepasses with no errorsbun run typecheckpasses with no errorsbun testpasses with no errorsRelated issues
#72
Additional context
Summary by CodeRabbit