Skip to content

fix(codex): include archived sessions in usage stats - #210

Merged
mike1858 merged 2 commits into
Piebald-AI:mainfrom
jimyag:fix/codex-archived-sessions
Jul 22, 2026
Merged

fix(codex): include archived sessions in usage stats#210
mike1858 merged 2 commits into
Piebald-AI:mainfrom
jimyag:fix/codex-archived-sessions

Conversation

@jimyag

@jimyag jimyag commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • discover and watch both active and archived Codex session directories
  • preserve existing conversation and message hashes by mapping archived rollouts to their original active-session paths
  • deduplicate active and archived copies when a rollout temporarily exists in both locations
  • add regression coverage for directory discovery, deduplication, and stable hashes across archival moves

Motivation

Codex moves completed sessions from ~/.codex/sessions to ~/.codex/archived_sessions. Splitrail only scanned the active directory, so usage disappeared from local statistics after a session was archived.

Validation

  • cargo build --quiet
  • cargo test --quiet (397 passed)
  • cargo clippy --quiet -- -D warnings
  • cargo doc --quiet
  • cargo fmt --all --quiet
  • manual splitrail stats verification against active and archived Codex data

Summary by CodeRabbit

  • New Features

    • Codex CLI session history now automatically discovers and watches both active sessions and archived session files.
    • Archived sessions are treated as the same logical session as their original active copy for browsing and analysis.
  • Bug Fixes

    • Duplicate session entries are filtered out when the same session exists in multiple locations.
    • Session/message identity calculations are now stable across active vs archived copies.

Scan active and archived Codex session directories so archived usage remains visible. Preserve canonical message identities across moves and deduplicate temporary copies.

Signed-off-by: jimyag <git@jimyag.com>
@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56042a55-e541-45be-803e-d90890dea5fe

📥 Commits

Reviewing files that changed from the base of the PR and between 6b6a2f9 and 48b330b.

📒 Files selected for processing (2)
  • src/analyzers/codex_cli.rs
  • src/analyzers/tests/codex_cli.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/analyzers/tests/codex_cli.rs
  • src/analyzers/codex_cli.rs

📝 Walkthrough

Walkthrough

Codex CLI analysis now watches active and archived session directories, canonicalizes archived files to active-session identities, deduplicates discovered sources, and produces stable message hashes across session archiving.

Changes

Codex archived session support

Layer / File(s) Summary
Session directory discovery and canonicalization
src/analyzers/codex_cli.rs, src/analyzers/tests/codex_cli.rs
Directory helpers include active and archived sessions; archived paths are canonicalized and duplicate JSONL sources are reduced to one active-session source.
Analyzer watching and path validation
src/analyzers/codex_cli.rs, src/analyzers/tests/codex_cli.rs
Globs, availability checks, discovery, and valid-path checks now cover both session directories.
Stable message hashing and validation
src/analyzers/codex_cli.rs, src/analyzers/tests/codex_cli.rs
User, assistant, and token-usage message hashes use canonical session paths, with tests verifying identical hashes across active and archived copies.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant CodexCliAnalyzer
  participant SessionDirectories
  participant JSONLSourceDiscovery
  participant MessageParser
  CodexCliAnalyzer->>SessionDirectories: inspect active and archived paths
  SessionDirectories->>JSONLSourceDiscovery: provide JSONL files
  JSONLSourceDiscovery->>JSONLSourceDiscovery: canonicalize and deduplicate session paths
  JSONLSourceDiscovery-->>CodexCliAnalyzer: return unique sources
  CodexCliAnalyzer->>MessageParser: parse a session file
  MessageParser->>MessageParser: hash messages using canonical session path
Loading

Poem

I hop through sessions, both near and far,
Archived trails beneath each star.
One path remains when copies roam,
Hashes stay steady, safely home.
Codex logs now bloom anew—
A bunny’s watchful work for you! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: archived Codex sessions are now included in usage stats.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/analyzers/tests/codex_cli.rs (1)

11-23: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise direct assistant-message hash stability.

The fixture emits only a user message and token usage, so the changed direct-assistant branch in src/analyzers/codex_cli.rs Lines 492-502 is untested. Add an assistant response_item before the token event and retain the active/archive hash assertions.

Also applies to: 69-89

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/analyzers/tests/codex_cli.rs` around lines 11 - 23, Add an assistant
`response_item` record to the fixture produced by `write_test_session`, placing
it before the existing token-count event and using the format expected by the
direct-assistant branch in `codex_cli.rs`. Keep the existing active/archive hash
assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/analyzers/codex_cli.rs`:
- Around line 183-186: Update is_valid_data_path to require the path to be
located under at least one directory returned by Self::data_dirs(), in addition
to being a file with a .jsonl extension. Add regression coverage proving paths
inside watched roots are accepted and unrelated .jsonl paths outside those roots
are rejected.

---

Nitpick comments:
In `@src/analyzers/tests/codex_cli.rs`:
- Around line 11-23: Add an assistant `response_item` record to the fixture
produced by `write_test_session`, placing it before the existing token-count
event and using the format expected by the direct-assistant branch in
`codex_cli.rs`. Keep the existing active/archive hash assertions unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 554cc2c1-aab7-4f50-a7b6-8e198a0407a0

📥 Commits

Reviewing files that changed from the base of the PR and between 658a746 and 6b6a2f9.

📒 Files selected for processing (2)
  • src/analyzers/codex_cli.rs
  • src/analyzers/tests/codex_cli.rs

Comment thread src/analyzers/codex_cli.rs
Reject JSONL files outside Codex data roots and cover direct assistant hash stability across archival moves.

Signed-off-by: jimyag <git@jimyag.com>

@mike1858 mike1858 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I didn't even know you could archive sessions in Codex! Will release with your other fix momentairily.

@mike1858
mike1858 merged commit 67d4087 into Piebald-AI:main Jul 22, 2026
6 checks passed
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.

2 participants