The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): a paste-only opener's expansion footer must not demote the title preview
teknium185f5f560c361
diff --git a/agent/title_generator.py b/agent/title_generator.pyindex d58b0f7cc56..e2303ca03a9 100644--- a/agent/title_generator.py+++ b/agent/title_generator.py@@ -48,6 +48,8 @@ RuntimeValidator = Callable[[], bool]MAX_TITLE_INPUT_CHARS = 1000_PASTE_PREVIEW_LABEL = "\n\nPasted content:\n"_ATTACHMENT_REF_RE = re.compile(r"@(?:file|folder):\S+")+# Footers the @-reference expander appends below the typed text (agent/context_references.py).+_CONTEXT_FOOTER_RE = re.compile(r"\n+--- (?:Context Warnings|Attached Context) ---\n.*", re.DOTALL)# Cap on the instant derived title; a raw fragment reads worse the longer it runs.MAX_DERIVED_TITLE_CHARS = 48# Answer-shaped guard: a tiny model sometimes answers instead of titling; longer is rejected, not truncated.@@ -224,6 +226,9 @@ def build_title_input(user_message: str, title_preview: str | None = None) -> stpreview = title_preview.strip() if isinstance(title_preview, str) else ""if not preview:return message[:MAX_TITLE_INPUT_CHARS]+ # The titler sees the message AFTER @-reference expansion, so the generated ref drags a+ # warnings/attached-context footer along; the preview already carries the topic, so drop it.+ message = _CONTEXT_FOOTER_RE.sub("", message).strip()# A paste-only opener is just the generated `@file:` ref: the preview IS the topic, so it# leads (derive_title takes the first line, and a file path is not a title).if not _ATTACHMENT_REF_RE.sub("", message).strip():diff --git a/tests/agent/test_title_generator.py b/tests/agent/test_title_generator.pyindex ad7bf9ca305..890bb321977 100644--- a/tests/agent/test_title_generator.py+++ b/tests/agent/test_title_generator.py@@ -40,6 +40,20 @@ class TestGenerateTitle:lead = paste_preview if instruction.startswith("@file:") else instructionassert derive_title(instruction, paste_preview).startswith(lead[:12])+ def test_expanded_paste_ref_footer_does_not_demote_the_preview(self):+ """The titler receives the opener AFTER @-reference expansion: the generated ref carries a+ `--- Context Warnings ---` (or `--- Attached Context ---`) footer, which must not turn a+ paste-only opener into "instruction + trailing preview" (live wire finding on #114984)."""+ ref = "@file:/home/u/.hermes/attachments/pasted_content_2026-09-18_14-09-43-735_d0ee85.txt"+ preview = "Quarterly incident analysis for the database cluster"+ for footer in (f"\n\n--- Context Warnings ---\n- {ref}: path is outside the allowed workspace",+ "\n\n--- Attached Context ---\n\n### file: pasted_content.txt\n" + preview):+ title_input = build_title_input(ref + footer, preview)++ assert title_input.startswith(preview)+ assert "---" not in title_input and "@file:" not in title_input+ assert derive_title(ref + footer, preview).startswith("Quarterly incident analysis")+def test_title_input_budget_and_manual_attachments_stay_unread(self):title_input = build_title_input("Describe the release plan", "p" * MAX_TITLE_INPUT_CHARS)