Skip to content

fix(agent): flush pending memory retains before compaction boundary - #9

Open
liuhao1024 wants to merge 1 commit into
mainfrom
liuhao/cron-bugfix-64315-hindsight-flush
Open

fix(agent): flush pending memory retains before compaction boundary#9
liuhao1024 wants to merge 1 commit into
mainfrom
liuhao/cron-bugfix-64315-hindsight-flush

Conversation

@liuhao1024

Copy link
Copy Markdown
Owner

What does this PR do?

Context compression triggers on_session_switch() without first flushing pending memory retains. When Hindsight's turn buffer is cleared, any sync_all() dispatched after the last successful retain but before compaction fires are silently lost at the compaction boundary.

The fix adds flush_pending(timeout=5.0) before the on_session_switch call, using the same try/except pattern as the existing memory manager calls. This ensures pending sync/prefetch work completes before the buffer is cleared.

Related Issue

Fixes NousResearch#64315

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

  • agent/conversation_compression.py: Add flush_pending(timeout=5.0) call before on_session_switch() at compaction boundary (10 lines)
  • tests/agent/test_compression_memory_flush.py: Add regression test that verifies flush_pending is called with timeout=5.0 before on_session_switch during compression

How to Test

  1. Run the new regression test:

    python -m pytest tests/agent/test_compression_memory_flush.py -v

    Observed result: test passes

  2. Run existing compression tests to ensure no regression:

    python -m pytest tests/agent/test_compression_concurrent_fork.py -v

    Observed result: all tests pass

  3. (Optional) Manual verification with Hindsight provider:

    • Configure memory.provider: hindsight in config.yaml
    • Set compression.threshold: 0.75 (default)
    • Run a long session that triggers compression
    • Check Hindsight container logs for batch_retain entries
    • Observed result: retain activity continues across compaction boundary with no gaps

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

For New Skills

  • This skill is broadly useful to most users (if bundled) — see Contributing Guide
  • SKILL.md follows the standard format (frontmatter, trigger conditions, steps, pitfalls)
  • No external dependencies that aren't already available (prefer stdlib, curl, existing Hermes tools)
  • I've tested the skill end-to-end: hermes --toolsets skills -q "Use the X skill to do Y"

Screenshots / Logs

Fixes NousResearch#64315. Context compression calls on_session_switch() without
first flushing pending memory retains. When Hindsight's turn buffer is
cleared, any pending retains dispatched after the last successful retain
but before compaction fires are silently lost at the compaction boundary.

The fix adds flush_pending(timeout=5.0) before the on_session_switch call,
using the same try/except pattern as the existing memory manager calls.
This ensures pending sync/prefetch work completes before the buffer is
cleared.

Adds a regression test that verifies flush_pending is called with
timeout=5.0 before on_session_switch during compression.
liuhao1024 pushed a commit that referenced this pull request Aug 15, 2026
- tests/agent/test_session_activity.py asserts against
  ACTIVITY_DESCRIPTION_MAX instead of the literal 120.
- The session-stall WARNING log line names its config knob
  (agent.session_stall_timeout) so operators can find the setting.
- hermes_state.py: collapse the triple blank line near line 191.
- hermes_cli/status.py no longer imports the private
  hermes_cli.main._relative_time: the helper moved to a public home
  (hermes_cli.timefmt.relative_time); main._relative_time stays as a
  thin back-compat wrapper (sessions_cmd and external patchers keep
  working).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction resets Hindsight turn buffer without flushing pending memories

1 participant