Skip to content

fix(cost): a sync shows on the Cost page at the next read - #2554

Open
Makisuo wants to merge 1 commit into
mainfrom
fix/cost-read-cache
Open

Makisuo wants to merge 1 commit into
mainfrom
fix/cost-read-cache

Conversation

@Makisuo

@Makisuo Makisuo commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What

After a cost source's first sync, the Cost page could keep showing a half-synced window for up to 15 minutes: the newest days were there, the month before was missing from the total, the filter rail and the table, while a slightly different window read correctly.

Cost reads are cached by their time range with the policy telemetry uses. That policy treats a window that ended more than 15 minutes ago as settled and holds its answer for 15 minutes, which is right for spans and wrong for cost: a sync writes past days. A source's history arrives in steps (the newest days first, older months after), so a read made between two steps was cached with part of the data and nothing changed its key.

The key now also carries when the org's cost sources were last written (the newest updated_at, which a sync stamps at every step). A sync step shows on the next read; between syncs the cache works as before.

How it was found

On the preview of #2541, with a real account: 13 minutes after the second sync step wrote October, the default window's total still covered November only. Other providers whose history arrives in steps are affected the same way on main.

Verification

  • New test in cost-reads.test.ts over a cache that keeps answers by key: the same window twice computes once; after a source's updated_at moves, it computes again. It fails with the fix removed.
  • cost-reads.test.ts (19) and registry/cost.test.ts (8) pass. Typecheck: query-engine, backend, api.
  • The compiled SQL is unchanged (the new field is not a query parameter), so the SQL baseline does not move.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

…the cached answer expires

Cost reads are cached by their time range with the policy telemetry uses, which holds a window that ended in the past for 15 minutes. A sync writes past days, so a read cached between two sync steps kept showing the half-synced window. The cached answer's key now carries when the org's sources were last written.
@maple-review-bot

maple-review-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Maple review

🟢 Confidence 10/10 · safe to merge. Cache-key-only field, verified to reach the real key, with a test that fails without it; no behavior outside cost reads changes.
no findings · tests covered · risk medium

Cost reads now key their cached warehouse answers on the org's newest cost_sources.updated_at, so a sync step stops hiding behind the settled-window cache. Contained to cost reads and safe to merge.

  • CostWindowPayload.written carries the newest source updated_at into the cache key only
  • windowOf computes written as the max over the org's sources
  • A new test proves the same window recomputes once a source moves

ffb4234 · What was checked, coverage and telemetry details are on the Maple / review check. Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.

@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d18c67d-8594-486d-8253-a78bd70c24c3
Commits

Reviewing files that changed from the base of the PR and between 55baa25 and ffb4234.

Files selected for processing: 5

  • docs/cloud-cost-plan.md
  • packages/backend/src/queries/cost-reads.test.ts
  • packages/backend/src/queries/cost-reads.ts
  • packages/query-engine/src/registry/cost.test.ts
  • packages/query-engine/src/registry/cost.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

This branch has not been deployed

No deployments
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.

1 participant