Skip to content

fix(codex): preserve established-empty history - #2932

Open
Yuxin-Qiao wants to merge 1 commit into
steipete:mainfrom
Yuxin-Qiao:codex/codex-known-zero-history
Open

fix(codex): preserve established-empty history#2932
Yuxin-Qiao wants to merge 1 commit into
steipete:mainfrom
Yuxin-Qiao:codex/codex-known-zero-history

Conversation

@Yuxin-Qiao

@Yuxin-Qiao Yuxin-Qiao commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve a completed Codex scan with no rows as an established empty history
  • expose known-zero token snapshots only after the requested history coverage is established
  • keep incomplete, pending catch-up, buffered retry, expanded-scope, and unpriced states unavailable
  • add cache hydration and local-day regression coverage

User impact

This fixes the Codex usage/spend dashboard remaining unavailable after a completed local scan has established that the selected history is empty, without turning incomplete scans into fabricated zeroes.

Validation

  • swift test --disable-sandbox --filter 'CostUsageFetcherTests|CostUsageFetcherCacheSnapshotTests|CostUsageTokenSnapshotDaySelectionTests'
  • 45 tests in 3 suites passed
  • git diff --check

Verification evidence

Redacted local fixture only; no Keychain, network, or real account was used.

  • Fixture: a temporary empty CODEX_HOME with sessions and archived_sessions directories.
  • After-fix fresh scan: swift run --disable-sandbox CodexBarCLI cost --provider codex --format json --days 7 --refresh --json-only --no-color returned source=local, historyCoverageIsEstablished=true, sessionTokens=0, sessionCostUSD=0, last30DaysTokens=0, last30DaysCostUSD=0, and daily=[].
  • A new process against the same fixture, without --refresh, returned the same zero fields and historyCoverageIsEstablished=true, demonstrating cache hydration of the established-empty result.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 11:53 PM ET / August 15, 2026, 03:53 UTC.

ClawSweeper review

What this changes

The PR makes completed empty Codex local-history scans return zero token and cost totals after fresh scans and cache hydration, while incomplete scans remain unavailable.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for normal merge review: current main still renders a completed empty Codex history as unavailable, while this focused patch preserves it as known zero and includes sufficient local after-fix proof.

Priority: P2
Reviewed head: aef668ecb3b8db696a8090c42ddec33de5a254ff

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused patch with strong after-fix local proof and targeted regression coverage; await the active CI rerun.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides redacted after-fix CLI evidence for an empty local fixture and a separate cache-hydration process.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides redacted after-fix CLI evidence for an empty local fixture and a separate cache-hydration process.
Evidence reviewed 5 items Current-main behavior remains unfixed: Current main returns nil totals when the daily report has no rows, even if history coverage is established; the PR head adds the established-empty branch that returns zero.
Proposed cache safety guards: The PR requires a scan time, matching timezone and roots, no pending or buffered-retry files, and no requested-range expansion before hydrating an empty cache as zero.
Regression coverage: The PR adds focused tests for fresh empty scans, cache hydration, pending catch-up, buffered fork retries, and empty snapshot selection.
Findings None None.
Security None None.

How this fits together

CodexBar scans local Codex session files into a persistent usage cache, then derives token and cost snapshots for the dashboard and CLI. This change controls whether an empty scan result is presented as confirmed zero usage or unavailable history.

flowchart LR
    A[Codex session folders] --> B[History scanner]
    B --> C[Usage cache]
    C --> D{Coverage complete?}
    D -->|Completed and empty| E[Known-zero snapshot]
    D -->|Pending or incomplete| F[Unavailable snapshot]
    E --> G[Dashboard and CLI]
    F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The earlier aggregate lint-build-test run failed without failure detail in the supplied context; the current rerun must complete green or be diagnosed before merge.
  • Complete next step (P2) - No mechanical repair is indicated; wait for the active CI rerun and inspect the aggregate gate only if it fails again.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +58/-4; tests +169/-9 across 5 files The implementation growth is paired with substantially larger focused coverage for fresh scans, cache hydration, and unavailable states.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge this narrow representation change once the current CI rerun confirms the focused cache behavior and aggregate workflow are green.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Merge this narrow representation change once the current CI rerun confirms the focused cache behavior and aggregate workflow are green.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main's empty-report path produces nil totals, while the supplied empty local-history fixture directly exercises the fresh-scan and cache-hydration paths the PR changes.

Is this the best way to solve the issue?

Yes. Representing only a completed, matching-scope empty scan as zero is the narrowest solution; the patch keeps pending, retry-buffered, and expanded-range states unavailable.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 844d3ece398b.

Labels

Label justifications:

  • P2: This fixes a bounded Codex usage-dashboard availability defect after a completed empty scan.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides redacted after-fix CLI evidence for an empty local fixture and a separate cache-hydration process.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides redacted after-fix CLI evidence for an empty local fixture and a separate cache-hydration process.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Available blame attributes the surrounding Codex cache and coverage baseline to the v0.49.6 shallow-history boundary; deeper origin history is unavailable locally. (role: current-main history boundary; confidence: low; commits: 62b5b5efa936, 844d3ece398b; files: Sources/CodexBarCore/CostUsageFetcher.swift)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Confirm the current aggregate CI rerun is green, or attach the scoped failure diagnosis if it fails again.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-08-14T14:39:26.595Z sha 290bb3a :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-14T16:17:05.615Z sha aef668e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-14T18:28:29.510Z sha aef668e :: needs maintainer review before merge. :: none

@Yuxin-Qiao
Yuxin-Qiao force-pushed the codex/codex-known-zero-history branch from 290bb3a to aef668e Compare August 14, 2026 16:12
@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 14, 2026
@Yuxin-Qiao
Yuxin-Qiao marked this pull request as ready for review August 15, 2026 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant