fix(cron): silent skip when context_from job has no output yet

This commit is contained in:
MorAlekss
2026-04-25 02:54:59 -07:00
committed by Teknium
parent e4a91ccb76
commit eb92222811
2 changed files with 8 additions and 20 deletions

View File

@@ -685,22 +685,14 @@ def _build_job_prompt(job: dict, prerun_script: Optional[tuple] = None) -> str:
try: try:
job_output_dir = OUTPUT_DIR / source_job_id job_output_dir = OUTPUT_DIR / source_job_id
if not job_output_dir.exists(): if not job_output_dir.exists():
prompt = ( continue # silent skip — no output yet
f"[Context job '{source_job_id}' has no output yet.]\n\n"
f"{prompt}"
)
continue
output_files = sorted( output_files = sorted(
job_output_dir.glob("*.md"), job_output_dir.glob("*.md"),
key=lambda f: f.stat().st_mtime, key=lambda f: f.stat().st_mtime,
reverse=True, reverse=True,
) )
if not output_files: if not output_files:
prompt = ( continue # silent skip — no output yet
f"[Context job '{source_job_id}' has no output yet.]\n\n"
f"{prompt}"
)
continue
latest_output = output_files[0].read_text(encoding="utf-8").strip() latest_output = output_files[0].read_text(encoding="utf-8").strip()
# Truncate to 8K characters to avoid prompt bloat # Truncate to 8K characters to avoid prompt bloat
_MAX_CONTEXT_CHARS = 8000 _MAX_CONTEXT_CHARS = 8000
@@ -715,16 +707,10 @@ def _build_job_prompt(job: dict, prerun_script: Optional[tuple] = None) -> str:
f"{prompt}" f"{prompt}"
) )
else: else:
prompt = ( continue # silent skip — empty output
f"[Context job '{source_job_id}' has no output yet.]\n\n"
f"{prompt}"
)
except (OSError, PermissionError) as e: except (OSError, PermissionError) as e:
logger.warning("context_from: failed to read output for job %r: %s", source_job_id, e) logger.warning("context_from: failed to read output for job %r: %s", source_job_id, e)
prompt = ( # silent skip — do not pollute the prompt with error messages
f"[Context job '{source_job_id}' output could not be read.]\n\n"
f"{prompt}"
)
# Always prepend cron execution guidance so the agent knows how # Always prepend cron execution guidance so the agent knows how
# delivery works and can suppress delivery when appropriate. # delivery works and can suppress delivery when appropriate.

View File

@@ -132,9 +132,11 @@ class TestBuildJobPromptContextFrom:
prompt="Summarize", schedule="every 2h", context_from=job_a["id"] prompt="Summarize", schedule="every 2h", context_from=job_a["id"]
) )
# job_a ещё не запускался — output dir не существует # job_a never ran — output dir does not exist
# expect silent skip: no placeholder injected, base prompt intact
prompt = _build_job_prompt(job_b) prompt = _build_job_prompt(job_b)
assert "no output yet" in prompt.lower() or "not found" in prompt.lower() assert "no output" not in prompt.lower()
assert "not found" not in prompt.lower()
assert "Summarize" in prompt assert "Summarize" in prompt
def test_injects_multiple_context_jobs(self, cron_env): def test_injects_multiple_context_jobs(self, cron_env):