Skip to content

feat(pi): retain token history for unsupported backends - #4628

Merged
steipete merged 2 commits into
mainfrom
triage/20260921-bugs-37b-4605
Oct 19, 2026
Merged

steipete merged 2 commits into
mainfrom
triage/20260921-bugs-37b-4605

Conversation

@steipete

Copy link
Copy Markdown
Owner

Summary

Retain valid timestamped assistant usage from unsupported Pi/OMP backends as unpriced tokens in standalone Pi history. Keep backend/model labels and incremental model context in the existing cache. These rows never enter native Claude/Codex history or borrow another provider's pricing.

Malformed or undated usage still leaves standalone history incomplete without poisoning native partitions. Bump the pricing-semantics revision once so previously ignored rows are rescanned; no new storage or settings.

Verification

The main baseline failed the unsupported-backend totals and cached model-context regressions. Both pass in the combined candidate, together with malformed/undated usage and native-partition isolation checks.

Local proof used a combined lane candidate; this PR is the independently split change, and exact-head PR CI is the broad gate. All data was synthetic. No running app, real account, Keychain, or browser-cookie probe was used.

  • Native macOS focused command: swift test --build-system native --jobs 2 -Xswiftc -gnone --filter 'CostUsageClaude(ArtifactWriter|CacheIsolation|Fragment|KimiAlias|MetadataParsing|Overflow|PriceRange|PricingRace|Rebuild|ReconciliationMemory|ReportContext|ReportWire|Resolver|RowCapacity|RowStorage|VertexClassifier|VertexPrecheck|WriteAmplification)Tests|CostUsageScanner(Claude.*)?Tests|PiSession.*Tests|PiBedrockPricingTests|PiNativeProjectionTests|PiInclusiveRefreshTests|PiSharedRootMergeTests|PiProviderTests|PiProjectOverflowTests|UsageStorePiHistoryScopeTests|OpenCodeGo.*Tests|CLICost.*Tests|CLICommonOptionsTests|CLIProviderSelectionTests|CostReportingPeriodTests|ProviderArchitectureGatekeeperTests|ProviderSettingsDescriptorTests|BrowserCookiePromptContractTests|SettingsStoreTokenCostSourceTests|SettingsStoreCoverageTests|SettingsStoreAdditionalTests|SpendDashboardModelTests', under the shared serial.sh lock with Scripts/test_environment.sh.
  • The combined selection ran 816 tests in 79 suites: 815 passed and one architecture-anchor check failed. The exact-line anchor was corrected, then the affected CLI/OpenCode/gate suites were rerun with --filter 'CLICost.*Tests|ProviderArchitectureGatekeeperTests|CLIProviderSelectionTests|CLICommonOptionsTests|OpenCodeGoLocalUsageReaderTests': ✔ Test run with 144 tests in 9 suites passed after 21.085 seconds..
  • After the Pi cleanup and OpenCode Go review corrections: swift test --build-system native --jobs 2 -Xswiftc -gnone --filter 'CostUsageScannerClaudeDesktopTests|CostUsageClaudeReportContextTests|CostUsageScannerClaudeMemoTests|CostUsageScannerClaudeRegressionTests|CostUsageClaudeCacheIsolationTests|PiSession.*Tests|PiBedrockPricingTests|PiNativeProjectionTests|PiInclusiveRefreshTests|PiSharedRootMergeTests|PiProviderTests|PiProjectOverflowTests|UsageStorePiHistoryScopeTests|ProviderArchitectureGatekeeperTests|CLICost.*Tests|CLIProviderSelectionTests|CLICommonOptionsTests|OpenCodeGo.*Tests|ProviderSettingsDescriptorTests|BrowserCookiePromptContractTests|CostUsageClaudeFragmentTests': ✔ Test run with 573 tests in 53 suites passed after 43.853 seconds..
  • make check: passed.
  • python3 /Users/steipete/Projects/CodexBar-triage-evidence/20260921/precheck-catalogs.py .: no findings before push.
  • Independent Codex autoreview through P2: no accepted/actionable findings in the final candidate.
  • Production delta: 2 files changed, 64 insertions(+), 62 deletions(-) (net +2); Tests: 2 files changed, 64 insertions(+), 8 deletions(-).

Fixes #4605

@clawsweeper

clawsweeper Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T06:20:14.151125Z 9095541 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 8467a1a720

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

