@@ -1673,6 +1673,63 @@ describe("OpenAI Compatible - Responses API conversation continuity", () => {
16731673 const args = mockResponsesCreate . mock . calls [ 1 ] [ 0 ]
16741674 expect ( args ) . not . toHaveProperty ( "previous_response_id" )
16751675 } )
1676+ it ( "does not include previous_response_id when prior stream fails before id; defaults to store:true" , async ( ) => {
1677+ // First call: stream throws before emitting any response.id
1678+ mockResponsesCreate
1679+ . mockImplementationOnce ( async ( _opts : any ) => {
1680+ return {
1681+ [ Symbol . asyncIterator ] : async function * ( ) {
1682+ yield { type : "response.text.delta" , delta : "Partial " }
1683+ throw new Error ( "stream interrupted" )
1684+ } ,
1685+ }
1686+ } )
1687+ // Second call: normal stream
1688+ . mockImplementationOnce ( async ( _opts : any ) => {
1689+ return {
1690+ [ Symbol . asyncIterator ] : async function * ( ) {
1691+ yield { type : "response.text.delta" , delta : "OK" }
1692+ yield {
1693+ type : "response.completed" ,
1694+ response : { usage : { input_tokens : 1 , output_tokens : 1 } } ,
1695+ }
1696+ } ,
1697+ }
1698+ } )
1699+
1700+ const handler = new OpenAiHandler ( {
1701+ openAiApiKey : "k" ,
1702+ openAiModelId : "gpt-5-mini" ,
1703+ openAiBaseUrl : "https://api.openai.com/v1/responses" ,
1704+ } )
1705+
1706+ // First call fails mid-stream, so no response.id is captured
1707+ const first = handler . createMessage ( "You are Roo." , [
1708+ { role : "user" , content : [ { type : "text" as const , text : "Hi" } ] } ,
1709+ ] )
1710+
1711+ await expect ( async ( ) => {
1712+ for await ( const _ of first ) {
1713+ // drain until error
1714+ }
1715+ } ) . rejects . toThrow ( "stream interrupted" )
1716+
1717+ // Second call should not include previous_response_id and should default to store:true
1718+ const chunks : any [ ] = [ ]
1719+ for await ( const ch of handler . createMessage ( "You are Roo." , [
1720+ { role : "user" , content : [ { type : "text" as const , text : "Hi" } ] } ,
1721+ ] ) ) {
1722+ chunks . push ( ch )
1723+ }
1724+
1725+ expect ( mockResponsesCreate ) . toHaveBeenCalledTimes ( 2 )
1726+ const secondArgs = mockResponsesCreate . mock . calls [ 1 ] [ 0 ]
1727+ expect ( secondArgs ) . not . toHaveProperty ( "previous_response_id" )
1728+ expect ( secondArgs ) . toHaveProperty ( "store" , true )
1729+ expect ( typeof secondArgs . input ) . toBe ( "string" )
1730+ expect ( secondArgs . input ) . toContain ( "Developer: You are Roo." )
1731+ expect ( secondArgs . input ) . toContain ( "User: Hi" )
1732+ } )
16761733} )
16771734
16781735// --- New: Responses API parity improvements tests ---
0 commit comments