Skip to content

fix(compaction): keep the idle gap across gateway turn-start resets (RIG-9162) - #51

Open
rigel-mintaka wants to merge 2 commits into
rigel-releasefrom
hermes-sync/rig-9162-keep-the-idle-gap-across-gateway-turn
Open

rigel-mintaka wants to merge 2 commits into
rigel-releasefrom
hermes-sync/rig-9162-keep-the-idle-gap-across-gateway-turn

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Idle compaction (compression.idle_compact_after_seconds) never fired on gateway turns, such as Discord, Cotal and cron. _idle_compaction measured time.time() - _last_activity_ts, but two turn-start paths reset that timestamp first, so the gap was always about 0:

  • gateway/run.py _init_cached_agent_for_turn (cached agent reuse);
  • DurableTurnLease.start.

Related Issue

RIG-9162. Nemo enables idle compaction after this ships (RIG-9148).

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • gateway/run.py and agent/turn_facade_lease.py: save the elapsed gap into _idle_resume_gap_s before the clock reset, keeping the larger value if both run. The watchdog reset is unchanged.
  • agent/turn_context_compaction.py: _idle_compaction reads and clears the saved gap, and falls back to the live gap if none was saved.
  • tests/agent/test_compression_trigger_labels.py: a regression for the cached-turn reset path.

How to Test

  1. The new regression fails before the fix (DID NOT RAISE _CompressionReached) and passes after.
  2. The idle-compaction guard, trigger-label, lease and cached-agent suites: 53 passed.
  3. Ruff passes.

Checklist

Code

  • Conventional Commits
  • Only this fix
  • Regression test added

Documentation & Housekeeping

  • Documentation: N/A. Idle compaction stays opt-in (default 0).

For New Skills

N/A.

Screenshots / Logs

N/A.

Refs RIG-9162

Co-authored-by: Matt Wilkinson matt@rigel.build

@linear-code

linear-code Bot commented Nov 10, 2026

Copy link
Copy Markdown

RIG-9162

@rigel-mintaka

Copy link
Copy Markdown
Collaborator Author

Review rounds

Round 1 (107f54f): 0 high, 1 medium, 5 low.

  • medium: no test covered the lease path. Fixed: tests/agent/test_idle_resume_gap.py covers the lease path, gateway then lease (max), and the clear when compression is disabled.
  • low: copied save block. Fixed: shared save_idle_gap under _activity_lock.
  • low: the carry rule was not stated. Fixed: comment and docs note.
  • low: field not declared. Fixed: _TURN_STATE.
  • low: the admission wait and the interrupt-recursive stall count as idle. Accepted: the cache is cold after that long either way.
  • low: separate read and reset. Fixed by the locked helper.

Round 2 (interdiff 107f54f..e27ac75): 0 high, 0 medium, 1 low (a wordy comment; non-gating). 11 passed; ruff is clean. All-clear on e27ac75.

@rigel-mintaka
rigel-mintaka marked this pull request as ready for review November 10, 2026 19:18
rigel-mintaka and others added 2 commits November 10, 2026 16:45
…RIG-9162)

Co-authored-by: Matt Wilkinson <matt@rigel.build>
…G-9162)

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka force-pushed the hermes-sync/rig-9162-keep-the-idle-gap-across-gateway-turn branch from e27ac75 to 71e3a1f Compare November 10, 2026 23:59
@rigel-mintaka

Copy link
Copy Markdown
Collaborator Author

Review all-clear on 71e3a1f (0 findings). The rebase over #50 moved only hunk context; the code hunks match all-clear e27ac75. Merge-ready.

This branch has not been deployed

No deployments
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.

1 participant