The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): warn and remediate opaque checkpoint_required blocks
KoNit-Kef7c7f9e082f
diff --git a/agent/agent_init.py b/agent/agent_init.pyindex cf2b06d460a..7fa654fb07d 100644--- a/agent/agent_init.py+++ b/agent/agent_init.py@@ -1894,6 +1894,8 @@ def _build_context_engine(agent, _agent_cfg, cs, _custom_providers, _effective_cif hasattr(_cc, _attr):setattr(_cc, _attr, _value)agent.compression_checkpoint_required = cs.checkpoint_required+ from agent.conversation_compression import _warn_checkpoint_required_without_capable_provider+ _warn_checkpoint_required_without_capable_provider(agent)agent.codex_app_server_auto_compaction = cs.codex_app_server_autoagent.codex_responses_native_compaction = cs.codex_responses_nativeagent.codex_responses_compact_threshold = cs.codex_responses_compact_thresholddiff --git a/agent/conversation_compression.py b/agent/conversation_compression.pyindex 54946df3edf..e2470581854 100644--- a/agent/conversation_compression.py+++ b/agent/conversation_compression.py@@ -1253,9 +1253,64 @@ class CompressionCheckpointUnavailable(RuntimeError):"""Raised when required durable pre-compress checkpointing is unavailable."""+# Shared by the startup warning and compress-time block so operators see the+# same recovery path: disable the fail-closed flag, or switch providers.+_CHECKPOINT_REQUIRED_REMEDIATION = (+ "set compression.checkpoint_required: false, or switch to a memory "+ "provider that implements checkpoint API v2"+)+++def _active_memory_provider_label(agent: Any) -> str:+ """Human-readable active provider name, or an explicit none sentinel."""+ memory_manager = getattr(agent, "_memory_manager", None)+ if memory_manager is None:+ return "no active provider"+ providers = getattr(memory_manager, "providers", None)+ names: list[str] = []+ if providers is not None:+ try:+ iterable = list(providers)+ except TypeError:+ iterable = []+ for provider in iterable:+ name = getattr(provider, "name", None)+ if isinstance(name, str) and name.strip():+ names.append(name.strip())+ return ", ".join(names) if names else "no active provider"++def _checkpoint_blocked(reason: str) -> CompressionCheckpointUnavailable:return CompressionCheckpointUnavailable(- f"BLOCKED_MISSING_PREREQUISITE: required pre-compress checkpoint unavailable: {reason}"+ f"BLOCKED_MISSING_PREREQUISITE: required pre-compress checkpoint unavailable: {reason}. "+ f"Recover by {_CHECKPOINT_REQUIRED_REMEDIATION}."+ )+++def _warn_checkpoint_required_without_capable_provider(agent: Any) -> None:+ """Startup warning when fail-closed compress will block (init itself must not refuse).++ Capability-probe exceptions are suppressed so a broken provider cannot crash+ agent construction — same fail-open style as the micro-compact warning.+ """+ if getattr(agent, "compression_checkpoint_required", False) is not True:+ return+ memory_manager = getattr(agent, "_memory_manager", None)+ if memory_manager is not None:+ supports_checkpoint = getattr(memory_manager, "supports_pre_compress_checkpoint", None)+ if callable(supports_checkpoint):+ try:+ if bool(supports_checkpoint(PRE_COMPRESS_CHECKPOINT_API_VERSION)):+ return+ except Exception:+ return+ logger.warning(+ "compression.checkpoint_required is enabled but the active memory "+ "provider (%s) does not implement checkpoint API v%s. Compress will "+ "fail closed. Recover by %s.",+ _active_memory_provider_label(agent),+ PRE_COMPRESS_CHECKPOINT_API_VERSION,+ _CHECKPOINT_REQUIRED_REMEDIATION,)diff --git a/tests/agent/test_pre_compress_checkpoint_contract.py b/tests/agent/test_pre_compress_checkpoint_contract.pyindex b54c0caef28..70252a94522 100644--- a/tests/agent/test_pre_compress_checkpoint_contract.py+++ b/tests/agent/test_pre_compress_checkpoint_contract.py@@ -556,3 +556,147 @@ def test_agent_init_suppresses_micro_compaction_under_checkpoint_gate():)assert assign_idx != -1assert suppress_idx < assign_idx+++def _warn_text(caplog) -> str:+ return "\n".join(r.getMessage() for r in caplog.records)+++def test_startup_warns_when_checkpoint_required_and_legacy_provider(caplog):+ """Fail-closed compress is correct, but operators need a startup hint.++ holographic-style v1 providers do not implement checkpoint API v2; with+ ``compression.checkpoint_required`` armed, init must warn with the config+ key, the active provider name, and how to recover.+ """+ import logging+ from types import SimpleNamespace++ from agent.conversation_compression import (+ _warn_checkpoint_required_without_capable_provider,+ )++ manager = MemoryManager()+ manager.add_provider(_BaseStubProvider("holographic"))+ agent = SimpleNamespace(+ compression_checkpoint_required=True,+ _memory_manager=manager,+ )++ with caplog.at_level(logging.WARNING, logger="agent.conversation_compression"):+ _warn_checkpoint_required_without_capable_provider(agent)++ text = _warn_text(caplog)+ assert "compression.checkpoint_required" in text+ assert "holographic" in text+ assert "false" in text.lower()+++def test_pre_compress_blocked_error_includes_checkpoint_required_remediation():+ """Compress-time block must name the flag, not just the missing API."""+ from types import SimpleNamespace++ from agent.conversation_compression import _pre_compress_memory_context++ manager = MemoryManager()+ manager.add_provider(_BaseStubProvider("legacy"))+ agent = SimpleNamespace(_memory_manager=manager)++ with pytest.raises(CompressionCheckpointUnavailable) as excinfo:+ _pre_compress_memory_context(+ agent, [{"role": "user", "content": "evidence"}], True+ )++ msg = str(excinfo.value)+ assert "BLOCKED_MISSING_PREREQUISITE" in msg+ assert "compression.checkpoint_required" in msg+++def test_startup_does_not_warn_when_provider_is_checkpoint_capable(caplog):+ import logging+ from types import SimpleNamespace++ from agent.conversation_compression import (+ _warn_checkpoint_required_without_capable_provider,+ )++ manager = MemoryManager()+ manager.add_provider(_CheckpointProvider("durable"))+ agent = SimpleNamespace(+ compression_checkpoint_required=True,+ _memory_manager=manager,+ )++ with caplog.at_level(logging.WARNING, logger="agent.conversation_compression"):+ _warn_checkpoint_required_without_capable_provider(agent)++ assert "compression.checkpoint_required" not in _warn_text(caplog)+++def test_startup_does_not_warn_when_checkpoint_required_is_false(caplog):+ import logging+ from types import SimpleNamespace++ from agent.conversation_compression import (+ _warn_checkpoint_required_without_capable_provider,+ )++ manager = MemoryManager()+ manager.add_provider(_BaseStubProvider("holographic"))+ agent = SimpleNamespace(+ compression_checkpoint_required=False,+ _memory_manager=manager,+ )++ with caplog.at_level(logging.WARNING, logger="agent.conversation_compression"):+ _warn_checkpoint_required_without_capable_provider(agent)++ assert "compression.checkpoint_required" not in _warn_text(caplog)+++def test_startup_warns_when_checkpoint_required_and_no_memory_manager(caplog):+ """skip_memory leaves no manager; compress still blocks, so init must warn."""+ import logging+ from types import SimpleNamespace++ from agent.conversation_compression import (+ _warn_checkpoint_required_without_capable_provider,+ )++ agent = SimpleNamespace(+ compression_checkpoint_required=True,+ _memory_manager=None,+ )++ with caplog.at_level(logging.WARNING, logger="agent.conversation_compression"):+ _warn_checkpoint_required_without_capable_provider(agent)++ text = _warn_text(caplog)+ assert "compression.checkpoint_required" in text+ assert "no active provider" in text.lower() or "none" in text.lower()+++def test_startup_probe_exception_fails_open_without_crash_or_warning(caplog):+ """A broken capability probe must not refuse init (micro_compact-style)."""+ import logging+ from types import SimpleNamespace++ from agent.conversation_compression import (+ _warn_checkpoint_required_without_capable_provider,+ )++ class _ExplodingManager:+ providers = []++ def supports_pre_compress_checkpoint(self, api_version):+ raise RuntimeError("probe exploded")++ agent = SimpleNamespace(+ compression_checkpoint_required=True,+ _memory_manager=_ExplodingManager(),+ )++ with caplog.at_level(logging.WARNING, logger="agent.conversation_compression"):+ _warn_checkpoint_required_without_capable_provider(agent)++ assert "compression.checkpoint_required" not in _warn_text(caplog)