Skip to content

Remember across a restart that a token was minted here - #38

Merged
matuszeg merged 1 commit into
mainfrom
remember-minted-token
Aug 25, 2026
Merged

matuszeg merged 1 commit into
mainfrom
remember-minted-token

Conversation

@matuszeg

Copy link
Copy Markdown
Owner

Closes #30.

LocalAuth lived only in PumpspyRuntime, so a restart forgot that a token had
been minted. Restart during an outage and
binary_sensor.pumpspy_local_local_token_issued read off while the device was
still carrying a token this integration issued, denying responsibility for the
vendor rejections it exists to explain.

What changed

The issued_at timestamp is persisted through the same Store that already
holds device state, and restored during setup. The token value is not, and
test_the_token_itself_is_never_written_down holds that line: relaying the
device's credential is the job, keeping a copy of it isn't.

One thing the issue didn't mention, and without it none of this would have
worked: request_save() was only ever called from _record, so a mint was
never written out on its own. _handle_auth now asks for the save on both mint
and clear. The mint case matters because the event that causes an outage is
often the same sort of event that takes the machine down with it. The clear case
matters because otherwise the sensor sticks on after recovery.

The staleness call

A stored record older than four hours is discarded rather than restored. That is
the device's own re-authentication interval, measured on 2026-08-20 and
2026-08-21, so if Home Assistant was down for longer the shim sent the device to
the vendor and it is holding a real token now. Restoring the flag at that point
would claim credit for rejections that aren't ours, and inventing a signal is a
worse fault in a diagnostic than the silence this replaces.

It rarely bites in practice. During an outage the device asks again roughly every
nine minutes, and every mint restamps the record.

Verification

Ten new tests covering the round trip, both directions of the staleness window,
an unreadable timestamp, storage written by an older version, and the entity
reading on after a full unload and setup cycle.

Then driven on a running instance rather than trusted to the tests, since this
sits behind the request handler. The dev upstream is refused by design, so the
vendor verdict goes down on its own, a token request mints, and after a restart:

INFO ... the device may still be carrying a token minted here at 2026-08-25 00:20:49.330180+00:00

with only {"issued_at": "..."} on disk and no UUID anywhere in the storage file.

239 tests pass.

LocalAuth lived only in the runtime, so a restart forgot it. Restart during an
outage and the sensor read off while the device was still carrying a token this
integration issued, which is the one moment it exists to explain. It denied
responsibility for the vendor rejections it had caused.

The timestamp is now persisted alongside the device state, through the same
Store. The token itself isn't, and there's a test holding that line: relaying
the device's credential is the job, keeping it isn't.

Minting also has to ask for the save itself. Only telemetry used to, so a mint
followed by a hard power cut, which is the sort of thing that causes an outage
to begin with, would have been lost anyway. Clearing asks too, or the sensor
would stick on after recovery.

A stored record older than four hours is discarded rather than restored. That's
the device's own re-authentication interval, so if Home Assistant was down that
long the shim sent it to the vendor and it's holding a real token now.
Restoring the flag then would claim credit for rejections that aren't ours,
which is a worse fault in a diagnostic than the silence it replaces. It rarely
comes up, since during an outage the device asks again every nine minutes and
each mint restamps the record.

Verified on a running instance as well as in tests. Minted, restarted, and the
log came back with "the device may still be carrying a token minted here at
...", with only the timestamp on disk.

Closes #30.
@matuszeg
matuszeg merged commit 111a0ea into main Aug 25, 2026
3 checks passed
@matuszeg
matuszeg deleted the remember-minted-token branch August 25, 2026 00:34
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.

A restart forgets that a token was minted, so the diagnostic sensor lies after the one event it exists for

1 participant