Repository navigation
Closed
Labels
P2Medium — degraded but workaround existsMedium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryGateway runner, session dispatch, deliveryduplicateThis issue or pull request already existsThis issue or pull request already existstype/bugSomething isn't workingSomething isn't working
Description
Bug Description
When context compression creates a child session (rotating session_id), the standing /goal is lost because state_meta key goal:<old_session_id> is never migrated to goal:<new_session_id>.
Root Cause
- Compression changes
session_entry.session_idin-place atgateway/run.py:8638-8643 - The post-turn goal hook (
_post_turn_goal_continuation) reads the new session_id fromget_or_create_session(source)at line 7569 GoalManager(session_id=new_sid)callsload_goal()which queriesstate_metaforgoal:<new_sid>→ returnsNoneis_active()returnsFalse→ Ralph loop silently stops
Reproduction
- Set a
/goalin a gateway session - Have a long enough conversation to trigger context compression
- After compression, the goal loop stops —
_post_turn_goal_continuationreturns early becauseis_active()isFalsefor the new session_id state_metastill hasgoal:<old_session_id>with status=active, but nothing reads it
Key Code Path
_handle_message_with_agent()
└─ agent runs, triggers compression
└─ line 8638: session_entry.session_id = new_sid # in-place mutation
_post_turn_goal_continuation()
└─ line 7569: session_entry = get_or_create_session(source) # returns entry with new_sid
└─ line 9512: GoalManager(session_id=new_sid)
└─ load_goal("goal:<new_sid>") → None # state_meta has goal:<old_sid> not new_sid
└─ is_active() → False → return # goal loop broken
Suggested Fix
Two complementary fixes:
1. Migrate goal on compression (primary)
After line 8638-8643 in gateway/run.py, copy the active goal to the new session:
if agent_result.get("session_id") and agent_result["session_id"] != session_entry.session_id:
_old_sid_for_goal = session_entry.session_id
session_entry.session_id = agent_result["session_id"]
self.session_store._save()
# ... existing topic binding sync ...
# Migrate active goal to new session
try:
from hermes_cli.goals import load_goal, save_goal
_old_goal = load_goal(_old_sid_for_goal)
if _old_goal and _old_goal.status == "active":
save_goal(session_entry.session_id, _old_goal)
except Exception:
pass2. Parent chain fallback in _goal_still_active_for_session
Walk the parent_session_id chain as a safety net:
def _goal_still_active_for_session(self, session_id: str) -> bool:
if not session_id:
return False
try:
from hermes_cli.goals import GoalManager
if GoalManager(session_id=session_id).is_active():
return True
# Walk parent chain
if self._session_db is not None:
cur = session_id
for _ in range(10):
row = self._session_db._conn.execute(
"SELECT parent_session_id FROM sessions WHERE id = ?", (cur,)
).fetchone()
parent = row[0] if row else None
if not parent:
break
if GoalManager(session_id=parent).is_active():
return True
cur = parent
return False
except Exception:
return FalseEnvironment
- Hermes Agent v0.16.0 (git install)
- Gateway mode (Feishu platform)
auxiliary.goal_judgeuses auto (main model)- Context compression is frequent in long quantitative research sessions
Metadata
Metadata
Assignees
Labels
P2Medium — degraded but workaround existsMedium — degraded but workaround existscomp/gatewayGateway runner, session dispatch, deliveryGateway runner, session dispatch, deliveryduplicateThis issue or pull request already existsThis issue or pull request already existstype/bugSomething isn't workingSomething isn't working
Activity
alt-glitch commentedon Jun 12, 2026
Duplicate of #33618 — same root cause:
state_metakeygoal:<old_session_id>is not migrated when context compression rotatessession_id, soGoalManager(new_sid).is_active()returns False and the goal loop stops. Competing fix PRs already open (#34035, #29955, #18749, #18427).teknium1 commentedon Jun 21, 2026
Fixed in #49772 (duplicate of #33618 — /goal migrates across compression rotation). #49772