Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(scheduled-research): stop interval creates from requiring a resolvable zone (#1004)

Pham Van Ngoan8915c7200bfc
diff --git a/agent/src/api/scheduled_routes.py b/agent/src/api/scheduled_routes.py
index 18809f5e1..61badb9b0 100644
--- a/agent/src/api/scheduled_routes.py
+++ b/agent/src/api/scheduled_routes.py
@@ -271,8 +271,10 @@ def register_scheduled_routes(
from src.scheduled_research.models import (
JobStatus,
ScheduledResearchJob,
+ is_interval_schedule,
validate_schedule,
validate_timezone,
+ validate_timezone_shape,
)
from src.scheduled_research.executor import next_due
@@ -291,7 +293,16 @@ def register_scheduled_routes(
try:
validate_schedule(request.schedule)
- validate_timezone(request.timezone)
+ # Interval schedules ignore the timezone, and the executor
+ # deliberately skips resolving it for them so an interval job keeps
+ # advancing on a host whose timezone database lacks the key. The
+ # create path follows the same rule: only a cron schedule, whose
+ # evaluation actually needs the zone, resolves it. Both forms still
+ # reject a blank value.
+ if is_interval_schedule(request.schedule):
+ validate_timezone_shape(request.timezone)
+ else:
+ validate_timezone(request.timezone)
except ValueError as exc:
raise HTTPException(status_code=422, detail=str(exc)) from exc
@@ -299,7 +310,7 @@ def register_scheduled_routes(
next_run_at = request.next_run_at
if next_run_at is None:
next_run_at = now_ms
- if request.timezone is not None and not request.schedule.strip().isdigit():
+ if request.timezone is not None and not is_interval_schedule(request.schedule):
# A timezone-carrying cron job's contract is the authored wall
# clock, so its first fire is the first authored occurrence —
# not the creation moment. Interval jobs and timezone-less
diff --git a/agent/src/scheduled_research/models.py b/agent/src/scheduled_research/models.py
index 0ca3dca8f..81e9384b0 100644
--- a/agent/src/scheduled_research/models.py
+++ b/agent/src/scheduled_research/models.py
@@ -93,6 +93,23 @@ def parse_cron_field(part: str, low: int, high: int) -> Optional[Set[int]]:
return values
+def is_interval_schedule(schedule: str) -> bool:
+ """Return whether *schedule* is the interval-milliseconds form.
+
+ The one place that answers "interval or cron?", so callers that treat the
+ two forms differently — the executor's advancement path, the create route's
+ timezone handling — cannot disagree about which is which.
+
+ Args:
+ schedule: A schedule string in either accepted form.
+
+ Returns:
+ ``True`` for a bare positive-integer interval, ``False`` otherwise
+ (including malformed input, which the validators reject separately).
+ """
+ return bool(_INTERVAL_MS_RE.fullmatch(str(schedule).strip()))
+
+
def validate_schedule(schedule: str) -> None:
"""Raise ``ValueError`` when *schedule* is malformed.
diff --git a/agent/tests/test_scheduled_routes.py b/agent/tests/test_scheduled_routes.py
index 55b6c5656..20f282d87 100644
--- a/agent/tests/test_scheduled_routes.py
+++ b/agent/tests/test_scheduled_routes.py
@@ -359,3 +359,52 @@ def test_create_accepts_ids_within_the_id_rule(
)
assert response.status_code == 201, good_id
assert client.delete(f"/scheduled-runs/{good_id}").status_code == 204
+def test_create_interval_accepts_a_timezone_it_will_never_use(
+ client: TestClient, store: ScheduledResearchJobStore
+):
+ # The composer attaches the browser zone to every create. An interval
+ # schedule ignores it, and the executor never resolves it, so a key this
+ # host cannot resolve must not block the create.
+ response = client.post(
+ "/scheduled-runs",
+ json={
+ "id": "interval-unknown-zone",
+ "prompt": "scan",
+ "schedule": "60000",
+ "timezone": "Mars/Olympus_Mons",
+ },
+ )
+
+ assert response.status_code == 201
+ saved = store.get("interval-unknown-zone")
+ assert saved is not None
+ assert saved.timezone == "Mars/Olympus_Mons"
+
+
+def test_create_cron_still_rejects_an_unresolvable_timezone(
+ client: TestClient, store: ScheduledResearchJobStore
+):
+ response = client.post(
+ "/scheduled-runs",
+ json={
+ "id": "cron-unknown-zone",
+ "prompt": "scan",
+ "schedule": "0 9 * * *",
+ "timezone": "Mars/Olympus_Mons",
+ },
+ )
+
+ assert response.status_code == 422
+ assert "IANA timezone" in response.json()["detail"]
+ assert store.get("cron-unknown-zone") is None
+
+
+def test_create_rejects_a_blank_timezone_for_both_schedule_forms(
+ client: TestClient, store: ScheduledResearchJobStore
+):
+ for schedule in ("60000", "0 9 * * *"):
+ response = client.post(
+ "/scheduled-runs",
+ json={"prompt": "scan", "schedule": schedule, "timezone": " "},
+ )
+ assert response.status_code == 422, schedule