Skip to content

Include archived Codex sessions in usage reports (rebased, supersedes #663)#667

Open
ozymandiashh wants to merge 1 commit into
mainfrom
fix/663-archived-harden
Open

Include archived Codex sessions in usage reports (rebased, supersedes #663)#667
ozymandiashh wants to merge 1 commit into
mainfrom
fix/663-archived-harden

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Rebases #663 by @gt-zhangshihao03 onto current main and opens it as a maintainer PR. The original had a merge conflict with main after #656 landed; the code is unchanged from #663 apart from resolving a README provider-table conflict. The original commit authorship is preserved.

What it does

Discovers Codex rollout-*.jsonl files from the flat ~/.codex/archived_sessions directory in addition to the date-partitioned ~/.codex/sessions/YYYY/MM/DD, using the same metadata validation and project attribution for both. Archiving a Codex conversation (which moves its rollout file to archived_sessions) no longer erases its historical usage from reports.

Maintainer verification

  • No double-counting if a session were ever present in both directories: parsing dedups on a content-based key (codex:${forkedFromId||sessionId}:${cumulativeTotal}:…) via a seenKeys set created once and shared across all sources (src/parser.ts). Identical content at two paths yields identical keys, so the second copy is skipped. Confirmed on code.
  • Archived-only home works: the readdir(sessionsDir).catch(() => []) change lets a home with no sessions/ directory fall through to the archived scan. The regression test builds a fresh temp home containing only archived_sessions/, so it genuinely exercises that path (the old early-return would have failed it).
  • Ordering: archived sources are appended after active ones; this doesn't affect totals or time-series because the day-aggregator buckets each session by its own firstTimestamp and sorts, rather than relying on discovery order.
  • npx tsc --noEmit clean; npx vitest run tests/providers/codex.test.ts green (22 tests).

Fixes #662
Supersedes #663 (original work by @gt-zhangshihao03)

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.

Codex usage disappears after archiving a session

2 participants