{"record":{"id":"7aabfaea283f0043","repo":"moeru-ai/airi","slug":"context-bridge-failed-to-refresh-completed-remot","errorCode":null,"errorMessage":"[context-bridge] Failed to refresh completed remote stream:","messagePattern":"\\[context-bridge\\] Failed to refresh completed remote stream:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/stage-ui/src/stores/mods/api/context-bridge.ts","lineNumber":133,"sourceCode":"    if (!guard.started) {\n      guard.started = true\n      chatStream.beginStream(guard.turnId)\n    }\n    for (const literal of guard.pendingLiterals.splice(0))\n      chatStream.appendStreamLiteral(literal)\n    if (guard.completed && !guard.refreshing)\n      void refreshCompletedRemoteStream(guard)\n    return true\n  }\n\n  async function refreshCompletedRemoteStream(guard: NonNullable<typeof remoteStreamGuard.value>) {\n    guard.refreshing = true\n    let loaded = false\n    try {\n      loaded = await chatSession.refreshSession(guard.sessionId)\n    }\n    catch (error) {\n      console.warn('[context-bridge] Failed to refresh completed remote stream:', errorMessageFrom(error))\n    }\n    if (remoteStreamGuard.value !== guard)\n      return\n    guard.refreshing = false\n    if (!loaded || guard.sessionId !== chatSession.activeSessionId)\n      return\n    if (chatSession.getSessionGenerationValue(guard.sessionId) !== guard.generation)\n      return\n\n    chatStream.resetStream()\n    remoteStreamGuard.value = undefined\n  }\n\n  function recordContextIngestRejected(options: {\n    channel: 'server' | 'broadcast' | 'input'\n    contextMessage: ContextMessage\n    details?: unknown\n    error: unknown","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/moeru-ai/airi/blob/677329427f32468c74b17f3ec47eeca4e05bec65/packages/stage-ui/src/stores/mods/api/context-bridge.ts#L115-L151","documentation":"After a remote streaming reply was marked completed, the bridge calls chatSession.refreshSession(guard.sessionId) to fetch the server's final state before resetting the local stream. If the refresh throws, loaded stays false, guard.refreshing resets to false, and the guard stays in place — so the completed && !refreshing check re-triggers the refresh on a later pass. The local stream is only reset after a successful refresh with matching session id and generation.","triggerScenarios":"refreshSession network call failing on a disconnected socket; the session deleted on the server after the stream completed; epoch/session churn causing repeated retries.","commonSituations":"Remote reply finished while the connection dropped; user switches sessions right as the refresh fires.","solutions":["Wait — the guard re-arms itself (completed && !refreshing) on the next check","Verify connectivity/auth for the session refresh endpoint if it keeps failing","Switch sessions or re-activate the chat to force a fresh refresh attempt","Confirm server-side the session still exists; a deleted session will never refresh"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  loaded = await chatSession.refreshSession(guard.sessionId)\n}\ncatch (error) {\n  console.warn('[context-bridge] Failed to refresh completed remote stream:', errorMessageFrom(error))\n}\n// loaded stays false; completed && !refreshing re-arms the refresh on a later check","preventionTips":["Treat refreshSession as best-effort; the guard re-arms itself","Compare remoteStreamGuard.value !== guard before mutating shared state after awaits (source pattern)","Drive retries from UI focus or session activation, not tight loops","Verify session existence server-side when a refresh never succeeds"],"tags":["context-bridge","refresh-session","remote-stream","retry"],"backgroundTag":"http-request-failed","analyzedSha":"677329427f32468c74b17f3ec47eeca4e05bec65","analyzedAt":"2026-08-18T17:29:58.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T11:17:13.642Z"}