From b4c1ad53077556e5401569a41a739f58a5ab2c86 Mon Sep 17 00:00:00 2001 From: t Date: Tue, 1 Dec 2026 17:42:15 -0700 Subject: Drain slow MCP tool results after ACP cancellation or disconnect agy can time out and cancel or disconnect an MCP request while Panto is still running the local tool. Failing immediately broke the turn or risked replying to a cancelled request. Request a 30-minute MCP timeout (timeoutSeconds=1800) for the pantograph relay and track Panto's active tool handoff (s.issued) independently of the cancellable MCP call. Keep the ACP idle timer alive while s.issued is pending, let notifications/cancelled and MCP disconnects clear s.call without aborting the turn, hold completion in s.settle until the local tool result and any queued steering drain, and record failed_handoff so a failed handoff surfaces on continuation. Document slow-tool handling in README.md and add a late-tool acceptance fixture in check.lua, tests/fake-agy.lua, and tests/tui.exp. --- acp.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'acp.lua') diff --git a/acp.lua b/acp.lua index 18dfaa7..9e648b9 100644 --- a/acp.lua +++ b/acp.lua @@ -107,7 +107,7 @@ M.probe = verified -- agy discovers named agents under /config/agents. Declare the -- relay on the agent itself: session/new MCP servers need not be inherited by -- custom agents. Never edit the user's agents or global MCP configuration. -local function relay(s) return {name='pantograph',command='/usr/bin/nc',args={'-U',s.dir..'/mcp'}} end +local function relay(s) return {name='pantograph',command='/usr/bin/nc',args={'-U',s.dir..'/mcp'},timeoutSeconds=1800} end local function install_agent(s, profile) local dir=profile for _,part in ipairs({'config','agents'}) do @@ -183,7 +183,7 @@ function M.launch(s, first, resume_id) assert(not waiting,'Overlapping ACP requests'); serial=serial+1; request_id=serial; waiting=coroutine.running() idle=(method=='session/prompt' or method=='authenticate') and 600000 or 60000 activity(); timer:start(1000,1000,function() - if s.call then activity() elseif uv.now()>=deadline then s.fail('ACP timeout: '..method) end + if s.call or s.issued then activity() elseif uv.now()>=deadline then s.fail('ACP timeout: '..method) end end) send({id=serial,method=method,params=params}); return coroutine.yield() end @@ -271,6 +271,13 @@ function M.launch(s, first, resume_id) advertised() turn(first) end + -- ACP may finish while Panto still owns a tool execution. Join both + -- sides before committing the turn (including any boundary steering). + s.settle=function() + if primary_reply and not s.issued and not next(steering) then + local co,result=waiting,primary_reply; waiting,primary_reply=nil,nil; timer:stop(); step(co,result) + end + end local function receive(q) assert(q.jsonrpc=='2.0','Invalid ACP envelope') if not q.method then @@ -286,9 +293,7 @@ function M.launch(s, first, resume_id) else assert(q.id==request_id and not primary_reply,'Unexpected ACP reply'); primary_reply=assert(q.result) end - if primary_reply and not next(steering) then - local co,result=waiting,primary_reply; waiting,primary_reply=nil,nil; timer:stop(); step(co,result) - end + s.settle() return end local p=q.params or {}; local ours=s.session and p.sessionId==s.session -- cgit v1.3