Skip to content

fix(agent): tiered context pressure warnings + gateway dedup#6411

Merged
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b0a4b31e
Apr 9, 2026
Merged

fix(agent): tiered context pressure warnings + gateway dedup#6411
teknium1 merged 1 commit into
mainfrom
hermes/hermes-b0a4b31e

Conversation

@teknium1

@teknium1 teknium1 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Combines the approaches from PR #6309 by @duan78 and PR #5963 by @KUSH42. Neither PR could merge as-is — they conflicted at the same 3 code locations and each had issues that the other solved.

Problem

  1. Gateway warning spam (fix: deduplicate context pressure warnings in gateway mode #6309): Gateway creates a new AIAgent per message, resetting _context_pressure_warned every time. Users above 85% got the warning on every single message.
  2. No escalation (fix(compaction): show status message + re-emit context pressure bar at 95% #5963): The boolean flag only fires once at 85% — users climbing from 88% → 97% never saw an update or color change.
  3. Silent compression: Auto-compaction ran for 10-30s with no feedback.

Solution

Tiered warnings (inspired by #5963):

  • Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
  • Fires at 85% (approaching) and re-fires at 95% (critical)
  • Adds ⟳ compacting context… status message before compression fires

Gateway dedup (inspired by #6309):

  • Class-level dict _context_pressure_last_warned survives across AIAgent instances
  • 5-minute cooldown per session prevents spam (same tier, same session)
  • Higher-tier warnings bypass cooldown (85% → 95% always fires)
  • Compression reset clears the dedup entry so a fresh warning cycle can start
  • Stale entries evicted (older than 2x cooldown) — fixes the memory leak in fix: deduplicate context pressure warnings in gateway mode #6309's approach

Cache impact

Zero. All warnings use _safe_print() (CLI) and status_callback() (gateway). Nothing is injected into the message stream.

Changes

  • run_agent.py — class-level dedup dict, tiered emission logic, compression reset, compaction status message
  • tests/run_agent/test_context_pressure.py — updated 3 existing tests for float semantics, added 9 new tests (tiered re-emit, no double-emit, insufficient compression, gateway dedup: cooldown suppression, higher-tier bypass, cooldown expiry, compression clears dedup, eviction)

Test plan

  • 31 context pressure tests pass (22 existing + 9 new)
  • py_compile clean

Closes #6309 (gateway spam). Addresses #5963 (tiered + status message).

Combines the approaches from PR #6309 (duan78) and PR #5963 (KUSH42):

Tiered warnings (from #5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from #6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes #6309. Fixes #5963.
@teknium1 teknium1 merged commit 54db7cb into main Apr 9, 2026
5 of 6 checks passed
saxster pushed a commit to saxster/hermes-agent that referenced this pull request Apr 9, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
@SHL0MS SHL0MS mentioned this pull request Apr 11, 2026
2 tasks
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
angelburgosrosado pushed a commit to angelburgosrosado/hermes-agent that referenced this pull request Apr 27, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…earch#6411)

Combines the approaches from PR NousResearch#6309 (duan78) and PR NousResearch#5963 (KUSH42):

Tiered warnings (from NousResearch#5963):
- Replaces boolean _context_pressure_warned with float _context_pressure_warned_at
- Fires at 85% (orange) and re-fires at 95% (red/critical)
- Adds 'compacting context...' status message before compression

Gateway dedup (from NousResearch#6309):
- Class-level dict _context_pressure_last_warned survives across AIAgent
  instances (gateway creates a new instance per message)
- 5-minute cooldown per session prevents warning spam
- Higher-tier warnings bypass the cooldown (85% → 95% always fires)
- Compression reset clears the dedup entry for the session
- Stale entries evicted (older than 2x cooldown) to prevent memory leak

Does NOT inject into messages — purely user-facing via _safe_print (CLI)
and status_callback (gateway). Zero prompt cache impact.

Fixes NousResearch#6309. Fixes NousResearch#5963.
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