Skip to content

fix(cli, gateway): migrate /goal across all session_id rebind sites#18749

Open
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/18467-migrate-goal-on-compress
Open

fix(cli, gateway): migrate /goal across all session_id rebind sites#18749
Tranquil-Flow wants to merge 2 commits into
NousResearch:mainfrom
Tranquil-Flow:fix/18467-migrate-goal-on-compress

Conversation

@Tranquil-Flow

@Tranquil-Flow Tranquil-Flow commented May 2, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Carries an in-flight /goal across every session_id rebind so the goal judge loop doesn't silently die after compression. The goal row is keyed by goal:<session_id> in SessionDB.state_meta; when _compress_context() mints a child session_id on the agent, every site that syncs a stored session_id to the agent's new id must also migrate that row, otherwise /goal status reports "No active goal" with no warning.

The reporter localised one site exactly (cli.py:7567-7572, manual /compress). Code review surfaced four more sites with the same rebind pattern that all need the same treatment:

Path Trigger
cli.py:7577 manual /compress
cli.py:9408 auto-compression mid-turn (run_conversation)
cli.py:12016 single-query / non-interactive run mode
gateway/run.py:6165 gateway post-run session_entry.session_id sync
gateway/run.py:12742 gateway session split on compression

This PR adds migrate_goal(old_sid, new_sid) in hermes_cli/goals.py and wires it at all five sites. Migration semantics:

  • Active and paused goals carry over (with turns_used, last_verdict, paused_reason intact).
  • Terminal goals (done, cleared) stay with the original session — they belong to the session that completed them.
  • The old key is marked cleared via the existing clear_goal() helper so /goal status under the dead session reflects reality.
  • No-ops on empty/identical session ids.

Gateway sites wrap the call in a defensive try/except since gateway logging deliberately swallows non-fatal errors.

Related Issue

Fixes #18467

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • hermes_cli/goals.py — add migrate_goal(old_session_id, new_session_id)
  • cli.py — wire migrate_goal at the manual /compress, auto-compression, and single-query rebind sites
  • gateway/run.py — wire migrate_goal at the post-run sync and session-split sites (with try/except for non-fatal failure)
  • tests/hermes_cli/test_goals.py — add TestMigrateGoal (7 unit cases: active carry, status preservation, old-cleared, done/cleared not migrated, paused state, no-goal noop, empty-sid noop)
  • tests/cli/test_manual_compress.py — add test_manual_compress_migrates_active_goal_to_child_session integration test that plants a goal, runs _manual_compress end-to-end, and asserts migration

How to Test

  1. python -m pytest tests/hermes_cli/test_goals.py tests/cli/test_manual_compress.py -q — 38/38 pass
  2. Manual: hermes/goal port the thing → a few turns → /compress/goal status should show the goal still active under the new session id (previously: "No active goal")

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: macOS 15.2

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

$ python -m pytest tests/hermes_cli/test_goals.py tests/cli/test_manual_compress.py -q
38/38 pass

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery labels May 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #18427 — both fix goal persistence across compression. This PR covers all 5 rebind sites vs #18427's approach.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #18427.

When auto- or manual context compression mints a child session_id on
the agent, every site that syncs a stored session_id to the agent's
new id must also migrate the goal row stored in SessionDB.state_meta
under goal:<sid>. Otherwise the judge loop silently dies under the
orphaned parent and /goal status reports "No active goal" with no
warning.

Five sites carried this rebind pattern; only the manual-/compress one
was wired in the first attempt:

  cli.py:7577       manual /compress
  cli.py:9408       auto-compression mid-turn (run_conversation)
  cli.py:12016      single-query / non-interactive run mode
  gateway/run.py:6165   gateway post-run session_entry sync
  gateway/run.py:12742  gateway session split on compression

Wire migrate_goal at all five. Gateway sites use a defensive
try/except around the helper since gateway logging deliberately
swallows non-fatal errors. Add a regression test under
tests/cli/test_manual_compress.py that plants a goal, runs
_manual_compress, and asserts the goal carried to the child session.

Fixes NousResearch#18467
@Tranquil-Flow Tranquil-Flow force-pushed the fix/18467-migrate-goal-on-compress branch from 63ac186 to 4a5f693 Compare May 25, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: /goal silently lost after manual /compress (session_id rebind doesn't migrate goal state)

2 participants