Skip to content

OpenCode 2.4.1: build courier_later on OpenCode's automations #656

Todo

Description

@ivopogace

Parked: not to be started until one of the conditions under "Reopen when" holds. The owner chose Delegate on 2026-11-23 and parked it again the same day, because a host firing steers into a running turn where courier_later waits behind it (decision).

The change

OpenCode 2.3.1 turned its experimental schedules into automations (anomalyco/opencode#64160). An automation can send a prompt to any session of the project at a time, on an interval or on a cron, with text the caller chooses, and can be listed per session and deleted by id. That covers what courier_later and courier_cancel do.

Since OpenCode 2.4.0 automations are no flag (anomalyco/opencode#65296): they are on unless the config says "automations": false (Config.latest(entries, "automations") ?? true in packages/core/src/automation.ts). Since 2.4.1 the plugin API has a domain for them (anomalyco/opencode#65747): ctx.experimental.automation.create, .list and .delete, for Promise and Effect plugins.

Evidence, on OpenCode 2.3.2

Through the HTTP API (/api/experimental/automation), with the scripted model:

  • With the flag off, which is the default in a release build, create is refused with 403.
  • With experimental.automations: true, a prompt to an idle session arrived 0.3 s after its due time and woke it.
  • The prompt text is delivered verbatim, so courier's <courier from=… scheduled=…> envelope fits.
  • Any session of the project can be the target, a spawned one included, with no creating session.
  • Deleting before the due time stops the delivery.
  • One that fell due while the server was down was delivered after the restart.

With a real model, a local prototype (spawned sessions allowed the automation tools, the brief asking for a check-in through automation_create, a pending automation counted as waiting), one run each way of two children that wait a minute, run a command and report:

courier_later automations
Both children waited, woke and reported yes yes
Wake after the one-minute mark 13 s late within 0.1 s
Model requests 19 23
Input / output tokens 37k / 1.6k 63k / 3.5k
To schedule one tool call a search, then automation_create inside Code Mode

With both mechanisms registered, every session chose courier_later; automations were used only once it was hidden.

What blocks it, at OpenCode 2.4.1

Read in @opencode/[email protected] and the host's source at tag v2.4.1.

  • A firing is always a steer. admit in packages/core/src/automation.ts calls sessions.prompt with delivery: "steer" as a literal, and Automation.Request (packages/schema/src/automation.ts) has no field for it. courier_later sends session.synthetic with delivery: "queue" (src/scheduling/later.ts), so its message waits behind a running turn. The code action can only call Code Mode tools and its send steers too; shell runs a command.
  • A plugin cannot switch a waiting item to queue. The host has SessionInbox.steer and .queue (packages/core/src/session/inbox.ts), but the plugin's SessionDomain (@opencode/plugin, dist/promise/session.d.ts) exposes neither, and an item may be promoted at the next step before a plugin sees its enqueued.
  • No automation events. The plugin API has create, list and delete only (dist/promise/plugin.d.ts), so isScheduled would read list, which filters by creating session or directory, not by target (packages/protocol/src/groups/automation.ts).
  • A firing is a user item whose only metadata is automation (admit, packages/core/src/automation.ts). Courier's own is a synthetic item with source: "courier", from, scheduled, scheduledAt and a description, which kindOf in src/tree/events.ts reads to tell a session's own check-in after its report from a new prompt.
  • Turning automations off after scheduling strands the entry. The row stays and is retried hourly (runDue, DISABLED_RETRY), while list and delete fail with Automation.DisabledError (findVisible and list in packages/core/src/automation.ts; HTTP 403 in packages/server/src/handlers/automation.ts), so courier can neither see nor cancel it. create fails the same way, so courier's scheduler has to stay as the fallback; if it delivers the entry on time, the host delivers it again once automations are back on, and the host's loop starts with the server (packages/server/src/process.ts), before plugins load.
  • The API is under experimental: "may change without compatibility guarantees" (packages/protocol/src/groups/automation.ts).
  • Smaller: an at trigger must be strictly in the future (firstDue), so delayMinutes: 0 would stay on courier's path; a fired at automation stays in the table as done (advance); a missing target session pauses the automation (pauseWith).
  • The tools are automation_create and the rest in their own automation namespace, Code Mode tools (packages/core/src/tool/plugin/automation.ts); CHILD_RULES in src/tree/spawn.ts denies automation_*.

What delegation would and would not gain

Would gain:

  • Delivery after a restart without waiting for the project's first use, since the host's loop runs from server start.
  • The host's deterministic message id (msg_<automation>_<run>) and SQLite lease: no double delivery on a crash or with two servers.
  • The message shows in the person's automation list.

Would not gain:

  • Timing: courier_later delivers within about a second of its time (Deliver a courier_later message within about a second of its time #660), so the 13 s in the table above is gone.
  • Less code: the fallback keeps all of src/scheduling/, and the host path adds a mapping from automation ids to later/ records, the clean-up of done rows and the reconciliation after automations are turned off and on.

Reopen when

  • OpenCode lets a caller choose queue for an automation's prompt action, or
  • @opencode/plugin sends automation events.

courier_later is the only courier message sent with queue; every other one is steered. Switching it to steer, a behaviour change of its own with a model-facing string, would also remove the difference.

Options, once reopened

  • Delegate (recommended): keep courier_later and courier_cancel as they are for models, and schedule through the host. No change to the tool surface.
  • Deprecate: keep the tools, say in their descriptions and the reference that the host does it, and remove them in a later minor release.
  • Remove: drop them. A breaking change to the tool surface.

Done when (Delegate)

  • src/scheduling/ schedules, lists and cancels through the host, and isScheduled reads the host's pending automations, so Waits and courier_stop behave as now.
  • CHILD_RULES in src/tree/spawn.ts and typedText in src/tree/relay.ts are revisited: what a spawned session may still not do itself, and which firings are courier's own.
  • The later/ storage keys (src/scheduling/, test/later.test.ts) get a migration, or a reason for none in architecture.md's Storage table.
  • Unit tests, the e2e later, schedules, own-checkin and wake groups, e2e/two-servers.sh, docs/reference.md ("Scheduled messages"), docs/maintainers/architecture.md ("courier_later's scheduler") and docs/maintainers/plugin-api-notes.md ("OpenCode's automations") are updated.

Activity

  1. ivopogace commented on Nov 23, 2026

    @ivopogace
    OwnerAuthor

    Both conditions under "Reopen when" hold on OpenCode 2.4.1, the target of the pin PR #664:

    What still stands from "What blocks it", read in the source at v2.4.1:

    • There are still no automation events. isScheduled would read automation.list.
    • A firing is still a steer (delivery: "steer", metadata.automation), so it goes into a running turn where courier_later waits behind it.
    • New: a person can turn automations off, and create then fails with Automation.DisabledError. A Delegate needs courier's own scheduler as the fallback for that case, or courier_later fails there.
    • The tools are now automation_create and the rest in their own automation namespace; the pin PR moves CHILD_RULES to automation_*.

    The options are the ones in the issue body. Recommendation: Delegate, keeping courier's scheduler for hosts with automations off, so the tool surface does not change. This waits for the owner's choice here and for #664 to merge.

  2. changed the title [-]OpenCode 2.3.2: build courier_later on OpenCode's automations[/-] [+]OpenCode 2.4.1: build courier_later on OpenCode's automations[/+] on Nov 23, 2026
  3. self-assigned this
    on Nov 23, 2026
  4. ivopogace commented on Nov 23, 2026

    @ivopogace
    OwnerAuthor

    Decision (owner, 2026-11-23): keep courier's own scheduler. Delegate is not built; this issue is parked again.

    Why

    Read in @opencode/[email protected] and the host's source at v2.4.1:

    • A firing cannot wait behind a running turn. admit in packages/core/src/automation.ts calls sessions.prompt with delivery: "steer" as a literal, and Automation.Request has no field for it. The host can switch a waiting item between steer and queue (packages/core/src/session/inbox.ts), but the plugin's SessionDomain exposes neither. courier_later sends session.synthetic with delivery: "queue". The code action can only call Code Mode tools and its send steers too; shell runs a command.
    • A firing is a user item whose only metadata is automation. Courier's own is a synthetic item with source: "courier", from, scheduled, scheduledAt and a description, which kindOf in src/tree/events.ts reads to tell a session's own check-in after its report from a new prompt.
    • Turning automations off strands an entry. The row stays and is retried hourly, while list and delete fail with Automation.DisabledError, so courier could neither see nor cancel it. If the fallback delivered it on time, the host would deliver it again once automations are back on, and the host's loop starts with the server (packages/server/src/process.ts), before plugins load.
    • Smaller ones. An at trigger must be strictly in the future, so delayMinutes: 0 would stay on courier's path. A fired at automation stays in the table as done. A missing target session pauses the automation. list filters by creating session or directory, not by target. The API is under experimental.

    What delegation would gain

    • Delivery after a restart without waiting for the project's first use.
    • The host's deterministic message id and SQLite lease: no double delivery on a crash or with two servers.
    • The message shows in the person's automation list.

    The timing gain measured above is gone: courier_later delivers within about a second of its time (#660). Delegation would remove no code, since the fallback keeps all of src/scheduling/ and the host path adds the id mapping, the clean-up of done rows and the off/on reconciliation.

    Reopen when

    • the host lets a caller choose queue for a prompt action, or
    • the plugin API sends automation events, or exposes the inbox's steer and queue.

    Apart from this issue: courier_later is the only courier message sent with queue; every other one is steered. Switching it to steer would be a behaviour change of its own, with a model-facing string and a real-model run, and would make a later delegation a refactor.

  5. removed their assignment
    on Nov 23, 2026
  6. added
    blocked-upstream
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    blocked-upstream

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions