From c47ec63e509f53484d84bcff0538ecf9c515bfe1 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sun, 22 Mar 2026 01:29:05 -0400 Subject: [PATCH] Enhance command polling: implement deduplication of processed commands and acknowledgment of command IDs --- inventoryWebBridge.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/inventoryWebBridge.lua b/inventoryWebBridge.lua index 2c34a11..cbb3919 100644 --- a/inventoryWebBridge.lua +++ b/inventoryWebBridge.lua @@ -196,17 +196,27 @@ local function stateForwarder() end -- Task 3: Poll web server for commands +local lastProcessedId = 0 -- track highest processed command ID for dedup + local function commandPoller() while running do local ok, err = pcall(function() local result = httpGet("/api/bridge/commands") if result and result.commands and #result.commands > 0 then - -- Process each command + local maxId = lastProcessedId + -- Process each command, skipping already-processed ones for _, cmd in ipairs(result.commands) do - pcall(processCommand, cmd) + local cmdId = cmd.id or 0 + if cmdId > lastProcessedId then + pcall(processCommand, cmd) + if cmdId > maxId then maxId = cmdId end + end + end + -- Acknowledge up to the highest processed ID + if maxId > lastProcessedId then + lastProcessedId = maxId + httpPost("/api/bridge/commands/ack", { lastProcessedId = lastProcessedId }) end - -- Acknowledge - httpPost("/api/bridge/commands/ack", {}) end end) sleep(POLL_INTERVAL)