moeru-ai/airi · warning

[context-bridge] Failed to refresh completed remote stream:

Error message

[context-bridge] Failed to refresh completed remote stream:

What it means

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.

Source

Thrown at packages/stage-ui/src/stores/mods/api/context-bridge.ts:133

    if (!guard.started) {
      guard.started = true
      chatStream.beginStream(guard.turnId)
    }
    for (const literal of guard.pendingLiterals.splice(0))
      chatStream.appendStreamLiteral(literal)
    if (guard.completed && !guard.refreshing)
      void refreshCompletedRemoteStream(guard)
    return true
  }

  async function refreshCompletedRemoteStream(guard: NonNullable<typeof remoteStreamGuard.value>) {
    guard.refreshing = true
    let loaded = false
    try {
      loaded = await chatSession.refreshSession(guard.sessionId)
    }
    catch (error) {
      console.warn('[context-bridge] Failed to refresh completed remote stream:', errorMessageFrom(error))
    }
    if (remoteStreamGuard.value !== guard)
      return
    guard.refreshing = false
    if (!loaded || guard.sessionId !== chatSession.activeSessionId)
      return
    if (chatSession.getSessionGenerationValue(guard.sessionId) !== guard.generation)
      return

    chatStream.resetStream()
    remoteStreamGuard.value = undefined
  }

  function recordContextIngestRejected(options: {
    channel: 'server' | 'broadcast' | 'input'
    contextMessage: ContextMessage
    details?: unknown
    error: unknown

View on GitHub (pinned to 677329427f)

Solutions

  1. Wait — the guard re-arms itself (completed && !refreshing) on the next check
  2. Verify connectivity/auth for the session refresh endpoint if it keeps failing
  3. Switch sessions or re-activate the chat to force a fresh refresh attempt
  4. Confirm server-side the session still exists; a deleted session will never refresh
Defensive patterns

Strategy: fallback

Try / catch

try {
  loaded = await chatSession.refreshSession(guard.sessionId)
}
catch (error) {
  console.warn('[context-bridge] Failed to refresh completed remote stream:', errorMessageFrom(error))
}
// loaded stays false; completed && !refreshing re-arms the refresh on a later check

Prevention

When it happens

Trigger: refreshSession network call failing on a disconnected socket; the session deleted on the server after the stream completed; epoch/session churn causing repeated retries.

Common situations: Remote reply finished while the connection dropped; user switches sessions right as the refresh fires.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of moeru-ai/airi@677329427f (2026-08-18). Data as JSON: /api/errors/7aabfaea283f0043. Report an issue: GitHub.