Skip to content

fix(state): skip DuckDB import UI after cutover and drop leftover sources - #1191

Merged
frahlg merged 1 commit into
masterfrom
feat/retire-legacy-history
Sep 9, 2026
Merged

frahlg merged 1 commit into
masterfrom
feat/retire-legacy-history

Conversation

@frahlg

@frahlg frahlg commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Summary

After a verified DuckDB history import, later boots no longer start an import or show Preparing FTW / Importing older history. Core drops the leftover SQLite history tables and imported Parquet files so DuckDB owns history and SQLite owns configuration.

This is the cutover that was missing on beta-to-beta updates: OpenWithBackgroundHistory always created a migration with history_complete=false and re-hashed every Parquet receipt, so a box that had already finished the first DuckDB hop still showed the import UI for ~30s.

  • Skip the background importer when sqlite-v1 is present, nothing is pending, the DuckDB generation is bound, and every on-disk Parquet file already has a receipt.
  • After that verified state, drop the SQLite history/sample/ledger tables, delete imported sample Parquet files, and skip recreating those tables on later boots.
  • Failed and interrupted imports keep the original sources.
  • Full backups still export portable SQLite history so restore and older Core can read it. Image-only downgrade stays refused.
  • Planner diagnostics stay in SQLite and cold/diagnostics/.

Fixes #1143.

Test plan

  • go test ./internal/state/ — including first import, failed import (sources kept), later boot with no incomplete progress, offline OpenWithLegacyHistory retire, and portable backup restore after retire
  • go test ./internal/backup/ ./internal/api/
  • CI go test + vet
  • Physical box: next beta should not show the DuckDB import UI; leftover ts_samples / cold sample Parquet should go away after start

Update flows

Flow Behaviour
First DuckDB hop Import UI, keep sources until verify, then drop
Interrupted / failed import Keep originals, resume with UI
Already-migrated beta → beta No import UI; drop leftovers; VACUUM on that boot
Later restart No import UI; history tables not recreated
Full backup / restore Portable SQLite export; restore re-imports then retires
Image-only downgrade Still refused (schema 3)

Note

Medium Risk
Irreversible deletion of SQLite history tables and imported Parquet after verified migration; incorrect idle detection could retire sources early or skip needed imports.

Overview
Fixes the post–DuckDB cutover experience on already-migrated boxes: OpenWithBackgroundHistory now treats history as idle when SQLite/Parquet import is fully verified (sqlite-v1, no pending imports, bound generation, every cold Parquet file has a receipt). In that case it does not start the background importer or flash incomplete import UI; it reports complete and may retireLegacyHistorySources on that boot.

Adds retireLegacyHistorySources: after a verified import, drops leftover SQLite history/sample/energy tables, deletes imported sample Parquet (not cold/diagnostics/), records history_legacy_sources_retired, and stops recreating those tables on later Open migrations. Failed or interrupted imports leave sources untouched.

Full backups still materialize portable SQLite history via ensureSqliteLegacyHistory in exportHistoryToSQLite even when live SQLite no longer holds those tables. Migration progress timing moves so “starting/seed” only appears when table seeding actually runs.

Reviewed by Cursor Bugbot for commit e95a161. Bugbot is set up for automated code reviews on this repo. Configure here.

…rces

A later beta boot was still starting a history import and showing
Preparing FTW even when DuckDB already had sqlite-v1 receipts. After a
verified import, Core now reports complete history immediately, drops
the leftover SQLite history tables and imported Parquet files, and
leaves SQLite for configuration.

Failed and interrupted imports keep the original sources. Full backups
still write portable SQLite history so restore and older Core can read
it. Image-only downgrade stays refused.

Fixes #1143

Signed-off-by: Fredrik Ahlgren <[email protected]>
@cursor

cursor Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_8d99f999-def5-4599-9367-09c6f240962a)

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-09T09:15:29.471329Z e95a161 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e95a16106a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

st.StartedAtMS = time.Now().UnixMilli()
})
return m
return &historyMigration{ctx: ctx, cancel: cancel, done: make(chan struct{}), progress: progress}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Initialize the timer for every background migration

When an existing DuckDB already has its SQLite seed but still needs background work—such as resuming an interrupted import or importing a newly discovered Parquet file—migrateSQLiteHistory is skipped, so nothing now initializes StartedAtMS. runHistoryMigration changes the state to running without setting it, and snapshotLocked consequently reports elapsed time as now - 0 (roughly 56 years), which is rendered directly in the migration UI. Initialize the timestamp when the non-idle background migration starts rather than only during SQLite seeding.

Useful? React with 👍 / 👎.

@frahlg
frahlg merged commit 0f092c9 into master Sep 9, 2026
17 checks passed
@frahlg
frahlg deleted the feat/retire-legacy-history branch September 9, 2026 09:17
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.

feat(state): drop SQLite history after a verified DuckDB import

1 participant