agentscope-ai/agentscope · error · ValueError

Expected a 5-field cron expression, got {record.data.cron_ex

Error message

Expected a 5-field cron expression, got {record.data.cron_expression!r}

What it means

The scheduler parses cron expressions manually (because CronTrigger.from_crontab cannot pass start_date/end_date) and requires exactly 5 whitespace-separated fields: minute hour day month day-of-week. Any other count raises this ValueError.

Source

Thrown at src/agentscope/app/_manager/_scheduler/_scheduler_manager.py:316

        """

        from apscheduler.triggers.cron import CronTrigger

        logger.info(
            "Registering schedule %s(%s) cron=%s tz=%s",
            record.id,
            record.data.name,
            record.data.cron_expression,
            record.data.timezone,
        )

        # ``CronTrigger.from_crontab`` is a thin helper that only forwards
        # the 5 parsed fields and ``timezone`` — it has no parameter for
        # ``start_date`` / ``end_date``.  Parse the expression ourselves so
        # the configured activation window is honoured.
        fields = record.data.cron_expression.split()
        if len(fields) != 5:
            raise ValueError(
                "Expected a 5-field cron expression, got "
                f"{record.data.cron_expression!r}",
            )
        minute, hour, day, month, day_of_week = fields

        trigger = self._build_trigger(record)
        job = self._scheduler.add_job(
            trigger,
            trigger=CronTrigger(
                minute=minute,
                hour=hour,
                day=day,
                month=month,
                day_of_week=day_of_week,
                timezone=record.data.timezone,
                start_date=record.data.started_at,
                end_date=record.data.ended_at,
            ),

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Convert to standard 5-field cron: drop the leading seconds field
  2. Replace Quartz-only tokens: '?' -> '*', and avoid day-of-week names unsupported by your parser version
  3. Validate cron fields client-side before submitting a schedule

Example fix

# before
schedule.cron_expression = "0 0 12 * * ?"  # 6 fields (Quartz)

# after
schedule.cron_expression = "0 12 * * *"  # 5 fields: min hour dom mon dow
Defensive patterns

Strategy: validation

Validate before calling

def valid_cron(expr: str) -> bool:
    return len(expr.split()) == 5

Try / catch

try:
    await scheduler.register_schedule(record)
except ValueError as e:
    if "5-field cron" in str(e):
        record.data.cron_expression = " ".join(expr.split()[1:])  # drop seconds

Prevention

When it happens

Trigger: Registering or updating a schedule whose cron_expression has 6 fields (with seconds, the Quartz-style format) or 4/fewer fields, e.g. '0 0 12 * * ?' or '* * * *'.

Common situations: Copy-pasting a 6-field Quartz cron from a Java/Spring config or AWS EventBridge example; using a UI cron picker that emits seconds; malformed/truncated cron strings in stored schedule records during restore.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/cc90a26e853454ef. Report an issue: GitHub.