The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(compression): fallback summaries, multiline setup notes and parallel loads keep skill markers right
Teknium297552a9d646
diff --git a/agent/context_compressor.py b/agent/context_compressor.pyindex 6d7ffbb853e..b6c53a54fd7 100644--- a/agent/context_compressor.py+++ b/agent/context_compressor.py@@ -34,7 +34,7 @@ from agent.context_engine import ContextEngine, sanitize_memory_contextfrom agent.context_compressor_prellm import PreLlmSkipMixinfrom agent.context_compressor_summary import SummaryDispatchMixinfrom agent.context_compressor_retry import retryable_user_text-from agent.context_compressor_tail import demote_stale_tail_tools, is_demoted_stub+from agent.context_compressor_tail import demote_stale_tail_tools, is_demoted_stub, skill_view_names_by_call_idfrom agent.context_compressor_telemetry import CompressionTelemetryMixinfrom agent.error_classifier import FailoverReason, classify_api_errorfrom agent.micro_compaction import MicroCompactionMixin@@ -884,12 +884,7 @@ def _collect_ghosted_skill_names(turns: list[dict[str, Any]]) -> list[str]:"""Skills about to be lost in compaction, whatever their size: marked or plain ``skill_view`` stubs, raw``skill_view`` bodies, and skills a ``/skill``, bundle or auto-load turn carried inline."""from agent.skill_commands import skills_loaded_by_scaffold- call_id_to_skill: dict[str, str] = {}- for idx, skill in _skill_view_call_sites(turns):- for tc in turns[idx].get("tool_calls") or []:- cid = _tc_get(tc, "id")- if cid and _tc_get(_tc_get(tc, "function", {}), "name") == "skill_view":- call_id_to_skill[cid] = skill+ call_id_to_skill = skill_view_names_by_call_id(turns)names: list[str] = []for msg in turns:content = msg.get("content")@@ -1727,8 +1722,10 @@ def _sum_execute_code(name, args, content, content_len, line_count):def _sum_skill_view(name, args, content, content_len, line_count):skill = args.get("name", "?")# Ghost-skill defense: any loaded body, however small, leaves the marker saying it is gone and how to reload.- failed = _result_failure_suffix(content)- marker = "" if skill == "?" or failed else " " + _skill_pruned_marker(str(skill))+ failed = _result_failure_suffix(content) or (" FAILED" if _skill_view_failed(content) else "")+ # Re-summarizing a stub (fallback summary) keeps that stub's own verdict instead of re-deciding blind.+ keep = SKILL_PRUNED_MARKER_PREFIX in content if _is_summary_stub(content) else not failed+ marker = " " + _skill_pruned_marker(str(skill)) if skill != "?" and keep else ""return f"[skill_view] name={skill}{failed} ({content_len:,} chars)" + marker@@ -3559,7 +3556,8 @@ class ContextCompressor(_collect_paths_from_jsonish(parsed, relevant_files)for msg in turns_to_summarize:role = msg.get("role", "unknown")- text = _compact_fallback_turn(msg.get("content"))+ content = msg.get("content")+ text = _compact_fallback_turn(_typed_user_text(content) if role == "user" and isinstance(content, str) else content)_collect_path_mentions(text, relevant_files)synthetic_user = role == "user" and self._is_synthetic_compression_user_turn(msg)tool_names = [_extract_tool_call_name_and_args(tc)[0] for tc in (msg.get("tool_calls") or [])] if role == "assistant" else []diff --git a/agent/context_compressor_tail.py b/agent/context_compressor_tail.pyindex 3e749b4c4af..6b9aa24de8b 100644--- a/agent/context_compressor_tail.py+++ b/agent/context_compressor_tail.py@@ -30,7 +30,7 @@ def _lean_recovery_stub(tool_name: str, content_len: int, session_id: str) -> st)-def _skill_view_names_by_call_id(messages: list[dict[str, Any]]) -> dict[str, str]:+def skill_view_names_by_call_id(messages: list[dict[str, Any]]) -> dict[str, str]:"""Map each ``skill_view`` tool-call id to the skill name it loaded."""from agent.context_compressor import _json_dict, _tc_get@@ -77,7 +77,7 @@ def demote_stale_tail_tools(if len(content) < _LEAN_TAIL_DEMOTE_MIN_CHARS or SKILL_PRUNED_MARKER_PREFIX in content or _is_summary_stub(content):continuestub = _lean_recovery_stub(msg.get("tool_name") or "", len(content), session_id)- skills = _skill_view_names_by_call_id(messages) if skills is None else skills+ skills = skill_view_names_by_call_id(messages) if skills is None else skillsif (skill := skills.get(str(msg.get("tool_call_id") or ""))) and not _result_failure_suffix(content):stub += " " + _skill_pruned_marker(skill)result[i] = _rewritten(msg, stub)diff --git a/agent/skill_commands.py b/agent/skill_commands.pyindex 93e09127b1f..fbdcc3c2477 100644--- a/agent/skill_commands.py+++ b/agent/skill_commands.py@@ -330,7 +330,7 @@ _SKILL_DIR_NOTE = (# Closing text of the optional blocks _build_skill_message appends after the directory note; the# auto-load describer skips them so they are never read as the user's typed request._SUPPORTING_FILES_END = "/scripts/foo.js`)."-_TRAILING_BLOCK_ENDS = (("[Skill config (", "\n]"), ("[Skill setup note: ", "\n"),+_TRAILING_BLOCK_ENDS = (("[Skill config (", "\n]"), ("[Skill setup note: ", "]\n\n"),("[This skill has supporting files", _SUPPORTING_FILES_END))_SETUP_SKIPPED_NOTE = ("Required environment setup was skipped. Continue loading the skill "diff --git a/tests/agent/test_ghost_skill_pruning.py b/tests/agent/test_ghost_skill_pruning.pyindex c9cac8c11ef..327734adbf1 100644--- a/tests/agent/test_ghost_skill_pruning.py+++ b/tests/agent/test_ghost_skill_pruning.py@@ -87,11 +87,16 @@ class TestSkillPrunedMarkerEmit:failed = json.dumps({"success": False, "error": "Skill 'nope' not found. " + "Available: a, b. " * 30})failed_stub = _summarize_tool_result("skill_view", '{"name":"nope"}', failed)assert SKILL_PRUNED_MARKER_PREFIX not in failed_stub- # Neither the raw failure nor its stub is listed for reload at a later compaction.+ # Neither the raw failure nor its stub is listed for reload later, by the collector or the fallback summary.for content in (failed, failed_stub):turns = _skill_view_pair("call_nope", "nope")turns[1]["content"] = contentassert _collect_ghosted_skill_names(turns) == []+ assert "skill_view(name='nope')" not in _make_compressor()._build_static_fallback_summary(turns)+ # Parallel loads on one assistant row are each listed under their own name.+ pair_one, pair_two = _skill_view_pair("call_1", "one", 300), _skill_view_pair("call_2", "two", 300)+ row = {**pair_one[0], "tool_calls": pair_one[0]["tool_calls"] + pair_two[0]["tool_calls"]}+ assert _collect_ghosted_skill_names([row, pair_one[1], pair_two[1]]) == ["one", "two"]def test_marker_extractor_round_trips_the_emitted_marker(self):"""Emit and check sides share one canonical string.@@ -270,7 +275,8 @@ class TestMarkerSurvivesRealCompress:user_instruction="remember PLUM-77")# A gateway auto-load turn whose skill lists supporting files: the request follows those blocks.auto = _build_skill_message(- {"name": "gw-skill", "content": "gateway skill body", "linked_files": {"references": ["references/gw.md"]}},+ {"name": "gw-skill", "content": "gateway skill body", "linked_files": {"references": ["references/gw.md"]},+ "setup_needed": True, "setup_note": "First setup step.\nSecond setup step."},Path("/skills/gw-skill"),'[IMPORTANT: The "gw-skill" skill is auto-loaded. Follow its instructions for this session.]',) + "\n\nhello from the gateway"