From 9530d3100ad400a3925d5c791dea79ee169c2a5e Mon Sep 17 00:00:00 2001 From: liuhao1024 Date: Sun, 5 Jul 2026 02:30:03 +0800 Subject: [PATCH] fix(cron): read per-job max_tokens from job config and pass to AIAgent run_job() never read job.get('max_tokens'), so any per-job max_tokens setting in jobs.json was silently ignored. AIAgent always defaulted to max_tokens=None regardless of the job config. Extract the value, validate it as int, and pass it through to the AIAgent constructor. --- cron/scheduler.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cron/scheduler.py b/cron/scheduler.py index 39f4ed82c003..31be7877b84b 100644 --- a/cron/scheduler.py +++ b/cron/scheduler.py @@ -2726,6 +2726,15 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: # Max iterations max_iterations = _cfg.get("agent", {}).get("max_turns") or _cfg.get("max_turns") or 90 + # Per-job max_tokens override (e.g. "max_tokens": 4096 in jobs.json) + job_max_tokens = job.get("max_tokens") + if job_max_tokens is not None: + try: + job_max_tokens = int(job_max_tokens) + except (ValueError, TypeError): + logger.warning("Job '%s': invalid max_tokens=%r, ignoring", job_id, job_max_tokens) + job_max_tokens = None + # Provider routing pr = _cfg.get("provider_routing") or {} @@ -2880,6 +2889,7 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]: acp_command=runtime.get("command"), acp_args=runtime.get("args"), max_iterations=max_iterations, + max_tokens=job_max_tokens, reasoning_config=reasoning_config, prefill_messages=prefill_messages, fallback_model=fallback_model,