(fallback?.isUnsupportedBackend == true ? fallback?.providerRawValue : nil),
self.mappedProvider(fromPiProvider: backend) == nil
{
let model = explicitModelText ?? (fallback?.providerRawValue == backend ? fallback?.modelName : nil)

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 Normalize unsupported backend IDs before matching context

When an unsupported backend is repeated with different casing between a model_change record and an assistant message (for example, OpenRouter followed by openrouter) and the message omits its model, this exact comparison refuses to reuse the otherwise matching model context. The row is then treated as incomplete and its valid tokens are discarded, even though provider classification elsewhere is case-insensitive; normalize both backend IDs before comparing them.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 19, 2026
@clawsweeper

clawsweeper Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codex review: blocked before merge.

What this changes

Retain valid unsupported-backend Pi/OMP usage as unpriced standalone Pi history.

Example: A timestamped OpenRouter assistant row records 30 input tokens using gpt-5.4.

  • Before: The 30 tokens are omitted and standalone Pi coverage remains incomplete.
  • After: Pi includes 30 unpriced tokens labeled openrouter/gpt-5.4, without adding them to native Claude or Codex history.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, narrowly scoped work with meaningful scanner coverage, a confirmed context-matching defect, and an uncleared cache-upgrade gate.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Standalone Pi history omits valid recorded tokens from unsupported Pi/OMP backends.
Reason: The report demonstrates meaningful missing history, and owner authorship approves changing the previously documented exclusion while retaining provider isolation.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this owner-authored PR open: the feature is useful and approved in direction, but backend-context matching still drops valid tokens when casing differs.

Priority: P2
Reviewed head: 8467a1a720ce2a7b1685cee64a83d6fb99a8c3af

Before merge

  • Match unsupported backend context consistently across casing (P2) - A model_change with provider OpenRouter and modelId gpt-5.4 followed by a timestamped assistant message with provider openrouter, no model, and usage {input: 10, output: 1} fails this exact comparison. The resolver returns nil, so all 11 valid tokens are omitted and standalone coverage remains incomplete, although backend classification elsewhere is case-insensitive. Normalize backend identity consistently before matching and cover both direct parsing and cached-context append. This confirms the existing discussion finding at feat(pi): retain token history for unsupported backends #4628 (comment).
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P2] Match unsupported backend context consistently across casing — Sources/CodexBarCore/PiSessionCostScanner.swift:1086

Tests

  • Missing end-to-end proof: No v0.77.0-to-head upgrade run shows previously ignored backend rows becoming unpriced history while preserving existing settings and native totals; supplied red/green results concern a combined candidate.
Agent review details

How this fits together

The Pi scanner reads local Pi/OMP JSONL transcripts, resolves assistant identity and usage, persists a shared scan cache, and produces standalone Pi and native-provider report partitions.

flowchart TD
  A[Pi and OMP transcripts] --> B[Assistant identity and usage parser]
  B --> C[Pi scan cache]
  C --> D[Standalone Pi report]
  C --> E[Native Claude and Codex partitions]
  D --> F[CLI dashboards and widgets]
  E --> F
Loading

Technical review

Best possible solution:

Use consistent backend identity matching within the existing resolver while preserving standalone-only unpriced accounting and native-provider isolation.

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

Current-main source and its existing reliability fixture establish the omission; source inspection also confirms the remaining mixed-case context failure, without executing target code.

Is this the best way to solve the issue?

The standalone-only fallback is a focused extension of existing unpriced accounting, with no competing scanner or new setting.

Full review comments:

  • [P2] Match unsupported backend context consistently across casing — Sources/CodexBarCore/PiSessionCostScanner.swift:1086
    A model_change with provider OpenRouter and modelId gpt-5.4 followed by a timestamped assistant message with provider openrouter, no model, and usage {input: 10, output: 1} fails this exact comparison. The resolver returns nil, so all 11 valid tokens are omitted and standalone coverage remains incomplete, although backend classification elsewhere is case-insensitive. Normalize backend identity consistently before matching and cover both direct parsing and cached-context append. This confirms the existing discussion finding at feat(pi): retain token history for unsupported backends #4628 (comment).
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7e31e74ea662.

Provenance checked

  • Unsupported-backend exclusion and incomplete coverage changes intended behavior with a stated reason (81c8a1c: Standalone Pi originally retained supported-backend estimates and unknown-model tokens while treating unsupported backends as incomplete coverage.)
  • Standalone partition and shared identity/pricing handling keeps the original intent (e069bff: Bedrock usage needed exact backend-specific pricing and exclusion from native Claude/Codex mirrors.)
  • Pi cache formula invalidation keeps the original intent (26ee8be: Changed token-pricing semantics require reparsing existing cached contributions without changing the artifact schema.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • swift test --filter PiSessionCostReliabilityTests
  • swift test --filter PiSessionCostScannerTests
  • swift test --filter PiSessionCostCompatibilityTests
  • swift test --filter PiBedrockPricingTests
  • swift test --filter ProviderArchitectureGatekeeperTests

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e069bff adds Sources/CodexBarCore/PiSessionCostScanner.swift:1254 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e069bff233c1; files: Sources/CodexBarCore/PiSessionCostScanner.swift)
  • Yuxin Qiao: Raw commit 81c8a1c adds Sources/CodexBarCore/PiSessionCostScanner+Aggregation.swift:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 81c8a1cbf9bb; files: Sources/CodexBarCore/PiSessionCostScanner+Aggregation.swift)

Review metrics

Metric Value Why it matters
Production and test delta Production +64/-62; tests +64/-8 The feature extends existing parsing and accounting owners with net two production lines; added coverage exercises retention, malformed usage, cached context, and isolation.

Labels

Label changes:

  • add P2: This improves an optional local-history workflow with substantial omitted tokens, without blocking core app use.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This improves an optional local-history workflow with substantial omitted tokens, without blocking core app use.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 19, 2026, 12:15 AM ET / 04:15 UTC.

steipete added a commit that referenced this pull request Oct 19, 2026
@steipete
steipete merged commit 6b4765d into main Oct 19, 2026
3 checks passed
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. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pi/OMP: retain token-only history for unsupported backends

1 participant