Skip to content

Fix buffer stall recovery aborting jobs during slow moves#262

Merged
knipknap merged 2 commits into
mainfrom
fix/buffer-stall-false-alarm
Jun 4, 2026
Merged

Fix buffer stall recovery aborting jobs during slow moves#262
knipknap merged 2 commits into
mainfrom
fix/buffer-stall-false-alarm

Conversation

@knipknap

Copy link
Copy Markdown
Contributor

Summary

  • Fix _on_buffer_stall returning False when machine is in Run state, which caused send_gcode() to raise BufferStallError and trigger a soft-reset mid-motion (GRBL ALARM:3). The machine being in Run state means it's actively executing moves — this is a transient stall, not a deadlock. Now returns True to signal "retry the wait."
  • Increase deadlock_timeout from 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-669 treated any non-idle machine state as a fatal condition. When GRBL was actively executing a slow move (e.g. F200), the ok ACKs were delayed beyond the timeout. The stall callback polled the machine, saw Run state, and returned False (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

  • Syntax check passes (py_compile)
  • No existing unit tests for the buffer stall callback path (tests require PyGObject system deps not available in this environment)

Fixes #256

knipknap added 2 commits May 28, 2026 19:50
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.
@knipknap
knipknap merged commit 320c85f into main Jun 4, 2026
29 checks passed
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.
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.

Serial communication issue

1 participant