Persist the printer token on connect (survive unclean restarts) - #36
Open
VGottselig wants to merge 1 commit into
Open
Persist the printer token on connect (survive unclean restarts)#36VGottselig wants to merge 1 commit into
VGottselig wants to merge 1 commit into
Conversation
The token obtained from the printer was only written to the known-hosts file by the shutdown defer in main(), which runs only on a graceful exit. On an unclean exit (SIGKILL, container restart, OOM, power loss) a freshly authorized token was therefore lost, forcing another touchscreen authorization on the next start. Additionally, the IP-only fallback printer (-host <ip> without discovery) was created without an ID, and LocalStorage.Add skips ID-less printers, so its token was never persisted even on a clean exit. Fix: - Add an OnPrinterUpdate hook, invoked right after a successful connect, which main() wires to ls.Add(printer) + ls.Save() -- persisting the (refreshed) token immediately instead of only at shutdown. - Give the IP-only fallback printer an ID (its host) so ls.Add persists it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018zWUoJhzouLTnkrpZE7rkJ
VGottselig
added a commit
to VGottselig/sm2uploader
that referenced
this pull request
Jul 30, 2026
The README still only described upstream, so nothing in this fork was documented: the web GUI, starting prints after upload, the token that survives restarts, and the Spoolman filament bookings. Everything upstream wrote stays as it was; the fork material sits below a divider, with a pointer at the top so a visitor knows which repo they are in and which two changes go upstream (macdylan#35, macdylan#36). Documents the parts that are easy to get wrong when using it: bookings are deltas so a correction is not a double booking, remaining weight is computed instead of read because Spoolman clamps it at 0, and uploads.yaml is the only record of what was booked -- deleting it orphans bookings Spoolman still holds. Flags are tabled with their env fallbacks, plus the compose snippet, because the container needs to share a network with Spoolman before the hostname resolves. Claims were checked against the code (poll intervals, row limits, net weight, tail windows, make targets). The G-code section says what was actually verified -- Snapmaker Orca 2.3.4 -- rather than implying PrusaSlicer was tested too. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QHt1eWHFiSbJaNjKVhU38N
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The printer token is only written to the known-hosts file by the shutdown
deferinmain(), which runs only on a graceful exit. On an unclean exit —SIGKILL, container restart, OOM, power loss — a freshly authorized token is lost, so the next start needs another touchscreen authorization.There is also a second gap: the IP-only fallback printer (
-host <ip>without discovery) is created without an ID:but
LocalStorage.Addskips ID-less printers:so that printer's token is never persisted, even on a clean exit.
Fix
OnPrinterUpdatehook, invoked right after a successful connect, thatmain()wires tols.Add(printer)+ls.Save()— persisting the (refreshed) token immediately instead of only at shutdown.ls.Addactually persists it.No change to the normal shutdown path; this just makes persistence happen eagerly and closes the ID-less-fallback gap.
Testing
go build ./...clean.docker kill/ container restarts and unclean power cycles — no re-authorization on the touchscreen on the next upload.