Skip to content

fix(claude): preserve cc-mirror tool result attribution - #659

Merged
IvGolovach merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/cc-mirror-variants-20260601
Jun 4, 2026
Merged

fix(claude): preserve cc-mirror tool result attribution#659
IvGolovach merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/cc-mirror-variants-20260601

Conversation

@IvGolovach

@IvGolovach IvGolovach commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Preserve cc-mirror variant client attribution for Claude tool_result usage rows.
  • Carry the cc-mirror variant provider fallback into tool-result parsing, so pricing and diagnostics stay provider-aware.
  • Add regression coverage for cc-mirror tool-result records using a variant client id and non-Anthropic provider.

Why

Tokscale can discover cc-mirror Claude-compatible variants, but Claude tool_result usage rows had a separate parsing path that could fall back to plain claude attribution. That makes variant-scoped usage harder to understand and can lose the provider context needed for accurate pricing when a cc-mirror variant points at a non-Anthropic backend.

Related issue: #610.

Diff scope

  • crates/tokscale-core/src/sessions/claudecode.rs: threads the active client and provider context through Claude tool-result usage parsing.
  • crates/tokscale-core/src/sessions/claudecode.rs: adds a regression fixture proving a cc-mirror variant keeps cc-mirror/<variant> client attribution and the variant provider fallback on tool-result usage.

Branch integrity

  • Base branch: main.
  • Validated base SHA: a86e688d620939d2c973c6d5625baa815ea223d7.
  • Ahead/behind: 0 behind / 1 ahead against origin/main.
  • Merge base: a86e688d620939d2c973c6d5625baa815ea223d7.
  • Fast-forward safety: origin/main is an ancestor of this branch.

Commit integrity

  • Introduced commit: 75b321952d6858d8551be8794426c0829f3c333f fix(claude): preserve cc-mirror tool result attribution.
  • The PR contains one logical change scoped to Claude parser attribution for cc-mirror tool-result usage.
  • Ledger: not applicable — not required for this change family.
  • Version: PASS, scripts/check-version-coherence.sh.

Diff hygiene

  • git diff --name-status origin/main...HEAD: only crates/tokscale-core/src/sessions/claudecode.rs changed.
  • git diff --check origin/main...HEAD: PASS, no output.

Validation mode and proof

Mode 2 — narrow runtime change, because the diff changes localized Claude parser attribution behavior and focused tests without touching migrations, auth, deployment tooling, or external service contracts.

  • TDD red proof: cargo test -p tokscale-core sessions::claudecode::tests::test_cc_mirror_tool_result_keeps_variant_client_and_provider failed before the implementation with plain claude attribution instead of the cc-mirror variant client.
  • cargo test -p tokscale-core sessions::claudecode::tests::test_cc_mirror_tool_result_keeps_variant_client_and_provider: PASS.
  • cargo test -p tokscale-core sessions::claudecode: PASS.
  • cargo test -p tokscale-core cc_mirror: PASS, 9 tests.
  • cargo fmt --all -- --check: PASS, no output.
  • scripts/check-version-coherence.sh: PASS, Version coherence OK: 3.0.0.
  • git diff --check origin/main...HEAD: PASS, no output.
  • Not run: frontend validation tests — frontend files were not touched.

Required remote gates

Pending — GitHub Actions and mergeability checks will run after the PR is opened.

Migration notes

Not applicable — no database migration changed.

Runtime safety

The change only passes existing parser context into an existing Claude usage branch. It does not add external I/O, persistent state, concurrency, or new scan paths. No invariant regression introduced.

Documentation integrity

Not applicable — no docs, commands, or runbooks changed.

Rollback plan

Rollback: revert this PR. DB downgrade: not applicable. Data repair: not applicable. Operational caveats: reverting would restore plain Claude attribution for cc-mirror tool-result usage rows.

Known residual risks

Remote CI and GitHub mergeability are pending until the PR is opened. This PR is intentionally scoped to preserving attribution for cc-mirror tool-result rows; it does not expand cc-mirror discovery beyond the support already present on main.


Summary by cubic

Preserves cc-mirror/<variant> client and provider attribution when parsing Claude tool_result rows. This keeps pricing and diagnostics provider-aware, including for non-Anthropic backends.

  • Bug Fixes
    • Threaded client_id and provider hints through Claude tool-result parsing.
    • Used the variant client in message metadata and dedup keys.
    • Added a regression test to validate variant client and provider are retained.

Written for commit 75b3219. Summary will update on new commits.

Review in cubic

Validation
* Validation tier: Tier 2 — Narrow Runtime Change, localized Claude parser attribution correction.
* TDD red: cargo test -p tokscale-core sessions::claudecode::tests::test_cc_mirror_tool_result_keeps_variant_client_and_provider: FAIL before implementation, expected client attribution mismatch.
* cargo test -p tokscale-core sessions::claudecode::tests::test_cc_mirror_tool_result_keeps_variant_client_and_provider: PASS
* cargo test -p tokscale-core sessions::claudecode: PASS
* cargo test -p tokscale-core cc_mirror: PASS
* cargo fmt --check: PASS
* git diff --check: PASS
* git diff --cached --check: PASS
* scripts/check-version-coherence.sh: PASS
* Ledger: not applicable — not required for selected validation tier/change family.
* Version: PASS, scripts/check-version-coherence.sh.
* Not run: frontend validation tests — frontend files were not touched.

Rollback
* git revert HEAD
@vercel

vercel Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
tokscale Ignored Ignored Preview Jun 1, 2026 6:28am

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

@IvGolovach
IvGolovach merged commit 7500b30 into junhoyeo:main Jun 4, 2026
15 checks passed
@IvGolovach
IvGolovach deleted the codex/cc-mirror-variants-20260601 branch June 4, 2026 22:49
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