From 4be2d7be8f7bf2ded9eaa5cb369da93b8878c5d8 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 29 Mar 2026 00:02:07 -0400 Subject: [PATCH] fix: replace sleep(0) with os.pullEvent() + add diagnostic logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sleep(0) wakes the processor only on timer ticks, causing a 1-tick delay. os.pullEvent() with no filter wakes the processor on ANY event — including the modem_message that triggered the capture — so items are processed in the same event cycle. Added logging to capture and processor tasks: - NET-CAP: logs each queued message with type and queue depth - NET-PROC: logs each message being processed - Both log on startup to confirm they're running --- inventoryManager.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index db44f3a..adbf68e 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -640,12 +640,15 @@ local function main() -- miss events while other tasks yield for "task_complete" etc. resilient("Network-capture", function() if not ctx.networkModem then + log.warn("NET-CAP", "No modem — capture task idle") while true do sleep(3600) end end + log.info("NET-CAP", "Capture task started, listening on ch %d", cfg.ORDER_CHANNEL) while true do local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message") if channel == cfg.ORDER_CHANNEL and type(message) == "table" then table.insert(networkQueue, { replyChannel = replyChannel, message = message }) + log.info("NET-CAP", "Queued: type=%s queue=%d", tostring(message.type), #networkQueue) end end end), @@ -653,16 +656,20 @@ local function main() -- Task 13b: Network message processor (drains queue — safe to yield) resilient("Network-processor", function() if not ctx.networkModem then + log.warn("NET-PROC", "No modem — processor task idle") while true do sleep(3600) end end + log.info("NET-PROC", "Processor task started") while true do if #networkQueue == 0 then - sleep(0) + os.pullEvent() end while #networkQueue > 0 do local entry = table.remove(networkQueue, 1) local message = entry.message local replyChannel = entry.replyChannel + log.info("NET-PROC", "Processing: type=%s id=%s queue=%d", + tostring(message.type), tostring(message.commandId), #networkQueue) if isCommandDuplicate(message.commandId) then log.debug("NET", "Duplicate command skipped: %s", tostring(message.commandId))