HKUDS/Vibe-Trading · error · TypeError

'last_run_at' must be an integer (epoch ms) or null

Error message

'last_run_at' must be an integer (epoch ms) or null

What it means

Raised by Job from_dict (agent/src/scheduled_research/models.py:444) when the optional 'last_run_at' field is present but is neither an int (epoch ms) nor null. Unlike the required timestamps, absence is fine (None); only a present wrong-typed value raises.

Source

Thrown at agent/src/scheduled_research/models.py:444

            The reconstructed ``ScheduledResearchJob``.

        Raises:
            KeyError: If a required field is missing.
            TypeError: If a field has the wrong type.
            ValueError: If ``status`` is not a recognized ``JobStatus`` value.
        """
        job_id = data["id"]
        prompt = data["prompt"]
        schedule = data["schedule"]
        if not isinstance(job_id, str) or not isinstance(prompt, str) or not isinstance(schedule, str):
            raise TypeError("'id', 'prompt', and 'schedule' must be strings")
        next_run_at = data["next_run_at"]
        created_at = data["created_at"]
        if not isinstance(next_run_at, int) or not isinstance(created_at, int):
            raise TypeError("'next_run_at' and 'created_at' must be integers (epoch ms)")
        last_run_at = data.get("last_run_at")
        if last_run_at is not None and not isinstance(last_run_at, int):
            raise TypeError("'last_run_at' must be an integer (epoch ms) or null")
        consecutive_failures = data.get("consecutive_failures", 0)
        if (
            isinstance(consecutive_failures, bool)
            or not isinstance(consecutive_failures, int)
            or consecutive_failures < 0
        ):
            raise TypeError("'consecutive_failures' must be a non-negative integer")
        last_error = data.get("last_error")
        failure_kind = data.get("failure_kind")
        if last_error is not None and not isinstance(last_error, str):
            raise TypeError("'last_error' must be a string or null")
        if failure_kind is not None and failure_kind not in {"dispatch", "schedule"}:
            raise ValueError("'failure_kind' must be 'dispatch', 'schedule', or null")
        # Never raises: the store quarantines the whole file when a single
        # record fails to load, so an unusable timezone value degrades that
        # one job to UTC — the semantics it had before the field existed —
        # instead of taking every other job down with it. Absent, blank, and
        # non-string values all normalize to None.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Use the same int-epoch-ms helper for all timestamp fields including last_run_at
  2. Convert on write: int(dt.timestamp() * 1000)
  3. Set it to null rather than 0 or "" when unknown

Example fix

// before
job["last_run_at"] = datetime.now(timezone.utc).isoformat()

// after
job["last_run_at"] = int(datetime.now(timezone.utc).timestamp() * 1000)
Defensive patterns

Strategy: validation

Validate before calling

def last_run_ok(d):
    v = d.get("last_run_at")
    return v is None or (isinstance(v, int) and not isinstance(v, bool))

Type guard

def safe_last_run(v):
    if v is None or isinstance(v, bool) or not isinstance(v, int):
        return None
    return v

Try / catch

try:
    job = Job.from_dict(record)
except TypeError as exc:
    if "last_run_at" in str(exc):
        record = dict(record); record["last_run_at"] = None
        job = Job.from_dict(record)
    else:
        raise

Prevention

When it happens

Trigger: {"last_run_at": "1767225600000"} or a float/ISO string in the last-run slot after a job has run at least once; absent key or explicit null is accepted.

Common situations: Same timestamp format drift as other fields but only appearing after the first run, so it surfaces late; retry writers formatting timestamps differently than the creation path.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/e14481cc7f65a367. Report an issue: GitHub.