Skip to content

fix(store): skip completed usage totals backfill - #665

Merged
Gajesh2007 merged 3 commits into
masterfrom
cursor/skip-usage-totals-backfill-e388
Aug 25, 2026
Merged

Gajesh2007 merged 3 commits into
masterfrom
cursor/skip-usage-totals-backfill-e388

Conversation

@Gajesh2007

@Gajesh2007 Gajesh2007 commented Aug 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Make the usage_totals backfill genuinely one-time and lossless under concurrent writes. Existing deployments adopt the already-populated counter without scanning usage; fresh databases use a durable two-phase cutoff so the historical scan runs without holding a writer-blocking table lock.

Linked issue

N/A

Before

flowchart LR
  subgraph Behavior
    B1[Coordinator startup] --> B2[Aggregate every usage row]
    B2 --> B3[Discover usage_totals conflict]
    B3 --> B4[Bind HTTP listener late]
  end
  subgraph Code
    C1[NewPostgres] --> C2[migrate statement loop]
    C2 --> C3[INSERT SELECT FROM usage ON CONFLICT]
  end
Loading

After

flowchart LR
  subgraph Behavior
    B1[Coordinator startup] --> B2{Applied marker or existing counter?}
    B2 -->|Yes| B3[Skip historical usage entirely]
    B2 -->|No| B4[Briefly fence inserts and persist max usage ID]
    B4 --> B5[Resume writers against zero counter]
    B5 --> B6[Aggregate only historical IDs]
    B6 --> B7[Atomically add baseline and mark complete]
    B3 --> B8[Continue startup]
    B7 --> B8
  end
  subgraph Code
    C1[NewPostgres] --> C2[migrateUsageTotals]
    C2 --> C3[prepareUsageTotalsMigration]
    C3 --> C4[usage_totals_backfill_state cutoff]
    C4 --> C5[finalizeUsageTotalsMigration]
    C5 --> C6[schema_migrations marker]
  end
Loading

Test plan

  • DATABASE_URL=... go test ./store -run 'Test(MigrateNoUngatedUsageTotalsAggregation|UsageTotalsMigration)' -count=10
  • DATABASE_URL=... go test ./store -count=1
  • go test -count=1 ./...
  • go vet ./store

Components touched

  • coordinator (Go)
  • provider (Rust, legacy)
  • provider-swift (Swift CLI)
  • console-ui (Next.js)
  • enclave (Swift)
  • infra / CI / release
  • docs

Protocol / interface changes

  • No protocol/interface changes
  • Yes — described above and matching side updated

Notes for reviewers

The old ON CONFLICT DO NOTHING was not a fast path: PostgreSQL evaluated the aggregate source before checking the destination conflict. The new checkpoint captures a stable ID cutoff while inserts are fenced only for a primary-key MAX(id), counter insert, and checkpoint insert. The full scan happens after writers resume; post-cutoff writes increment the live counter while finalization atomically adds only id <= cutoff. An interrupted process resumes from the checkpoint without double-counting.

Open in Web Open in Cursor 

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Co-authored-by: gajesh <gajesh@eigenlabs.org>
@vercel

vercel Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
d-inference Ready Ready Preview Aug 22, 2026 8:00am
d-inference-console-ui-dev Ready Ready Preview Aug 22, 2026 8:00am
d-inference-landing Ready Ready Preview Aug 22, 2026 8:00am

Request Review

Co-authored-by: gajesh <gajesh@eigenlabs.org>
Co-authored-by: gajesh <gajesh@eigenlabs.org>
@Gajesh2007
Gajesh2007 marked this pull request as ready for review August 25, 2026 05:41
@Gajesh2007
Gajesh2007 merged commit 9976baa into master Aug 25, 2026
15 of 17 checks passed
@Gajesh2007
Gajesh2007 deleted the cursor/skip-usage-totals-backfill-e388 branch August 25, 2026 05:45
Gajesh2007 added a commit that referenced this pull request Aug 25, 2026
Resolve the post-#665 branch update by retaining only the serialized checkpoint DDL fix and its regression coverage.

Co-authored-by: Cursor <cursoragent@cursor.com>
Gajesh2007 added a commit that referenced this pull request Aug 31, 2026
…60822

Brings the test-suite refactor up to date with the 22 commits master
gained since the last sync (#700-#790: Qwen3-VL and Qwen3.8 serving,
first-content deadline admission, MTP-in-the-weights, serial-number
privacy, MLX core 0.32.2, usage-checkpoint fixes).

Every master-side test added or modified inside files this branch
deletes, splits, or rewrites was re-homed into the refactor's successor
suites and lanes rather than dropped, including:

- PrefillDeadlineProductionConfigTests and the Qwen required-tool-choice
  tests into the slimmed EngineV2ProductionWiringTests
- bridgeDeadlineRefusalReleasesRealStaging into
  SSDPrefixCacheReservationTests
- excludesInferenceControls into WatchdogRecoveryTests
- the rewritten #777 MTP config/beta suites into ConfigTests and
  BetaFeaturesTests (MTPConfigTests stays deleted)
- vision/DeepStack/media additions into the split EngineV2Vision* and
  MediaIngest suites
- the #704 writeDeferred provider-writer tests, first-content-budget
  wire test, #730 serial-privacy subtests, and #752 benchmark-control
  tests into their branch successors

Master-added test files were audited against the lane architecture:
the Qwen3.8 production canary trio moved to Live/ (with a #filePath
depth fix), SchedulerPrefillDecision's real-weights suite split out to
Probes/ behind its per-probe gates, and hermetic additions stay in the
default lane. docs/developer/test.md updated to match.

Production-code unions of note: registry.go keeps both the branch's
PrivateOnly/catalog public-listing gates and master's per-model
capability gating; provider_writer.go carries both determinism-seam
families; LaunchAgent forwards the union of both env allowlists;
postgres_model_registry.go extends nil-canonicalization to master's new
required_provider_capabilities column. The branch-side prefill-keepalive
tests were dropped with the feature master removed in #704.

Two master-branch interaction defects fixed so the merged tree is green:
the store contract harness now re-seeds the usage_totals counter row its
truncate wipes (the #665 migration guard treats the bare marker as
corruption), and the #730 log-report migration test restores the pooled
connection's search_path before release.

Submodules: mlx-swift and mlx-swift-lm test branches merged with
master's 0.32.2-era pins; relocated suites verified present.

Verified: go vet + full coordinator/testbed tests green; store contracts
green twice consecutively against real Postgres 16; swift build
--build-tests clean; default Swift lane 2,264 tests in 248 suites all
passing.

This branch had an error being deployed

1 failed and 3 active deployments
Preview – d-inference-console-ui-dev — dc3af040 Deployed Aug 22, 2026 by vercel[bot]
Preview – d-inference — dc3af040 Deployed Aug 22, 2026 by vercel[bot]
Preview – d-inference-landing — dc3af040 Deployed Aug 22, 2026 by vercel[bot]
benchmarks — dc3af040 Deployed Aug 22, 2026 by cursor[bot] via E2E Benchmarks #174
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