@@ -241,6 +241,63 @@ describe("opencode run (non-interactive subprocess)", () => {
241241 60_000 ,
242242 )
243243
244+ cliIt . concurrent (
245+ "recovers from a provider size error via compaction without emitting an error event" ,
246+ ( { llm, opencode } ) =>
247+ Effect . gen ( function * ( ) {
248+ yield * llm . error ( 413 , {
249+ error : { type : "request_too_large" , message : "Request exceeds the maximum size" } ,
250+ } )
251+ yield * llm . text ( "compacted history" )
252+ yield * llm . text ( "recovered output" )
253+
254+ const result = yield * opencode . run ( "recover after overflow" , {
255+ format : "json" ,
256+ env : { OPENCODE_DISABLE_AUTOCOMPACT : "0" } ,
257+ } )
258+
259+ opencode . expectExit ( result , 0 )
260+ const events = opencode . parseJsonEvents ( result . stdout )
261+ expect ( events . some ( ( event ) => event . type === "error" ) ) . toBe ( false )
262+ expect (
263+ events . some (
264+ ( event ) =>
265+ event . type === "text" &&
266+ typeof event . part === "object" &&
267+ event . part !== null &&
268+ "text" in event . part &&
269+ event . part . text === "recovered output" ,
270+ ) ,
271+ ) . toBe ( true )
272+ } ) ,
273+ 60_000 ,
274+ )
275+
276+ cliIt . concurrent (
277+ "exits nonzero with an error event when compaction cannot shrink the session" ,
278+ ( { llm, opencode } ) =>
279+ Effect . gen ( function * ( ) {
280+ yield * llm . error ( 413 , {
281+ error : { type : "request_too_large" , message : "Request exceeds the maximum size" } ,
282+ } )
283+ yield * llm . error ( 413 , {
284+ error : { type : "request_too_large" , message : "Request exceeds the maximum size" } ,
285+ } )
286+
287+ const result = yield * opencode . run ( "overflow beyond recovery" , {
288+ format : "json" ,
289+ env : { OPENCODE_DISABLE_AUTOCOMPACT : "0" } ,
290+ } )
291+
292+ opencode . expectExit ( result , 1 )
293+ const events = opencode . parseJsonEvents ( result . stdout )
294+ const errors = events . filter ( ( event ) => event . type === "error" )
295+ expect ( errors . length ) . toBe ( 1 )
296+ expect ( JSON . stringify ( errors [ 0 ] ) ) . toContain ( "too large to compact" )
297+ } ) ,
298+ 60_000 ,
299+ )
300+
244301 cliIt . concurrent (
245302 "rejects requested permissions by default and allows them with the dangerous flag" ,
246303 ( { home, llm, opencode } ) =>
0 commit comments