Skip to content

feat(nfdrs): add Driver state persistence - #26

Merged
michaelpeterswa merged 1 commit into
mainfrom
feat/nfdrs-driver-state
Aug 3, 2026
Merged

feat(nfdrs): add Driver state persistence#26
michaelpeterswa merged 1 commit into
mainfrom
feat/nfdrs-driver-state

Conversation

@michaelpeterswa

Copy link
Copy Markdown
Member

Summary

Add Driver.State() and Driver.SetState(), so a caller can persist a warm
driver and resume without the spin-up. This is the piece an ingest service
needs: the 1000-hour stick has a long time lag, so a cold start needs about six
weeks of history before the energy release component is right. With a saved
state, a restart resumes at once.

What it adds

  • DriverState holds the state of the four Nelson sticks, the two live fuel
    moisture models, the drought index, and the driver's daily accumulators and
    last outputs.
  • Driver.State() returns the state. Driver.SetState() restores it. The
    caller constructs the driver with the same Config first.
  • SetState checks the schema version and that every sub-model is present.
  • The Indices type gets JSON tags, so the stored state has stable keys.

Validation

TestDriverStateRoundTrip runs a driver across two daily boundaries, marshals
the state to JSON, restores it into a second driver, and confirms:

  • the second marshal is byte-identical to the first;
  • both drivers produce identical indices and dead fuel moisture for the same
    further weather.

TestDriverSetStateErrors checks that SetState rejects a wrong schema version
and an absent sub-model. Passes in the workspace and in isolation.

Why now

This unblocks the backfill: a year of history streams through the driver in one
pass, then State() snapshots the warm driver for a live ingest service. See
the storage schema proposed in lfprocks/timescale-migrations#6.

🤖 Generated with Claude Code

Add the DriverState type and the State and SetState methods. DriverState
holds the state of the four Nelson sticks, the two live fuel moisture
models, the drought index, and the driver's daily accumulators and last
outputs. It marshals to JSON and back with an exact round trip.

A caller can now snapshot a warm driver and restore it, so a restart does
not repeat the spin-up that the 1000-hour stick needs from a cold start.
The caller constructs the driver with the same Config, then restores the
state. SetState checks the schema version and that every sub-model is
present.

Add JSON tags to the Indices type, so the stored state has stable keys.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@michaelpeterswa
michaelpeterswa merged commit 55c388c into main Aug 3, 2026
2 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