Skip to content

fix: recover history writes after long counter gaps - #1184

Merged
frahlg merged 2 commits into
masterfrom
fix/ledger-counter-gap-memory
Sep 8, 2026
Merged

frahlg merged 2 commits into
masterfrom
fix/ledger-counter-gap-memory

Conversation

@frahlg

@frahlg frahlg commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

Several energy counters returning after a long gap can exhaust DuckDB memory inside one telemetry transaction. This also occurs at startup when a former hardware identity briefly becomes current again. Retrying or reopening the database cannot fix a transaction that consumes the same memory on every attempt.

Replace the per-bucket INSERT loop with one INSERT SELECT over the interval's five-minute buckets. Keep the same overlap-weighted energy, provenance, sample counts and conflict updates. History, scalar samples, all energy flows, cursors and the retry receipt still commit together. The database memory limit stays unchanged.

A small fresh-database reproduction with five counters returning after 24 hours and 161 scalar samples failed before the change at 243.9/244.1 MiB. It now passes at the same 256 MB setting. The regression also checks partial first/last buckets, rollback when the last observation is invalid, all five cursor updates and a same-receipt retry without duplicate energy. No large fixture or physical box change was needed.

When history writes are blocked during import, show the current write failure in the import panel and hide the rate/ETA. Recovery and disconnect clear or update that state. The display keeps the first error line and omits DuckDB tuning advice.

Validation: the focused ledger/full-tick tests pass with the race detector (3.236 s). The UI task ran ten focused tests and checked the rendered failure state in a browser using captured box health. Integrated make verify passed on the combined ledger/UI change (tests, vet and build). Its first run hit two unchanged control tests at a quarter-hour boundary; both passed in an isolated rerun and in the full rerun. Physical recovery belongs to the beta validation task. This PR does not change device identity selection.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 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-08T12:18:50.836513Z 965c60e 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.

@cursor

cursor Bot commented Sep 8, 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_228d7703-0c29-4f30-bbde-bcd60525ce65)

@cursor

cursor Bot commented Sep 8, 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_386edb03-0b28-4015-a0e1-ab268066a5b2)

@frahlg frahlg changed the title fix(state): keep long counter gaps within the history memory budget fix: recover history writes after long counter gaps Sep 8, 2026
@frahlg
frahlg merged commit 9f6ed6c into master Sep 8, 2026
18 checks passed
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