fix(cron): always require bound automation sessions

This commit is contained in:
chengyongru
2026-06-16 14:16:12 +08:00
parent 6239114c46
commit b24b5f19fc
4 changed files with 57 additions and 14 deletions
+2 -8
View File
@@ -146,14 +146,12 @@ class CronService:
store_path: Path,
on_job: Callable[[CronJob], Coroutine[Any, Any, str | None]] | None = None,
max_sleep_ms: int = 300_000, # 5 minutes
require_bound_agent_jobs: bool = False,
):
self.store_path = store_path
self._action_path = store_path.parent / "action.jsonl"
self._run_records_dir = store_path.parent / "runs"
self._lock = FileLock(str(self._action_path.parent) + ".lock")
self.on_job = on_job
self.require_bound_agent_jobs = require_bound_agent_jobs
self._store: CronStore | None = None
self._timer_task: asyncio.Task | None = None
self._running = False
@@ -161,11 +159,7 @@ class CronService:
self.max_sleep_ms = max_sleep_ms
def _is_unbound_agent_job(self, job: CronJob) -> bool:
return (
self.require_bound_agent_jobs
and job.payload.kind == "agent_turn"
and not is_bound_cron_job(job)
)
return job.payload.kind == "agent_turn" and not is_bound_cron_job(job)
def _enforce_agent_binding(self, job: CronJob) -> bool:
"""Disable user cron jobs that cannot be routed to a concrete session."""
@@ -175,7 +169,7 @@ class CronService:
not job.enabled
and job.state.next_run_at_ms is None
and job.state.last_status == "error"
and job.state.last_error == self._UNBOUND_AGENT_JOB_REASON
and job.state.last_error
):
return False