summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-12-01 17:42:15 -0700
committert <t@tjp.lol>2026-12-04 13:53:47 -0700
commitb4c1ad53077556e5401569a41a739f58a5ab2c86 (patch)
tree0b121e7c16c7c7c385d68a2d6e4b24866b13f86f
parent8c1c5786ebfe8dda40a70571f332e876b184ad4d (diff)
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.
-rw-r--r--README.md2
-rw-r--r--acp.lua15
-rw-r--r--check.lua10
-rw-r--r--extensions/antigravity-acp.lua93
-rw-r--r--tests/fake-agy.lua24
-rw-r--r--tests/tui.exp1
6 files changed, 99 insertions, 46 deletions
diff --git a/README.md b/README.md
index 368bbfa..ace2077 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,8 @@ reasoning_levels = ["low", "medium", "high", "xhigh"]
**Tools:** By default the `pantograph` MCP server exports the active Panto tools, including extension tools. They run with Panto's permissions, not agy's shell sandbox. Use a trusted rig; if it contains tools you don't want Neon to run, narrow `tools` or disable those extensions in the rig. Full input schemas are listed, including nested arrays and objects; an unsupported schema constraint rejects the call rather than disabling the catalog. ACP now selects a per-thread [custom main agent](https://antigravity.google/docs/subagents/) with `excludeDefaultComponents: true`, `tools: []`, and no inherited customizations or MCP. The agent file in the isolated profile declares only the thread's `pantograph` relay (none for `tools = []`); each exported tool requests eager loading so agy need not read schema files with a native tool. The same relay is passed explicitly to ACP `session/new` or `session/resume` so agy discovers it during setup. With tools exported, the adapter requires a live relay that served `tools/list` before sending the first prompt. Schema-cache timestamps are not used. The Panto rig prompt still uses ACP's advertised append extension.
+**Slow tools:** The generated agy agent requests a 30-minute MCP timeout for its `pantograph` server. If agy times out an MCP call, the local tool may still finish. Panto records its result, but the adapter does not send it to a cancelled request, rerun the tool, or start a new prompt. The existing turn drains the result and any queued steering before it can finish.
+
**Native tool visibility:** During a prompt, reported ACP native calls such as `manage_task` appear above the input with their name and status. The component shows the latest six calls until the next prompt or session close; it isn't saved transcript history. It never executes tools or prints raw inputs/results. Calls through the Panto relay still get their ordinary Panto cards, not duplicates.
**Live acceptance check:** Restart Panto after each config change and use a fresh thread in a disposable workspace without other agents, hooks or MCP servers. Generate a fresh marker with `uuidgen > panto-probe.txt` before each test; don't paste its contents into chat.
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 <gemini-dir>/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
diff --git a/check.lua b/check.lua
index b8abfdd..4d58e8d 100644
--- a/check.lua
+++ b/check.lua
@@ -69,7 +69,15 @@ return {name='test.signature', activate=function()
ext.register_tool{name='fixture.echo',description='Return a nested value.',
schema={type='object',properties={rows={type='array',minItems=1,items={type='object',properties={value={type='integer'}},required={'value'}}}},required={'rows'}},
handler=function(input)
- if not uv.fs_stat(os.getenv('HOME')..'/.local/share/panto-antigravity/google/usage-failure') then ext.agent:submit('boundary workflow notice') end
+ local profile=os.getenv('HOME')..'/.local/share/panto-antigravity/google'
+ if input.rows[1].value==43 then
+ local f=assert(io.open(profile..'/tool-running','w')); f:close()
+ local co=coroutine.running(); local timer=uv.new_timer()
+ timer:start(10,10,function()
+ if uv.fs_stat(profile..'/return-result') then timer:close(); assert(coroutine.resume(co)) end
+ end)
+ coroutine.yield()
+ elseif not uv.fs_stat(profile..'/usage-failure') then ext.agent:submit('boundary workflow notice') end
return tostring(input.rows[1].value)
end}
end}
diff --git a/extensions/antigravity-acp.lua b/extensions/antigravity-acp.lua
index 8484bce..0f3faa9 100644
--- a/extensions/antigravity-acp.lua
+++ b/extensions/antigravity-acp.lua
@@ -9,7 +9,7 @@ local function companion(name)
return require('panto-antigravity.'..name)
end
local catalog,acp=companion('catalog'),companion('acp')
-local active
+local active, failed_handoff
local function stop()
local s=active; if not s then return end; active=nil
if s.card then s.card:unmount() end
@@ -19,11 +19,17 @@ local function stop()
if s.lock then uv.fs_rmdir(s.lock) end
if s.notify then s.notify() end
end
-local function release(id) if active and active.sid==id then stop() end end
+local function release(id)
+ if failed_handoff and failed_handoff.sid==id then failed_handoff=nil end
+ if active and active.sid==id then stop() end
+end
local function send(c,msg) msg.jsonrpc='2.0'; c:write(json.encode(msg)..'\n') end
local function rpc(s,c,q)
if type(q)~='table' or q.jsonrpc~='2.0' or type(q.method)~='string' then error('Invalid MCP request') end
- if q.method=='notifications/cancelled' and s.call and q.params and q.params.requestId==s.call.id then s.fail('MCP call cancelled'); return end
+ if q.method=='notifications/cancelled' then
+ if s.call and q.params and q.params.requestId==s.call.id then s.call=nil end
+ return
+ end
if q.id==nil then return end
assert(type(q.id)=='string' or math.type(q.id)=='integer','Invalid MCP request ID')
local function fail(code,msg) send(c,{id=q.id,error={code=code,message=msg}}) end
@@ -76,7 +82,12 @@ end
local function start(req,by,list,signature,save)
local dir=assert(uv.fs_mkdtemp('/tmp/panto-antigravity-XXXXXX'))
local s={sid=req.context,dir=dir,server=uv.new_pipe(false),by=by,list=list,seq=0,notify=req.notify}; active=s
- s.fail=function(msg) if active==s then s.error=tostring(msg):gsub('[%c]',' '):sub(1,512); stop() end end
+ s.fail=function(msg)
+ if active~=s then return end
+ s.error=tostring(msg):gsub('[%c]',' '):sub(1,512)
+ if s.issued then failed_handoff={sid=s.sid,error=s.error} end
+ stop()
+ end
s.model,s.instructions,s.cwd,s.signature,s.save=req.model,req.system_prompt or '',assert(uv.cwd()),signature,save
if save then
assert(s.sid:match('^[%x-]+$'),'Invalid Panto session ID')
@@ -89,7 +100,7 @@ local function start(req,by,list,signature,save)
local c=uv.new_pipe(false); if not s.server:accept(c) or s.peer then c:close(); return end
s.peer=c; local buf=''; c:read_start(function(e,chunk)
if active~=s or s.peer~=c or c:is_closing() then return end
- if e or not chunk then if s.call then s.fail('MCP disconnected during tool call') else s.peer=nil; s.listed=false; c:close() end; return end
+ if e or not chunk then s.call=nil; s.peer=nil; s.listed=false; c:close(); return end
buf=buf..chunk
while active==s do
local at=buf:find('\n',1,true); if (at or #buf)>1048576 then s.fail('Oversized MCP request'); return end
@@ -150,7 +161,7 @@ end,activate=function()
return #offers>0 and ('Gemini models: '..table.concat(offers,'; ')) or 'No displayable Gemini models were advertised.'
end}
ext.on('session_ready',function() ready=true end)
- ext.on('session_end',function() ready=false; offers=nil; stop() end)
+ ext.on('session_end',function() ready=false; offers=nil; failed_handoff=nil; stop() end)
ext.register_protocol{name='antigravity-acp',effort_levels=acp.effort_levels,close=stop,cancel_turn=release,reset_context=release,release_context=release,open=function(req)
local info=ext.session_info()
if not ready or not info or req.purpose~='turn' or info.session_id~=req.context then return terminal('Interactive primary thread required') end
@@ -163,9 +174,44 @@ end,activate=function()
-- Panto extensions submit workflow completions as ordinary user text.
-- They may continue a matching live turn, never open or reseed one.
local warm=s and not s.pending and s.last~=nil
- local awaiting=s and s.pending and s.call and s.call.sent
- if not awaiting and (direct or warm) and last and last.role=='user' and #last.blocks==1 and b.type=='text' then
- if s and s.pending then return terminal('An Antigravity turn is already pending') end
+ if failed_handoff then
+ local failure=failed_handoff
+ if direct or failure.sid==req.context then failed_handoff=nil end
+ if not direct and failure.sid==req.context then return terminal(failure.error) end
+ end
+ -- An emitted tool call belongs to Panto until its result returns,
+ -- independently of the (cancellable) MCP request that asked for it.
+ local awaiting=s and s.issued
+ if awaiting then
+ -- Panto may append one or more user messages after the single tool
+ -- result. Never search past other roles/results for a reusable tag.
+ local i=#msgs; local steer=json.array({})
+ while i>0 and msgs[i].role=='user' and msgs[i].blocks[1] and msgs[i].blocks[1].type=='text' do i=i-1 end
+ local carrier=msgs[i]; b=carrier and carrier.blocks[1]
+ if not (carrier and carrier.role=='user' and #carrier.blocks==1 and b.type=='tool_result' and b.tool_use_id==awaiting.tag) then
+ s.fail('Missing matching tool result at ACP continuation'); return terminal(s.error)
+ end
+ for j=i+1,#msgs do for _,v in ipairs(msgs[j].blocks) do
+ if v.type~='text' then s.fail('Only text can steer an active ACP turn'); return terminal(s.error) end
+ steer[#steer+1]={type='text',text=v.text}
+ end end
+ s.prefix=history(msgs,#msgs); s.response={}
+ if #steer>0 then s.steer(steer) end
+ if s.call==awaiting then
+ local parts=json.array({}); local failed=b.is_error
+ for _,v in ipairs(b.content) do
+ if v.type=='text' then parts[#parts+1]={type='text',text=v.text}
+ elseif v.type=='media' and v.media_type:match('^image/') then parts[#parts+1]={type='image',mimeType=v.media_type,data=v.data}
+ else failed=true; parts[#parts+1]={type='text',text='Unsupported tool result content'} end
+ end
+ send(s.peer,{id=awaiting.id,result={isError=failed,content=parts}}); s.call=nil
+ end
+ s.issued=nil; s.settle()
+ elseif s and s.pending then
+ s.fail('Unexpected Panto continuation'); return terminal(s.error)
+ else
+ if not (last and last.role=='user' and #last.blocks==1 and b.type=='text') then return terminal('No matching Antigravity tool handoff or text prompt') end
+ if not (direct or warm) then return terminal('Antigravity requires direct TUI input on a provenance-aware Panto build. No subscription request sent.') end
local cfg=ext.config.providers[req.provider]; validate(cfg); local by,list=catalog.catalog(req,cfg.tools)
local sig=('%016x:skip'):format(digest(json.encode({'panto-agent-acp-v2',uv.cwd(),req.provider,req.model,req.system_prompt or '',list})))
local prompt=b.text
@@ -213,36 +259,12 @@ end,activate=function()
end
s.turn=(s.turn or 0)+1
local ok,err=pcall(function() if s.submit then s.submit(prompt) else acp.launch(s,prompt,tag and tag.session) end end); if not ok then s.fail(err) end
- elseif awaiting then
- -- Panto may append one or more user messages after the single tool
- -- result. Never search past other roles/results for a reusable tag.
- local i=#msgs; local steer=json.array({})
- while i>0 and msgs[i].role=='user' and msgs[i].blocks[1] and msgs[i].blocks[1].type=='text' do i=i-1 end
- local carrier=msgs[i]; b=carrier and carrier.blocks[1]
- if not (carrier and carrier.role=='user' and #carrier.blocks==1 and b.type=='tool_result' and b.tool_use_id==s.call.tag) then
- s.fail('Missing matching tool result at ACP continuation'); return terminal(s.error)
- end
- for j=i+1,#msgs do for _,v in ipairs(msgs[j].blocks) do
- if v.type~='text' then s.fail('Only text can steer an active ACP turn'); return terminal(s.error) end
- steer[#steer+1]={type='text',text=v.text}
- end end
- s.prefix=history(msgs,#msgs); s.response={}
- local parts=json.array({}); local failed=b.is_error
- for _,v in ipairs(b.content) do
- if v.type=='text' then parts[#parts+1]={type='text',text=v.text}
- elseif v.type=='media' and v.media_type:match('^image/') then parts[#parts+1]={type='image',mimeType=v.media_type,data=v.data}
- else failed=true; parts[#parts+1]={type='text',text='Unsupported tool result content'} end
- end
- if #steer>0 then s.steer(steer) end
- send(s.peer,{id=s.call.id,result={isError=failed,content=parts}}); s.call=nil
- else
- if s and s.pending then s.fail('Unexpected Panto continuation') end
- return terminal('Antigravity requires direct TUI input on a provenance-aware Panto build. No subscription request sent.')
end
s.notify=req.notify
return {next=function()
if s.error then return {type='error',kind='terminal',message=s.error} end
if active~=s then return {type='error',kind='terminal',message='Antigravity session closed'} end
+ if s.issued then return {type='done',termination={reason='tool_use'},metadata=s.context_window and {context_window=s.context_window}} end
if s.bytes>0 then
local chunk=table.remove(s.chunks,1); s.bytes=s.bytes-#chunk.text; append_reply(s.response,chunk.kind,chunk.text)
return {type=chunk.kind..'_delta',text=chunk.text}
@@ -256,8 +278,7 @@ end,activate=function()
local call=s.call; if not call then return nil end
-- A single ACP prompt can span many Panto messages. Publish its
-- latest occupancy at tool boundaries too, without billing a turn.
- if call.sent then return {type='done',termination={reason='tool_use'},metadata=s.context_window and {context_window=s.context_window}} end
- call.sent=true; return {type='tool_call',id=call.tag,name=call.name,input_json=call.input}
+ s.issued=call; return {type='tool_call',id=call.tag,name=call.name,input_json=call.input}
end}
end}
end}
diff --git a/tests/fake-agy.lua b/tests/fake-agy.lua
index ae671c3..4f76d8d 100644
--- a/tests/fake-agy.lua
+++ b/tests/fake-agy.lua
@@ -43,9 +43,12 @@ local function load_catalog(server)
local input, output = assert(uv.pipe()), assert(uv.pipe())
local proc = assert(uv.spawn(server.command, {args=server.args, stdio={input.read, output.write, 2}}, function() end))
uv.fs_close(input.read); uv.fs_close(output.write)
- local function rpc(id, method, params)
+ local function write(id, method, params)
local line = json.encode({jsonrpc='2.0', id=id, method=method, params=params or {}}) .. '\n'
assert(uv.fs_write(input.write, line, -1) == #line)
+ end
+ local function rpc(id, method, params)
+ write(id,method,params)
local buf = ''
repeat
local chunk = assert(uv.fs_read(output.read, 4096, -1)); assert(chunk ~= '', 'relay closed'); buf = buf .. chunk
@@ -56,14 +59,25 @@ local function load_catalog(server)
local tools = rpc(2, 'tools/list').result.tools
local schemas={}; for _,t in ipairs(tools) do assert(t._meta['antigravity/alwaysLoad']==true); schemas[t.name]=t.inputSchema end
assert(schemas.std__read and schemas.std__edit and schemas.fixture__echo.properties.rows.items.required[1]=='value')
- return function()
+ return function(late_prompt)
+ if late_prompt then
+ write(7,'tools/call',{name='fixture__echo',arguments={rows={{value=43}}}})
+ while not uv.fs_stat(profile..'/tool-running') do uv.sleep(10) end
+ write(nil,'notifications/cancelled',{requestId=7})
+ assert(rpc(8,'ping').result) -- cancellation consumed while Panto still owns call 7
+ finish(late_prompt,'timeout-handled-ok')
+ send({id='barrier',method='fixture/barrier'})
+ assert(read().id=='barrier') -- ACP finished before the local tool returned
+ local f=assert(io.open(profile..'/return-result','w')); f:close()
+ return function() assert(rpc(9,'ping').result) end -- no late reply to 7
+ end
assert(rpc(3, 'tools/call', {name='not_exported', arguments={}}).error.code == -32602)
assert(rpc(5, 'tools/call', {name='fixture__echo', arguments={rows={{value='bad'}}}}).error.code == -32602)
local echo=rpc(6, 'tools/call', {name='fixture__echo', arguments={rows={{value=42}}}}).result
assert(echo.isError==false and echo.content[1].text=='42')
local r = rpc(4, 'tools/call', {name='std__read', arguments={path=uv.cwd() .. '/.panto/SYSTEM.md'}}).result
assert(r.isError == false and r.content[1].text:find('Short answers', 1, true))
- proc:kill('sigkill'); uv.fs_close(input.write); uv.fs_close(output.read); uv.run(); proc:close()
+ -- Keep the peer connected for subsequent turns.
end
end
@@ -85,6 +99,7 @@ if uv.fs_stat(profile..'/no-tools') then assert(#servers==0) else assert(#server
assert(#setup.mcpServers==#servers)
local server=setup.mcpServers[1]
if server then
+ assert(server.timeoutSeconds==1800 and servers[1].timeoutSeconds==1800, 'expected 30-minute timeout in ACP setup and generated agent')
assert(server.name==servers[1].name and server.command==servers[1].command and json.encode(server.args)==json.encode(servers[1].args) and json.encode(server.env)=='[]')
end
local check_relay=server and not uv.fs_stat(profile..'/skip-list') and load_catalog(server)
@@ -144,6 +159,7 @@ else
finish(q, 'primary-tool-ok'); reply(steer,{stopReason='end_turn',usage={inputTokens=1000,outputTokens=6,totalTokens=1006}}) -- out of request order also works
set_level('high')
finish(prompt('again'), 'same-session-ok')
- finish(prompt('[subagents] Workflow fixture completed. Output below: marker'), 'workflow-notice-ok')
+ local verify=check_relay(prompt('late-tool'))
+ q=prompt('[subagents] Workflow fixture completed. Output below: marker'); verify(); finish(q, 'workflow-notice-ok')
end
for _ in io.lines() do end -- keep the session alive until Panto closes stdin
diff --git a/tests/tui.exp b/tests/tui.exp
index b8cdf4d..77ef267 100644
--- a/tests/tui.exp
+++ b/tests/tui.exp
@@ -20,6 +20,7 @@ foreach {prompt answer} {hello primary-tool-ok again same-session-ok} {
send -- "/reasoning high"; see {/reasoning high}; send -- "\r"; see {reasoning -> high}
} else {see $answer}
}
+send -- "late-tool"; see {late-tool}; send -- "\r"; see {timeout-handled-ok}
send -- "/fixture-notice "; see {/fixture-notice }; send -- "\r"; see {workflow-notice-ok}
send -- "\003"; expect eof; wait
set flag [open "$env(HOME)/.local/share/panto-antigravity/google/usage-failure" w]; close $flag