Skip to content

fix(cost): show a new cost source at once and sync it within minutes - #2522

Merged
Makisuo merged 1 commit into
mainfrom
fix/cost-first-sync
Nov 12, 2026
Merged

Makisuo merged 1 commit into
mainfrom
fix/cost-first-sync

Conversation

@Makisuo

@Makisuo Makisuo commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Problem

After turning on AWS Cost for a connected account, the Cost page stayed on the "No cost source yet / Connect AWS" on-ramp, which reads as broken. Two causes:

  1. The cost_sources row was only created by the hourly cost_sync tick, so until then the page had no source and fell back to the on-ramp instead of the "Waiting for the first sync" state it already has.
  2. The first pull then waited for the same hourly tick, so the wait could be up to an hour.

Seen in prod: Cost turned on at 00:16 UTC, check passed at 00:21, previous tick at 00:00, next at 01:00.

Change

  • Reconcile on write. The AWS reconcile in CostSyncService (create a source for a connection that supplies cost, turn it off when cost is no longer supplied, remove it when the connection is deleted) moves to services/cost/aws-cost-sources.ts, a MapleDb helper with an optional org scope. AwsConnectionService runs it for its own org inside the same transaction as a module change, a check (which is where a grant shows up), and a delete. The sync lane still runs it unscoped every tick.
  • Faster cadence. cost_sync moves from 0 * * * * to 2-59/5 * * * *, next to vercel (that fire had five free lane slots). A tick with nothing due costs a reconcile and a due-query. Heads are still pulled once a day, and the monthly request budgets are unchanged. History backfills faster but within the same budget. MAX_SOURCES_PER_TICK drops from 20 to 6 to fit the 270s deadline (about 1 minute per claim, 2 at a time). The lease (20 min) still outlives the deadline.
  • Copy: "The first sync runs within a few minutes." The plan doc is updated.

The rollout hold stays at 50 minutes. It only matters for an org whose cloudCost flag is withdrawn.

Verification

  • New AwsConnectionService test replays the flow: Cost asked for but not granted (no source), setup re-run and checked (source enabled), turned off (disabled, kept), turned back on (enabled), connection deleted (source gone).
  • CostSyncService, AwsConnectionService, alerting scheduled/tick-dispatch, and the cost page scene tests pass.
  • tsc clean for packages/backend, apps/alerting, apps/api. oxlint -c .oxlintrc.effect.json clean on changed files.

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

Turning on AWS Cost left the Cost page on the "No cost source yet" on-ramp
until the hourly cost_sync tick created the source, then waited for that
same tick to pull anything.

- The AWS cost source reconcile moves to a shared helper that the AWS
  connection runs for its own org in the same write as a module change, a
  check (which can grant or lose cost) and a delete. The page shows
  "Waiting for the first sync" as soon as the grant is seen.
- cost_sync moves from the hourly fire to the 2-59/5 fire. A tick with
  nothing due is a few queries; heads are still pulled once a day and the
  monthly request budgets are unchanged. Sources per tick drop to 6 to fit
  the 270-second deadline.
@coderabbitai

coderabbitai Bot commented Nov 12, 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 29 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: 3a1eb2ee-6ab1-4a44-88c1-58c792f262ad
Commits

Reviewing files that changed from the base of the PR and between 7bddd6f and 51ad96d.

Files selected for processing: 8

  • apps/alerting/src/schedule.ts
  • apps/web/src/page/cost/cost.scene.test.ts
  • apps/web/src/page/cost/view.ts
  • docs/cloud-cost-plan.md
  • packages/backend/src/services/cost/CostSyncService.ts
  • packages/backend/src/services/cost/aws-cost-sources.ts
  • packages/backend/src/services/integrations/AwsConnectionService.test.ts
  • packages/backend/src/services/integrations/AwsConnectionService.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

@maple-review-bot

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

Copy link
Copy Markdown

Maple review

🟢 Confidence 10/10 · safe to merge. The moved reconcile is behaviour-preserving and the new call sites are org-scoped; only the untested 6-claims-in-270s tuning of the faster lane needs watching after deploy.
no findings · tests covered · risk medium · 2/2 new units observable

Moves the AWS cost-source reconcile into a shared MapleDb helper and runs it from the AWS connection's write, check and delete, so a new cost source shows immediately; cost_sync moves to the 5-minute lane. The extraction is faithful and the new call sites are org-scoped.

  • AwsConnectionService reconciles cost sources on module change, check and delete, in the same transaction
  • AWS reconcile moves to cost/aws-cost-sources.ts with an optional org scope
  • cost_sync moves to the 5-minute lane with 6 sources per tick
  • Cost page copy promises the first sync within minutes

Before merge

  • Manual · Watch the first cost_sync window after deploy: 6 claims of up to 3 steps must finish inside the 270-second lane or claims get interrupted

51ad96d · 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.

@Makisuo
Makisuo merged commit 4a0ddd7 into main Nov 12, 2026
37 checks passed
@Makisuo
Makisuo deleted the fix/cost-first-sync branch November 12, 2026 00:55
@maple-review-bot

Copy link
Copy Markdown

Merged with 1 step from "Before merge" still open. If it is done, tick it on the review comment; if not, now is the time.

  • Manual · Watch the first cost_sync window after deploy: 6 claims of up to 3 steps must finish inside the 270-second lane or claims get interrupted

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