From ec1a681924d1b91ab919ef7fd482a06142d7cb87 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 28 Mar 2026 23:40:09 -0400 Subject: [PATCH] fix: replace custom event wake-up with polling, remove craftItem double-capture Two robustness improvements to the Network capture/processor split: 1. Processor wake-up: replaced os.queueEvent('network_queued') / os.pullEvent('network_queued') with sleep(0) polling. Custom events can be consumed by other coroutines (e.g. craftItem's unfiltered os.pullEvent()) or swallowed by the OS event layer. Polling the shared queue every tick is simpler and guaranteed reliable. 2. craftItem: removed ORDER_CHANNEL message buffering and re-queuing. With the dedicated Network-capture task, ORDER_CHANNEL messages are already safely captured into networkQueue. The old buffering caused double-capture: capture task adds to queue, craftItem also buffers, then re-queues via os.queueEvent -> capture captures again -> dup. The commandId dedup caught these, but removing the source is cleaner. --- inventoryManager.lua | 3 +-- manager/operations.lua | 8 +------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/inventoryManager.lua b/inventoryManager.lua index 9d9424f..db44f3a 100644 --- a/inventoryManager.lua +++ b/inventoryManager.lua @@ -646,7 +646,6 @@ local function main() 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 }) - os.queueEvent("network_queued") end end end), @@ -658,7 +657,7 @@ local function main() end while true do if #networkQueue == 0 then - os.pullEvent("network_queued") + sleep(0) end while #networkQueue > 0 do local entry = table.remove(networkQueue, 1) diff --git a/manager/operations.lua b/manager/operations.lua index 5002d93..6b57b86 100644 --- a/manager/operations.lua +++ b/manager/operations.lua @@ -1338,7 +1338,6 @@ function O.craftItem(recipeIdx, batches) log.info("CRAFT", "Waiting for turtle reply (timeout: %ds)...", cfg.CRAFT_TIMEOUT) local deadline = os.clock() + cfg.CRAFT_TIMEOUT local result = nil - local bufferedMessages = {} while os.clock() < deadline do local timerId = os.startTimer(math.max(0.1, deadline - os.clock())) @@ -1350,18 +1349,13 @@ function O.craftItem(recipeIdx, batches) if channel == cfg.CRAFT_REPLY_CHANNEL and type(message) == "table" and message.type == "craft_result" then result = message break - elseif channel == cfg.ORDER_CHANNEL then - table.insert(bufferedMessages, {event, p1, p2, p3, p4, p5}) end + -- ORDER_CHANNEL messages are captured by the Network-capture task elseif event == "timer" and p1 == timerId then -- Timeout tick end end - for _, msg in ipairs(bufferedMessages) do - os.queueEvent(table.unpack(msg)) - end - activity.crafting = false state.needsRedraw = true state.smelterNeedsRedraw = true