DSH / Atlas
2026-09-17implementedarchitecture

Standalone schedules and Session targets

独立计划任务与 Session 目标

Host tasks need global management and explicit delivery targets while remaining recognizable in their Workspace.

English

Problem

Host tasks need global management and explicit delivery targets while remaining recognizable in their Workspace.

Decision

The storage domain, importer, placeholder RRULE, and parallel API decisions are superseded by typed rule storage and shared recurrence. Keep the existing schedule domain and one management API; the target, execution, and notice decisions below remain current.

Targets are session, new_once, or new. session stores one existing Session id; create and edit check, without activating that Session, that it exists and does not belong to a delegated child. new_once reserves a Session id when the task is created or retargeted, creates that exact Session at first delivery, and then becomes session. new saves a reserved Session id in pendingDelivery before each create attempt, so a retry after a failed delivery uses the same Session. A created Session uses the target's working directory and Agent preset, or the Host defaults. When the target names a working directory, the Session joins the Workspace registered there, if any. While the Session has no title, it takes the task title; a new target adds the Session's creation minute in the timing rule's zone, for example Weekday digest · 2026-10-12 09:00, so the Sessions of successive deliveries stay distinguishable. A failed join or rename is logged and does not block delivery. involvedSessionIds lists the creating and editing Agent Sessions and each existing or reserved target Session in first-involvement order; Sessions that a new target creates are not listed.

The runtime keeps latest-only catch-up. It delivers the latest occurrence at or before the delivery decision and advances to the next future occurrence; an exhausted rule stays stored with ended status, and a paused task has no timer. Each delivery of one task, timed or manual, comes at least 60 seconds after the occurrence of the previous delivery, and the occurrence of a manual run is its run time; for a new target, whose every delivery creates a Session, a deployment can raise that interval through newSessionIntervalSeconds, which defaults to 60. The floor counts from the previous occurrence when the next stored occurrence keeps the interval, and from the previous acknowledgment otherwise, so acknowledgment latency does not accumulate and a late delivery does not shift later occurrences; the next on-time occurrence can then follow the late delivery by less than one interval. A task delivered to a reused Session, session or new_once, holds its execution slot until the target Agent is idle, and occurrences that become due meanwhile coalesce into one later delivery, so that Session has at most one pending delivery of the task; a new target holds no slot, and its launches run beside one another with only the delivery interval between them. Due tasks with a session target share one message per target Session, except After and At tasks. Manual run shares target resolution, the delivery interval, Session inbox persistence, the receipt, and the involvement update with timed delivery, but keeps the next occurrence and status. Both refuse an archived destination Session, including a reserved retry, because the archived-Session gate would block the turn that the message wakes. Session inbox persistence precedes the task receipt write, so a crash between the two stores can repeat a message. The implementation adds no scheduler, run, or ownership service.

After a committed create, update, or delete, Schedule queues a change notice on its own chain, so Session I/O never holds the mutation and delivery queue. Each involved Session other than the actor whose Agent is loaded receives a schedule-sourced message for its next model step that does not start a model turn, so notices queued while the Session is idle reach the model with its next input instead of each running as a model turn; the message names the change and carries the task id and title as JSON strings. A Session without a loaded Agent receives nothing and reads the current task when it next lists tasks. A notice failure is logged and does not roll back the committed change. Shutdown drains queued notices before storage closes.

Alternatives considered

Require a caller-supplied schedule id. A user-facing title and canonical identity serve different purposes, but accepting ids would expose collision and validation policy. The Host generates identity and returns it for later operations.

Keep creator Session ownership. Ownership would keep list and mutation APIs scoped and would conflict with global management, retargeting, and Session creation policies. Historical involvement is metadata and notification routing, not authorization.

Check spacing by sampling upcoming occurrences. Each occurrence query enumerates from DTSTART, so a high-frequency rule with an early start blocked the Host thread before a sampled check could refuse it, and a sample cannot bound the complete sequence. Static rule checks before enumeration and the per-task delivery interval enforce the spacing instead.

Add scheduler, run, and notification services. The existing Schedule service, storage domain, runtime, and Session controller already own these responsibilities at the required scale. New layers would add indirection without changing durability.

Leave created Sessions untitled and outside Workspaces. Such a Session appears as one more untitled Session outside the Workspace that owns its directory, so the user cannot tell which task created it or, for a new target, which delivery it received. Joining the Workspace at the target directory and naming the Session after the task, with the creation minute for new, needs no stored field. A failure is only logged because delivery has priority over presentation.

Consequences

Tasks outlive Agents and are managed by id. Archive admission reports active Session targets; explicit stop deletes tasks. Host availability, cross-store at-least-once delivery, best-effort notices, and unbounded per-delivery concurrency remain limitations. The Schedule reference owns the exact current contracts and the management upgrade guide covers changed callers.

中文

Problem

宿主任务需要全局管理和显式执行目标,并在工作区中可辨认。

Decision

存储领域、导入器、占位 RRULE 和并行 API 决策由带类型规则存储与共享重复计算替代。保留现有 schedule 领域和统一管理 API;下述目标、执行和通知决策保持有效。

