Skip to content

fix(state): one unreadable Parquet file never stops boot - #1901

Merged
frahlg merged 2 commits into
masterfrom
f3-skip-bad-parquet-at-boot
Oct 27, 2026
Merged

frahlg merged 2 commits into
masterfrom
f3-skip-bad-parquet-at-boot

Conversation

@frahlg

@frahlg frahlg commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Item F3 of the stable plan.

Problem

At boot, main.go calls AbsorbColdHistory and exits on any error. One damaged bucket file in the cold folder makes AbsorbColdHistory return at the first read error (history_plain.go:229-243). The file stays in place, so systemd restarts Core every 5 s and it fails the same way each time. The site gets no control until someone moves the file by hand.

Scenario: a cold folder holds two days. One file reads well; the next day's .buckets.parquet is cut to half its size, as a bad copy would leave it. On master, boot stops with read 18.buckets.parquet: invalid magic footer of parquet file, and the cleanup of the good day never runs.

Change

  • An unreadable bucket file (hash or Parquet read failure) is logged with slog.Warn and renamed to DD.buckets.parquet.unreadable. The other days import and the cleanup runs.
  • The new name does not end in .parquet, so the history readers (aggregatePaths), the cold converter and backup verification skip it. Day views, CSV exports and wide charts over that day keep working. With the file left at its normal name, every series query over the day failed with the Parquet error (review finding, and Codex P2 on the first version).
  • If the day's .buckets.parquet is unreadable, its .legacy-buckets.parquet stays on disk, unimported, and serves reads for the day. Importing it would put its hours in history.db; a good copy of the original restored later would then differ from those hours, and boot would stop with archive differs from stored hour. Now a restored original (put back under its normal name) imports on the next boot, and the legacy copy goes with no conflict.
  • /api/health lists moved files under history_storage.unreadable_cold_files on every boot, found by name, so the fault does not pass in silence.
  • If the rename fails, the file stays at its normal name, is listed, and boot still goes on.
  • A cancelled context and database write errors still stop the import, as before. main.go is unchanged.

Tests

  • TestAbsorbColdHistorySkipsUnreadableBucketFile, from the audit repro TestReproAbsorbColdHistoryCorruptDayFailsAll (caa-135). It runs for a truncated file and for a file with no read permission. It opens the store with the same cold folder for reads and for absorb, as main.go does. Over two boots it checks that the good day imports, the damaged file is moved aside and listed, the legacy copy stays and serves its hour, and series reads over the day succeed for the damaged metric and an unrelated one (maxPoints 0 and 200), and for a year chart.
  • TestAbsorbColdHistoryImportsRestoredBucketFile: a damaged file whose legacy copy holds one of its two minutes. After the first boot, a good copy goes back under the normal name. The second boot succeeds, the hour holds both minutes, both files go and nothing is listed.
  • With the first version's source, both tests fail.
  • cd go && go test -race ./internal/state/...: ok
  • cd go && go test -race -run 'Health|Storage|History' ./internal/api/: ok
  • cd go && go vet ./internal/state ./cmd/ftw && go build ./...: ok

Risk

Low. Only the boot import of old bucket files changes. A damaged file now stays on disk under a new name across boots, where before it stopped boot. A file with no read permission still fails a backup, as before.

🤖 Generated with Claude Code

AbsorbColdHistory returned the first read error, and main.go exits on
it. The bad file stayed in place, so every restart failed the same way.
Now an unreadable bucket file is logged, kept for recovery and listed
as unreadable_cold_files in the history health report. The other days
import, and the day's older legacy copy is used when it reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-10-27T13:42:05.046627Z 704ec9a 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: 704ec9a7c0

ℹ️ 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".

}
var kept []string
for path := range unreadable {
keep[path] = true

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 Exclude retained unreadable files from history queries

When a damaged bucket file is retained here, every history query spanning that day still discovers it through aggregatePaths. In series_archive.go, walkMergedSeriesStatsBinned then falls back to walkAggregateSeries, which calls walkBucketFile on the damaged file and propagates its read error. Consequently, charts and exports spanning that day fail even for unrelated metrics or when the legacy fallback was successfully imported into SQLite. Keep the file for recovery, but exclude known-unreadable files from normal history discovery so the successfully imported data remains queryable.

Useful? React with 👍 / 👎.

The first version kept a damaged DD.buckets.parquet at its normal name.
aggregatePaths still found it, so every series query over that day
failed with the Parquet error, on every boot.

Rename the file to DD.buckets.parquet.unreadable instead. No reader,
importer or converter opens a name that does not end in .parquet. List
these files in history health on every boot.

Keep the day's legacy copy on disk, unimported, while its original is
unreadable. It serves reads for the day. Importing it would make a good
copy of the original, restored later, conflict with the stored hours and
stop boot with "archive differs from stored hour".

Tests open the store with the same cold folder for reads and absorb, as
main.go does, and cover a restored original.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@frahlg
frahlg merged commit 3448637 into master Oct 27, 2026
22 checks passed
@frahlg
frahlg deleted the f3-skip-bad-parquet-at-boot branch November 11, 2026 09:16
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