Skip to content

Background-stream error notice never shown — checkBackgroundStream purges the entry before its own error branch runs #167

Description

@jdmanring

Summary

When a background stream errors while the user is on a different session, the failure is never shown. Returning to that session displays a chat that simply stopped, with no indication the background response failed.

Root cause

checkBackgroundStream(sessionId) (static/js/chat.js) begins by calling _purgeStaleBackgroundStreams(), which deletes every completed/error entry from _backgroundStreams — including the current session's. The has(sessionId) guard on the next line then early-returns, so the error branch that appends "[Background stream encountered an error]" to #chat-history is now unreachable dead code.

The error branch is original behavior (commit e5c99a5e, "Odysseus v1.0"). It was killed by fork commits: 67268d2b added the _purgeStaleBackgroundStreams primitive, and 1e8a217a placed a call to it at the top of checkBackgroundStream. Upstream has no purge, so this is a fork-introduced regression.

The error entry is intentionally left in the map by the catch handler (bgErr.status = 'error', not deleted) precisely so checkBackgroundStream can surface it later — the top-of-function purge defeats that.

Fix

Exclude the current sessionId from the purge: _purgeStaleBackgroundStreams(exceptSid) skips that entry, so other sessions' finished streams are still cleaned up while the current session's error/completed entry survives for its own branch to handle.

Classification

Fork-only regression (the purge exists only on the fork). Fix on develop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions