Commit graph

2 commits

Author SHA1 Message Date
Pascal André
4d6a517602
fix(missions): resolve scheduled wakes from native message records (OpenCode 2.2.6) (#1350)
## Problem

On OpenCode 2.2.6, scheduled Mission wakes no longer start their
passage. Upstream anomalyco/opencode#61018 removed the `metadata` copy
from the LLM messages plugins see in session context hooks. CodeNomad
classified wakes from `metadata.schedule` on that projection, so a 2.2.6
wake looked inconsistent: the drain failed with `schedule-carrier-wake`
and the passage was never admitted.

## Fix

The context projection still carries each native message `id`, and the
stored native message still carries `metadata.schedule`. Wake
classification now resolves user-role context IDs through the existing
bounded native message reader and classifies the authoritative stored
records by type and status, ignoring projected metadata. Resolved
records are reused for the candidate proof, so a wake row is read once.
Classification and recovery reads have separate read and byte budgets,
and exceeding a bound surfaces a coverage error instead of dropping the
wake. Placement, mapping, deterministic identities, source-byte fences,
RPC checks and CAS/high-water behavior are unchanged. The minimum stays
2.2.3.

The canonical authority and bounds contract is in
`dev-docs/MISSIONS_NATIVE_SCHEDULE_TRANSPORT.md`.

Native facts, checked on isolated CLIs:

| CLI | Context message ID | Context `metadata.schedule` | Stored
`metadata.schedule` |
|---|---|---|---|
| 2.2.3 | kept | present | present |
| 2.2.5 | kept | present | present |
| 2.2.6 | kept | absent | present |

## Tests

- Unit coverage for metadata-free and conflicting projections, notices,
compactions, invalid native records, a context of 128 wake entries,
eight recovery reads and independent byte budgets.
- `tests-runtime-contracts` gains a native context/storage check and the
cold scheduled-Mission product check on minimum and latest, and uploads
the fixtures' receipts and failure diagnostics when a step fails. The
schedule fixtures read the actual CLI version instead of a hardcoded
2.2.3, poll for the PID-matching ready registration, and set the `at`
time after activation, just before Play. The cold wait allows 120 s
(leader-lease recovery exceeds 45 s on dev too).
- On 2.2.6, an `origin/dev` snapshot fails the cold product check
(`schedule-carrier-wake`); this branch passes `at` and `in` with the
exact CI command (product step: 102 s on 2.2.3, 208 s on 2.2.6).
- Foundation fixtures pass on 2.2.3 and 2.2.6 (3 CAS applications, cold
recovery, no provider requests); an earlier revision also passed them on
2.2.5. Server Missions suites: 1,406 passed. Server/UI typechecks and
native bundle builds pass. The full runtime-contract sequence passes
locally on 2.2.3 (15 min) and 2.2.6 (23 min 26 s, against the job's
25-minute timeout).

## Known limitation

`experimental.part_rows` (off by default) stores assistant parts in
`session_part`, which CodeNomad's history, search, outline, gallery and
pruning readers do not read. Documented in
`dev-docs/SESSION_HISTORY_QUERIES.md`, not addressed here.
2026-11-07 22:01:03 +01:00
Pascal André
a5efdefc8d
feat(missions): resume recurring Missions after OpenCode restarts with native schedules (#1259)
Closes #926.

## What changes

Recurring Missions now survive OpenCode restarts (update, crash and
relaunch, reboot) without a manual **Resume**, and the scheduler offers
more than "once a day at a fixed time".

- **Native schedules.** OpenCode's own scheduler
(`experimental.schedules`, OpenCode 2.2.3+) owns the calendar; Missions
decides whether a passage may run (CAS admission, no duplicates,
Pause/Stop, errors and uncertain states stay manual). A dedicated
technical conversation with a local no-op model carries the wake, so
wakes, titles and compaction make no provider HTTP requests.
- **Richer scheduling**, in one collapsed **Scheduling** section of the
Create/Edit editor (default: once, immediately, no condition): date,
delay, interval (≥15 min), daily, chosen weekdays, up to eight times a
day, day of month, native cron; optional end date/duration and a maximum
number of launched passages; five event conditions (another schedule
succeeds, a one-time Mission completes, new local commits, a new message
in a followed conversation, explicit files change). Up to five upcoming
dates are previewed in the saved IANA zone.
- **Created paused, started with Play.** Everything is editable before
the first launch; after it, edits follow the approved matrix (future
parameters between passages, objective/notes journaled during a
passage).
- **Keep OpenCode running.** A Preferences setting supervises the shared
OpenCode service through the OS (Windows Task Scheduler with a periodic
recovery task, macOS LaunchAgent, Linux systemd user unit with
lingering, WSL from Windows). ON by default at the first Play unless OFF
was saved; OFF removes supervision without stopping OpenCode; a live
service is never killed or duplicated.
- **Existing daily schedules** keep their path and controls; no
migration.
- Help (English and nine translations) and dev-docs are updated.

## Validation

- Typechecks (4 workspaces); server Missions/host-lifetime suites; UI
unit tests 1945/1945; help 31/31 and build.
- Real isolated OpenCode services (2.2.5, minimum 2.2.3): resting
schedule resumes after service restart with no client and no Resume; 32
real passages with history/quota/phase preserved; concurrent wakes admit
once; DST and catch-up for every frequency type; forced local
auto-compaction and restart during maintenance with zero provider HTTP;
real upgrade 2.2.3 → 2.2.5.
- OS supervision on Windows, WSL, Ubuntu VM (two real reboots, healthy
before login; OFF without a session) and macOS VM (Aqua session,
crashes, OFF/adoption). On the final bundle: two real periodic Windows
recovery relaunches; WSL OFF/Retry on a live HTTP 500 service keeps the
same process.
- Windows Electron and Tauri packages run in private profiles: paused
creation, nine frequencies, preview.
- Full browser suite: 956/957 in the last tier; the failure is
`directory-browser.test.ts` (folder picker timeout), unchanged by this
branch, and that file passes 20/20 on rerun. Earlier dev-baseline runs
on the same machine also lost module loads to
`net::ERR_NO_BUFFER_SPACE`.

## Known limits (not qualified in this PR)

- macOS reboot followed by a real login, and a Windows host reboot/logon
(needs a disposable bench).
- Real screen-reader output (keyboard, ARIA and RTL checks pass).
- Linux/macOS desktop packages.
- OpenCode's background *pre*-compaction never applies to the technical
wake conversations: their local model reports zero tokens, below the
native minimum. Their automatic local compaction is qualified.

## Follow-up

Integration with native `/goal` comes in a separate PR.
2026-11-01 14:40:24 +01:00