{"record":{"id":"940fc7f7578d1b2a","repo":"BigPizzaV3/CodexPlusPlus","slug":"native-history-940fc7","errorCode":null,"errorMessage":"历史消息分页游标重复","messagePattern":"历史消息分页游标重复","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tools/conversation-canvas/native-history.mjs","lineNumber":36,"sourceCode":"    for(const turn of page.data){\n      if(typeof turn.id!=='string')throw Error('历史轮次缺少 ID');\n      if(!turnIds.has(turn.id)){turnIds.add(turn.id);turns.push(turn);}\n    }\n    cursor=page.nextCursor??null;\n    onProgress(`正在读取轮次目录 · ${turns.length} 轮…`);\n  }while(cursor!==null);\n  const messages=[],seen=new Set();\n  for(const [index,turn] of turns.entries()){\n    signal?.throwIfAborted();onProgress(`正在读取历史 ${index+1}/${turns.length}…`);\n    const key=`${threadId}:${turn.id}`,cached=await cache.get(key);\n    let parsed;\n    if(cached&&turn.status==='completed')parsed=cached;\n    else{\n      const partial=turn.status==='completed'?await cache.get(`${key}:partial`):null;\n      parsed=partial?.messages?.slice()||[];let itemCursor=partial?.cursor??null,limit=32;const cursors=new Set();\n      do{\n        signal?.throwIfAborted();\n        if(cursors.has(itemCursor))throw Error('历史消息分页游标重复');\n        let page;\n        for(;;){\n          try{page=await send('thread/items/list',{threadId,turnId:turn.id,cursor:itemCursor,limit,sortDirection:'asc'});break;}\n          catch(error){\n            if(limit>1&&/decoded message length too large/i.test(error.message)){limit=Math.max(1,Math.floor(limit/2));continue;}\n            throw error;\n          }\n        }\n        if(!Array.isArray(page?.data))throw Error('历史消息接口返回格式无效');\n        cursors.add(itemCursor);\n        for(const row of page.data){\n          if(row.turnId!=null&&row.turnId!==turn.id)throw Error('历史消息所属轮次不匹配');\n          const item=row.item??row;\n          if(!['userMessage','agentMessage'].includes(item.type))continue;\n          if(typeof item.id!=='string')throw Error('历史消息缺少稳定 ID');\n          const role=item.type==='userMessage'?'user':'assistant';\n          const content=role==='user'?(item.content??[]):[{text:item.text??''}];\n          const message=parseMessage({type:'response_item',payload:{type:'message',id:item.id,role,phase:role==='assistant'?(item.phase??'final_answer'):'',content}},item.id);","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/tools/conversation-canvas/native-history.mjs#L18-L54","documentation":"Within each turn, readNativeHistory pages thread/items/list tracking used cursors; a repeated itemCursor means the items pagination is looping. The function throws to prevent an infinite fetch cycle. (Note the surrounding code also halves `limit` on 'decoded message length too large' errors.)","triggerScenarios":"thread/items/list returns a nextCursor equal to a previously used cursor for the same turn, so the do/while would never terminate.","commonSituations":"Backend bug in per-turn item pagination; huge turns whose cursor handling overflows; proxy/mocked responses with constant cursors; protocol version mismatch.","solutions":["Upgrade/restart the codex backend to fix items pagination","Test with a smaller turn to isolate whether only oversized turns loop","Inspect the mocked/proxied send('thread/items/list') for a static nextCursor","Report the cursor loop upstream with the threadId/turnId"],"exampleFix":"// before\nif(cursors.has(itemCursor))throw Error('历史消息分页游标重复');\n// after\nif(cursors.has(itemCursor)){ console.warn('cursor loop for turn', turn.id); break; } // degrade gracefully","handlingStrategy":"try-catch","validationCode":"// no pre-call check; detect loop after response\nif (cursors.has(page.nextCursor)) throw new Error('item cursor loop');","typeGuard":"const isItemsPage = p => p && Array.isArray(p.data);","tryCatchPattern":"try { await readNativeHistory(send, threadId) } catch (e) { if (e.message === '历史消息分页游标重复') { usePartialMessagesForTurn(); } else throw e; }","preventionTips":["Update the backend if items pagination loops on large turns","Pass an AbortSignal to bound runtime","Watch for 'decoded message length too large' and expect limit halving","Report persistent loops with threadId/turnId upstream"],"tags":["pagination","network","api"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}