summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort <t@tjp.lol>2026-12-03 08:44:58 -0700
committert <t@tjp.lol>2026-12-04 13:53:47 -0700
commitf1f1c5bc66ea1d6019f84050aa21e4476330a719 (patch)
tree0ba0fe085a704b03e92d9cdcd29ddf089c7064dd
parentea36b1af7dc5e553b26c46b7dda2cb0dd5bcc2b7 (diff)
Preserve ACP sessions across Esc and resume unconditionally
Killing agy on Esc and defaulting save_session off forced cold ACP restarts that re-billed the flattened conversation transcript as uncached input. Storing session checkpoints in Panto's global state.toml also leaked unbounded per-session keys into UI preferences. Send ACP session/cancel on Esc with a non-extendable 3s SIGKILL fallback and reconcile post-cancel prefix hashes so follow-up prompts and /proceed keep the warm session. Remove save_session and panto.ext.state usage, tracking each ACP session's valid resume tip atomically under the isolated Google profile instead. Breaking: [providers.<name>].save_session is rejected; native session resume is now always enabled.
-rw-r--r--README.md4
-rw-r--r--acp.lua72
-rw-r--r--check.lua4
-rw-r--r--extensions/antigravity-acp.lua78
-rw-r--r--tests/fake-agy.lua11
-rw-r--r--tests/tui.exp3
6 files changed, 129 insertions, 43 deletions
diff --git a/README.md b/README.md
index e716063..bdfec39 100644
--- a/README.md
+++ b/README.md
@@ -65,11 +65,11 @@ Every ACP chat launch uses `--dangerously-skip-permissions` and `--sandbox`, eve
## Steering and thinking
-Plain Enter during a tool-using turn steers at the next tool boundary. Queued text and workflow notices go to the same live agy session as user input, not as tool output. Ctrl+Enter queues a separate follow-up. If an earlier failure left an unanswered text message, resume that Panto thread and press Ctrl+P (`/proceed`) in the idle TUI to send the pending message once; this requires the Panto build with direct `/proceed` provenance. Reload alone does not retry it. Ctrl+K shows thinking text **if agy sends it**; reasoning-token counts are not displayable text.
+Plain Enter during a tool-using turn steers at the next tool boundary. Queued text and workflow notices go to the same live agy session as user input, not as tool output. Ctrl+Enter queues a separate follow-up. Esc sends ACP `session/cancel` to stop the active turn while keeping the warm ACP session for the next prompt (force-killing `agy` if it does not settle within 3s). If an earlier failure left an unanswered text message, resume that Panto thread and press Ctrl+P (`/proceed`) in the idle TUI to send the pending message once; this requires the Panto build with direct `/proceed` provenance. Reload alone does not retry it. Ctrl+K shows thinking text **if agy sends it**; reasoning-token counts are not displayable text.
## Branch and resume
-Matching live turns keep the warm ACP session. With `save_session = true`, an exact saved checkpoint can resume natively (local state is written even under `--incognito`). Otherwise, the next direct submission after `/tree` or a cold resume starts a new ACP session: Panto sends its selected `history_transcript` as background and the new request once, in a single user message. Past tool calls and results are text, not dispatches. If Panto cannot supply the transcript for existing history, the turn fails rather than silently dropping context.
+Matching live turns keep the warm ACP session. Exact saved checkpoints record their current tip in the isolated profile and resume natively via ACP `session/resume`. Otherwise, the next direct submission after `/tree` or a cold resume starts a new ACP session: Panto sends its selected `history_transcript` as background and the new request once, in a single user message. Past tool calls and results are text, not dispatches. If Panto cannot supply the transcript for existing history, the turn fails rather than silently dropping context.
## Session boundaries
diff --git a/acp.lua b/acp.lua
index 9e648b9..f401a70 100644
--- a/acp.lua
+++ b/acp.lua
@@ -104,6 +104,35 @@ local function verified(run, on_error)
return cancel
end
M.probe = verified
+local function checkpoint_path(id)
+ assert(type(id)=='string' and #id>0 and #id<=128 and id:match('^[%w_-]+$'),'Invalid ACP session ID')
+ local dir=private_profile()..'/checkpoints'
+ local made,err,code=uv.fs_mkdir(dir,448); assert(made or code=='EEXIST',err)
+ local st=assert(uv.fs_lstat(dir)); assert(st.type=='directory' and st.uid==uv.getuid() and st.mode & 63==0,'Unsafe checkpoint directory')
+ return dir..'/'..id
+end
+function M.checkpoint(id, ...)
+ if select('#',...)==0 then
+ local ok,data=pcall(function()
+ local path=checkpoint_path(id)
+ local st=uv.fs_lstat(path); if not st or st.type~='file' or st.uid~=uv.getuid() then return nil end
+ local fd=uv.fs_open(path,'r',384); if not fd then return nil end
+ local v=uv.fs_read(fd,512,0); uv.fs_close(fd); return v
+ end)
+ return ok and data or nil
+ end
+ local value=(...)
+ local path=checkpoint_path(id)
+ if value==nil then
+ local ok,err,code=uv.fs_unlink(path); assert(ok or code=='ENOENT',err); return
+ end
+ local tmp=path..'.tmp.'..tostring(uv.hrtime())
+ local fd=assert(uv.fs_open(tmp,'wx',384))
+ local n,err=uv.fs_write(fd,value,0); assert(uv.fs_close(fd))
+ if n~=#value then uv.fs_unlink(tmp); error(err or 'Incomplete checkpoint write') end
+ local ok,rerr=uv.fs_rename(tmp,path)
+ if not ok then uv.fs_unlink(tmp); error(rerr) end
+end
-- 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.
@@ -115,8 +144,8 @@ local function install_agent(s, profile)
local made,err,code=uv.fs_mkdir(dir,448); assert(made or code=='EEXIST',err)
local st=assert(uv.fs_lstat(dir)); assert(st.type=='directory' and st.uid==uv.getuid() and st.mode & 18==0,'Unsafe agy agent directory')
end
- -- Saved sessions already hold an exclusive lock on this thread ID.
- local name='panto-'..(s.save and s.sid or s.dir:match('([^/]+)$')):lower()
+ -- Active threads hold an exclusive lock on this Panto session ID.
+ local name='panto-'..s.sid:lower()
local servers=json.array({})
if #s.list>0 then servers[1]=relay(s) end
local data=([[---
@@ -161,12 +190,12 @@ function M.launch(s, first, resume_id)
end
s.shutdown=function()
if closed then return end; closed=true
- local cancel=child and s.pending and s.session
- if cancel then pcall(send,{method='session/cancel',params={sessionId=s.session}}) end
+ local active_turn=child and (s.pending or s.cancelling) and s.session
+ if active_turn and not s.cancelling then pcall(send,{method='session/cancel',params={sessionId=s.session}}) end
if cancel_check then cancel_check() end
if s.agent_path then uv.fs_unlink(s.agent_path); s.agent_path=nil end
close(stdout)
- if cancel then timer:stop(); timer:start(500,0,cleanup) else cleanup() end
+ if active_turn then timer:stop(); timer:start(500,0,cleanup) else cleanup() end
end
local function step(co,...)
local ok,err=coroutine.resume(co,...); if not ok then s.fail(tostring(err)) end
@@ -178,15 +207,29 @@ function M.launch(s, first, resume_id)
serial=serial+1; steering[serial]=true
send({id=serial,method='session/prompt',params={sessionId=s.session,prompt=parts}})
end
- local function activity() if waiting then deadline=uv.now()+idle end end
+ local function activity() if waiting and not s.cancelling then deadline=uv.now()+idle end end
local function call(method,params)
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 or s.issued then activity() elseif uv.now()>=deadline then s.fail('ACP timeout: '..method) end
+ if not s.cancelling and (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
+ s.cancel=function()
+ if closed or not s.prompting or not s.session then return false end
+ if not s.cancelling then
+ s.cancelling=true
+ if not primary_reply or next(steering) then
+ send({method='session/cancel',params={sessionId=s.session}})
+ deadline=uv.now()+3000; timer:stop(); timer:start(100,100,function()
+ if uv.now()>=deadline then s.fail('ACP timeout: session/cancel') end
+ end)
+ end
+ end
+ s.settle()
+ return true
+ end
local selectors, opts, configuring = {}, {}, false
local function advertised()
local model=config(opts,s.selector)
@@ -228,6 +271,13 @@ function M.launch(s, first, resume_id)
s.prompting=true
if s.refresh then pcall(s.refresh) end
local r=call('session/prompt',{sessionId=s.session,prompt={{type='text',text=text}}})
+ if s.cancelling then
+ assert(r.stopReason=='cancelled' or r.stopReason=='end_turn' or r.stopReason=='max_tokens',
+ 'Turn stopped: '..tostring(r.stopReason))
+ s.prompting,s.cancelling=false,false; steer_usage,last_steer=nil,nil
+ if s.cancelled then s.cancelled() end
+ return
+ end
local reason=({end_turn='end_turn',max_tokens='max_tokens'})[r.stopReason]
assert(reason,'Turn stopped: '..tostring(r.stopReason))
local usage=M.usage(r.usage)
@@ -284,7 +334,7 @@ function M.launch(s, first, resume_id)
assert(waiting,'Unexpected ACP reply'); assert(not q.error,(q.error or {}).message or 'ACP error')
if steering[q.id] then
local r=assert(q.result); local reason=r.stopReason
- assert(not reason or reason=='end_turn' or reason=='max_tokens','ACP steering rejected: '..tostring(reason))
+ assert(s.cancelling or not reason or reason=='end_turn' or reason=='max_tokens','ACP steering rejected: '..tostring(reason))
if reason and (not last_steer or q.id>last_steer.id) then last_steer={id=q.id,reason=reason} end
local u=M.usage(r.usage); if u then
if steer_usage then for k,v in pairs(u) do steer_usage[k]=steer_usage[k]+v end else steer_usage=u end
@@ -301,11 +351,11 @@ function M.launch(s, first, resume_id)
local u=p.update
if u.sessionUpdate=='config_option_update' and s.wire and not configuring then
opts=u.configOptions or {}; assert(confirmed(),'Configured model or reasoning level changed'); advertised()
- elseif s.prompting and u.sessionUpdate=='usage_update' and count(u.used) and count(u.size) and u.size>0 and u.used<=u.size then
+ elseif s.prompting and not s.cancelling and u.sessionUpdate=='usage_update' and count(u.used) and count(u.size) and u.size>0 and u.used<=u.size then
s.context_window={used=u.used,size=u.size}
- elseif s.prompting and (u.sessionUpdate=='tool_call' or u.sessionUpdate=='tool_call_update') then
+ elseif s.prompting and not s.cancelling and (u.sessionUpdate=='tool_call' or u.sessionUpdate=='tool_call_update') then
pcall(s.observe,u) -- a cosmetic mount failure must not cancel an agy turn
- elseif (u.sessionUpdate=='agent_message_chunk' or u.sessionUpdate=='agent_thought_chunk') and u.content.type=='text' and s.prompting then
+ elseif (u.sessionUpdate=='agent_message_chunk' or u.sessionUpdate=='agent_thought_chunk') and u.content.type=='text' and s.prompting and not s.cancelling then
s.delta(u.sessionUpdate=='agent_message_chunk' and 'text' or 'thinking',u.content.text)
end
elseif q.id~=nil then send({id=q.id,error={code=-32601,message='Unsupported client method'}}) end
diff --git a/check.lua b/check.lua
index 8c6a915..36b8e2f 100644
--- a/check.lua
+++ b/check.lua
@@ -30,6 +30,8 @@ local function check()
{name='fixture.echo',description='Echo',input_schema_json='{"type":"object"}'}}}
local _,none=catalog(req,{}); assert(#none==0)
local by,one=catalog(req,{'std.read'}); assert(#one==1 and by.std__read and not by.fixture__echo)
+ local configure=dofile(root..'/extensions/antigravity-acp.lua').configure
+ assert(not pcall(configure,{providers={antigravity={protocol='antigravity-acp',save_session=true}}}))
local cfg, data = home .. '/.panto', home .. '/.local/share/panto'
assert(run('/bin/mkdir', {'-p', cfg .. '/extensions', data}) == 0)
assert(run('/bin/cp', {'-cR', assert(os.getenv('HOME')) .. '/.local/share/panto/rocks', data .. '/rocks'}) == 0)
@@ -42,7 +44,6 @@ local function check()
[providers.antigravity]
protocol="antigravity-acp"
-save_session=true
]])
write(cfg .. '/models.toml', '[antigravity.fast]\nmodel="gemini-test"\ninput=10.0\noutput=10.0\ncache_read=1.0\ncache_write=10.0\n')
write(cfg .. '/SYSTEM.md', 'Short answers.')
@@ -105,6 +106,7 @@ end}
if tui~=0 then error('TUI check failed: '..read(home..'/screen'):gsub('\27%[[0-9;?]*[A-Za-z]', ''):sub(-3500)) end
assert(uv.fs_stat(home..'/thinking-rendered'),'ACP thought did not reach the native thinking component')
local agents = assert(uv.fs_scandir(google .. '/config/agents')); assert(not uv.fs_scandir_next(agents), 'Generated agent left in private profile')
+ assert(not uv.fs_stat(data .. '/state.toml') or not read(data .. '/state.toml'):find('antigravity', 1, true), 'state.toml polluted with session checkpoint')
local screen = read(home .. '/screen'):gsub('\27%[[0-9;?]*[A-Za-z]', '')
assert(screen:find('1.3k/1M ctx',1,true),'expected ACP context occupancy, not summed turn inputs')
assert(screen:find('3.4k tok',1,true),'expected primary and steering usage counted exactly once')
diff --git a/extensions/antigravity-acp.lua b/extensions/antigravity-acp.lua
index 0f3faa9..52b067d 100644
--- a/extensions/antigravity-acp.lua
+++ b/extensions/antigravity-acp.lua
@@ -19,11 +19,25 @@ local function stop()
if s.lock then uv.fs_rmdir(s.lock) end
if s.notify then s.notify() end
end
+local function send(c,msg) msg.jsonrpc='2.0'; c:write(json.encode(msg)..'\n') 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 cancel_turn(id)
+ if failed_handoff and failed_handoff.sid==id then failed_handoff=nil end
+ local s=active; if not s or s.sid~=id or not (s.pending or s.cancelling) then return end
+ if s.card then s.card:unmount(); s.card=nil end
+ if s.call and s.peer and not s.peer:is_closing() then
+ pcall(send,s.peer,{id=s.call.id,error={code=-32800,message='Turn cancelled'}})
+ end
+ s.call,s.issued,s.queued=nil,nil,nil
+ s.pending,s.finished,s.chunks,s.bytes=false,nil,{},0
+ s.turn=(s.turn or 0)+1; s.last,s.cancelled_prefix=nil,s.turn_prefix
+ local ok,kept=false,false
+ if s.cancel then ok,kept=pcall(s.cancel) end
+ if not (ok and kept) then stop() end
+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' then
@@ -42,7 +56,7 @@ local function rpc(s,c,q)
if v==nil then v={} end
if not tool then return fail(-32602,'Tool unavailable') end
local ok,why=catalog.arguments(tool.schema,v); if not ok then return fail(-32602,why or 'Tool arguments rejected') end
- if not s.prompting then return fail(-32000,'No human turn pending') end
+ if not s.prompting or s.cancelling then return fail(-32000,'No human turn pending') end
if s.call then return fail(-32000,'Another Panto tool call is pending') end
s.seq=s.seq+1; s.call={id=q.id,tag=s.dir:match('[^/]+$')..'-'..s.seq,name=tool.name,input=json.encode(v)}; s.notify(); return
else return fail(-32601,'Unsupported method') end
@@ -79,7 +93,7 @@ local function native_activity(s)
s.card:invalidate()
end
end
-local function start(req,by,list,signature,save)
+local function start(req,by,list,signature)
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)
@@ -88,13 +102,10 @@ local function start(req,by,list,signature,save)
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')
- local lock='/tmp/panto-antigravity-lock-'..uv.getuid()..'-'..s.sid
- assert(uv.fs_mkdir(lock,448),'Saved thread locked: '..lock); s.lock=lock
- end
- s.key='antigravity_acp.checkpoint.'..s.sid
+ s.model,s.instructions,s.cwd,s.signature=req.model,req.system_prompt or '',assert(uv.cwd()),signature
+ assert(s.sid:match('^[%x-]+$'),'Invalid Panto session ID')
+ local lock='/tmp/panto-antigravity-lock-'..uv.getuid()..'-'..s.sid
+ assert(uv.fs_mkdir(lock,448),'Saved thread locked: '..lock); s.lock=lock
assert(s.server:bind(dir..'/mcp')); assert(s.server:listen(1,function(err)
if err or active~=s then return end
local c=uv.new_pipe(false); if not s.server:accept(c) or s.peer then c:close(); return end
@@ -134,9 +145,8 @@ local function history(msgs,n)
end
local function terminal(message) return {next=function() return {type='error',kind='terminal',message=message} end} end
local function validate(cfg)
- for _,key in ipairs({'save_session','usage_footer'}) do
- assert(cfg[key]==nil or type(cfg[key])=='boolean',key..' must be a boolean')
- end
+ assert(cfg.save_session==nil,'save_session was removed; saved Panto sessions resume natively')
+ assert(cfg.usage_footer==nil or type(cfg.usage_footer)=='boolean','usage_footer must be a boolean')
if cfg.tools~=nil then
assert(type(cfg.tools)=='table','tools must be a list of Panto tool names')
for i,name in pairs(cfg.tools) do assert(math.type(i)=='integer' and i>=1 and i<=#cfg.tools and type(name)=='string' and name~='', 'Invalid tools list') end
@@ -154,7 +164,7 @@ end,activate=function()
ext.register_command{name='antigravity-status',description='Show local Antigravity connection status (no account request).',handler=function()
if not active or not active.session then return 'Antigravity: no connected ACP session. Submit text to start; sign-in is managed by the Google CLI.' end
local model=(active.wire or active.model)..(active.thought and ' ('..active.thought..')' or '')
- return ('Antigravity: %s · %s · %d Panto tools · MCP %s · %d calls'):format(model,active.pending and 'turn pending' or 'ready',#active.list,active.listed and 'listed' or 'not listed',active.seq)
+ return ('Antigravity: %s · %s · %d Panto tools · MCP %s · %d calls'):format(model,active.pending and 'turn pending' or active.cancelling and 'cancelling' or 'ready',#active.list,active.listed and 'listed' or 'not listed',active.seq)
end}
ext.register_command{name='antigravity-models',description='List Gemini families and reasoning levels from the last ACP setup (no account request).',handler=function()
if not offers then return 'No model list yet. Submit a turn to let the Google CLI advertise its available models.' end
@@ -162,12 +172,12 @@ end,activate=function()
end}
ext.on('session_ready',function() ready=true 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)
+ ext.register_protocol{name='antigravity-acp',effort_levels=acp.effort_levels,close=stop,cancel_turn=cancel_turn,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
local msgs=req.messages; local last=msgs[#msgs]; local b=last and last.blocks[1]; local s=active
if s and s.sid~=req.context then
- if s.pending or not req.tui_submission then return terminal('Another thread owns this session') end
+ if s.pending or s.cancelling or not req.tui_submission then return terminal('Another thread owns this session') end
stop(); s=nil
end
local direct=req.tui_submission==true
@@ -216,14 +226,15 @@ end,activate=function()
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
local prior=msgs[#msgs-1]; local tag=prior and prior.metadata and prior.metadata.antigravity_acp
- local key='antigravity_acp.checkpoint.'..req.context
- if prior or s then
+ local after_cancel=s and s.sid==req.context and s.signature==sig and s.cancelled_prefix and
+ (history(msgs,#msgs-1)==s.cancelled_prefix or history(msgs,#msgs)==s.cancelled_prefix)
+ if not after_cancel and (prior or s) then
local reply={}; for _,v in ipairs(prior and prior.blocks or {}) do
if v.type~='text' and v.type~='thinking' then reply=nil; break end
append_reply(reply,v.type,v.text)
end
if not (tag and tag.thread==req.context and tag.signature==sig and tag.history==history(msgs,#msgs-2) and reply and tag.response==reply_key(reply) and
- ((s and s.last==tag.turn) or (not s and cfg.save_session==true and tag.session and ext.state.get(key)==tag.turn))) then
+ ((s and s.last==tag.turn) or (not s and tag.session and acp.checkpoint(tag.session)==tag.turn))) then
if not direct then return terminal('Extension follow-up requires a matching live Antigravity checkpoint') end
stop(); s=nil; tag=nil
if prior then
@@ -234,8 +245,8 @@ end,activate=function()
end
end
if not s then
- local ok,value=pcall(start,req,by,list,sig,cfg.save_session==true); if not ok then stop(); return terminal(tostring(value)) end; s=value
- if tag and s.save and ext.state.get(key)~=tag.turn then stop(); return terminal('Saved Antigravity checkpoint changed') end
+ local ok,value=pcall(start,req,by,list,sig); if not ok then stop(); return terminal(tostring(value)) end; s=value
+ if tag and acp.checkpoint(tag.session)~=tag.turn then stop(); return terminal('Saved Antigravity checkpoint changed') end
end
if s.resolve then
local wire,why=s.resolve(req.effort); if not wire then return terminal(why) end
@@ -243,8 +254,12 @@ end,activate=function()
if s.card then s.card:unmount(); s.card=nil end
s.observe=native_activity(s); s.context_window=nil; s.usage=nil
s.effort=req.effort
- if s.save then local ok,err=ext.state.set(key,nil); if not ok then stop(); return terminal(tostring(err)) end end
- s.pending=true; s.notify=req.notify; s.chunks={}; s.bytes=0; s.response={}; s.prefix=history(msgs,#msgs)
+ local active_session=s.session or (tag and tag.session)
+ if active_session then
+ local ok,err=pcall(acp.checkpoint,active_session,nil); if not ok then stop(); return terminal(tostring(err)) end
+ end
+ s.cancelled_prefix=nil; s.turn_prefix=history(msgs,#msgs)
+ s.pending=true; s.notify=req.notify; s.chunks={}; s.bytes=0; s.response={}; s.prefix=s.turn_prefix
s.delta=function(kind,text)
assert(type(text)=='string' and s.bytes+#text<=4<<20,'Invalid ACP text'); if text=='' then return end
local tail=s.chunks[#s.chunks]; if tail and tail.kind==kind then tail.text=tail.text..text
@@ -257,13 +272,20 @@ end,activate=function()
s.usage=usage
assert(not s.call,'Prompt ended with an outstanding MCP call'); s.last=s.dir..':'..tostring(s.turn); s.finished=reason; s.notify()
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
+ s.turn=(s.turn or 0)+1; local started=s.turn
+ s.cancelled=function()
+ local q=s.queued
+ if q and s.pending and s.turn==started then s.queued=nil; s.submit(q) end
+ end
+ local ok,err=pcall(function()
+ if s.cancelling then s.queued=prompt elseif 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
end
- s.notify=req.notify
+ s.notify=req.notify; local turn_id=s.turn
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 turn_id~=s.turn then return nil 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)
@@ -272,8 +294,8 @@ end,activate=function()
if s.finished then
local reason=s.finished; s.finished=nil; s.pending=false
if s.refresh then pcall(s.refresh) end
- if s.save then assert(ext.state.set(s.key,s.last)) end
- return {type='done',usage=s.usage,termination={reason=reason},metadata={context_window=s.context_window,antigravity_acp={thread=s.sid,session=s.save and s.session or nil,turn=s.last,signature=s.signature,history=s.prefix,response=reply_key(s.response)}}}
+ acp.checkpoint(s.session,s.last)
+ return {type='done',usage=s.usage,termination={reason=reason},metadata={context_window=s.context_window,antigravity_acp={thread=s.sid,session=s.session,turn=s.last,signature=s.signature,history=s.prefix,response=reply_key(s.response)}}}
end
local call=s.call; if not call then return nil end
-- A single ACP prompt can span many Panto messages. Publish its
diff --git a/tests/fake-agy.lua b/tests/fake-agy.lua
index 4f76d8d..b1537ad 100644
--- a/tests/fake-agy.lua
+++ b/tests/fake-agy.lua
@@ -141,11 +141,20 @@ elseif resumed then local resumed_prompt=prompt('resume'); check_relay(); finish
if current~='boundary workflow notice' then assert(text:find('[Assistant]: primary-tool-ok',1,true)) end
if current=='branch-probe' then
finish(q,'branch-seed-ok'); finish(prompt('warm-probe'),'warm-after-seed-ok')
+ local esc=prompt('esc-probe')
+ send({method='session/update',params={sessionId='test-session',update={
+ sessionUpdate='agent_message_chunk',content={type='text',text='esc-window-open'},
+ }}})
+ local cancel=request('session/cancel'); assert(cancel.id==nil and cancel.params.sessionId=='test-session')
+ reply(esc,{stopReason='cancelled'})
+ finish(prompt('after-esc-probe'),'after-esc-ok')
reply(prompt('cancel-probe'),{stopReason='cancelled'})
elseif current=='boundary workflow notice' then
assert(text:find('[User]: boundary steer',1,true) and text:find('[Tool result',1,true)); finish(q,'proceed-recovered-ok')
else
- assert(current=='cold-probe' and text:find('[Assistant]: warm-after-seed-ok',1,true)); finish(q,'cold-resume-ok')
+ assert(current=='cold-probe' and text:find('[Assistant]: warm-after-seed-ok',1,true)
+ and text:find('[User]: esc-probe',1,true) and not text:find('esc-window-open',1,true)
+ and text:find('[Assistant]: after-esc-ok',1,true)); finish(q,'cold-resume-ok')
end
else
q = prompt('hello')
diff --git a/tests/tui.exp b/tests/tui.exp
index 77d3537..fdbad27 100644
--- a/tests/tui.exp
+++ b/tests/tui.exp
@@ -36,6 +36,9 @@ send -- "primary-tool-ok"; after 150; send -- "\r"; see {branched from}
foreach {query answer} {branch-probe branch-seed-ok warm-probe warm-after-seed-ok} {
send -- $query; see $query; send -- "\r"; see $answer
}
+send -- "esc-probe"; see {esc-probe}; send -- "\r"; see {esc-window-open}
+send -- "\033"; see {\[interrupted\]}
+send -- "after-esc-probe"; see {after-esc-probe}; send -- "\r"; see {after-esc-ok}
# The installed module's longer path can wrap the error across terminal rows.
send -- "cancel-probe"; see {cancel-probe}; send -- "\r"; see {stopped:}; see {cancelled}
send -- "\003"; expect eof; wait