Retention prune can evict the last completed calculation result #32

Open
opened 2026-07-17 03:07:46 +00:00 by claude-bot · 0 comments
Contributor

runAndStoreCalculationForHome prunes to the newest 25 rows per home (calculationRunner.js:111-113), and both repository implementations (repository.pg.js:347-360, repository.memory.js:242-249) order purely by created_at with no status distinction. A repeated-failure loop (invalid saved state, recurring input error) writes failed rows until the last completed result falls out of the window — at which point reports/current 404s (reportBuilder.js:12-16) and calculation status regresses to missing/failed.

Fix: exclude the most recent completed result from pruning unconditionally, and cap failed rows separately. Keep the window sizes configurable so issue #16's retention decision can tune them later.

Acceptance criteria

  • A completed result survives any number of subsequent failures
  • Failed rows capped independently
  • Test simulating a failure loop confirms reports stay available

Relations: relates to #16

(Audit finding F-11, 2026-07-16 — Severity: Medium, Confidence: Medium)

`runAndStoreCalculationForHome` prunes to the newest 25 rows per home (`calculationRunner.js:111-113`), and both repository implementations (`repository.pg.js:347-360`, `repository.memory.js:242-249`) order purely by `created_at` with no status distinction. A repeated-failure loop (invalid saved state, recurring input error) writes `failed` rows until the last `completed` result falls out of the window — at which point `reports/current` 404s (`reportBuilder.js:12-16`) and calculation status regresses to missing/failed. Fix: exclude the most recent `completed` result from pruning unconditionally, and cap failed rows separately. Keep the window sizes configurable so issue #16's retention decision can tune them later. **Acceptance criteria** - [ ] A completed result survives any number of subsequent failures - [ ] Failed rows capped independently - [ ] Test simulating a failure loop confirms reports stay available **Relations:** relates to #16 *(Audit finding F-11, 2026-07-16 — Severity: Medium, Confidence: Medium)*
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rbrooks/BatteryStorageCalculator#32
No description provided.