← Back to library

Cron 任务投递错会话修复:显式校验 agentId 并绑定目标 session

解决定时任务在 `agentId` 未出现在 agents.list 时落入错误会话的问题。前置:可调整 cron 调度与 session 路由逻辑。步骤:触发前校验 agentId→无效则拒绝或回退默认策略→写入运行日志标注路由决策→回归多代理并发场景。关键配置:`sessionTarget` 与 payload 类型必须一致。验证:同批任务稳定落入预期代理会话。风险:错误回退策略会造成静默误投。

GITHUBDiscovered 2026-02-15Author yinghaosang
Prerequisites
  • Multi-agent setup exists with at least one isolated and one main session target.
  • You can inspect cron run history and session routing logs.
Steps
  1. Before enqueue, validate `agentId` against `agents.list`; reject unknown IDs with clear error code.
  2. Bind each cron run to an explicit target session key instead of implicit fallback selection.
  3. Record routing decision (`jobId`, `agentId`, `sessionKey`) in run metadata for auditability.
  4. Regression-test with mixed jobs (systemEvent + agentTurn) and verify no cross-session leakage.
Commands
openclaw gateway status
openclaw help
npm run build
Verify

Cron runs with valid `agentId` consistently execute in expected session; invalid IDs fail fast and never land elsewhere.

Caveats
  • Avoid silent fallback to default agent for invalid IDs in production.
  • Legacy jobs created before routing fix may need migration or manual review(需验证).
Source attribution

This tip is aggregated from community/public sources and preserved with attribution.

Open original source ↗
Visit original post