mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-24 16:54:43 +00:00
fix(compress): classify unconfirmed lock-acquire failures and cover all manual-compress surfaces
Follow-up to the salvaged #57634 commits: - agent/manual_compression_feedback.py: new describe_compression_lock_skip() — single source of truth for lock-skip wording. A descriptive holder string means another compressor CONFIRMED holds the lock ('already in progress (holder: ...)'); True/None means acquisition failed without a confirmed holder (hermes_state.try_acquire_compression_lock catches sqlite3.Error internally and returns False), so the message says 'could not acquire ... the lock check failed' instead of falsely claiming a concurrent compression is running. - cli.py, gateway/slash_commands.py, tui_gateway/server.py (all three in-process consumers: session.compress RPC, command.dispatch compress branch, slash.exec mirror) now route through the shared helper. - tui_gateway/server.py command.dispatch compress branch: catch CompressionLockHeld explicitly — it previously fell into the generic 'compress failed' error handler. - Deferred-notify contract (#69324): lock-skip discards the pending context-engine notification (committed=False) in _compress_session_history and the CLI path before returning. - tests: lock-skip wording pins per surface, VISIBLE_COMPRESSION_MESSAGES noise-filter carve-outs for both wordings, MagicMock signal opt-outs for sibling tests added on main after the original PR.
This commit is contained in:
parent
e8000b42e7
commit
eb7be2edde
10 changed files with 338 additions and 70 deletions
|
|
@ -85,6 +85,8 @@ def test_manual_compress_reports_aborted_summary_without_success_banner(capsys):
|
|||
"Provider 'opencode-zen' is set in config.yaml but no API key was found."
|
||||
)
|
||||
shell.agent._compress_context.return_value = (list(history), "")
|
||||
# Explicit non-lock-skip: MagicMock getattr would return a truthy mock.
|
||||
shell.agent._compression_skipped_due_to_lock = False
|
||||
|
||||
with patch("agent.model_metadata.estimate_request_tokens_rough", return_value=100):
|
||||
shell._manual_compress()
|
||||
|
|
@ -246,6 +248,8 @@ def test_manual_compress_runs_when_auto_compaction_disabled(capsys):
|
|||
shell.agent.tools = None
|
||||
shell.agent.session_id = shell.session_id
|
||||
shell.agent._compress_context.return_value = (compressed, "")
|
||||
# Explicit non-lock-skip: MagicMock getattr would return a truthy mock.
|
||||
shell.agent._compression_skipped_due_to_lock = False
|
||||
|
||||
with patch("agent.model_metadata.estimate_request_tokens_rough", return_value=100):
|
||||
shell._manual_compress()
|
||||
|
|
@ -281,10 +285,13 @@ def test_manual_compress_no_sync_when_session_id_unchanged():
|
|||
assert shell._pending_title == "keep me"
|
||||
|
||||
|
||||
def test_manual_compress_shows_lock_in_progress_when_skipped_due_to_lock(capsys):
|
||||
"""When _compress_context skips due to a concurrent compression lock,
|
||||
_manual_compress must print a clear "already in progress" message,
|
||||
NOT show the misleading "No changes from compression" no-op text."""
|
||||
def test_manual_compress_shows_lock_skip_without_confirmed_holder(capsys):
|
||||
"""When _compress_context skips due to the compression lock WITHOUT a
|
||||
confirmed holder (signal=True — acquisition failed but
|
||||
get_compression_lock_holder returned nothing, e.g. a SQLite error made
|
||||
try_acquire return False), _manual_compress must print the unconfirmed
|
||||
lock-skip wording, NOT claim another compression is definitely running,
|
||||
and NOT show the misleading "No changes from compression" no-op text."""
|
||||
shell = _make_cli()
|
||||
history = _make_history()
|
||||
shell.conversation_history = history
|
||||
|
|
@ -306,7 +313,10 @@ def test_manual_compress_shows_lock_in_progress_when_skipped_due_to_lock(capsys)
|
|||
shell._manual_compress()
|
||||
|
||||
output = capsys.readouterr().out
|
||||
assert "Compression already in progress" in output
|
||||
assert "Compression skipped" in output
|
||||
assert "could not acquire" in output
|
||||
# No confirmed holder → must not assert one is running.
|
||||
assert "already in progress" not in output
|
||||
assert "No changes from compression" not in output
|
||||
# Signal should be cleared after use.
|
||||
assert shell.agent._compression_skipped_due_to_lock is None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue