Skip to content

Fix token cost estimation for non-Anthropic models in Claude logs (#2393) - #2413

Open
Yuxin-Qiao wants to merge 2 commits into
steipete:mainfrom
Yuxin-Qiao:fix/claude-proxy-model-pricing-2393
Open

Fix token cost estimation for non-Anthropic models in Claude logs (#2393)#2413
Yuxin-Qiao wants to merge 2 commits into
steipete:mainfrom
Yuxin-Qiao:fix/claude-proxy-model-pricing-2393

Conversation

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor

Summary

Fixes #2393.

When users run non-Anthropic models (such as GPT-4o, GPT-5.4, or DeepSeek) inside Claude Code via proxies (like CLIProxyApi), Claude Code logs store assistant entries with model names like "gpt-5.4". CodexBar was previously hardcoding model pricing lookup to the anthropic provider for Claude Code logs, causing cost calculations to return nil ($0.00 / unpriced).

This PR:

  1. Adds ModelsDevCatalog.pricing(modelID:) to search across all catalog providers when provider ID is unknown or mismatched.
  2. Adds cross-provider fallback pricing in CostUsagePricing.claudeCostUSD and CostUsagePricing.codexCostUSD with recursion protection (allowFallback).
  3. Updates CodexParserHash.generated.swift.
  4. Adds test cases covering non-Anthropic model pricing in Claude Code logs.

Testing

  • swift test --filter CostUsagePricingTests (47/47 passed)
  • swift test --filter CostUsageScannerClaudeRegressionTests (13/13 passed)
  • make check (passed)

@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: 40c26b9f2d

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

inputTokens: totalPromptTokens,
cachedInputTokens: cacheReadInputTokens,
outputTokens: outputTokens,
cacheWriteInputTokens: 0,

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 Keep cache-write tokens in OpenAI fallback

When a Claude Code log row for a GPT/OpenAI model includes nonzero cache_creation_input_tokens (for example gpt-5.6, which has cache-write rates in the bundled Codex table), this fallback folds those tokens into totalPromptTokens but then passes cacheWriteInputTokens: 0. codexCostUSD therefore bills those cache writes as ordinary uncached input instead of the cache-write rate, so cost totals are wrong for those proxy logs. Pass cacheCreationInputTokens through as cacheWriteInputTokens rather than dropping it.

Useful? React with 👍 / 👎.

Comment thread .github/workflows/release-cli.yml Outdated

publish-release-assets:
runs-on: ubuntu-24.04
needs: build-cli

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 Publish assets before dispatching the tap update

In release-cli.yml release runs, publish-release-assets and update-homebrew-tap both only depend on build-cli, so after the matrix finishes they can run in parallel. Since the tap workflow is dispatched with an artifact_template that points at GitHub release assets, it can start resolving or publishing the formula before this new publisher job has completed gh release upload, causing the Homebrew update to fail or reference assets that are not available yet. Make the tap job depend on publish-release-assets (or keep uploading before dispatch).

Useful? React with 👍 / 👎.

@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: 6d22c2ea7f

ℹ️ 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 +776 to +779
if let lookup = self.modelsDevLookupAnyProvider(
model: key,
catalog: modelsDevCatalog,
cacheRoot: modelsDevCacheRoot)

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 fallback providers in the Pi pricing key

When this new any-provider fallback prices a Claude Pi-compatible row via models.dev for a Google or DeepSeek model, PiSessionCostScanner.pricingContext still fingerprints only anthropic and openai, while buildReport reuses complete cached costNanos without recomputing. After a models.dev price change for one of the providers added here, the Pi cache remains valid and continues showing stale costs for those rows; include every provider this fallback can read in the pricing key before caching those computed costs.

Useful? React with 👍 / 👎.

@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/claude-proxy-model-pricing-2393 branch from 6d22c2e to 3fce373 Compare July 23, 2026 14:39

@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: 3fce373039

ℹ️ 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 thread Sources/CodexBar/UsagePaceText.swift Outdated
Comment on lines +44 to +48
L("≈%d full 5h window of weekly left"),
1)
} else {
String.localizedStringWithFormat(
L("≈%d full 5h windows of weekly left"),

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 Preserve localized plural resources

By splitting the existing .stringsdict lookup into new standalone L(...) keys, these strings no longer match the localized plural entries, which are still keyed by the original combined sentence (and the verdict key has the same issue below). In any non-English locale this falls back to the English key text for the session-equivalent details instead of using the translated resources; keep formatting through the existing stringsdict key or add localized entries for every new key.

Useful? React with 👍 / 👎.

Comment on lines +606 to +609
if let lookup = self.modelsDevLookupAnyProvider(
model: model,
catalog: modelsDevCatalog,
cacheRoot: modelsDevCacheRoot)

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 Fingerprint every fallback provider before caching costs

This expands Codex-session pricing to models.dev providers beyond OpenAI, but the regular Codex daily cache is still keyed through CostUsageScanner.codexPricingKey, which fingerprints only OpenAI pricing. For a Codex history row priced via this fallback, such as a deepseek-r1 model, a later DeepSeek/Google/Anthropic models.dev price change will leave the cached costNanos valid and reports will continue showing the stale cost until users force-rescan or clear the cache; include all providers reachable from this fallback in the Codex pricing key or bump the cache formula.

Useful? React with 👍 / 👎.

@MoridinBG

Copy link
Copy Markdown

I built the latest version of the PR and the calculations might be off.

GPT 5.6 sol in Codex
image

GPT 5.6 sol in claude cli
image

The estimated token cost is way higher in Claude cli. It should also really be counted towards Codex usage, no Claude

@MoridinBG

Copy link
Copy Markdown

I tested with gpt-5.6-sol via CLIProxyAPI.

CLIProxyAPI correctly separates uncached input and cache-read tokens. However, Claude CLI writes multiple transcript rows for a single response—typically thinking, tool_use, and text—with the same message.id but no requestId.

CodexBar currently deduplicates only when both IDs exist. Without requestId, every row is counted and priced separately.

In my sample:

  • Current: 13,546 rows, 1.71B tokens, $4,565
  • Final row per file-local message.id: 3,688 responses, 494M tokens, $680
    ~500M is much closer to the expected token cost, considering the workload and the codex plan usage.

The final row often reclassifies interim uncached input as cache reads, so summing the rows inflates cost significantly.

Suggested fix: when requestId is missing, deduplicate by file-local message.id and keep the last row. Apply the same fallback during incremental cache merging.

Relevant code:

  • ID extraction: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:207-229
  • Current in-file deduplication: CostUsageScanner+Claude.swift:231-239
  • Incremental merge key: CostUsageScanner+Claude.swift:304-307

A regression test with interim and final rows sharing a message.id but lacking requestId should cover it.

@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. 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. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed July 30, 2026, 11:32 AM ET / 15:32 UTC.

ClawSweeper review

What this changes

The branch deduplicates Claude log rows that have only a message ID or request ID, and separately adds retry logic around Swift toolchain installation in CI.

Merge readiness

Blocked until real behavior proof from a real setup is added - 10 items remain

Keep this PR open: the new single-ID deduplication can correct file-local Claude log rows, but incremental refreshes still use different identity rules and can retain both cumulative snapshots, inflating token and cost totals. The branch also lacks after-fix real behavior proof; the available user report instead describes an incorrect built-PR result.

Priority: P2
Reviewed head: 818481e85172a84fa13276cfd5f00bb15c4fe54e

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The branch has a focused useful direction, but unresolved incremental/cache correctness defects and mock-only proof make it not merge-ready.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR supplies focused tests and checks but no redacted after-fix live scanner output; please add a real proxy-backed log or terminal proof showing corrected final-row deduplication and pricing, with private data redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) 3 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR supplies focused tests and checks but no redacted after-fix live scanner output; please add a real proxy-backed log or terminal proof showing corrected final-row deduplication and pricing, with private data redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Single-ID identity changes only the initial parse path: At the PR head, the changed scanner code falls back to a lone message ID or request ID for in-file deduplication. The supplied review discussion identifies that the incremental merge still uses the older two-ID-only key, so appended cumulative rows can both survive and be summed.
Existing user feedback reports inflated Claude-side cost totals: A commenter tested the earlier branch with CLIProxyAPI and reported duplicated transcript rows sharing a message ID without a request ID, with substantially inflated token and cost totals. Their proposed file-local final-row rule directly motivates the new code but does not prove the latest head fixes incremental refreshes.
The changed behavior has no cache migration evidence: Changing row identity does not by itself revisit unchanged JSONL files already represented in the Claude/Vertex cache. The review discussion identifies no producer-key, artifact-version, or equivalent invalidation adjustment in this two-file head.
Findings 3 actionable findings [P1] Use the same fallback key during incremental merges
[P2] Avoid treating an empty or reused lone ID as unique
[P2] Invalidate caches after changing row identity
Security None None.

How this fits together

CodexBar scans Claude Code JSONL transcripts, turns assistant usage rows into cached usage records, and then aggregates those records into menu-bar token and cost estimates. Row identity must stay consistent between an initial file scan, incremental cache merge, and cache invalidation so the displayed cost remains accurate.

flowchart LR
    A[Claude Code JSONL logs] --> B[Claude usage scanner]
    B --> C[Row identity and deduplication]
    C --> D[Incremental usage cache]
    D --> E[Cost aggregation]
    E --> F[CodexBar menu estimates]
    G[CI Swift installation] --> H[Build workflow]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR supplies focused tests and checks but no redacted after-fix live scanner output; please add a real proxy-backed log or terminal proof showing corrected final-row deduplication and pricing, with private data redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Use the same fallback key during incremental merges (P1) - The new parse-time fallback retains the final row for a stream with only one ID, but the incremental merge still recognizes rows only when both IDs exist. After an append refresh, the old cached cumulative row and the new cumulative row can both remain and be summed, recreating the inflated cost this change intends to fix.
  • Avoid treating an empty or reused lone ID as unique (P2) - This fallback accepts any present lone ID, including an empty-string placeholder, as a dictionary key. Proxy logs that omit one field this way can collapse unrelated rows into one retained entry; require a nonempty identity and cover reused-ID behavior before dropping rows.
  • Invalidate caches after changing row identity (P2) - Existing Claude/Vertex cache entries for unchanged JSONL files are not revisited by this changed in-file rule. Without a cache-version change or equivalent migration, affected users can keep seeing pre-upgrade overcounted totals until a manual full rescan.
  • Resolve merge risk (P1) - Incremental scans can continue double-counting a stream when only one identifier is present, because the new in-file key is not shared by the cached-row merge path.
  • Resolve merge risk (P1) - Existing cached Claude/Vertex rows may retain pre-upgrade overcounted totals until a full rescan if row-identity changes do not invalidate or migrate those caches.
  • Complete next step (P2) - A contributor must first supply real after-fix behavior proof, and the remaining correctness work spans parser identity, cache compatibility, and an unrelated workflow change rather than a safely autonomous one-file repair.
  • Improve patch quality - Use the same validated row key for in-file and incremental deduplication, with append-refresh regression coverage.
  • Improve patch quality - Add cache-version or migration coverage proving existing cached Claude/Vertex rows are recomputed after upgrade.
  • Improve patch quality - Post redacted real after-fix terminal output or a log-based demonstration; updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review.

Findings

  • [P1] Use the same fallback key during incremental merges — Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237-240
  • [P2] Avoid treating an empty or reused lone ID as unique — Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237-240
  • [P2] Invalidate caches after changing row identity — Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237-240
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Changed surface 2 files affected: 1 scanner, 1 workflow The PR combines a usage-accounting change with an unrelated CI retry change.
Patch size 23 added, 4 removed The small diff makes shared identity, cache compatibility, and real-runtime proof the decisive review concerns.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #2393
Summary: This PR is a candidate implementation for the open canonical report about model-aware cost estimation, while the older related PR was closed unmerged and is not a safe replacement.

Members:

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

Merge-risk options

  • The unrelated CI retry change broadens this pricing-focused PR and can alter workflow timing without corresponding workflow-specific proof.

Maintainer options:

  1. Unify scanner and incremental identities (recommended)
    Share one nonempty single-ID fallback key between initial parsing and incremental cache merging, then add an append/refresh regression before merging.
  2. Invalidate affected cached rows
    Bump or migrate the Claude/Vertex cache identity so unchanged existing logs are reprocessed under the new deduplication rule.
  3. Split the CI retry change
    Move the Swift installer retry loop into a separately justified workflow PR so scanner correctness and CI behavior can be reviewed independently.

Technical review

Best possible solution:

Use one validated, nonempty row-identity helper for both parsing and incremental merging, rotate or migrate affected cached Claude/Vertex rows, add focused regressions for those upgrade paths, and provide redacted after-fix output from a real proxy-backed Claude log before merge.

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

Yes, at source level: scan a Claude JSONL file with cumulative rows sharing only a nonempty message ID or request ID, cache it, append another cumulative row, then perform an incremental refresh. The initial scan and merge currently take different identity paths, giving a focused regression route.

Is this the best way to solve the issue?

No. The in-file fallback alone is not the narrowest correct fix because the incremental merge and existing cache state do not use the same identity contract; a shared helper plus cache compatibility coverage is safer.

Full review comments:

  • [P1] Use the same fallback key during incremental merges — Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237-240
    The new parse-time fallback retains the final row for a stream with only one ID, but the incremental merge still recognizes rows only when both IDs exist. After an append refresh, the old cached cumulative row and the new cumulative row can both remain and be summed, recreating the inflated cost this change intends to fix.
    Confidence: 0.96
  • [P2] Avoid treating an empty or reused lone ID as unique — Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237-240
    This fallback accepts any present lone ID, including an empty-string placeholder, as a dictionary key. Proxy logs that omit one field this way can collapse unrelated rows into one retained entry; require a nonempty identity and cover reused-ID behavior before dropping rows.
    Confidence: 0.82
  • [P2] Invalidate caches after changing row identity — Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237-240
    Existing Claude/Vertex cache entries for unchanged JSONL files are not revisited by this changed in-file rule. Without a cache-version change or equivalent migration, affected users can keep seeing pre-upgrade overcounted totals until a manual full rescan.
    Confidence: 0.91

Overall correctness: patch is incorrect
Overall confidence: 0.93

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8ef86077e70a.

Labels

Label justifications:

  • P2: Incorrect token-cost estimates are a normal-priority usage-accounting defect with a bounded but user-visible blast radius.
  • merge-risk: 🚨 compatibility: Existing cached Claude/Vertex results can remain based on the prior row-identity rule after users upgrade.
  • merge-risk: 🚨 automation: The branch changes CI Swift-install retry behavior independently of the scanner fix.
  • merge-risk: 🚨 other: A mismatch between initial and incremental deduplication can continue overstating displayed usage and monetary estimates.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; 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 supplies focused tests and checks but no redacted after-fix live scanner output; please add a real proxy-backed log or terminal proof showing corrected final-row deduplication and pricing, with private data redacted. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Single-ID identity changes only the initial parse path: At the PR head, the changed scanner code falls back to a lone message ID or request ID for in-file deduplication. The supplied review discussion identifies that the incremental merge still uses the older two-ID-only key, so appended cumulative rows can both survive and be summed. (Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237, 818481e85172)
  • Existing user feedback reports inflated Claude-side cost totals: A commenter tested the earlier branch with CLIProxyAPI and reported duplicated transcript rows sharing a message ID without a request ID, with substantially inflated token and cost totals. Their proposed file-local final-row rule directly motivates the new code but does not prove the latest head fixes incremental refreshes. (Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:231, 818481e85172)
  • The changed behavior has no cache migration evidence: Changing row identity does not by itself revisit unchanged JSONL files already represented in the Claude/Vertex cache. The review discussion identifies no producer-key, artifact-version, or equivalent invalidation adjustment in this two-file head. (Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift:237, 818481e85172)
  • Real behavior proof remains mock-only: The PR body reports focused unit tests and make check, but no redacted post-fix live output, log fixture result, or recording. The supplied screenshot/report is evidence of an incorrect prior built result rather than proof of the latest behavior. (818481e85172)
  • Repository policy was applied: The full repository AGENTS.md requires focused parser coverage, make check after code changes, and avoiding provider-data mixing; this review applies its preference for stable scanner/model seams and real behavior evidence without invoking live account probes. (AGENTS.md:1, 8ef86077e70a)

Likely related people:

  • steipete: The supplied context establishes steipete as the repository owner; no usable feature-history output was available in the review materials to identify a more specific current-main scanner owner. (role: repository owner and likely area router; confidence: low; files: Sources/CodexBarCore/Vendored/CostUsage/CostUsageScanner+Claude.swift, .github/workflows/ci.yml)

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 (1 earlier review cycle)
  • reviewed 2026-07-30T11:30:23.709Z sha 3fce373 :: needs real behavior proof before merge. :: [P2] Order the tap update after asset publication | [P2] Preserve cache-write pricing in the Claude-to-Codex fallback

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@Yuxin-Qiao

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 30, 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@Yuxin-Qiao
Yuxin-Qiao force-pushed the fix/claude-proxy-model-pricing-2393 branch from 9d93fe0 to 90bf63f Compare July 30, 2026 15:25

@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: 90bf63f306

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

if let messageId, let requestId {
return "\(messageId):\(requestId)"
}
return messageId ?? requestId

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply single-ID deduplication when merging increments

When a stream with only messageId or requestId appends after its file has already been cached, this parser deduplicates the newly read chunk by that lone ID, but mergeClaudeRows still calls claudeInFileKey, which returns a key only when both IDs exist. The cached cumulative snapshot and the appended cumulative snapshot therefore both survive and are summed, inflating tokens and cost during normal incremental refreshes; use the same single-ID key semantics in the merge path.

Useful? React with 👍 / 👎.

if let messageId, let requestId {
return "\(messageId):\(requestId)"
}
return messageId ?? requestId

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 Preserve distinct rows when a lone identifier is reused

When a proxy omits one identifier and reuses the other—especially when it writes an empty-string placeholder—this turns every such row into the same dictionary entry and retains only the last one. The existing claude counts different request ids separately test already establishes that a message ID alone is not sufficient to distinguish requests, so logs with that request field omitted will now undercount unrelated assistant calls; validate that a lone ID is nonempty and uniquely identifies a stream before using it as a deduplication key.

Useful? React with 👍 / 👎.

Comment on lines +234 to +238
let key: String? = {
if let messageId, let requestId {
return "\(messageId):\(requestId)"
}
return messageId ?? requestId

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 Invalidate Claude caches after changing row identity

For users upgrading with affected rows already stored in the Claude/Vertex v6 cache, unchanged JSONL files are skipped by processClaudeFile, and these providers have neither a producer key nor an artifact-version change to invalidate their cached rows. Consequently the new deduplication behavior is not applied to existing logs until a force/full rescan happens, leaving previously overcounted usage visible after the upgrade; rotate the Claude/Vertex cache version or add an equivalent migration trigger.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. and removed proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 automation 🚨 Merging this PR could break CI, automerge, proof capture, label sync, or automation. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Token cost estimate is tied only to the harness, not to the model.

2 participants