Skip to content

fix(warp): scan aggregate usage cache files - #662

Merged
IvGolovach merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/warp-cache-cost-days-20260601
Jun 5, 2026
Merged

fix(warp): scan aggregate usage cache files#662
IvGolovach merged 1 commit into
junhoyeo:mainfrom
IvGolovach:codex/warp-cache-cost-days-20260601

Conversation

@IvGolovach

@IvGolovach IvGolovach commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Enable Warp's aggregate cache files to be discovered by the local scanner.
  • Count cost-only or message-only contribution days as active days in summary statistics.
  • Keep Warp out of default submit while still making local report/graph paths able to parse the cache when selected.

Why

Warp records aggregate usage in usage*.json cache files, but the scanner only understood the CSV variant of that pattern. As a result, Warp cache files could be declared in the client registry but still never be found. Warp rows can also carry spend and request counts without token totals, so the summary active-day calculation should treat those rows as activity instead of dropping them from the active-day denominator.

Diff scope

  • crates/tokscale-core/src/clients.rs: marks Warp as locally parseable while keeping submit_default: false.
  • crates/tokscale-core/src/scanner.rs: adds deterministic usage*.json matching for usage.json and per-account usage.<account>.json, excluding archive and backup files.
  • crates/tokscale-core/src/aggregator.rs: counts days with tokens, cost, or messages as active and adds regression coverage.

Branch integrity

  • Base branch: main
  • Validated base SHA: a86e688d620939d2c973c6d5625baa815ea223d7
  • Ahead/behind against fetched origin/main: 0 behind / 1 ahead
  • Merge base: a86e688d620939d2c973c6d5625baa815ea223d7
  • Diff proof was computed against the fetched base.

Commit integrity

  • Introduced commit: 31f3711 fix(warp): scan aggregate usage cache files
  • Final PR diff contains only the intended core scanner, client registry, and summary changes.
  • Ledger: not applicable — not required for selected validation mode/change family.
  • Version: not applicable — not required for selected validation mode/change family.

Diff hygiene

  • git diff --name-status origin/main...HEAD: M crates/tokscale-core/src/aggregator.rs, M crates/tokscale-core/src/clients.rs, M crates/tokscale-core/src/scanner.rs
  • git diff --check origin/main...HEAD: PASS, no output

Validation mode and proof

  • Validation mode: Mode 2 — narrow runtime change in core local scanning and summary aggregation.
  • cargo test -p tokscale-core test_warp_client_registered_as_aggregate_cache_source: PASS
  • cargo test -p tokscale-core test_scan_directory: PASS, 11 tests
  • cargo test -p tokscale-core test_calculate_summary: PASS, 5 tests
  • cargo test -p tokscale-core warp: PASS, 2 tests
  • cargo fmt --check: PASS
  • Full workspace suite not run locally because targeted core tests cover the changed scanner, client registry, parser, and summary behavior; remote PR CI should provide final full-suite proof after the PR is opened.

CI context confirmation

  • Pending — required GitHub Actions checks will run after the PR is created.
  • CI workflow context names unchanged.

Runtime safety

  • Reviewed changed runtime paths: client registry lookup, scan_directory, and calculate_summary.
  • No new blocking locks, unbounded queues, network calls, or cache writes were introduced.
  • No invariant regression introduced.

Migration notes

Not applicable — no DB migration changed.

Documentation integrity

Not applicable — no docs, commands, or user-facing CLI behavior changed.

Rollback plan

Rollback: revert this PR.
DB downgrade: not applicable.
Data repair: not applicable.
Operational caveats: none known.

Known residual risks

  • Remote CI has not run yet because the PR has not been opened.
  • This change intentionally makes Warp locally parseable but does not add Warp to default submit.

Summary by cubic

Enables local scanning of Warp aggregate cache files (usage*.json) and counts cost-only or message-only days as active in summary stats. Warp stays out of default submit, but local reports/graphs can read its cache.

  • Bug Fixes
    • Scanner now matches usage.json and usage.<account>.json, skipping archive/ and usage.backup*.
    • Warp is parse_local: true while keeping submit_default: false.
    • Summary counts a day as active if tokens, cost, or messages > 0 (with new regression test).

Written for commit 3be1542. Summary will update on new commits.

Review in cubic

@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 10:35pm

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.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/tokscale-core/src/aggregator.rs">

<violation number="1" location="crates/tokscale-core/src/aggregator.rs:964">
P2: Regression test for cost-only active days uses fixture with non-zero messages count, undermining regression protection for the cost-only branch.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/tokscale-core/src/aggregator.rs Outdated
totals: DailyTotals {
tokens: 0,
cost: 1.25,
messages: 3,

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.

P2: Regression test for cost-only active days uses fixture with non-zero messages count, undermining regression protection for the cost-only branch.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/tokscale-core/src/aggregator.rs, line 964:

<comment>Regression test for cost-only active days uses fixture with non-zero messages count, undermining regression protection for the cost-only branch.</comment>

<file context>
@@ -938,6 +941,53 @@ mod tests {
+                totals: DailyTotals {
+                    tokens: 0,
+                    cost: 1.25,
+                    messages: 3,
+                },
+                intensity: 0,
</file context>
Suggested change
messages: 3,
messages: 0,

Validation
* Validation tier: Tier 2R - post-review test-only correction for the cost-only active-day regression fixture.
* git diff --check: PASS
* git diff --cached --check: PASS
* cargo test -p tokscale-core test_calculate_summary_counts_cost_only_days_as_active: PASS
* cargo fmt --check: PASS
* Ledger: not applicable - not required for selected validation tier/change family.
* Version: not applicable - not required for selected validation tier/change family.
* Not run: full workspace test suite - not required locally for selected validation tier; targeted aggregation regression test covers this correction and remote CI is expected to run final PR gates.

Rollback
* git revert HEAD
@IvGolovach
IvGolovach force-pushed the codex/warp-cache-cost-days-20260601 branch from 31f3711 to 3be1542 Compare June 1, 2026 22:35
@IvGolovach
IvGolovach merged commit 63a44d7 into junhoyeo:main Jun 5, 2026
14 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