Fix buffer stall recovery aborting jobs during slow moves#262
Merged
Conversation
The buffer stall callback (_on_buffer_stall) was returning False (recovery failed) when the machine was in Run state, causing send_gcode to raise BufferStallError and trigger a soft-reset. This produced GRBL ALARM:3 by aborting the machine mid-motion. When the machine is actively running (not idle), a buffer stall is transient -- the machine simply hasn't finished its current move yet. Return True to signal retry instead of False (abort). Also increase deadlock_timeout from 2s/10s to 5s/30s to better accommodate slow feed rates (e.g. F200 takes 30s for a 100mm move). Fixes #256
Adds a new "Deadlock detection" toggle to the GRBL serial and telnet driver settings. When disabled (default), the buffer stall callback simply retries the wait without attempting deadlock detection or recovery. This prevents false ALARM:3 errors caused by the driver misinterpreting slow moves as deadlocks. When enabled, the driver will poll the machine state during stalls and attempt G4 P0.01 recovery if a true deadlock is detected. The option appears as a switch in the device settings UI alongside the existing "Poll device status during jobs" toggle.
This was referenced May 28, 2026
StevenIsaacs
pushed a commit
to StevenIsaacs/rayforge
that referenced
this pull request
Jun 7, 2026
Instead of a fixed deadlock_timeout, compute a per-gcode-line timeout from Ops.estimate_command_times(). Each line's timeout is set to max(5s, estimated_move_time * 3), capped at 120s. Lines without an op_index fall back to a 30s default. This replaces the previous static 2s/10s/30s timeouts from PR barebaric#262 with values that scale with actual move duration, preventing false ALARM:3 errors on slow moves while keeping deadlock detection fast on short moves.
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.
Summary
_on_buffer_stallreturningFalsewhen machine is inRunstate, which causedsend_gcode()to raiseBufferStallErrorand trigger a soft-reset mid-motion (GRBL ALARM:3). The machine being inRunstate means it's actively executing moves — this is a transient stall, not a deadlock. Now returnsTrueto signal "retry the wait."deadlock_timeoutfrom 2s/10s to 5s/30s to accommodate slow feed rates. At F200, a 100mm move takes 30 seconds, so the previous timeouts were far too aggressive.Root Cause
The buffer stall recovery in
grbl_serial.py:666-669treated any non-idle machine state as a fatal condition. When GRBL was actively executing a slow move (e.g. F200), theokACKs were delayed beyond the timeout. The stall callback polled the machine, sawRunstate, and returnedFalse(recovery failed). This triggered a soft-reset (\x18) while the machine was in motion, producing GRBL ALARM:3.Full RCA with log evidence: #256 (comment)
Testing
py_compile)Fixes #256