目标分为 session、new_once 和 new。session 存储一个现有 Session id;创建和编辑会在不激活该 Session 的情况下检查它存在且不属于被委派的子 Agent。new_once 在创建任务或重新指定目标时预留 Session id,在首次投递时创建该精确 Session,然后转换为 session。new 在每次创建尝试前把预留的 Session id 保存在 pendingDelivery 中,因此投递失败后的重试使用同一 Session。新建 Session 使用目标中的工作目录和 Agent preset,未提供时使用 Host 默认值。目标指定工作目录时,该 Session 加入在该目录注册的 Workspace(若存在)。该 Session 尚无标题时以任务标题命名;new 目标再加上该 Session 的创建时间(精确到分钟,按规则 DTSTART 的时区),例如 Weekday digest · 2026-10-12 09:00,以便区分各次投递创建的 Session。加入或命名失败只记录日志,不阻止投递。involvedSessionIds 按首次参与顺序列出创建和编辑任务的 Agent Session,以及每个现有或预留的目标 Session;new 目标创建的 Session 不列入其中。

运行时保留仅补发最新发生时点的行为。它投递不晚于投递判断时刻的最新发生时点,并推进到下一个未来发生时点;耗尽的规则以 ended 状态保留在存储中,暂停的任务没有计时器。同一任务的每次投递,无论定时还是立即执行,都在上一次投递的发生时点之后至少 60 秒,立即执行的发生时点是其运行时间;new 目标的每次投递都会创建 Session,部署可通过 newSessionIntervalSeconds 加大该间隔,默认 60。下一个已存储发生时点满足该间隔时,最小投递间隔从上一次发生时点起算,否则从上一次确认时间起算,因此确认延迟不会累积,延迟的投递也不会推移之后的发生时点;下一个准时的发生时点随后可能在延迟投递之后不足一个间隔到来。投递到复用 Session(session 或 new_once)的任务在目标 Agent 空闲之前一直占用其执行槽位,期间到期的发生时点合并为之后的一次投递,因此该 Session 最多有该任务的一次待处理投递;new 目标不占用槽位,各次启动并行运行,彼此之间只隔投递间隔。目标为 session 的到期任务按目标 Session 共享一条消息,After 和 At 任务除外。立即执行与定时投递共用目标解析、投递间隔、Session 收件箱持久化、回执与相关 Session 更新,但保留下一发生时点和状态。二者都拒绝已归档的目的 Session,包括重试时复用的预留 Session,因为已归档会话门禁会阻止该消息唤醒的轮次。Session 收件箱持久化先于任务回执写入,因此两个存储之间崩溃可能重复消息。实现不增加 scheduler、run 或 ownership service。

create、update 或 delete 提交后,Schedule 在独立的链上排队一条变更通知,因此 Session I/O 不会占用变更与投递队列。除操作者之外、Agent 已加载的每个相关 Session 都会收到一条供下一个模型步骤读取的 schedule 来源消息,该消息不会启动模型轮次,因此 Session 空闲期间排队的通知会随其下一条输入到达模型,而不会各自作为一个模型轮次运行;消息说明变更类型,并以 JSON 字符串携带任务 id 和标题。没有已加载 Agent 的 Session 不会收到消息,会在下次列出任务时读取当前任务。通知失败会记录日志,但不会回滚已提交的变更。关闭时先排空已排队的通知,再关闭存储。

Alternatives considered

要求调用方提供计划任务 id。 用户可见标题与规范身份用途不同,但接受 id 会暴露冲突与校验策略。Host 生成身份并返回,供后续操作使用。

保留创建者 Session 所有权。 所有权会让 list 与 mutation API 保持作用域限制,并与全局管理、重新指定目标和 Session 创建策略冲突。历史参与关系是元数据和通知路由,不是授权。

通过抽样即将到来的发生时点检查间隔。 每次发生时点查询都从 DTSTART 开始枚举,因此起始时间较早的高频规则会在抽样检查拒绝它之前阻塞 Host 线程,而且抽样无法约束完整序列。改为在枚举之前做静态规则检查,并用每个任务的投递间隔约束间隔。

增加 scheduler、run 和 notification service。 现有 Schedule service、存储领域、runtime 和 Session 控制器已按所需规模承担这些职责。新层级只会增加间接性,不改变持久性。

让新建 Session 保持无标题且不属于任何 Workspace。 这样的 Session 会作为又一个无标题 Session 出现在拥有其目录的 Workspace 之外,用户无法分辨是哪个任务创建了它,也无法分辨对于 new 目标它接收了哪一次投递。加入目标目录处的 Workspace,并以任务标题命名 Session(new 再加创建分钟),不需要存储字段。失败只记录日志,因为投递优先于呈现。

Consequences

任务寿命长于 Agent,并按 id 管理。归档准入报告活动 Session 目标;显式停止删除任务。宿主可用性、跨存储至少一次投递、尽力通知和每次新建目标的无界并发仍是限制。Schedule 参考拥有精确的当前契约,管理升级指南说明调用方变更。