From 8c167c49f18c76f1f867778341ac821591d9d990 Mon Sep 17 00:00:00 2001 From: t Date: Thu, 3 Dec 2026 16:43:51 -0700 Subject: Carry oversized history reseeds in the system prompt append agy keeps only the first ~191 KB of a user message, so a large cold reseed dropped the newest history and the current request. When transcript plus request exceed 160 KB, move the older part of the transcript into the new session's system prompt append, framed as a verbatim record, and keep the newest part with the request in one user message. Refuse a single request too large to fit. Record the probes in docs/findings.md and the separate ~9.9 KB MCP tool result cap in BUGS.md. --- acp.lua | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'acp.lua') diff --git a/acp.lua b/acp.lua index f401a70..bf3919d 100644 --- a/acp.lua +++ b/acp.lua @@ -177,6 +177,28 @@ function M.usage(u) if i+o==t and r+w<=i then i=i-r-w elseif i+o+r+w~=t then return end return {input=i,output=o,cache_read=r,cache_write=w,reasoning=h} end +-- agy 1.5.22 keeps only the first ~191 KB of a user message, including text +-- split across content or resource blocks. systemPrompt.append has no such cap +-- and persists across session/resume, so an oversized reseed carries the older +-- history there. Returns that head and the newest tail of at most `room` bytes, +-- cut before a transcript entry when one starts in the tail's first half and +-- never inside a UTF-8 character. head..tail == text. +M.message_bytes = 160000 +function M.history_split(text, room) + if room >= #text then return '', text end + if room <= 0 then return text, '' end + local at = #text - room + 1 + local entry = text:find('\n\n[', math.max(at - 2, 1), true) + if entry and entry + 2 - at <= room // 2 then at = entry + 2 + else while (text:byte(at) or 0) & 0xC0 == 0x80 do at = at + 1 end end + return text:sub(1, at - 1), text:sub(at) +end +local function add_usage(total, u) + if not u then return total end + if not total then return u end + for k, v in pairs(u) do total[k] = total[k] + v end + return total +end function M.launch(s, first, resume_id) local cancel_check local child, pid, stdin, stdout, waiting, timer, serial=nil,nil,nil,nil,nil,uv.new_timer(),0 @@ -280,10 +302,7 @@ function M.launch(s, first, resume_id) 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) - if steer_usage then - if usage then for k,v in pairs(steer_usage) do usage[k]=usage[k]+v end else usage=steer_usage end - end + local usage=add_usage(M.usage(r.usage),steer_usage) s.prompting=false; s.complete(last_steer and last_steer.reason or reason,usage); steer_usage,last_steer=nil,nil end s.submit=function(text) step(coroutine.create(turn),text) end @@ -301,9 +320,10 @@ function M.launch(s, first, resume_id) assert((caps.sessionCapabilities or {}).resume,'ACP resume unavailable'); params.sessionId=resume_id session=call('session/resume',params); assert(not session.sessionId or session.sessionId==resume_id,'Wrong resumed session'); s.session=resume_id else - if s.instructions~='' then + local append=s.instructions..(s.record or '') + if append~='' then assert(((((caps._meta or {}).antigravity or {}).systemPrompt or {}).append)==true,'Rig instruction append unavailable') - params._meta.antigravity={systemPrompt={append=s.instructions}} + params._meta.antigravity={systemPrompt={append=append}} end session=call('session/new',params); assert(type(session.sessionId)=='string' and #session.sessionId>0,'Missing session ID'); s.session=session.sessionId end -- cgit v1.3