Skip to content

fix: use map key as fallback SessionID in map-format sessions.json - #7

Open
bughunt8 wants to merge 2 commits into
SammyLin:masterfrom
bughunt8:fix/empty-session-id
Open

fix: use map key as fallback SessionID in map-format sessions.json#7
bughunt8 wants to merge 2 commits into
SammyLin:masterfrom
bughunt8:fix/empty-session-id

Conversation

@bughunt8

@bughunt8 bughunt8 commented Apr 8, 2026

Copy link
Copy Markdown

Summary

Fixes #5 — When sessions.json is in map format, the map keys (which are the session IDs) were discarded, causing empty SessionID fields and phantom .jsonl file lookups.

Problem

loadSessions() in collector/token.go parses sessions.json as 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 a sessionId field (since the ID is the map key), the resulting sessionEntry.SessionID is empty. This causes readSessionUsage() 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.SessionID is empty:

for k, v := range asMap {
    if v.SessionID == "" {
        v.SessionID = k
    }
    entries = append(entries, v)
}

Warp conversation

Co-Authored-By: Oz oz-agent@warp.dev

bughunt8 and others added 2 commits April 8, 2026 11:48
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Map-format sessions.json discards map keys, causing empty SessionID and phantom file lookups

1 participant