The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): split archives on the last heading; match lane silence forms
liuhao1024a11b77fe3932
diff --git a/cron/scheduler_prompt.py b/cron/scheduler_prompt.pyindex 9db47a261da..4050c7ab57c 100644--- a/cron/scheduler_prompt.py+++ b/cron/scheduler_prompt.py@@ -53,9 +53,9 @@ def _job_skill_names(job: dict) -> list[str]:_MAX_CONTEXT_CHARS = 8000_SELF_CONTEXT_INTRO = (- "The following is this job's most recent output from its previous run. Use it for "- "continuity: avoid repeating what was already reported, and continue where the last run "- "left off."+ "The following is this job's most recent non-silent output from a previous run. Use it "+ "for continuity: avoid repeating what was already reported, and continue where the last "+ "run left off.")_UPSTREAM_CONTEXT_INTRO = ("The following is the most recent output from a preceding cron job. Use it as context for "@@ -64,17 +64,21 @@ _UPSTREAM_CONTEXT_INTRO = (def _archive_answer(archive: str) -> str | None:- """The reusable answer of a stored run: the text after ``## Response``.-- Archives without the heading (script-mode runs) stay whole-document.- ``None`` marks "no usable answer" — a ``[SILENT]`` or blank response — so- the caller falls through to an older archive instead of injecting prompt- noise the job already has.+ """The reusable answer of a stored run: the text after the last ``## Response``.++ Archives without the heading (script-mode runs) stay whole-document. The LAST+ occurrence is the writer's boundary — the assembled prompt half can itself carry+ the literal heading (a skill documenting its response format, an injected previous+ answer quoting it), so an early split would re-inject the prompt noise this+ extraction exists to drop.+ ``None`` marks "no usable answer" — a blank or silent response (any form the+ delivery lane itself suppresses) — so the caller falls through to an older+ archive instead of injecting prompt noise the job already has."""if "## Response" not in archive:return archive- answer = archive.partition("## Response")[2].strip()- if answer in ("", "[SILENT]"):+ answer = archive.rpartition("## Response")[2].strip()+ if not answer or _sched._is_cron_silence_response(answer):return Nonereturn answerdiff --git a/tests/cron/test_context_from_response_extraction.py b/tests/cron/test_context_from_response_extraction.pyindex 53755a0c6ef..2b4b5216f9e 100644--- a/tests/cron/test_context_from_response_extraction.py+++ b/tests/cron/test_context_from_response_extraction.py@@ -118,6 +118,57 @@ class TestUnusableAnswersFallThrough:assert prompt == "Report"+class TestPromptHalfCarryingTheHeading:+ """The assembled prompt half can itself contain a literal ``## Response`` heading+ (a skill documenting its response format, an injected previous answer quoting it).+ The writer appends the response section last, so the LAST occurrence is the+ boundary — an early split would inject the prompt tail plus the answer."""++ def test_heading_inside_prompt_half_does_not_split_early(self, cron_env):+ from cron.jobs import create_job+ from cron.scheduler import _build_job_prompt++ job = create_job(prompt="Run the daily check", schedule="0 8 * * *", context_from="self")+ _write_archive(+ cron_env, job["id"], "2026-09-19_08-00-00.md",+ "# Cron Job: probe\n\n## Prompt\n\n"+ "Use this format:\n\n## Response\n\nSKILL-DOCUMENTED-FORMAT\n"+ "\nEnd of format spec.\n\n## Response\n\nREAL-RUN-ANSWER-7\n",+ )++ prompt = _build_job_prompt(job)++ assert "REAL-RUN-ANSWER-7" in prompt+ assert "SKILL-DOCUMENTED-FORMAT" not in prompt # prompt-half copy is dropped+++class TestBracketlessSilenceFallsThrough:+ """The delivery lane suppresses more than the literal ``[SILENT]`` — bracketless+ ``SILENT`` / ``NO_REPLY`` forms too (#46917, #51438). An archive whose answer is one+ of those forms carries no usable continuity either, and must not be injected."""++ @pytest.mark.parametrize("silent_answer", ["SILENT", "NO_REPLY", "[SILENT] No changes today"])+ def test_bracketless_silent_answer_falls_through(self, cron_env, silent_answer):+ from cron.jobs import create_job+ from cron.scheduler_prompt import _inject_context_from++ job = create_job(prompt="Report", schedule="0 8 * * *", context_from="self")+ _write_archive(+ cron_env, job["id"], "2026-09-18_08-00-00.md",+ "# Cron Job: probe\n\n## Prompt\n\ndo the thing\n\n## Response\n\nOLDER-REAL-ANSWER\n",+ )+ _write_archive(+ cron_env, job["id"], "2026-09-19_08-00-00.md",+ "# Cron Job: probe\n\n## Prompt\n\ndo the thing\n\n## Response\n\n" + silent_answer + "\n",+ )++ prompt, injected = _inject_context_from(job, "Report")++ assert injected is True+ assert "OLDER-REAL-ANSWER" in prompt+ assert silent_answer not in prompt++class TestScriptModeArchives:"""Archives without a ## Response heading (script-mode) stay whole-document."""