Skip to content

fix: commit context engine sessions on rotation - #22599

Closed
Tosko4 wants to merge 1 commit into
NousResearch:mainfrom
Tosko4:fix/context-engine-session-end-commit
Closed

fix: commit context engine sessions on rotation#22599
Tosko4 wants to merge 1 commit into
NousResearch:mainfrom
Tosko4:fix/context-engine-session-end-commit

Conversation

@Tosko4

@Tosko4 Tosko4 commented May 9, 2026

Copy link
Copy Markdown
Contributor

Summary

commit_memory_session() now commits the active context engine as well as the memory manager when an agent session rotates without tearing providers down.

The memory manager and context engine are handled independently, so a missing or failing memory provider no longer prevents a context engine from receiving on_session_end(session_id, messages). This keeps plugin context engines able to flush their final transcript window before /new, TUI session close, or compression rollover moves to the next physical session.

Fixes stephenschoettler/hermes-lcm#134

Why

Hermes Agent already notifies context engines during full shutdown through shutdown_memory_provider(), but the lighter session-commit path only called the memory manager. That left context engines such as hermes-lcm without a final boundary callback on session rotation, which can skip final ingest or lifecycle finalization for messages that arrived after the last compression pass.

Validation

Focused validation passed locally:

python -m pytest -q \
  tests/run_agent/test_commit_memory_session.py \
  tests/run_agent/test_compression_boundary_hook.py \
  tests/test_lazy_session_regressions.py \
  tests/test_tui_gateway_server.py::test_session_close_commits_memory_and_fires_finalize_hook \
  tests/gateway/test_agent_cache.py

81 passed

Related run-agent memory/compression checks also passed:

python -m pytest -q \
  tests/run_agent/test_memory_sync_interrupted.py \
  tests/run_agent/test_compress_focus_plugin_fallback.py

17 passed

Additional checks:

python -m py_compile run_agent.py tests/run_agent/test_commit_memory_session.py tests/run_agent/test_compression_boundary_hook.py
git diff --check

Notes

This does not call shutdown_all(). It preserves the existing lightweight commit behavior, but extends it to context engines so they see the same session boundary that memory providers already receive.

@Tosko4

Tosko4 commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

CI note after first run:

ruff + ty diff is red because the workflow tried to post its diff summary comment from a fork PR and GitHub returned 403 Resource not accessible by integration. The report itself showed no new issues:

ruff: 0 on HEAD, 0 on base
new issues: none
ty: 7887 on HEAD, 7887 on base
new issues: none

The test job also hit failures outside this PR's diff. I compared the failing tests locally against origin/main; the same gateway media/topic and Tencent context-length failures reproduce on main. The restart-drain failure from CI did not reproduce locally on this branch or on main in the targeted run.

PR-local validation remains:

81 passed: commit/session boundary, lazy session, TUI close, gateway agent cache slice
17 passed: run_agent memory sync/compress focus slice
python -m py_compile run_agent.py tests/run_agent/test_commit_memory_session.py tests/run_agent/test_compression_boundary_hook.py
git diff --check

@Tosko4

Tosko4 commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

Closing this now because Teknium’s #22764 landed the host-side fix in Hermes Agent and closed #22394. That covers the same lifecycle callback this PR was for, so keeping this open would just create noise.

@Tosko4 Tosko4 closed this May 9, 2026
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/plugins Plugin system and bundled plugins tool/memory Memory tool and memory providers labels May 9, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #22764 (merged). Same fix: notify context engine on commit_memory_session(). Also competing with #22431 and #22433.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/plugins Plugin system and bundled plugins P2 Medium — degraded but workaround exists tool/memory Memory tool and memory providers type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

commit_memory_session() missing context_compressor.on_session_end() call

2 participants