Skip to content

[codex] Add project-level Codex cost rollups - #1820

Closed
clemenspeters wants to merge 1 commit into
steipete:mainfrom
clemenspeters:codex/project-cost-rollups
Closed

[codex] Add project-level Codex cost rollups#1820
clemenspeters wants to merge 1 commit into
steipete:mainfrom
clemenspeters:codex/project-cost-rollups

Conversation

@clemenspeters

Copy link
Copy Markdown
Contributor

Summary

  • add project-level Codex cost rollups grouped by canonical project path
  • resolve Codex worktree CWDs back to their Git main worktree while preserving source CWD details
  • expose project/source rollups in CLI JSON, --group-by project, and the cost history submenu

Why

Codex sessions spawned in .codex/worktrees/*/<repo> were shown as separate projects, which made customer/project totals hard to read. This keeps the detailed source breakdown while showing the true combined project total first.

Closes #1819

Validation

  • swift build --product CodexBarCLI
  • swift build --product CodexBar
  • swift test --filter 'CostUsageScannerBreakdownTests|CostUsageCacheTests|CLICostTests|CostHistoryChartMenuViewTests'
  • local smoke test: codexbar cost --provider codex --group-by project --days 30 --no-color

@clemenspeters
clemenspeters marked this pull request as ready for review July 1, 2026 12:54

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05481806da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

ForEach(Array(self.projects.prefix(Self.maxVisibleProjectRows)), id: \.projectRowID) { project in
VStack(alignment: .leading, spacing: Self.projectSourceSpacing) {
self.projectParentRow(project)
if project.sources.count > 1 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Show single differing source paths

When a project has exactly one source whose path differs from the canonical project path, such as usage that came only from a .codex/worktrees/... checkout, this condition hides the only source row. The submenu then shows the rolled-up main worktree path but drops the source CWD detail that the project rollup is supposed to preserve; consider showing sources when the sole source path differs from project.path, not only when there are multiple sources.

Useful? React with 👍 / 👎.

Comment on lines +171 to +176
[
project.name,
project.path ?? "",
"\(project.totalTokens ?? -1)",
Self.formatOptionalDoubleForSignature(project.totalCostUSD),
].joined(separator: ",")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Include project sources in refresh signatures

When an open menu already has a Codex project row and only its source breakdown changes while the project total stays the same, this signature remains unchanged because it records only the parent project fields. In that case didMenuAdjunctReadinessChange can skip invalidation and leave the visible Projects section showing stale source rows; include source path/name/totals in the project signature.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Jul 1, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 1, 2026, 9:15 AM ET / 13:15 UTC.

Summary
The branch adds Codex project/source cost rollups across scanner cache, snapshot models, CLI JSON/text --group-by project, menu UI, docs, and focused tests.

Reproducibility: yes. source inspection gives a high-confidence reproduction path for the review findings: a single differing source is hidden by project.sources.count > 1, and source-only changes do not enter the menu readiness signature.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 15 files, +1288/-34. The diff spans scanner/cache, CLI payloads, menu UI, tests, and docs, so correctness and upgrade review cannot be limited to one layer.
  • Persistent cache version: Codex v8 -> v10. The PR changes the stored cache filename/schema, which makes upgrade behavior maintainer-visible before merge.
  • Public output surface: 1 CLI flag and project/source JSON fields added. The new --group-by project option and JSON fields expose normalized local project/source paths to users and integrations.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #1819
Summary: This PR is the candidate implementation for the open project-level Codex cost rollup feature request it closes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🧂 unranked krab
Patch quality: 🦪 silver shellfish
Result: blocked until real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Fix the source-row rendering and menu-refresh signature findings.
  • [P1] Add maintainer-visible proof or tests for the v8-to-v10 Codex cache upgrade behavior.
  • [P1] Add redacted terminal output or a short screenshot/recording showing the CLI and menu project rollups after the fix.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR body lists validation commands but no after-fix output or visual proof; the contributor should add redacted terminal output or a short menu/CLI recording or screenshot, then update the PR body so ClawSweeper can re-review.

Mantis proof suggestion
A real menu proof would materially help review because the PR changes visible cost-history submenu behavior and project/source row rendering. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis visual task: verify Codex cost history shows project rollups and source CWD rows with redacted paths.

Risk before merge

  • [P1] Real behavior proof is missing; the PR body lists commands and a smoke-test command but no redacted output, screenshot, recording, or log showing the after-fix behavior.
  • [P1] The feature exposes project and source filesystem paths in menu and CLI JSON output, so maintainers should approve the product/privacy contract before merge.
  • [P1] The Codex cost cache version changes from v8 to v10 and will ignore existing v8 cache files, so upgraded-user rebuild behavior needs proof or explicit maintainer acceptance.
  • [P1] Until the review findings are fixed, the menu can omit the only source CWD detail or keep stale source rows while a menu is open.

Maintainer options:

  1. Add upgrade proof before merge (recommended)
    Add a focused upgrade test or maintainer-visible proof that changing Codex cache v8 to v10 intentionally rebuilds or preserves user-visible totals without surprising upgraded users.
  2. Accept a one-time cache reset
    Maintainers can explicitly accept that existing Codex cache files are ignored and users may see a one-time rescan or missing derived rows if original logs are unavailable.
  3. Pause for product/privacy direction
    If exposing raw project/source paths is not yet approved, pause or narrow this PR until the reporting contract is decided.

Next step before merge

  • [P1] Human review is needed for product/privacy and cache-upgrade decisions, and the external contributor must add real behavior proof before merge.

Security
Cleared: No dependency, CI, secret, or network-surface change was found; local path exposure and cache upgrade remain product/privacy and compatibility review items.

Review findings

  • [P2] Show single differing source rows — Sources/CodexBar/CostHistoryChartMenuView.swift:241-245
  • [P2] Include project sources in refresh signatures — Sources/CodexBar/StatusItemController+MenuRefreshScheduling.swift:169-178
  • [P2] Prove the cache-version upgrade path — Sources/CodexBarCore/Vendored/CostUsage/CostUsageCache.swift:11
Review details

Best possible solution:

Land a narrow additive project-rollup implementation after maintainers approve path/privacy and cache-upgrade behavior, and after the branch preserves source details, refreshes source rows correctly, and includes real CLI/menu proof.

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

Yes, source inspection gives a high-confidence reproduction path for the review findings: a single differing source is hidden by project.sources.count > 1, and source-only changes do not enter the menu readiness signature.

Is this the best way to solve the issue?

No. The feature direction is plausible, but this implementation should first fix source-detail rendering and refresh invalidation, prove cache upgrade behavior, add real behavior proof, and get maintainer approval for path exposure.

Full review comments:

  • [P2] Show single differing source rows — Sources/CodexBar/CostHistoryChartMenuView.swift:241-245
    When a rollup has exactly one source whose path differs from the canonical project path, this condition hides the only source row. That drops the source CWD detail the feature promises to preserve for .codex/worktrees/... usage, so show sources when the sole source differs from project.path too.
    Confidence: 0.9
  • [P2] Include project sources in refresh signatures — Sources/CodexBar/StatusItemController+MenuRefreshScheduling.swift:169-178
    The open-menu readiness signature records only parent project fields. If the project total stays the same but source rows change, the signature is unchanged and the visible Projects section can stay stale; include source path/name/totals in this signature.
    Confidence: 0.88
  • [P2] Prove the cache-version upgrade path — Sources/CodexBarCore/Vendored/CostUsage/CostUsageCache.swift:11
    Changing Codex from codex-v8.json to codex-v10.json means upgraded users stop reading their existing cost cache and rely on a rebuild. Because this is a persisted cache schema change, add focused upgrade coverage or maintainer-visible proof that the one-time reset/rescan behavior is intentional and does not lose expected user-visible totals.
    Confidence: 0.74

Overall correctness: patch is incorrect
Overall confidence: 0.87

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 54003cfe5f43.

Label changes

Label changes:

  • add P3: This is a useful but non-urgent reporting feature with limited blast radius and no broken existing workflow.
  • add merge-risk: 🚨 compatibility: The PR changes the persisted Codex cost cache version and public CLI JSON/text surface, so upgraded-user and consumer behavior needs proof or maintainer acceptance.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists validation commands but no after-fix output or visual proof; the contributor should add redacted terminal output or a short menu/CLI recording or screenshot, then update the PR body so ClawSweeper can re-review.

Label justifications:

  • P3: This is a useful but non-urgent reporting feature with limited blast radius and no broken existing workflow.
  • merge-risk: 🚨 compatibility: The PR changes the persisted Codex cost cache version and public CLI JSON/text surface, so upgraded-user and consumer behavior needs proof or maintainer acceptance.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body lists validation commands but no after-fix output or visual proof; the contributor should add redacted terminal output or a short menu/CLI recording or screenshot, then update the PR body so ClawSweeper can re-review.
Evidence reviewed

What I checked:

  • Repository policy read: AGENTS.md was read fully; its guidance to prefer CLI/focused validation for provider/parser behavior and avoid unrequested live probes informed this read-only review. (AGENTS.md:1, 54003cfe5f43)
  • PR scope: The proposed commit changes 15 files with 1288 additions and 34 deletions across scanner/cache, CLI, menu UI, tests, and docs. (05481806da29)
  • Current main lacks the requested project rollup surface: A current-main search for the new project-rollup types, CLI text, and canonical project path fields returned no matches, so this PR is not redundant with main. (54003cfe5f43)
  • Single-source UI defect: The menu only renders source rows when project.sources.count > 1, so a project whose only source path differs from the canonical project path drops the source CWD detail the feature is meant to preserve. (Sources/CodexBar/CostHistoryChartMenuView.swift:241, 05481806da29)
  • Refresh signature omits source rows: The open-menu readiness signature includes only parent project name/path/totals and omits source path/name/totals, so source-only changes can leave visible rows stale. (Sources/CodexBar/StatusItemController+MenuRefreshScheduling.swift:169, 05481806da29)
  • Cache schema compatibility risk: The Codex cost cache artifact changes from codex-v8.json to codex-v10.json and adds persisted project path fields, which needs upgrade/rebuild proof before merge. (Sources/CodexBarCore/Vendored/CostUsage/CostUsageCache.swift:11, 05481806da29)

Likely related people:

  • steipete: Current blame for the cost scanner, fetcher, CLI cost command, and menu chart surfaces traces to the v0.37.3 development baseline, with additional row-identity cache work in the same scanner area. (role: baseline and adjacent owner; confidence: high; commits: ef8007fc16ce, 7cece2360ef1, ff53454201ed; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift, Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift, Sources/CodexBarCore/CostUsageFetcher.swift)
  • kiranmagic7: Recent merged work preserved Codex archived rows and fixed cached row refresh/dedupe behavior in the same scanner/cache row identity path this PR extends. (role: recent scanner/cache contributor; confidence: medium; commits: d648a9612920, d205e1a4a5fc, 0065ca42e6ab; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift, Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+CacheHelpers.swift)
  • Zihao Qi: Recent work changed stale today usage buckets adjacent to CostUsageTokenSnapshot and history-window semantics that this PR extends with project rollups. (role: recent cost snapshot contributor; confidence: medium; commits: 929d55aaf1d7; files: Sources/CodexBarCore/CostUsageModels.swift, Sources/CodexBarCore/CostUsageFetcher.swift)
  • dylanstieri: Recent Codex cost inflation work touched scanner aggregation after the release baseline, making this person relevant for cost-total correctness review. (role: recent scanner contributor; confidence: medium; commits: e71db5e47a07; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner.swift)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. labels Jul 1, 2026
@steipete

steipete commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Superseded and landed via #1884 at 1e49619.

The maintainer rewrite preserved contributor credit, rebased the feature onto current main, added project-name normalization and deterministic rollup coverage, and passed the full exact-head CI matrix plus built-app/CLI proof. I used a maintainer branch because the available OAuth authorization could not update the fork branch after upstream workflow changes.

Thanks @clemenspeters for the original project-rollup contribution!

@steipete steipete closed this Jul 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: project-level Codex token and cost rollups

2 participants