From af6b5b75ca381013abdabbd4e43448d24f928906 Mon Sep 17 00:00:00 2001 From: Luca Toniolo Date: Sun, 26 Apr 2026 18:07:40 +0800 Subject: [PATCH] task: tighten AUTO read-ahead wait-clear to match MDI Auto mode cleared the read-ahead wait on execState==DONE alone, so a G38 issued just before an emcMotionUpdate snapshot could let the next read fire while motion.traj.queue was still non-zero, tripping NCE_QUEUE_IS_NOT_EMPTY_AFTER_PROBING. Add the queue==0 + io.status ==DONE conjuncts already used by mdi_execute_hook. Closes #3650, #662, #263. --- src/emc/task/emctaskmain.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/emc/task/emctaskmain.cc b/src/emc/task/emctaskmain.cc index 1d709157425..c39e899113c 100644 --- a/src/emc/task/emctaskmain.cc +++ b/src/emc/task/emctaskmain.cc @@ -494,11 +494,18 @@ void readahead_reading(void) int count = 0; interpret_again: if (emcTaskPlanIsWait()) { - // delay reading of next line until all is done + // delay reading of next line until all is done. + // Match the stricter check used by mdi_execute_hook: + // trusting only execState==DONE can race when motion + // hasn't yet processed a just-issued command (e.g. a + // G38 probe), letting the next read see a non-empty + // queue. if (interp_list.len() == 0 && emcTaskCommand == 0 && emcStatus->task.execState == - EMC_TASK_EXEC::DONE) { + EMC_TASK_EXEC::DONE && + emcStatus->motion.traj.queue == 0 && + emcStatus->io.status == RCS_STATUS::DONE) { emcTaskPlanClearWait(); } } else {