Skip to content

Feat: Add Codex tiered and priority pricing#917

Merged
steipete merged 7 commits into
steipete:mainfrom
iam-brain:iam-brain/codex-tiered-priority-pricing-clean
May 14, 2026
Merged

Feat: Add Codex tiered and priority pricing#917
steipete merged 7 commits into
steipete:mainfrom
iam-brain:iam-brain/codex-tiered-priority-pricing-clean

Conversation

@iam-brain
Copy link
Copy Markdown
Contributor

@iam-brain iam-brain commented May 11, 2026

Summary

  • add Codex priority trace enrichment from local appserver logs_2.sqlite without persisting websocket request bodies
  • apply Codex base pricing per rollout token row, then add priority/Fast surcharge only for matched priority rows at <=272,000 input tokens
  • long-context Codex pricing for any priority-marked row above the 272k input boundary
  • gate SQLite-backed trace scanning/tests on canImport(SQLite3), falling back to base pricing on platforms without SQLite3
  • bump the Codex cost cache artifact and cover priority parsing, privacy, missing-DB fallback, per-row pricing, cumulative-total, cached-input threshold, and long-context regressions

Validation

  • swift test --filter CostUsageScannerCodexPriorityTests passed: 5 tests
  • swift test --filter CostUsageScannerPriorityTests passed: 5 tests
  • swift test --filter CostUsagePricingTests passed: 23 tests
  • make check passed: 0 SwiftFormat/SwiftLint violations
  • earlier full focused suite passed: swift test --filter "CostUsagePricingTests|CostUsageScannerPriorityTests|CodexPriorityTraceScannerTests|CostUsageCacheTests|ModelsDevPricingTests" passed: 51 tests
  • swift build -c release --product CodexBarCLI passed
  • ./Scripts/compile_and_run.sh built the app target
  • validated against local ~/.codex/logs_2.sqlite and rollout JSONL with swift run CodexBarCLI cost --provider codex --format json --pretty --refresh

@iam-brain iam-brain force-pushed the iam-brain/codex-tiered-priority-pricing-clean branch from 6394cc9 to aa892b5 Compare May 11, 2026 20:48
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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: 6394cc9012

ℹ️ 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".

var forkedFromId: String?
var inheritedTotals: CostUsageCodexTotals?
var remainingInheritedTotals: CostUsageCodexTotals?
var currentTurnID: String?
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 Persist the Codex turn across incremental scans

When scanCodexFile resumes from a cached parsedBytes offset, parseCodexFile restores initialModel and initialTotals but this new currentTurnID always starts as nil. If CodexBar scans while a priority turn is still being appended, the cached prefix may already contain the task_started event and later token_count rows commonly rely on that state instead of repeating turn_id; those newly appended rows then get cached with turnID == nil, so codexPrioritySurchargeUSD never applies priority pricing for the rest of that turn until a full rescan.

Useful? React with 👍 / 👎.

@iam-brain iam-brain force-pushed the iam-brain/codex-tiered-priority-pricing-clean branch from f838e59 to 7188fe8 Compare May 12, 2026 02:49
@iam-brain iam-brain changed the title Add Codex tiered and priority pricing Feat: Add Codex tiered and priority pricing May 13, 2026
@steipete steipete force-pushed the iam-brain/codex-tiered-priority-pricing-clean branch from 7188fe8 to 70c6487 Compare May 14, 2026 07:53
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

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: 70c6487f85

ℹ️ 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".

Comment on lines +1145 to +1146
sinceDayKey: range.sinceKey,
untilDayKey: range.untilKey)
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 adjacent days when loading priority turn metadata

loadCodexDaily fetches priority turn metadata only for range.sinceKey...range.untilKey, but Codex token rows can land on a new day while still belonging to a turn that started just before midnight. In that cross-day case, rows for the report day keep the prior turn ID, but priorityTurns omits that turn, so Fast/Priority surcharge is silently skipped for those rows. This under-reports cost for overnight sessions and can be fixed by loading priority metadata over the scanner window (scanSinceKey/scanUntilKey) or another boundary-safe span.

Useful? React with 👍 / 👎.

@steipete steipete merged commit 2f6a31c into steipete:main May 14, 2026
4 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