Skip to content

fix(gateway): preserve compressed session in queued follow-ups - #79322

Open
richkapp wants to merge 1 commit into
NousResearch:mainfrom
richkapp:fix/queued-followup-compression-session
Open

fix(gateway): preserve compressed session in queued follow-ups#79322
richkapp wants to merge 1 commit into
NousResearch:mainfrom
richkapp:fix/queued-followup-compression-session

Conversation

@richkapp

@richkapp richkapp commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

What changed

Queued follow-up turns now continue on the live session returned by the immediately preceding turn. Previously, when that turn compressed its transcript, the recursive follow-up reused the closed parent session and failed with CompressionSessionClosedError.

The effective session now drives:

  • queued follow-up agent construction
  • history/cache refresh after the completed turn
  • recursive follow-up execution
  • queued /goal activity checks

When an active goal must move from the compressed parent to its continuation, the state transfer is now one BEGIN IMMEDIATE transaction with source-value CAS and a destination-absent guard. A partial write rolls back, and a child pause/clear cannot be overwritten. If goal state is temporarily unreadable, the synthetic continuation is retried once and then parked in FIFO rather than silently discarded or hot-looped.

The cached-agent snapshot advances parent→child only when that same cached agent reports the returned child session, preserving warm-prefix reuse without weakening stale/dead-session eviction.

If a result omits session_id, behavior still falls back to the original session.

Why

Compression closes the parent session and publishes a live continuation. Reusing the parent for a queued message risks a persistence failure even though storage, permissions, and the database are healthy. Goal migration also has to preserve user control and survive partial writes; otherwise a queued synthetic continuation can vanish during the same rotation boundary.

Tests

  • HERMES_TEST_FILE_RETRIES=0 scripts/run_tests.sh tests/gateway/test_agent_cache.py tests/gateway/test_queued_native_image_session_key.py tests/gateway/test_session_id_cache_coherence.py tests/gateway/test_first_turn_session_meta_rebaseline.py tests/gateway/test_goal_continuation_drain.py tests/hermes_cli/test_goals.py tests/gateway/test_compression_session_id_persistence.py tests/agent/test_compression_rotation_state.py tests/state/test_compression_lineage_guard.py tests/gateway/test_transcript_offset.py tests/gateway/test_queue_consumption.py -q — 122 passed
  • ruff check gateway/run.py hermes_cli/goals.py hermes_state.py tests/gateway/test_queued_native_image_session_key.py tests/hermes_cli/test_goals.py
  • git diff --check

Regression coverage includes the rotated-session route, non-null-parent missing-result fallback, cache re-baselining, queued-goal call-site ID forwarding, real-DB migration, rollback after an injected archive failure, paused/cleared child preservation, strict read-error handling, and bounded retry/FIFO parking.

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages labels Aug 5, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #57895. Both PRs make queued follow-ups use the compression-rotated session ID returned by the previous turn for the recursive run, goal check, and cache refresh. #57895 is the earlier open implementation.

@richkapp
richkapp force-pushed the fix/queued-followup-compression-session branch from 8028d69 to 2af1da3 Compare August 5, 2026 12:30
@richkapp
richkapp force-pushed the fix/queued-followup-compression-session branch from 2af1da3 to f9f8231 Compare August 5, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants