Skip to content

OpenCode scheduled tasks: migrate the Muse→OpenCode cron wrappers into OpenChamber scheduled tasks (waves, monitoring gates) #2174

Open

Description

@dezren39

What this is

Drew, 2026-10-29: find where OpenCode-native scheduled tasks can replace the Muse cron jobs that currently launch OpenCode — to save Muse tokens or raise throughput — with proper management and monitoring of those tasks and their outcomes. Study: ~/workspace/research_notes/opencode-scheduled-tasks-20261029/findings.md.

Verdict: PARTIAL — the trigger exists, in OpenChamber, not OpenCode

  • OpenCode core has no scheduler. Zero cron/timer code in packages/core|server|cli; sessions are purely event-driven.
  • OpenChamber has a real scheduled-tasks subsystem (packages/web/server/lib/scheduled-tasks/): cron/daily/weekly/once with timezones, per-project + chats scopes, new-session-per-run (model/agent pinning, permission auto-accept, goal mode with token budget, sessions stamped metadata.kind='scheduled') or prompt-into-existing-session, cross-instance occurrence claiming, loop files (.agents/loops/*.md), REST + UI + CLI + an agent tool (openchamber_schedule).
  • But it is a prompt scheduler, not a job system: state holds only the last run, no token capture, no alerting, in-code defaults of 4 global / 2 per-project concurrent runs, and a 30-minute run cap (vs ~90-minute shift windows).

Migration waves (Claude input tokens, trailing-24h, runtime-DB attribution)

Wave 1 (~3.4B/day of the fleet's ~5.1B/day):

  1. Repo-queue worker shifts — ~2.26B/day, save ~2.1–2.2B. The Muse layer is claim/checkpoint/terminal-verbs via repo-queue.py plus implementation over laptop-ssh — the identical runbook an OpenCode session already executes when dispatcher-launched. Ports near-verbatim as per-queue scheduled tasks. Blockers: repo-queue.py must run laptop-side; sandbox lane-lock files replaced by the atomic DB claim; run cap raised.
  2. Issue creators — ~0.96B/day, save ~0.9B. The runbook already is a self-contained prompt. One API-created scheduled task per repo-lane. Note: this reprices the 3.93M-Claude-tokens/filed-issue figure behind Drew's held creator-throttle decision into pool tokens.
  3. OpenChamber dispatcher + babysitter — ~390M/day, save ~350–370M. The most rule-bound jobs in the fleet, currently spending Claude tokens operating the API of the system that would run the loop natively. Port as existing-session scheduled pokes into persistent sessions (cross-round state lives in session context instead of being re-read at ~1.4M/run).

Wave 2 (~0.25B): fleet-monitor, pr-diff pair, issue-sweep, pool-quota-steward (partial fits).

Keep on Muse: fleet-watchdog (it is the monitor — it must instead gain coverage of the OpenChamber tasks) and orchestration-pass (the consumer/escalation collector).

The honest trade

The throughput ceiling moves from Claude-subscription/cron concurrency to pool quotas + the laptop's 12-session cap. At a known-100% pool the native fleet stalls where Muse lanes currently sail past. This makes the migration dependent on the full-quota utilization program (#2173) keeping pools fed and rotated.

Gating monitoring gaps (fix before migrating anything)

  1. Per-run history — scheduled-task state is last-run-only (laptop JSON). Consume the already-emitted openchamber:scheduled-task-ran SSE events into Supabase.
  2. Token accounting — every OpenCode assistant message already carries cost + tokens (schema/session-message.ts), but nothing exports it; the mirror covers only the Muse runtime. Build an OpenCode-side exporter twin of runtime-db-export (this is External-system observability: unified PM + queue + quota attribution (webhooks, hot list, session IDs, projections) #2072 work).
  3. Failure alerting / dead-man's switch — fleet-watchdog polls GET /api/openchamber/scheduled-tasks/status + queue-claim staleness.
  4. Server residency — the scheduler dies with the OpenChamber server process; confirm the laptop deployment is always-on (not socket-activated or idle-stopped).
  5. Shared-state locality — fleet bookkeeping (backlogs, sweep.log, lane locks) is sandbox-resident; OpenCode sessions are laptop-resident. Move per-job state to Supabase, following the queue pattern.
  6. Identity binding (task id / session id / queue task id in one place), the loop-file approval gate (silently pauses migrated jobs), escalation path for urgent classes.

Acceptance

  • Gaps 1–4 closed and demonstrated on one pilot: ONE queue lane running as an OpenChamber scheduled task for 48h with per-run history, token accounting, and watchdog coverage — reviewed against its Muse-cron baseline (outcome, tokens, time), then a go/no-go for the rest of wave 1.

Acceptance criteria

  • Each Muse cron wrapper that launches OpenCode is inventoried (in the linked study or a comment here) with a disposition: migrated to an OpenChamber scheduled task, kept on Muse cron with a named reason, or retired.
  • Migrated tasks run in waves with monitoring gates between waves: a wave's runs are observed completing (run records + outcome checks) before the next wave migrates.
  • For every migrated task, the Muse-token cost change is measured or explicitly estimated, and any throughput change is noted — the migration's stated purpose is token savings or throughput, so the result must say which it got.

Activity

  1. developing-today commented on Oct 29, 2026

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

    @dezren39
    MemberAuthor

    DREW DIRECTION (2026-10-29, main chat) — corrections to this issue's framing:

    1. The 30-minute run cap is ours to turn off. OpenChamber is our code; treat the cap as a config/code change, not a constraint.
    2. Tokens: the data exists. OpenCode stores every session; any run can be looked up. The work is an EXPORTER that pulls from OpenCode's own history database (Drew's preferred approach — pull it out of the giant OpenCode DB), not new capture. This is the External-system observability: unified PM + queue + quota attribution (webhooks, hot list, session IDs, projections) #2072 exporter leg.
    3. Alerting: monitoring these jobs is Muse's job (the watchdog). Jobs can also self-signal — e.g. file a GitHub issue when they hit a problem — and alerting can be built into OpenCode/OpenChamber where it belongs.
    4. ROLLOUT IS ADDITIVE. Add OpenChamber scheduled tasks alongside the existing Muse crons; do NOT migrate or remove the Muse side first. Adjust over time as comparison evidence accumulates. OpenClaw's scheduler (OpenClaw scheduled tasks: use the native automations scheduler for watchdog-class and laptop-local work #2177) is the complementary piece, not a competitor.
    5. Pace: faster than a 48-hour single-lane pilot — stand up MORE THAN ONE queue lane as scheduled tasks from the start.
    6. Review metrics are RELATIVE, never absolute token counts across systems: cost-relative tokens, time taken, and outcome quality. (Same frame applies to the OpenClaw: finish setup, begin passing jobs, and review results against OpenCode #2171 review.)

    The 'gates' in the issue body are hereby build tasks, not gates: per-run history export (from the OpenCode DB), watchdog monitoring of the scheduled tasks, residency confirmation. First build dispatched 2026-10-29: two queue lanes as OpenChamber scheduled tasks, additive, DB-claim only, Muse lanes untouched.

  3. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    OpenChamber scheduled lanes — LIVE (additive, per Drew's direction 2026-10-29)

    Two OpenChamber scheduled tasks now run the repo-health queues ADDITIVELY alongside the existing Muse cron lanes. No Muse cron job was touched; no OpenChamber/OpenCode config file was edited outside the scheduled-tasks CLI.

    Lane OpenChamber task id Project Schedule Model / agent Session per run
    code queue (repo-health-code-pilot) 8ac61616-3815-4e7b-b33d-840a3829154a /home/user/git/code cron */40 * * * *, America/Chicago opencode-route/workhorse (route pool, no raw model pin) / build new session
    opencode queue (repo-health-opencode-pilot) 3fe37e8a-c61b-419c-9e97-769ecd264d5d /home/user (no OpenChamber project exists for ~/git/opencode; the prompt anchors the session at ~/git/opencode and uses absolute worktree paths) cron */40 * * * *, America/Chicago opencode-route/workhorse / build new session

    Each task's prompt = a lane header + the SAME per-repo worker runbook the Muse lanes execute, verbatim. Header adaptations only: no sandbox lane-lock files (the atomic DB claim is the only claim), health gate first, worktrees under ~/git/fleet, ~30-min run discipline with terminal park/complete verbs, first checkpoint carries "origin": "openchamber-scheduled-lane" for audit, sandbox backlog/sweep-log writes skipped (bookkeeping noted in the complete() result instead). Worker ids unchanged (repo-worker-code / repo-worker-opencode).

    Verification (2026-10-29, fleet clock UTC)

    • Pre-checks passed: repo-queue.py health runs on the laptop against Supabase; openchamber schedule CLI surface works; quota re-read before triggering — no workhorse pool walled.
    • Manual trigger: code session ses_e5e795f9576ffe8tuA71C91x8c, opencode session ses_e5e795f8099ffeWHVRz8NTmgh8.
    • First unattended cron occurrence fired on time (08:00:00Z / 08:00:01Z): code session ses_e5e7953b638ffenCsU6ORljLIC, opencode session ses_e5e7953b16fffevBgwWxHh8ur1; next occurrence 08:40Z. Both tasks remain ENABLED.
    • Claims audit (via the origin marker in agent.tasks.progress): OpenChamber lanes claimed tasks 2827, 2828, 3227, 2833 (code) and 2712, 2705, 2900 (opencode) — all distinct ids; Muse lanes claimed different tasks in the same window (2661, 2681, plus the pre-existing 2821/2825/2990/2826/3223). No task was double-claimed. The atomic claim is doing its job.
    • Work product already real: task 2827 completed a full triage of mcpx: administration by intent — finish the operation surface, then route a sentence to a declared operation #1931 (verdict + comment + follow-up task 3226 enqueued); 2828 also completed; 3227 and 2705 parked properly with resume briefs; 2712/2833/2900 in flight.

    Notes / watch items:

  4. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    Second OpenChamber scheduled lane for the code queue is live (Drew's direction, 2026-10-29) — mirroring the first code lane exactly: task 2717091f-6f5a-4a46-beae-5e7db58d376b, project /home/user/git/code, cron */40 * * * * America/Chicago, model opencode-route/workhorse, agent build, new session per run, same lane prompt (header + code worker runbook verbatim), atomic DB claim only, origin marker openchamber-scheduled-lane. The CLI accepted the identical task name with no refusal.

    Verification: manual trigger → session ses_e5e793aea23ffeFylbU3awqnEu (lastStatus success). Its first claim landed 51s after dispatch: task 2869 (triage of code#1968), claimed 2026-10-29T08:27:56Z with the origin marker in its first checkpoint, attempts=1. No first-lane cron occurrence existed in that window, and the concurrent Muse-lane claims (2864, 2866, 2871) carry no origin marker — zero overlap, the atomic claim held across two OpenChamber code lanes + the Muse lanes. Left ENABLED on the regular */40 cadence. Full record: rollout addendum in ~/workspace/research_notes/opencode-scheduled-tasks-20261029/rollout.md. No existing lane or Muse cron was touched.

  5. added
    kind/infrastructureInfrastructure / host-portability work
    source/humanFiled directly by a human
    priority/highImportant and time-sensitive
    effort/lLarge: multi-day or open-ended; expect staged check-ins
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    on Oct 29, 2026
  6. dezren39 commented on Oct 29, 2026

    @dezren39
    MemberAuthor

    Intake review

  7. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    Lane expansion — Drew, 2026-10-31 ~07:56 CDT: +4 code, +1 openchamber, +1 nix OpenChamber scheduled lanes.

    Created via the laptop openchamber schedule CLI, all ENABLED, all cron */40 * * * * America/Chicago, model opencode-route/workhorse, agent build, new session per run, origin marker openchamber-scheduled-lane:

    • code: c29174f1-48e0-4b13-b4ff-9b73ab67e9ab, 262eb403-3347-4a7c-ba6b-e7bc263ca853, 335a5d1f-bfc1-4831-99ea-850c8939a727, 7b47536b-c162-444c-be8a-3a9538cc4cb5 (project ~/git/code; staged lane prompt reused verbatim)
    • openchamber: 46984602-51a3-438c-b3a5-f2857811adb1 (project /home/user — no registered project for this repo; prompt anchors at the primary clone ~/git/openchamber-fork)
    • nix: 8d133595-c60c-4dcb-8e82-59b7d0ac9b5a (project /home/user; prompt anchors at ~/code/dezren39-nix)

    Openchamber/nix prompts = the 2026-10-29 rollout header adaptations + each queue's own worker runbook verbatim; staged in hatch-personal workspace/research_notes/opencode-scheduled-tasks-20261029/prompts/ (commit d95bfaf7b) and copied to the laptop with sha256 verification.

    Verification: manual triggers of one new code lane (session ses_e5e6df34549ffeX6juJcU0fKTk), the openchamber lane (ses_e5e6df34345ffePROYiiixfhjY), and the nix lane (ses_e5e6df34175ffewvlbwb0qw4Lm) all ended lastStatus=success. The nix queue currently holds 0 queued tasks, so that lane idles until work lands. Pre-flight quota read (aggregator, 12:45Z): workhorse route doors have weekly headroom (opencode-go.personal 39%, opencode-go.lab 75%, command-code 64%); the Meta reserve door reads 100% weekly.

    Store inventory now: 9 enabled queue lanes (code ×6, opencode ×1, openchamber ×1, nix ×1) plus the #3026 claimant task (disabled).

    Two discrepancies vs the 2026-10-29 record — flagged, not silently fixed:

    1. The recorded second code lane 2717091f is no longer in the store. The second code lane present is 9aca43b4-5439-4939-9f71-323f5d32521b: prompt byte-identical to the lane prompt, but cron is 20,40 * * * * and the model is unset (falls back to the project default instead of the pinned workhorse route).
    2. The laptop's hatch-personal clone has diverged from origin (fast-forward pull refused), so the prompt files reached the laptop by checksum-verified transfer rather than git pull.
  8. 124 remaining items

  9. added
    design/executor-expansionDesign: executor-expansion - all issues of this effort carry it
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 11, 2026
  10. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (triaged)

  11. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (triaged)

  12. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    Addendum to the task 19721 triage note above: after task 19721 completed, the Gap 3 packet was enqueued successfully — task 20699 (queued, repo-health-code-pilot): "Fix #2174 Gap 3: watchdog coverage over OpenChamber scheduled-task run history (missing/stale run alerts)". The scoped next step for #2174 is now a live queue task, not just a note.

  13. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — state: done (Gap 3 landed), lane any-h, task 20699, at 2026-11-17T09:35Z

    Gap 3 (watchdog coverage over scheduled-task run history) is landed via PR #11158 (squash-merged, 0f5ee58).

    What landed, in pm-stack/scheduled-history/:

    • watchdog.py check consumes the Gap 1 collect.py store and flags per task: missing_run (no run scheduled within the expected cadence window), stale (newest run older than the stale threshold — default 2× the window — with nothing in flight), and failed_latest (most recent terminal outcome is an error class). The expected window is a declared per-task window (--windows JSON) when present, otherwise the observed schedule (minimum interval between consecutive scheduled_for instants), and the source is stated in every alert's evidence. First-window grace: a task whose history is younger than one window cannot alert for missing/stale; disabled tasks are skipped.
    • Alert path: one JSON document (scheduled-history-watchdog/v1) on stdout — task, condition, evidence timestamps — with exit 1 on any alert; that document is the input the fleet-watchdog cron consumes.
    • Tests: test_watchdog.py 13/13 (healthy, missing, stale, failed-latest, first-window, declared-window override both ways, disabled, in-flight); test_collect.py still 19/19. Live smoke against the real store: 37 tasks checked, 29 alerts (mostly stale — the collector store had not ticked for ~6h at that moment, exactly the silence this check surfaces).

    Per-gap status: Gap 1 closed (openchamber PR #2082 + code PR #8437). Gap 2 (token accounting) is next in sequence but is #2072-owned. Gap 3 done here. Gap 4 (server residency), Gap 5 (shared-state locality), and Gap 6 (identity binding) have no packets yet.

  14. removed their assignment
    on Nov 20, 2026
  15. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Merged work, still open. Every pull request that references this issue has merged (#8437, #2082, #11011, #11158) and none is open, but the issue kept status:in-review. Tasks that name it as a blocker have been waiting on it.

    status:in-review is removed. Whoever takes this next: run the issue's done check against main. Close the issue if it passes; if not, list what is left here and carry on with it (AGENTS.md, "Finishing work").

    By: Claude, 2026-11-22 flow review.


    Generated by Claude Code

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

    design/executor-expansionDesign: executor-expansion - all issues of this effort carry iteffort/lLarge: multi-day or open-ended; expect staged check-insepic/opencode-platformReprioritization program epic (2026-11-12)kind/infrastructureInfrastructure / host-portability workmeta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/highImportant and time-sensitivequeue/parkedQueue task is parked (waiting on CI, time, or an event)source/humanFiled directly by a humanstatus/parkedDeliberately paused with a recorded resume conditionstatus/triagedTriaged and routed (see agent note)task/triageQueue packet kind: verify, reproduce, and route this itemwork/assignedQueue worker lifecycle state

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions