Repository navigation
fix(machine): recover orphaned jobs after a sidecar crash - #268
Merged
Merged
Conversation
The machine-control sidecar owns the serial port. If it crashes mid-stream the
in-memory job is lost and the OS releases the port (DTR resets the controller);
a re-attaching client then polled a job id the fresh process had never heard of
and got a 404.
Backend: the machine service writes a small recovery snapshot for the active
job (deleted on every clean terminal transition and on disconnect). On startup,
a snapshot still marked active means a prior process died mid-job, so the job is
reconstructed as `orphaned` — the port is NOT reopened (a blind re-open would
DTR-reset a possibly-moving controller); recovery is an explicit reconnect.
`GET /machine/jobs/{id}` then returns `orphaned` instead of 404.
GUI: the API client memoised the sidecar base URL for the app's lifetime, so
after a crash + respawn (on a new ephemeral port) every later call hit the dead
port forever. It now drops its memo on a fetch error, letting the next call
re-resolve the respawned sidecar. The streaming poll loop tolerates a few failed
polls to ride through the respawn, then surfaces an interrupted-job notice with
a reconnect prompt. Also corrects two stale "M0 sent"/"M108 sent" pause/resume
log strings left over from the pre-0.9.0 streamer.
Validated end to end on the RAMPS test rig: crash mid-stream -> snapshot
survives -> fresh sidecar reports `orphaned` (not 404) -> reconnect recovers the
controller.
Closes #200
Member
Author
|
Filed the streaming-guide rewrite as #269 (the broader |
Wrap the orphaned-job error string the way ruff format prefers; CI runs ruff format --check, which the prior commit missed.
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.
Closes #200.
The machine-control sidecar owns the serial port. If it crashes mid-stream, the in-memory job is lost and the OS releases the port (DTR resets the controller). A re-attaching client then polled a job id the fresh process had never heard of and got a 404 — confusing, and the GUI client was wedged pointing at the dead port.
Backend — orphaned-job recovery
orphaned, soGET /machine/jobs/{id}returnsorphanedinstead of 404.GUI — reach the respawned sidecar + surface the interruption
getApiClient()memoised the sidecar base URL for the app's lifetime, so after a crash + respawn on a new ephemeral port every later call hit the dead port forever (app restart required). The client now drops its memo on a fetch error (onErrormiddleware), letting the next call re-resolve the respawned sidecar.orphanedis handled as a terminal state that drops to disconnected.M0 sent/M108 sentpause/resume log strings left from the pre-0.9.0 streamer.Verification
tests/api/test_machine_recovery.py(9 new): snapshot→orphaned, paused→orphaned, terminal/corrupt snapshots ignored, id-counter anti-reuse, and a persist-on-start/clear-on-complete lifecycle test viaFakeTransport. Full backend suite 124 passed; mypy clean; ruff clean.interrupted).orphaned(not 404) → reconnect recovers the controller. All assertions passed.Notes on the other acceptance points
base_url→is_dead→ respawn); it never kills a live one. No change needed there.marlin-streaming.md"Technical Details" section is still pre-0.9.0 (React /interactive.py/ M0/M108). That's the same drift as docs: refresh README Architecture section for the local-API sidecar #232 but larger than this fix's scope — filed separately (follow-up issue) and left out here; this PR adds only the recovery-path subsection build(gui): sidecar serial-crash / orphaned-job recovery #200 requires.