fix(desktop): guard reconnect sockets and keep branch search precise
Avoid stale WebSocket events from an old reconnect attempt flipping the gateway state after a newer socket opens. Also limit session-search dedupe to compression edges so branch-specific hits still open the branch instead of collapsing to the parent.
This commit is contained in:
@@ -466,6 +466,40 @@ class TestWebServerEndpoints:
|
||||
assert hit["session_id"] == "search-tip"
|
||||
assert hit["lineage_root"] == "search-root"
|
||||
|
||||
def test_search_keeps_branch_specific_hits_on_branch(self):
|
||||
"""Branch sessions share parent_session_id, but they are not compression
|
||||
continuations. A query that only exists in the branch must open the
|
||||
branch instead of being collapsed back to the parent/root."""
|
||||
import time as _time
|
||||
|
||||
from hermes_state import SessionDB
|
||||
|
||||
db = SessionDB()
|
||||
try:
|
||||
now = _time.time()
|
||||
db.create_session(session_id="branch-parent", source="cli")
|
||||
db.append_message(session_id="branch-parent", role="user", content="ancestor context")
|
||||
db.end_session("branch-parent", "branched")
|
||||
db._conn.execute(
|
||||
"UPDATE sessions SET started_at = ?, ended_at = ? WHERE id = ?",
|
||||
(now - 100, now - 90, "branch-parent"),
|
||||
)
|
||||
db.create_session(session_id="branch-child", source="cli", parent_session_id="branch-parent")
|
||||
db._conn.execute("UPDATE sessions SET started_at = ? WHERE id = ?", (now - 80, "branch-child"))
|
||||
db.append_message(session_id="branch-child", role="user", content="branchspecificneedle only here")
|
||||
db._conn.commit()
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
resp = self.client.get("/api/sessions/search?q=branchspecificneedle")
|
||||
assert resp.status_code == 200
|
||||
results = resp.json()["results"]
|
||||
|
||||
assert any(
|
||||
r["session_id"] == "branch-child" and r.get("lineage_root") == "branch-child"
|
||||
for r in results
|
||||
)
|
||||
|
||||
def test_get_sessions_archived_is_boolean(self):
|
||||
from hermes_state import SessionDB
|
||||
|
||||
|
||||
Reference in New Issue
Block a user