fix: use map key as fallback SessionID in map-format sessions.json - #7
Open
bughunt8 wants to merge 2 commits into
Open
fix: use map key as fallback SessionID in map-format sessions.json#7bughunt8 wants to merge 2 commits into
bughunt8 wants to merge 2 commits into
Conversation
When sessions.json is a map (dict), the map keys may be the only source of session IDs. Previously the keys were discarded, leaving SessionID empty and causing readSessionUsage to look for a file named '.jsonl'. Now the map key is used as the SessionID when the value's sessionId field is empty. Fixes SammyLin#5 Co-Authored-By: Oz <oz-agent@warp.dev>
Verifies that map keys are used as SessionID when the value's sessionId field is empty. Also tests array format, explicit sessionId preservation, missing file, and invalid JSON cases. Co-Authored-By: Oz <oz-agent@warp.dev>
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
Fixes #5 — When
sessions.jsonis in map format, the map keys (which are the session IDs) were discarded, causing emptySessionIDfields and phantom.jsonlfile lookups.Problem
loadSessions()incollector/token.goparsessessions.jsonas either a map or an array. In the map path, only the values were used (for _, v := range asMap), throwing away the keys. If the JSON values don't contain asessionIdfield (since the ID is the map key), the resultingsessionEntry.SessionIDis empty. This causesreadSessionUsage()to try to open a file named.jsonl(no basename), which always fails silently — meaning token metrics for those sessions are never reported.Fix
When iterating the map, use the key as a fallback if
v.SessionIDis empty:Warp conversation
Co-Authored-By: Oz oz-agent@warp.dev