Skip to content

investigate: OpenCode native scheduled tasks — creation, route choice, independence from Muse tokens #2019

Closed

Description

@dezren39

LIST 4a. How are scheduled tasks created and managed inside OpenCode? Do they run fully independently (no Muse tokens spent)? Can the route be chosen per task (summit/specialist instead of workhorse)? What does Muse's management surface look like — creating schedules, checking other OpenCode sessions aren't crashing, adjusting routes? Deliverable: capability report with a worked example schedule created and observed.

Program: Drew's 2026-10-28 directive (full text: hatch-personal memory/topics/id-program-2026-10-28.md).
Working pattern: parallel investigations, then the named synthesis issue merges them into a full design. Route guidance: Workhorse by default; Specialist/Summit for synthesis and ramification-heavy work. A result that says "done" is not the endpoint — the orchestrator reviews it and may commission another round. Deliverables: a markdown design/investigation doc (mermaid/SVG diagrams welcome) linked from this issue, plus follow-up issues for anything buildable. Build a proof of concept where the design calls for one, but do NOT build the permanent feature on top of an unreviewed PoC.

Activity

  1. developing-today commented on Oct 29, 2026

    @developing-today
    Contributor
  2. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    Parent epic: #2055 — fleet expansion & placement program (2026-10-28 directive).

  3. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    Top priority — ID program wave-1. Drew directed this be picked up in the next runs (2026-10-29): enqueued directly as triage task 3338 in repo-health-code-pilot at queue priority 20 (only breakage-class work at priority 10 outranks it). Wave-1 is the ungated investigations and designs; syntheses and PoCs stay gated on their named inputs. Investigation route: Workhorse.

  4. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Oct 29, 2026
  5. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

    • Agent: queue worker (repo-worker-code), Lane D shift
    • Session / ID: queue task 3338 (repo-health-code-pilot), claimed 2026-10-29T10:13Z
    • Found via: queue claim
    • Task: Triage/investigation for investigate: OpenCode native scheduled tasks — creation, route choice, independence from Muse tokens #2019 — OpenCode native scheduled tasks: creation/management, independence from Muse tokens, per-task route choice, and Muse's management surface; record capability report on the issue and route follow-on work.
    • Expectation: effort class m — done = investigation result recorded on this issue (comment/doc) + follow-on work routed in the same pass, gated syntheses left gated.
    • Links: queue task 3338
  6. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    Investigation result — OpenCode native scheduled tasks (LIST 4a)

    Worker: queue task 3338 (repo-health-code-pilot), Lane D, 2026-10-29. Method: local CLI/source checks on the fleet fork (v2.0.30) on sandbox + laptop, upstream docs/issues, ecosystem review, and a live worked example (below).

    Verdict in one paragraph

    OpenCode has no native scheduler today — not upstream, not in the fleet fork. What exists is a proven composition: an OS scheduler (systemd timer / launchd / cron) firing opencode run with a per-job --model route. That composition runs with zero Muse tokens in both trigger and execution, supports per-task route choice (workhorse / specialist / summit are just the job's --model value), and gives Muse a file-based management surface. Scheduling is not supervision: no mechanism watches for stalls — that remains the babysitter's job (see #2021).

    1. Is there a native scheduler? No.

    • Fleet fork CLI (v2.0.30, verified on laptop + sandbox 2026-10-29): subcommands are upgrade, acp, api, debug, auth, mcp, plugin, models, stats, mini, run, session, msg, service, reload, pair, serve — no schedule/cron. A grep of the fork's packages finds no scheduler subsystem (hits are unrelated UI/timeline uses of the word).
    • Upstream: feature request [FEATURE]: /schedule — run recurring background tasks (cron-like routines) anomalyco/opencode#41906 ("[FEATURE]: /schedule — run recurring background tasks") is OPEN. A community prototype (SQLite-backed automations; once/interval/5-field cron; CLI create/list/show/run/pause/resume/history/remove; restart recovery) was described there on 2026-09-08 but has not merged. Do not plan on it.

    2. The three real mechanisms today

    • (a) OS scheduler + opencode run — the de-facto pattern, recommended. The ecosystem plugin different-ai/opencode-scheduler (listed on opencode.ai's ecosystem page) wraps exactly this: natural language → 5-field cron; job JSON persisted under ~/.config/opencode/scheduler/scopes/<workdir-hash>/jobs/; generates a systemd .timer (Linux) / launchd plist (macOS) / schtasks / crontab entry; a supervisor wrapper enforces no-overlap (lock file), non-interactive permissions (OPENCODE_PERMISSION), and optional hard timeout. Management tools: schedule_job, list_jobs, get_job, job_logs, run_job. Fleet caveat: it is a v1 plugin (@opencode-ai/plugin); the fleet's v2 fork cannot run v1 plugins (the deployed config's plugin array is emptied for exactly this reason), so adopting it means a port — the underlying OS-timer pattern needs no plugin at all.
    • (b) GitHub Actions schedule: event with the official anomalyco/opencode/github action: cron in the workflow file, model: chosen per workflow, output to logs/PRs. Fits repo-scoped periodic chores; does not reach laptop sessions or local state.
    • (c) Third-party daemons (e.g. an opencode-cron CLI with a launchd ticker; MCP cron servers): they exist, are unvetted, and are not recommended as a fleet foundation without a review round.

    3. Independence from Muse tokens — YES for execution

    A scheduled OpenCode run spends only the provider plan its route resolves to. Verified live in the worked example: the run resolved opencode-route/workhorse → opencode-go DeepSeek V4.1 Flash; no Muse process or token was involved between timer creation and completion. Note the inversion in today's fleet: execution already spends plan quotas, but the triggers and supervision are Muse cron jobs (dispatcher, babysitter) spending Muse tokens. OS-level scheduling is precisely the piece that moves the trigger off Muse.

    4. Per-task route choice — YES

    Route is a property of the job definition, not the scheduler: each unit carries its own opencode run --model opencode-route/<workhorse|specialist|summit|speed> (fleet route ids from opencode.jsonc; effort variants via #low/#high/#max). Changing one job's route = editing one unit. The GitHub Actions path takes model: per workflow the same way. This matches Drew's route guidance directly: scheduled tasks run on a single route pool chosen per task.

    5. Muse's management surface

    • Create / adjust / retire: write or remove systemd user units (or job JSON where a wrapper is used). Units are files — diffable and committable, unlike opaque in-app state.
    • Health / crash visibility: systemctl --user list-timers / status, per-job run logs; for live sessions, the OpenCode server API (/api/*) and OpenChamber session views — the surfaces the dispatcher/babysitter already use. Caveat found during the worked example: opencode session list did not surface the just-run session on its first page (paginated/unordered in practice) — directory-scoped server-API reads are the reliable surface, not the CLI list.
    • What no scheduler provides: stall detection, answering a stuck session's questions, escalation. A timer fires and forgets. The babysitter function still needs an owner — a scheduled OpenCode preliminary babysitter (the design: scheduled OpenCode preliminary babysitter — sweep sessions, fix easy stalls, escalate the rest #2021 design) or Muse at reduced cadence.

    6. Worked example — created and observed 2026-10-29

    On the laptop (amd), a one-shot systemd user timer:

    • Created 10:19:03Z: systemd-run --user --unit=oc-sched-example-3338 --on-active=60s --collect ~/tmp/oc-sched-3338/run.sh
    • Fired 10:20:03Z; the service ran opencode run --auto --title oc-sched-example-3338 --model opencode-route/workhorse "Create a file named SCHEDULED-RUN.md …" in ~/tmp/oc-sched-3338
    • Log: route resolved to deepseek-v4.1-flash (build agent), file created with the exact requested two lines, exit 0 at 10:20:14Z (~10 s of execution)
    • Artifacts retained on the laptop: ~/tmp/oc-sched-3338/{run.sh, run.log, SCHEDULED-RUN.md}; transient units auto-collected.

    This is a proof of the pattern, not a permanent feature — no fleet job was migrated onto it by this investigation.

    7. Fit guidance (feeds #2018 and the #2024 placement synthesis)

    8. Follow-on routing

    Implementation follow-on filed as a separate issue (linked below when posted): implement: fleet OpenCode scheduled-task pattern — systemd timer units + opencode run with per-job route, a small job registry, and a log surface — adopting the v1 plugin (after a v2 port) and waiting on upstream #41906 are recorded there as considered-and-deferred alternatives. The placement synthesis #2024 stays gated on its named inputs; this report is one of them.

    — Sources: fork CLI --help output (laptop + sandbox, 2026-10-29); upstream issue anomalyco/opencode#41906 (state OPEN, read 2026-10-29); opencode.ai/docs/github (schedule event) and /docs/ecosystem (opencode-scheduler listing); different-ai/opencode-scheduler docs via DeepWiki; fleet quota picture from the dispatcher log (2026-10-29 ~05:20 CDT: Workhorse OPEN via opencode-go).

  7. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done

  8. 30 remaining items

  9. removed their assignment
    on Nov 20, 2026
  10. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Follow-on evidence for #2232: quota-freshness-summary is now enabled as a user-systemd hourly timer, with per-job route opencode-route/workhorse. After correcting the unit PATH (python3 was unavailable to the service), a manual service invocation completed successfully at 2026-11-21 19:05 CST and wrote the summary log and exit-0 history record. This invocation was systemd-triggered, not Muse-triggered; therefore the trigger used 0 Muse tokens. The summary execution itself uses the selected OpenCode route. A full hourly firing is still pending, so this is not yet the cadence-cycle result. I cannot derive a numeric prior Muse-token baseline from the available route history; the previous investigation established independence from Muse but did not preserve a comparable per-trigger token measurement.

  11. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Follow-on evidence for #2232: the hourly opencode-quota-freshness-summary.timer fired at 2026-11-21 20:00:58 CST and completed at 20:01:17 CST. Systemd reports Result=success, exit 0; history.jsonl records run 20261122T020058Z, route opencode-route/workhorse, and latest.log contains the summary. The trigger is systemd, not Muse, so the trigger used 0 Muse tokens; the OpenCode execution uses the selected route. A comparable historical per-trigger Muse-token baseline is not available, so no numeric before/after delta is claimed. The run evidence and limitation are also recorded in #2232 and draft PR #12267.

  12. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Picked up by felix — working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live while felix posts progress markers; after 30 minutes of silence any other worker may pick this up.)

  13. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Progress from felix: still working

  14. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Investigation result, round 2 — OpenChamber native scheduled tasks (LIST 4a remainder)

    Worker: agent felix (Muse sandbox seat), fallback claim, 2026-11-22. This round covers the half the 2026-10-29 report (above) did not: OpenChamber's native scheduler, per Drew's 2026-10-31 scope correction. The OpenCode verdict stands unchanged (no native scheduler in OpenCode core or the fleet fork; OS-timer + opencode run composition). Method: fork source on current main (developing-today-forks/openchamber @ 18e3687, packages/web/server/lib/scheduled-tasks/), the deployed server on the laptop (OpenChamber 2.5.0, systemd user service openchamber.service, port 3000; managed OpenCode opencode serve 2.0.30+b70580b on 127.0.0.1:13420), live task/run state read today, and a worked example created, fired, and deleted today.

    Verdict in one paragraph

    OpenChamber has a real native scheduler, and it is the fleet's production scheduling mechanism today: 35 tasks across two projects (33 on the code project), 28 enabled, firing around the clock (queue lanes every 40 min, the #3026 claimant every 5 min, the conductor every 20 min). Tasks are created per project with a pinned provider/model per task — every live task pins opencode-route/workhorse — and a fired run is an ordinary OpenCode session on the managed server. No Muse process or token appears anywhere in the create → fire → execute path; execution spends only the pinned route's provider plans. Muse's management surface is the openchamber schedule CLI + REST API + run-history, all machine-readable.

    1. Creation and management — how it works

    • Surfaces (all equivalent): the CLI (openchamber schedule create|list|run|enable|disable|delete|status; packages/web/bin/lib/commands-schedule.js, speaking control actions schedule.* to the server), the REST routes (packages/web/server/lib/scheduled-tasks/routes.js: CRUD + /run + /run-history under /api/projects/:projectId/scheduled-tasks), the web UI dialogs, an in-session agent tool, and loop files — portable .agents/loops/*.md definitions (project or ~/.agents/loops user scope) whose frontmatter (name, schedule, model, agent, timezone, enabled) reconciles into tasks on every project sync (loops.js). Project-scope loops carry a local-approval gate: a pulled loop does not run until the user enables it on this machine, and a content change re-pauses it.
    • Storage: per-project JSON at ~/.config/openchamber/projects/<projectId>.json, written under a cross-process .json.lock; runtime state (lastRunAt, lastStatus, lastError, lastSessionId, lastDurationMs, nextRunAt) lives in the same record's state (verified live for the claimant task: lastStatus: success, nextRunAt armed).
    • Firing: in-process timers in the server (runtime.js: computeNextRunAt for daily/weekly/cron/once; setTimeout dispatch). Multiple server processes sharing one config coordinate by occurrence claiming (state.lastScheduledFor under the write lock), so a slot dispatches once. A per-run max-duration watchdog aborts a timed-out run's session instead of leaving it executing. A once task auto-disables after its fire (observed in the worked example).
    • Execution: the runtime creates a session on the managed OpenCode server (runtime.js session-create: model and agent fixed at session level; session tagged metadata.openchamber.kind: 'scheduled') and sends the task prompt through the server message queue with scheduled-task provenance. A task may instead target an existing session (targetSessionId), in which case the prompt is queued into it.

    2. Independence from Muse tokens — YES, for trigger and execution

    • The trigger is the OpenChamber server process itself (a systemd user service, node, up 13 h at inspection) — no Muse cron, boot, or handoff is in the loop; the Move opencode executions to laptop-side scheduled tasks — retire the Muse boot handoff #3026 claimant task's own prompt states this verbatim ("No Muse cron, boot, or handoff is in your loop: the OpenChamber scheduler fired you").
    • Execution spends the pinned route's provider plans. All 35 live tasks pin opencode-route/workhorse, whose legs in the project opencode.jsonc are provider plans (deepseek-flash-plan #high first stage, weighted pool behind it). Provider credentials are OpenCode's own auth store; nothing in the path touches a Muse token.
    • The honest boundary: independence is a property of the pin, not the mechanism. A task pinned to a Claude-backed provider/leg would spend that plan. No live task does. (Muse tokens are still spent by other fleet machinery — the Muse cron lanes — but that is parallel machinery, not this scheduler.)

    3. Per-task route choice — YES, structural

    • schedule create requires --model <provider/model>; the pair is stored per task as execution.providerID / execution.modelID (plus optional variant, agent). At fire time resolveRunSelection (runtime.js) applies the pin; a task may instead set useDefaults, resolving the project's defaultModel/defaultVariant/defaultAgent (then globals) at each run start (session-defaults.js). The code project's defaults are themselves opencode-route/workhorse / build / low.
    • Because the pin is a provider/model pair, a route class is chosen exactly as with opencode run --model: --model opencode-route/summit or opencode-route/specialist pins that task to the summit/specialist pool; a direct provider model (the loop-format example in the module docs is anthropic/claude-sonnet-4-5) works too. Changing one task's route = editing that one task.
    • Usage today is uniform: 35/35 live tasks pin workhorse. The capability for per-task summit/specialist exists and is unused — a placement choice for the design: task-placement framework v1 — decision rules and a shared-pool efficiency model #2024 framework, not a missing feature.

    4. Muse's management surface

    5. Worked example — created and observed 2026-11-22 (laptop)

    • 16:44 CST: openchamber schedule create --dir /home/user --name investigate-2019-example --model opencode-route/workhorse --once 2026-11-22 --time 16:53 --timezone America/Chicago --prompt "Create a file at /home/user/tmp/oc-sched-2019/SCHEDULED-EXAMPLE-2019.md containing exactly one line: openchamber-scheduled-example-ok — then stop." → task 03f66574-c4fd-48de-846a-c60141838ec6, enabled.
    • 16:53:00 CST the timer fired it (no human or Muse action in between). Result: lastStatus: success, duration 11.0 s, session ses_e5dfaa7c6ffe9isB7SqMM7He6b created with model {providerID: opencode-route, id: workhorse, variant: high} — the pin held at session level. The marker file exists with exactly the requested line; a run-history row was appended (outcome: success, tokens: null per §4). The once task auto-disabled after firing.
    • 16:5x CST: task deleted via openchamber schedule delete; the user project is back to its two production tasks. Artifacts retained on the laptop at ~/tmp/oc-sched-2019/.

    6. What this closes

    With round 1 (OpenCode: no native scheduler; OS-timer composition; per-job route; zero Muse tokens) and this round (OpenChamber: native scheduler, in production, same route and token answers), every LIST 4a question is answered for both systems the corrected scope names, each with a worked example. The placement synthesis (#2024) already consumed round 1; this report is its OpenChamber input. Recommendation: treat OpenChamber scheduled tasks as the default trigger for OpenCode-side fleet automation (already the de-facto state), keep Muse cron for work that needs judgement at trigger time, and leave per-task route elevation (summit/specialist pins) to the placement framework rather than ad-hoc edits.

    — Sources: fork source packages/web/server/lib/scheduled-tasks/{runtime.js,routes.js,loops.js,service.js,session-defaults.js,DOCUMENTATION.md}, packages/web/bin/lib/commands-schedule.js, packages/ui/src/lib/scheduledTasksApi.ts (developing-today-forks/openchamber main @ 18e3687, read 2026-11-22); live CLI reads (schedule status|projects|list, deployed 2.5.0) and on-disk state (~/.config/openchamber/projects/*.json, scheduled-task-run-history.jsonl) on the laptop, 2026-11-22; worked-example session and file artifacts as above.

  15. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Closing: LIST 4a is fully answered. Round 1 (2026-10-29, comment above) covered OpenCode — no native scheduler; OS-timer + opencode run composition; per-job route; zero Muse tokens; worked example observed. Round 2 (2026-11-22, comment 7087077592) covers the OpenChamber half named by the 2026-10-31 scope correction — a native scheduler in production (35 tasks, 28 enabled), per-task pinned routes, no Muse token in the create→fire→execute path, CLI/REST/run-history management surface, and a worked example created, fired on its timer, verified, and deleted today. Remaining gaps found are already owned (#2072 token exporter, #2174 Gap-3 watchdog, #1338 babysitter); no new follow-up needed. — agent felix

  16. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Released by felix (outcome: done). Investigation complete: round-2 note (comment 7087077592) answers LIST 4a for OpenChamber native scheduled tasks with a live worked example; issue closed.

  17. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    event: scheduler-audit
    by: agent felix (kind muse, Muse sandbox seat)
    at: 2026-11-22

    Lane-constancy audit, run on Drewry's direct order (2026-11-22: "ensure appropriate lanes are constantly running using OpenChamber scheduled tasks"). Method: live read of the laptop's OpenChamber task store (35 tasks, 28 enabled, across the /home/user and code projects), the run-history JSONL (5,000-row window), the claimant state dir, and the quota record — all read 2026-11-22T23:54Z. No production task was created, modified, or deleted by this audit.

    Need-by-need map:

    1. CLAIMANT / LANE-TAKER — EXISTS, HEALTHY. Task "Opencode lane claimant/executor - Move opencode executions to laptop-side scheduled tasks — retire the Muse boot handoff #3026" (*/5, enabled, opencode-route/workhorse). Mode file reads live. Run history: 945 fires in the window; the last three before the audit succeeded at 23:40, 23:45, 23:50 UTC. Inside each fire, claimant.py deterministically runs the supervision, babysitter, and nudge steps (not prompt-improvised).
    2. QUEUE LANES — EXISTS, HEALTHY. 16 enabled "Queue lane (scheduled)" tasks (code-f..j, oc-code-01..08, any-n, any-o, not-code-d) firing on staggered crons, ~159–160 runs each in the window. Seven further lane/monitor tasks sit disabled as spare capacity under the claimant's 36-root cap — left untouched; not a defect.
    3. BABYSITTER ROUNDS + STALL NUDGES (Babysitter live: interval rounds over all OpenCode sessions with verdicts, quota, and pool attribution #1338/OpenChamber dispatch v1.1: admission control, hand-backs, stall nudges, harvesting, Workhorse-first routing #1187) — EXISTS, RUNNING, ONE FEED GAP. No separate OpenChamber task exists by design: babysitter.py's verdict rounds ride the claimant fire (claimant.py loads it as a module), and nudges.py consumes confirmed stalls in the same fire. Evidence: babysitter-rounds.jsonl rounds 16–19 at 23:40/23:45/23:50 UTC, each verdicting ~28,700 sessions with the full verdict kinds (progressing / stalled / done-unreported / idle); nudge-state.json fresh at 23:50 UTC. GAP: every round records pool_state: "unread" — pool-state.json exists nowhere on the laptop. The deployed quota gatherer is a Nix-store binary predating PR feat(pm-stack): quota gatherer writes the babysitter pool-state feed (#1338) #12689 and its unit sets no POOL_STATE_PATH, so the babysitter's wall input is absent in production (walls default to not-walled). Filed as deploy: babysitter pool-state feed not live on the laptop (aggregator predates #12689, no POOL_STATE_PATH) #12718 with the deploy fix shape; it is a deployment step, not a scheduler or code gap.
    4. CONDUCTOR / QUEUE HEALTH — EXISTS, HEALTHY. "Fleet conductor — session sweep + dispatch" (*/20, enabled; last runs 23:00/23:20/23:40 UTC, success), "Orchestration pass" (hourly, enabled), "Builder's advocate" (hourly, enabled). Queue health and triage on this surface do not depend on any chat session. (Felix's muse-seat shortlist is a separate seat mechanism and not an OpenChamber concern.)
    5. QUOTA GATHER — EXISTS, HEALTHY, NOT DUPLICATED. The gather runs on the laptop's systemd user timer (~15 min); quota-current.json generated 23:45:14Z, heartbeat ok:true at the audit. The OpenChamber "Quota gatherer guardian" (*/20, enabled, firing successfully) watches freshness and repairs the known pin failure — verified rather than duplicated.

    Conclusion: the lane loop on the OpenChamber surface is self-sustaining — claimant, lanes, conductor, babysitter, and nudges all fire without a human or a Muse session in the loop. The single production gap is the pool-state deployment, #12718.

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

    epic/opencode-platformReprioritization program epic (2026-11-12)priority/highImportant and time-sensitivesource/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions