Skip to content

fix(cron): read per-job max_tokens from job config and pass to AIAgent - #58440

Closed
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-58423-max-tokens
Closed

fix(cron): read per-job max_tokens from job config and pass to AIAgent#58440
liuhao1024 wants to merge 1 commit into
NousResearch:mainfrom
liuhao1024:liuhao/cron-bugfix-58423-max-tokens

Conversation

@liuhao1024

Copy link
Copy Markdown
Contributor

What does this PR do?

Wires up the per-job max_tokens config key so cron jobs can override the output token limit. Previously, run_job() read job.get("model"), reasoning config, prefill messages, toolsets, etc. from the job config — but never read max_tokens, so any "max_tokens": 4096 (or any value) in a job's jobs.json entry was silently ignored and AIAgent always defaulted to max_tokens=None.

Related Issue

Fixes #58423

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

Changes Made

  • cron/scheduler.py: Extract job.get("max_tokens") with int validation and warning on invalid values, then pass it as max_tokens=job_max_tokens to the AIAgent(...) constructor call in run_job().

How to Test

  1. Run grep -n 'max_tokens' cron/scheduler.py — should now show the extraction (L2729) and the AIAgent kwarg (L2891).
  2. Run python -c "from cron.scheduler import run_job; print('import ok')" — should pass without errors.
  3. Run pytest tests/cron/ -q — should pass (pre-existing unrelated failures in test_all_token_case_insensitive are upstream issues).
  4. Create a test cron job with "max_tokens": 4096 in its jobs.json entry, trigger it, and observe the agent respects the per-job limit instead of silently ignoring it.

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass (pre-existing failures in unrelated tests: test_all_token_case_insensitive, test_explicit_origin_no_origin_emits_notice, test_cron_duplicate_target_is_skipped_and_explained)
  • I've added tests for my changes — N/A: config plumbing fix; the int validation + warning is verified by grep and python -c import checks above
  • I've tested on my platform: macOS 26.4.1

Documentation & Housekeeping

  • I've updated relevant documentation — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture — or N/A
  • I've considered cross-platform impact — N/A (config plumbing only)
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

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.
@teknium1

teknium1 commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Thanks — the diagnosis was correct (the scheduler never read max_tokens from job config, so the key was silently inert), and the implementation was clean. Closing on a policy decision rather than a code-quality one: after review, we don't want per-job max_tokens as a user-facing knob at all. Output-token caps interact badly with agent loops (truncated tool calls, malformed JSON mid-generation) and the failure modes are worse than the truncation loops they'd be limiting. The rest of your batch from today (#58431, #58378, #58397) was salvaged and merged with your authorship preserved — thanks for the solid work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cron Cron scheduler and job management P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] cron scheduler.py run_job() never reads per-job max_tokens — AIAgent() always gets None

3 participants