Skip to content

Fix Codex daily usage refresh for paginated sessions - #532

Closed
zhangkom wants to merge 1 commit into
nesszer:mainfrom
zhangkom:codex/fix-paginated-subagent-history
Closed

zhangkom wants to merge 1 commit into
nesszer:mainfrom
zhangkom:codex/fix-paginated-subagent-history

Conversation

@zhangkom

@zhangkom zhangkom commented Sep 18, 2026 •

Copy link
Copy Markdown

Problem

On Windows, Codex Desktop paginated v2 subagent rollouts carry their own cumulative token counters even when their session metadata describes conversation ancestry. The scanner treated that ancestry as a billable parent dependency. When the parent was unavailable, a bounded background pass retained the previous report and stopped scanning, so healthy sessions and new local days stopped reaching the daily history.

Changes

  • Recognize the paginated v2 subagent markers and bill the child session from its own counters.
  • Treat parsed session metadata as authoritative so stale cached parent dependencies are cleared.
  • Bump the Codex cache schema to rebuild caches produced by the old accounting behavior.
  • Keep an unresolved legacy fork queued and conservative, while allowing verified files and new days to refresh in the background.
  • Add regression coverage for subagent accounting, cache recovery, continued parent sessions, unresolved legacy forks, and background daily refresh.

Validation

  • cargo test -p codexbar --lib -- --nocapture — 1852 passed, 0 failed, 1 ignored.
  • cargo test -p codexbar-desktop-tauri --bin codexbar-desktop-tauri -- --nocapture — 432 passed, 0 failed.
  • cargo clippy --workspace --all-targets -- -D warnings — passed.
  • Release desktop and CLI builds completed on Windows.

The patch is intentionally conservative for old fork formats whose inherited usage cannot be proven: those files remain incomplete instead of being double-counted, but they no longer block unrelated daily usage.

Summary by CodeRabbit

  • Bug Fixes
    • Improved Codex usage tracking for paginated subagents, preventing parent usage from being counted twice.
    • Corrected billing relationships when a subagent’s parent session is unavailable or changes.
    • Improved recovery from previously stalled or incomplete Codex scans.
    • Daily usage remains current while unresolved session relationships are being reconciled.
  • Chores
    • Updated cached scan data to support the latest Codex session tracking behavior.

@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1e836eb9-b674-4360-90c5-711e304a4905

📥 Commits

Reviewing files that changed from the base of the PR and between f259abe and c8d8d6d.

📒 Files selected for processing (5)
  • rust/src/core/jsonl_scanner/codex.rs
  • rust/src/core/jsonl_scanner/tests.rs
  • rust/src/cost_scanner/codex.rs
  • rust/src/cost_scanner/codex/pending_range.rs
  • rust/src/cost_scanner/tests.rs

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The change separates paginated v2 subagent usage from inherited fork accounting. It updates cache migration, clears stale fork dependencies, and changes unresolved-fork refresh handling. Tests cover identity parsing, cache rebuilds, usage totals, daily refreshes, and legacy fork recovery.

Changes

Codex accounting

Layer / File(s) Summary
Metadata identity and cache migration
rust/src/core/jsonl_scanner/codex.rs, rust/src/core/jsonl_scanner/tests.rs
Paginated v2 subagent markers now produce independent session identities. Cache schema version 2 rebuilds stale version 1 refresh state.
Pending fork refresh behavior
rust/src/cost_scanner/pending_range.rs, rust/src/cost_scanner/codex.rs, rust/src/cost_scanner/tests.rs
Unresolved-fork-only pending work no longer preserves a NoProgress pause. Healthy daily usage remains available while unresolved legacy forks stay pending.
Cost scanner identity integration
rust/src/cost_scanner/codex.rs, rust/src/cost_scanner/tests.rs
Parsed independent identities clear cached fork parents. Paginated subagent totals, continued parents, background refreshes, and recovery paths are tested.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Suggested reviewers: finesssee

Sequence Diagram(s)

sequenceDiagram
  participant CodexScanner
  participant SessionMetadata
  participant CostUsageCache
  participant PendingRange
  CodexScanner->>SessionMetadata: parse paginated v2 subagent metadata
  SessionMetadata->>CodexScanner: return independent session identity
  CodexScanner->>CostUsageCache: clear inherited fork dependency
  CodexScanner->>PendingRange: evaluate unresolved pending paths
  PendingRange->>CodexScanner: clear stale NoProgress pause
  CodexScanner->>CostUsageCache: store usage and acknowledge scan range
Loading

Merge Risk: ⚪ Minimal · up to c8d8d

The updated Codex accounting and refresh behavior has no identified merge-blocking issue.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 73.91% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 23 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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: fixing Codex daily usage refresh for paginated sessions. It is concise, specific, and relevant to the pull request.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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.

@Finesssee

Copy link
Copy Markdown
Collaborator

Thermo-nuclear review of the current head (c8d8d6d427222a756412d26275bda95e83415c53) found these actionable maintainability issues:

  • P1 — oversized accounting orchestrator: rust/src/cost_scanner/codex.rs grew past 1,000 lines; the new scan path owns queue, pause, report, and range transitions. Extract a typed pending-scan disposition/state transition into codex/pending_range.rs or a dedicated recovery module.
  • P2 — ambiguous lineage model: paginated v2 subagents clear forked_from_id, making None mean both no parent and independent billing. Introduce separate lineage and billing-parent fields or a typed CodexUsageRelation.
  • P2 — duplicated pending policy: unresolved-fork behavior is interpreted in both cost_scanner/codex.rs and codex/pending_range.rs. Centralize it in one typed pending disposition policy.
  • P2 — oversized test modules: new scenarios are appended to already large test files (cost_scanner/tests.rs and jsonl_scanner/tests.rs). Move paginated-subagent cases into focused test modules using the existing test-module pattern.

Merge verdict: not thermo-clean until the P1/P2 structure issues are addressed. Review was read-only.

@Finesssee

Copy link
Copy Markdown
Collaborator

Superseded by the owned remediation PR #539, which completes the typed pending disposition, lineage, scan extraction, and focused test-module fixes. This original head is intentionally left unmerged.

@Finesssee Finesssee closed this Sep 18, 2026
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