fix(desktop): resolve reaction write key for rehydrated/rotated sessions - #80675
Open
fluxkapacitor wants to merge 1 commit into
Open
fix(desktop): resolve reaction write key for rehydrated/rotated sessions#80675fluxkapacitor wants to merge 1 commit into
fluxkapacitor wants to merge 1 commit into
Conversation
message.react failed with 4040 ("message not found in this session") on
resumed desktop conversations: registry entries for sessions predating the
session_key column carry session_key=None, and auto-compaction rotation can
leave a stale parent key while the durable rows live under the continuation
tip. set_message_reaction(None, ...) short-circuits to None, so the RPC
errored even though every row was present.
Fall back to the routed session id (matching the turn payload's `or sid`)
and, on a miss, retry once via the compression-continuation tip — safe
because message row ids are globally unique. Log the 4040 shape for
diagnosability.
fluxkapacitor
force-pushed
the
fix/reactions-4040-resumed-session-key
branch
from
August 7, 2026 00:35
87fd091 to
bd13ada
Compare
Author
|
Friendly ping — this PR fixes #80670 (4040 "Could not react" on resumed/rotated sessions) with a session-key fallback chain (session_key → routed session_id → lineage-tip retry) plus regression tests, and is currently mergeable against main. Context for triage: it's distinct from the reactions availability fix (7ad9ace) and the live-paint feature (6ec319f) — both of which are merged. This one covers the write-key resolution path in the message.react RPC for sessions predating the session_key column or rotated by compression. Happy to rebase or adjust if needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #80670 — the
message.reactRPC returns 4040 ("Could not react" / "message not found in this session") when reacting to messages in resumed or long-lived conversations, even though every message row exists. Fresh conversations react fine; old/resumed ones hard-fail in the desktop UI.Root cause
Two session-key resolution gaps in the handler (
tui_gateway/methods_session.py):session_keycolumn insessionshavesession_key = NULL(verified on real data: a 403-message session row withsession_key=Nonewhile all rows live undersession_id). On resume, the registry entry inherits that, andSessionDB.set_message_reaction(None, row_id, …)short-circuits toNone(hermes_state.py:5833—if not session_id …: return None) → 4040.None→ 4040.The handler wrote with
session["session_key"]unconditionally, while the turn payload already usessession.get("session_key") or sid(server.py:1656) — the RPC never got that fallback.Fix
message.reactnow:session_key or routed session_id(matching the turn payload), so keyless resumed sessions address their durable rows.db.resolve_resume_session_id(write_key)(the same continuation-tip resolutionsession.resumeuses), then the routed id as a final candidate. Safe because message row ids are globally unique — a retry can only land on the exact row the client addressed, never on a different message.logger.warningwith session/row/key) so a genuinely stale client row id is diagnosable instead of a silent dead-end.Behavior preserved
newest_role(live-message, no-row-id) path works through the same key resolution.WHERE id=? AND session_id=?).hermes_state.pyuntouched), the gate, or any other RPC.Testing
tests/tui_gateway/test_message_react_rpc.py— 4 tests: keyless-session fallback ✓, lineage-tip retry ✓, role-based path with fallback key ✓, still-4040 with diagnostic log ✓scripts/run_tests.sh tests/tui_gateway/ tests/test_message_reactions.py— 359 tests, 0 failedDeliberately not mixed with any other carry (e.g. #69593 BlueBubbles, #80659 reactions gate).