Skip to content

fix(gateway): bound hygiene compression failures - #53380

Closed
westkite1201 wants to merge 1 commit into
NousResearch:mainfrom
westkite1201:fix/gateway-hygiene-timeout-cooldown
Closed

fix(gateway): bound hygiene compression failures#53380
westkite1201 wants to merge 1 commit into
NousResearch:mainfrom
westkite1201:fix/gateway-hygiene-timeout-cooldown

Conversation

@westkite1201

Copy link
Copy Markdown
Contributor

Summary

  • add a bounded timeout for gateway pre-agent hygiene compression
  • add a per-session cooldown after hygiene compression timeout/abort so repeated messages do not block on the same broken auxiliary backend
  • document the new compression.hygiene_timeout_seconds and compression.hygiene_failure_cooldown_seconds knobs

Why

Long-running gateway sessions can become oversized and trigger hygiene compression before handling an inbound message. If the auxiliary compression backend is depleted, misconfigured, or slow, the gateway can appear stuck by repeatedly blocking on that pre-agent recovery path.

Tests

  • python -m pytest tests/gateway/test_session_hygiene.py -q
  • python -m pytest tests/gateway/test_session_hygiene.py tests/gateway/test_compress_command.py::test_compress_command_passes_session_db_and_persists_rotated_session tests/agent/test_compression_rotation_state.py tests/agent/test_compression_concurrent_fork.py -q
  • python -m py_compile gateway/run.py hermes_cli/config.py
  • git diff --check

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery area/config Config system, migrations, profiles sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state P2 Medium — degraded but workaround exists labels Jun 27, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: #49905 bounds the agent context-compression summary stall; this PR bounds the gateway pre-agent hygiene compression path. Same compression-stall family, different code path — flagging the cluster so a maintainer can decide whether to consolidate.

@westkite1201

Copy link
Copy Markdown
Contributor Author

Thanks for flagging. Agreed: this is the same compression-stall family as #49905, but it intentionally covers the gateway pre-agent hygiene path rather than the agent's in-loop context-compressor summary path.

I'm happy to rebase/consolidate if maintainers prefer that both timeout/fallback paths land together, but keeping this PR scoped to gateway hygiene avoids changing the agent compression wrapper while still preventing inbound gateway messages from repeatedly blocking on a slow/depleted auxiliary compression backend.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Comment (core gateway change)

This PR adds 293 lines (22KB diff) to gateway/run.py, introducing timeout and cooldown settings for hygiene compression failures. The changes are well-documented and follow the existing config parsing pattern.

However, this modifies core gateway behavior (compression failure handling) and the 22KB diff size includes significant context. Key considerations:

  • Timeout and cooldown settings affect all conversations
  • Default values (30s timeout, 300s cooldown) need validation against production behavior
  • Config parsing follows existing patterns but touches critical path

The implementation is clean, but the gateway is a critical component. Recommend human review of the timeout/cooldown defaults and their interaction with existing compression logic.


Reviewed by Hermes Agent

@Kinkoolino-Hermes

Copy link
Copy Markdown
Contributor

Small consolidation note after related compaction fixes landed elsewhere: this PR still appears to cover a distinct path.

The merged Codex/max-output and in-loop compaction fixes address agent-side recovery/flush behavior. This PR is about the gateway pre-agent hygiene compression path, where a slow or broken auxiliary compression backend can block before the agent turn is even reached.

So the useful review question is whether Hermes wants a bounded timeout/cooldown for that gateway hygiene path, independent of the agent-context compression recovery fixes.

@westkite1201
westkite1201 force-pushed the fix/gateway-hygiene-timeout-cooldown branch from 72a47e0 to e43d4b5 Compare July 7, 2026 02:55
@westkite1201

Copy link
Copy Markdown
Contributor Author

Rebased this branch onto current main and resolved the gateway hygiene conflict. The conflict resolution keeps the PR's timeout behavior, but uses the current main off-loop cleanup path when the hygiene compression worker did not time out.

Validation run locally:

  • uv run --with pytest-timeout pytest tests/gateway/test_session_hygiene.py -q -k 'hygiene_timeout or failure_cooldown'\n- uv run --with pytest-timeout pytest tests/gateway/test_session_hygiene.py -q\n- uv run ruff check gateway/run.py hermes_cli/config.py tests/gateway/test_session_hygiene.py\n- python3 -m py_compile gateway/run.py hermes_cli/config.py tests/gateway/test_session_hygiene.py\n- git diff --check\n- python3 scripts/check-windows-footguns.py --diff origin/main\n\nGitHub now reports the PR as mergeable again.

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for targeting the distinct gateway pre-agent hygiene stall path; current main still awaits this compression before _run_agent at gateway/run.py:11316-11322.

Problems

  • The timeout path starts executor work at gateway/run.py:10991 and then intentionally skips the only cleanup at gateway/run.py:11173-11176. The current cleanup routine shuts down the memory provider and closes tool/client resources (gateway/run.py:6037-6076), so a timed-out worker that eventually returns leaks its temporary agent.
  • Current main now binds hygiene compaction to the live SessionDB (gateway/run.py:11278-11309) and starts _run_agent after hygiene failure handling (gateway/run.py:11632-11650). Salvage must not let a timed-out worker continue mutating that session concurrently with the new turn.

Suggested changes

  • Use a lifecycle boundary that stops/fences timed-out compression before the live turn proceeds, and ensure cleanup happens after worker completion.
  • Add a SessionDB-bound timeout regression covering both no post-timeout compaction and eventual resource cleanup.

Automated hermes-sweeper review.

Comment thread gateway/run.py
@@ -10953,13 +10987,53 @@ async def _handle_message_with_agent(self, event, source, _quick_key: str, run_g
_hyg_agent._print_fn = lambda *a, **kw: None

loop = asyncio.get_running_loop()
_compressed, _ = await loop.run_in_executor(
_hyg_timed_out = False
_hyg_future = loop.run_in_executor(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait_for() bounds the await, not this executor thread. The timeout path later skips cleanup entirely, so a worker that eventually returns leaks its temporary AIAgent; once salvaged onto current main, that worker can also race the SessionDB-bound hygiene compactor. Please fence/terminate completion before proceeding to the live turn and arrange cleanup after it is safe.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 15, 2026
@westkite1201
westkite1201 force-pushed the fix/gateway-hygiene-timeout-cooldown branch from e43d4b5 to 95adbe5 Compare July 15, 2026 06:17
@teknium1 teknium1 added the area/compression Context compression and continuation sessions label Jul 19, 2026
@alt-glitch alt-glitch added comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Jul 19, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #69866 (commit 2e9765b). Salvaged with worker fencing added: bounded await + cancellation-token no-op for late workers + temp-agent cleanup + lock-reacquire verification. Note: the commit was authored by @kshitijk4poor and lands with his authorship; PR-submission credit to you in the merged body.

@teknium1 teknium1 closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions area/config Config system, migrations, profiles comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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.

6 participants