diff options
| -rw-r--r-- | BUGS.md | 26 | ||||
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | catalog.lua | 35 | ||||
| -rw-r--r-- | check.lua | 5 | ||||
| -rw-r--r-- | docs/findings.md | 14 | ||||
| -rw-r--r-- | extensions/antigravity-acp.lua | 41 | ||||
| -rw-r--r-- | tests/fake-agy.lua | 18 |
7 files changed, 100 insertions, 41 deletions
diff --git a/BUGS.md b/BUGS.md deleted file mode 100644 index b984026..0000000 --- a/BUGS.md +++ /dev/null @@ -1,26 +0,0 @@ -# Known bugs - -## agy cuts MCP tool results to ~9.9 KB before the model sees them - -**Status:** open, not investigated further. Found 2026-12-03 while probing history reseed; `agy --version` reported 1.5.23 that day. - -**Effect:** any Panto tool result (`std.read`, `std.shell`, ...) larger than about 10 KB reaches Gemini with its middle removed. agy keeps roughly the first and last halves of 9,860–9,862 bytes, inserts `<truncated N of M bytes from the middle of the output>`, and prefixes: - -> The tool's output was truncated due to being too long. You can find the full output in a file at file:///…/antigravity-cli/brain/<session>/.system_generated/steps/<n>/output.txt. - -The model can't read that file: agy's native tools are disabled, and reading it through a Panto tool hits the same cap. - -Panto's own transcript keeps the full result, so the TUI shows output the model never received, and a cold reseed hands the model more than the warm session ever saw. - -**Evidence:** -- Live probe (Hydrogen, stdio MCP server with `antigravity/alwaysLoad`): a 10,386-byte text result was stored and sent to the model as 9,862 bytes with 606 cut from the middle. Confirmed in the model request (`gen_metadata.data`), not only in the stored step. -- Existing conversations in `~/.local/share/panto-antigravity/google/antigravity-cli/conversations/*.db`: 135 tool results carry the same marker, every one kept at exactly 9,860 or 9,862 bytes, from originals of 10,279 up to 816,745 bytes. For these the marker was matched in stored steps only; the model request was not inspected. -- MCP `resources/read` of a 20 KB resource is worse: nothing is inlined, the whole body goes to a `resource_0.txt` spill file. - -**Not yet checked:** -- Whether the cap is per tool result or per content block. If per block, the relay could split a large text result into several blocks. -- Whether a setting, agent-definition field or tool `_meta` hint raises it. -- Whether image or other non-text blocks are exempt. One real `std__read` step is 65 KB and carries no marker. -- Whether the cap is bytes or tokens. - -**Reproduce:** serve one MCP tool that returns more than 10 KB of text, have the model call it, then search the conversation DB's `steps.step_payload` for `truncated`. Probe scripts were at `/tmp/agy-probe/mcp_big.py` and `probe3.py` (temporary; not in this repo). @@ -48,6 +48,8 @@ By default the `pantograph` MCP server exports the active Panto tools, including **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. +**Large results:** agy cuts the middle out of any MCP tool result over about 10 KB and points the model at a file it has no tool to read. The relay therefore sends text results over 10,000 bytes in parts of at most 9,600 bytes: the first with the tool's reply, the rest when the model asks for them through the relay's own `result_part` tool. The tool runs once, and Panto's card and transcript show the whole result; part requests are not Panto tool calls and get no card. Fetching the remaining parts usually takes one more model call in the same turn. The model may also stop after the parts it needs. The relay holds the eight most recent large results of the live session; a part requested after a restart or after eight newer ones is refused, and the model is told to run the tool again. Image results are passed through unchanged; whether agy caps them is unverified. + ### Native tool activity 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. diff --git a/catalog.lua b/catalog.lua index 31297d0..d4b0c80 100644 --- a/catalog.lua +++ b/catalog.lua @@ -1,5 +1,38 @@ local json = require('panto').ext.json local M = {} +-- agy 1.5.23 cuts the middle out of any MCP tool result it would store above +-- 10,240 bytes (its built-in tool-output-max-bytes flag). Content blocks are +-- joined first and its own ~80-byte timestamp header counts. The model is +-- pointed at a spill file it has no tool to read, and no block type or setting +-- avoids the cut, so the relay sends larger text in parts: the first with the +-- result, the rest on request through this relay-only tool. docs/findings.md. +M.result_bytes = 10000 +M.part_tool = {name='result_part', + description='Return one later part of a tool result that was too large for a single reply. Use it only when a result says it has more parts.', + inputSchema={type='object',properties={result={type='integer'},part={type='integer',minimum=1}},required={'result','part'}}, + _meta={['antigravity/alwaysLoad']=true}} +-- Consecutive pieces of at most result_bytes-400 bytes (room for the notice), +-- ending on a newline when the piece's second half has one and never inside a +-- UTF-8 character. table.concat(pages) == text. +function M.pages(text) + local size, out, at = M.result_bytes - 400, {}, 1 + while #text - at + 1 > size do + local stop = at + size - 1 + local nl = text:sub(at, stop):match('^.*()\n') + if nl and nl > size // 2 then stop = at + nl - 1 + else for _ = 1, 3 do if (text:byte(stop + 1) or 0) & 0xC0 ~= 0x80 then break end; stop = stop - 1 end end + out[#out + 1] = text:sub(at, stop); at = stop + 1 + end + out[#out + 1] = text:sub(at); return out +end +-- What the model receives for part i of result n. The wording was checked +-- against live Hydrogen: it fetched every remaining part in one response. +function M.part(pages, n, i) + if i > 1 then return ('[pantograph: part %d of %d of result %d]\n'):format(i, #pages, n) .. pages[i] end + local bytes = 0; for _, p in ipairs(pages) do bytes = bytes + #p end + return pages[1] .. ('\n\n[pantograph: this is part 1 of %d of result %d (%d bytes in all); the tool ran once and nothing was lost. Call result_part with result=%d and part=2%s for the rest, requesting every part you need in a single response.]') + :format(#pages, n, bytes, n, #pages > 2 and ' through ' .. #pages or '') +end function M.catalog(req, names) local all, by, list = {}, {}, json.array({}) for _,t in ipairs(req.tools) do all[t.name]=t end @@ -9,7 +42,7 @@ function M.catalog(req, names) for i,name in ipairs(names) do local t=assert(all[name], 'Tool not in active rig: '..name); local s=json.decode(t.input_schema_json) assert(s.type=='object','Expected MCP object input schema for '..name) - local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire], 'Invalid or colliding MCP tool name: '..name) + local wire=name:gsub('%.','__'); assert(wire:match('^[%w_-]+$') and #wire<=128 and not by[wire] and wire~=M.part_tool.name, 'Invalid or colliding MCP tool name: '..name) by[wire]={name=name,schema=s}; list[i]={name=wire,description=t.description,inputSchema=s,_meta={['antigravity/alwaysLoad']=true}} end return by,list @@ -34,7 +34,10 @@ local function check() local u={inputTokens=155,outputTokens=41,thoughtTokens=8,cachedReadTokens=55,cachedWriteTokens=10,totalTokens=196} local v=usage(u); assert(v.input==90 and v.output==41 and v.cache_read==55 and v.cache_write==10 and v.reasoning==8) u.totalTokens=261; assert(usage(u).input==155); u.totalTokens=99; assert(not usage(u) and not usage({}) and not usage(nil)) - local catalog=dofile(root..'/catalog.lua').catalog + local cat=dofile(root..'/catalog.lua'); local catalog=cat.catalog + local wide='a'..('\u{754C}'):rep(8000); local pages=cat.pages(wide) -- no newline to cut at: characters stay whole + assert(#pages==3 and table.concat(pages)==wide and #cat.pages('abc')==1) + for i,p in ipairs(pages) do assert(utf8.len(p) and #cat.part(pages,7,i)<=cat.result_bytes) end local req={tools={{name='std.read',description='Read',input_schema_json='{"type":"object"}'}, {name='fixture.echo',description='Echo',input_schema_json='{"type":"object"}'}}} local _,none=catalog(req,{}); assert(#none==0) diff --git a/docs/findings.md b/docs/findings.md index 467e395..8b5efd7 100644 --- a/docs/findings.md +++ b/docs/findings.md @@ -45,7 +45,19 @@ A cold `/tree` reseed of a 756 KB transcript answered the session's first prompt - The same bytes in `_meta.antigravity.systemPrompt.append`: complete at 492 KB (149k input tokens) and 1.48 MB (433k). - Four `session/prompt` requests sent without waiting: each became its own user message, uncut, but stored out of order (part 2, question, part 1, part 3). Staggered 300 ms they arrived in order, yet ACP gives no per-prompt acknowledgement, so the order is a timing race. With 2 KB parts: no delay gave one model call in a different shuffled order every run; 20–100 ms between every send kept order but the first part ran its own model call; a short opener, one 20 ms wait, then a burst was shuffled in 4 of 4 runs and the opener's reply leaked as visible text in 2. - Awaiting each part's reply is ordered but costs a model call and an agy-only assistant turn per part. Rejected. -- `resource_link` blocks: the model receives the path only. MCP tool results are cut to ~9.9 KB and `resources/read` bodies are spilled to a file (see `BUGS.md`), so no tool route can carry a transcript. +- `resource_link` blocks: the model receives the path only. MCP tool results are cut to ~9.9 KB and `resources/read` bodies are spilled to a file (see the next section), so no tool route can carry a transcript. - Overflow split, 246 KB in the append plus a 103 KB user message: one model call (107k input tokens), every marker present and in order in the stored model request, nothing truncated. After `session/resume` in a fresh process with no append re-sent, the model quoted a line from the append it had never output, with 106,982 cached-read tokens. A resume that does send an append takes effect too; whether it replaces or adds to the stored one is untested and the adapter never does it. The adapter therefore keeps one user message and moves only the older history that does not fit into the system prompt append of the new session. Costs: that history sits at system level, framed as a record; agy's own context management cannot reclaim it; and agy appears to store the append with every user step, so a seeded conversation's database grows by about the record's size per turn. In the probe a one-line prompt after resume was stored as a 250 KB step; in ordinary sessions every user step is ~12 KB regardless of prompt length, consistent with it carrying the rig instructions. This is disk only: the resumed call read the record from cache. + +## MCP tool result cap (agy 1.5.23, December 2026) + +agy cuts the middle out of a large MCP tool result before the model sees it: it keeps the head and tail, inserts `<truncated N of M bytes from the middle of the output>` and prefixes `The tool's output was truncated due to being too long. You can find the full output in a file at file:///…/brain/<session>/.system_generated/steps/<n>/output.txt.` The model cannot read that file: native tools are disabled, and reading it through a Panto tool hits the same cap. Panto's transcript kept the full result, so the TUI showed output the model never received. + +- Size. In the profile's conversation databases about 140 tool results carry the marker, each stored at 10,237–10,240 bytes, from originals up to 816,745 bytes. The largest unmarked relay result is 10,214 bytes. The stored text includes agy's own `Created At` / `Completed At` header (78 bytes), so about 10,160 bytes of payload fit. The binary's embedded default flags contain `"tool-output-max-bytes": 10240`, and its changelog for 1.4.7 says MCP results "of up to 10 KB" are returned directly. The limit is bytes, not tokens. +- No setting found. Agent frontmatter keys, `settings.json` keys in the changelog and the `AGY_*` environment names in the binary offer nothing for it. Internal config fields exist (`mcp_max_output_bytes`, `ToolOutputConfig.max_output_bytes`), but no user-facing route to them was found. Overriding flags through `AGY_CLI_VARIANTS` or rewriting results with a `PostToolUse` hook (`overwriteResult`, 1.5.21) was not tried. +- Per result, not per block (live Hydrogen, standalone ACP client, marker tokens). Four 8 KB `text` blocks in one result were joined and cut as one (`<truncated 23293 of 33155 bytes …>`, 2 of 8 markers reached the model request). Two 8 KB embedded `resource` blocks: same (`6788 of 16650`). A 20 KB `resources/read` body is not inlined at all; it goes to a `resource_0.txt` spill file. +- Parts work. The same 33 KB served as four results of at most 9.6 KB, the first ending with a notice naming a `result_part` tool: the model requested parts 2–4 in a single response, all 8 markers were in the final model request, nothing was truncated. Three model calls in total; agy ran the three part calls one after another, about 1.2 s each. +- Not checked: whether image blocks count toward the cap. An earlier 65 KB `std__read` step without a marker turned out to be 58 KB of thought signature around a small result. + +The relay therefore sends text over 10,000 bytes in parts of at most 9,600 bytes and answers `result_part` itself from the eight most recent large results. The tool runs once; Panto never sees the part requests. diff --git a/extensions/antigravity-acp.lua b/extensions/antigravity-acp.lua index cdeb38a..d994cb3 100644 --- a/extensions/antigravity-acp.lua +++ b/extensions/antigravity-acp.lua @@ -50,18 +50,40 @@ local function rpc(s,c,q) local result if q.method=='initialize' then result={protocolVersion='2025-06-18',capabilities={tools={}},serverInfo={name='pantograph',version='0.1'}} elseif q.method=='ping' then result={} - elseif q.method=='tools/list' then s.listed=true; result={tools=s.list} + elseif q.method=='tools/list' then + -- result_part stays out of s.list, which is part of the checkpoint signature. + s.listed=true; local tools=json.array({}); for i,t in ipairs(s.list) do tools[i]=t end + tools[#tools+1]=catalog.part_tool; result={tools=tools} elseif q.method=='tools/call' then local args=q.params or {}; local tool=s.by[args.name]; local v=args.arguments 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 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 + if args.name==catalog.part_tool.name then + -- Answered here, not dispatched: Panto's transcript already holds the whole result. + if not catalog.arguments(catalog.part_tool.inputSchema,v) then return fail(-32602,'Tool arguments rejected') end + local pages; for _,r in ipairs(s.results) do if r.n==v.result then pages=r.pages end end + local text=pages and pages[v.part] and catalog.part(pages,v.result,v.part) + result={isError=not text,content=json.array({{type='text',text=text or (pages and ('Result %d has parts 1 to %d.'):format(v.result,#pages) + or 'That result is no longer held: only the 8 most recent large results of the running session are kept. Run the original tool again, asking for less output if it can.')}})} + else + 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 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 + end else return fail(-32601,'Unsupported method') end send(c,{id=q.id,result=result}) end +-- Text over agy's MCP result cap goes out in parts; see catalog.result_bytes. +local function paged(s,parts) + local texts,out={},json.array({}) + for _,v in ipairs(parts) do if v.type=='text' then texts[#texts+1]=v.text else out[#out+1]=v end end + local text=table.concat(texts,'\n\n'); if #text<=catalog.result_bytes then return parts end + -- Clock-based so a number quoted by a natively resumed session never names a newer relay's result. + local pages,n=catalog.pages(text),math.max(os.time(),(s.results[#s.results] or {n=0}).n+1) + s.results[#s.results+1]={n=n,pages=pages}; if #s.results>8 then table.remove(s.results,1) end + table.insert(out,1,{type='text',text=catalog.part(pages,n,1)}); return out +end -- ACP tool notifications are observations, NOT Panto tool invocations. Keep -- a small live component for the current/last prompt; never enter tool dispatch. local function native_activity(s) @@ -74,7 +96,8 @@ local function native_activity(s) if not row then local name=u.name or (type(u.title)=='string' and u.title:match('^Run ([%w_.-]+)$')) if type(name)~='string' or #name>96 or not name:match('^[%w_.-]+$') then return end - if s.by[name:match('^mcp_pantograph_(.+)$') or false] then return end + local relayed=name:match('^mcp_pantograph_(.+)$') + if relayed and (s.by[relayed] or relayed==catalog.part_tool.name) then return end row={id=id,name=name,status='reported'}; rows[#rows+1]=row if #rows>6 then table.remove(rows,1) end end @@ -95,7 +118,7 @@ local function native_activity(s) end 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 + local s={sid=req.context,dir=dir,server=uv.new_pipe(false),by=by,list=list,seq=0,results={},notify=req.notify}; active=s s.fail=function(msg) if active~=s then return end s.error=tostring(msg):gsub('[%c]',' '):sub(1,512) @@ -214,7 +237,7 @@ end,activate=function() 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 + send(s.peer,{id=awaiting.id,result={isError=failed,content=paged(s,parts)}}); s.call=nil end s.issued=nil; s.settle() elseif s and s.pending then diff --git a/tests/fake-agy.lua b/tests/fake-agy.lua index 904f3bf..3f1643a 100644 --- a/tests/fake-agy.lua +++ b/tests/fake-agy.lua @@ -58,7 +58,7 @@ local function load_catalog(server) assert(rpc(1, 'initialize').result.serverInfo.name == 'pantograph') 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') + assert(schemas.std__read and schemas.std__edit and schemas.result_part and schemas.fixture__echo.properties.rows.items.required[1]=='value') return function(late_prompt) if late_prompt then write(7,'tools/call',{name='fixture__echo',arguments={rows={{value=43}}}}) @@ -78,10 +78,22 @@ local function load_catalog(server) 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)) -- Push later transcript reseeds past one agy message (acp.message_bytes). + -- Each result is over agy's MCP result cap, so it arrives in parts. for i=1,4 do - local f=rpc(20+i,'tools/call',{name='std__read',arguments={path=uv.cwd()..'/.panto/history-filler.txt'}}).result - assert(f.isError==false and #f.content[1].text>40000) + local f=rpc(i*20,'tools/call',{name='std__read',arguments={path=uv.cwd()..'/.panto/history-filler.txt'}}).result + assert(f.isError==false and #f.content==1 and #f.content[1].text<=10000,'large result over the agy cap') + local text,parts,n=f.content[1].text:match('^(.*)\n\n%[pantograph: this is part 1 of (%d+) of result (%d+) ') + assert(parts,'large result not sent in parts') + for part=2,tonumber(parts) do + local more=rpc(i*20+part,'tools/call',{name='result_part',arguments={result=tonumber(n),part=part}}).result + assert(more.isError==false and #more.content[1].text<=10000) + text=text..assert(more.content[1].text:match('^%[pantograph: part '..part..' of '..parts..' of result '..n..'%]\n(.*)$')) + end + local last=0; for line in text:gmatch('filler line (%d%d%d%d) abcdefghij') do assert(tonumber(line)==last+1,'parts lost or reordered text'); last=last+1 end + assert(#text>40000 and last>1400) end + assert(rpc(10,'tools/call',{name='result_part',arguments={result=999,part=2}}).result.isError==true) + assert(rpc(11,'tools/call',{name='result_part',arguments={result='1',part=2}}).error.code==-32602) -- Keep the peer connected for subsequent turns. end end |
