Make the calculation input hash cover actual state content #38

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

buildCalculationDataRevision (src/lib/calculationRuntime.js:445-464) fingerprints inputs by counts and IDs only, and cacheableInput (backend/src/calculationRunner.js:423-437) hashes little more than that revision string. Cache correctness therefore rests entirely on home.data_revision being bumped by every input-affecting write (currently true — verified all markHomeDataChanged call sites in app.js). Any future write path that misses the bump serves stale results silently.

Fix: include the full normalized state in the hashed payload (stableStringify is already there; strip volatile fields like generatedAt). Keep data_revision as the cheap fast-path staleness check. Add a comment at both sites explaining the two-layer scheme.

Acceptance criteria

  • Changing any calculation-affecting state field changes the input hash even with counts unchanged
  • Fast path behavior unchanged for identical state
  • Test: circuit status flip (same assignment count) invalidates cache without a data_revision bump

Relations: relates to #15, #16

(Audit finding F-17, 2026-07-16 — Severity: Low, Confidence: High)

`buildCalculationDataRevision` (`src/lib/calculationRuntime.js:445-464`) fingerprints inputs by counts and IDs only, and `cacheableInput` (`backend/src/calculationRunner.js:423-437`) hashes little more than that revision string. Cache correctness therefore rests entirely on `home.data_revision` being bumped by every input-affecting write (currently true — verified all `markHomeDataChanged` call sites in app.js). Any future write path that misses the bump serves stale results silently. Fix: include the full normalized state in the hashed payload (`stableStringify` is already there; strip volatile fields like `generatedAt`). Keep `data_revision` as the cheap fast-path staleness check. Add a comment at both sites explaining the two-layer scheme. **Acceptance criteria** - [ ] Changing any calculation-affecting state field changes the input hash even with counts unchanged - [ ] Fast path behavior unchanged for identical state - [ ] Test: circuit status flip (same assignment count) invalidates cache without a data_revision bump **Relations:** relates to #15, #16 *(Audit finding F-17, 2026-07-16 — Severity: Low, Confidence: High)*
Sign in to join this conversation.
No milestone
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#38
No description provided.