fix(session-state): lineage walks survive cleared end_reason on reopened links - #92533
Open
sebmarion wants to merge 1 commit into
Open
fix(session-state): lineage walks survive cleared end_reason on reopened links#92533sebmarion wants to merge 1 commit into
sebmarion wants to merge 1 commit into
Conversation
…ned links
A mistaken TUI reaper close ('ws_orphan_reap') followed by stale-route
recovery (reopen_session) clears the parent's mutable end_reason. Every
lineage walk keyed on end_reason='compression' then silently lost the
link: set_session_archived / set_session_pinned / set_session_hidden /
set_session_read only covered the segment below the break, so the
unarchived, re-active root kept resurrecting the conversation in the
sidebar after the user archived it.
Fix follows the existing _reset_from pattern (reopen_session already
stamps children before clearing mutable end_reason):
1. publish_compression_child stamps $._compression_from=<parent> on the
continuation child at rotation time.
2. _insert_session_row stamps children created under an already-ended
compression parent (covers the child-inserted-before-ended_at race).
3. The four lineage-flipping CTEs gain a fallback arm following the raw
parent edge when the marker is present.
get_compression_tip is intentionally untouched: with archive covering
the whole lineage, the archived filter hides the root regardless of tip
projection, and resume-ordering semantics stay unchanged.
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.
PR: fix(session-state): lineage walks survive cleared end_reason on reopened links
Open with:
https://github.com/NousResearch/hermes-agent/compare/main...sebmarion:hermes-agent:fix/archive-lineage-reopened-links?expand=1
Problem
Archiving a conversation only archived part of it, and the chat kept resurfacing in the sidebar. Reproduced in production.
Root cause chain:
end_reason = 'ws_orphan_reap'.reopen_session, which clearsended_at/end_reason(by design — that is how resume works).set_session_archived,set_session_pinned,set_session_hidden,set_session_read) traverses onlyparent.end_reason = 'compression'edges.The codebase already acknowledges this fragility:
reopen_sessionstamps children with$._reset_frombefore clearing the parent's mutableend_reason, precisely because other logic depends on it. Compression chains had no equivalent durable marker.Fix
Follows the existing
_reset_frompattern:publish_compression_childwrites$._compression_from = <parent id>into the continuation child'smodel_config(idempotent, NULL-guarded)._insert_session_rowstamps children created under an already-ended compression parent — covers the documented race where a child row is inserted before the parent'sended_atlands.get_compression_tipis intentionally untouched: once archive/pin cover the whole lineage, the archived filter hides the root regardless of tip projection; resume-ordering semantics are unchanged. Diff stays minimal (64 lines inhermes_state.py, all additive).Testing
tests/hermes_state/test_session_archiving.py: real-rotation stamping, reap→reopen→archive reaching the whole lineage, unarchive restoring it, pin coverage, and creation-time stamping under an already-ended parent.tests/hermes_state/— 156 passedtests/agent/test_compression_rotation_state.py tests/agent/test_compression_concurrent_fork.py tests/run_agent/test_compression_boundary_hook.py— 70 passed