Skip to content

Fix stale stream exception writeback guards - #2158

Merged
1 commit merged into
nesquena:masterfrom
franksong2702:franksong2702/issue-2154-stream-guards
May 13, 2026
Merged

1 commit merged into
nesquena:masterfrom
franksong2702:franksong2702/issue-2154-stream-guards

Conversation

@franksong2702

@franksong2702 franksong2702 commented May 13, 2026

Copy link
Copy Markdown
Contributor

Thinking Path

Closes #2154. The issue identified two remaining stale-stream writeback sites after PR #2136: the credential self-heal retry success path and the outer exception error persistence path. Both paths can run after active_stream_id has rotated to a newer stream, so they need the same ownership check already used by the normal success path.

What Changed

  • Added _stream_writeback_is_current(s, stream_id) guards before the self-heal retry success writeback mutates context_messages, display messages, or saves the session.
  • Added the same guard before the outer exception path materializes a pending user turn, clears active_stream_id, appends an error marker, or writes a turn journal event.
  • Added regression coverage that pins both guards before their respective persistence operations.
  • Updated CHANGELOG.md under Unreleased.

Why It Matters

A stale worker should never be able to write retry results or error markers into a newer active stream's transcript. This keeps messages, context_messages, turn journal state, and active_stream_id ownership aligned after cancel/retry or stream rotation races.

Verification

  • /Users/xuefusong/hermes-webui/.venv_test/bin/python -m pytest -q tests/test_stale_stream_writeback.py
  • /Users/xuefusong/hermes-webui/.venv_test/bin/python -m py_compile api/streaming.py
  • git diff --check

Risks / Follow-ups

Low risk. The new guards reuse the existing ownership predicate and only short-circuit non-ephemeral stale streams after ownership has rotated. I did not change the normal success path or cancel path behavior.

Model Used

OpenAI GPT-5.4-Codex

@nesquena-hermes nesquena-hermes closed this pull request by merging all changes into nesquena:master in fdbbb0d May 13, 2026
franksong2702 pushed a commit to franksong2702/hermes-webui-fork that referenced this pull request May 13, 2026
Fix stale stream exception writeback guards (closes nesquena#2154)

# Conflicts:
#	CHANGELOG.md
SysAdminDoc pushed a commit to SysAdminDoc/hermes-webui that referenced this pull request Jun 26, 2026
Fix stale stream exception writeback guards (closes nesquena#2154)

# Conflicts:
#	CHANGELOG.md
bernyforce pushed a commit to bernyforce/hermes-webui that referenced this pull request Jul 29, 2026
Fix stale stream exception writeback guards (closes nesquena#2154)

# Conflicts:
#	CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend _stream_writeback_is_current() guard to outer except handler and self-heal retry success path

2 participants