Skip to content

Run read-only routines on a timer - #267

Merged
BunsDev merged 1 commit into
mainfrom
routines-phase1
Oct 16, 2026
Merged

BunsDev merged 1 commit into
mainfrom
routines-phase1

Conversation

@BunsDev

@BunsDev BunsDev commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Routines Phase 1 of the routines spec: read-only routines with all three exit tests. Routines that change code (Phase 2), the approval gate decision and launch at login are out of scope. Full description: docs/routines.md.

What a routine is

A saved record holds a name, a project, instructions, Chat or Plan, a provider and model, and a trigger: once, or every N minutes, hours or days (at least 5 minutes) from a start time. Routines live in a new Routines rail surface, where you can create, edit, pause, resume, delete and run them now. An Activity list shows each run's trigger, start and end, status, thread and page revision.

What a run does

  1. It re-checks the routine as it is at that moment. A saved routine grants nothing (invariant 3), so a routine that isn't Chat or Plan, or whose project is gone, fails before any turn.
  2. It creates an ordinary thread. The thread is in Chat (Plan when asked), in the project checkout, named after the routine, and marked with its run. It opens with a notice saying what ran it and that it is read-only.
  3. It runs one unattended turn. runner.sendUnattended refuses a thread that is not read-only, and answers every approval "no" with a policy:routine receipt card. Nobody is there to answer, and the turn is read-only anyway.
  4. It writes the reply to the routine's Space page in the project's notes, under Routines/, one revision per run. A notice in the transcript gives the page title and revision.

Why Modex writes the page. The spec says "through the Pages MCP", but a Chat or Plan turn only gets the read-only Pages tools. So Modex writes the reply itself, through the same revision-checked notes store the Pages MCP uses, with the routine as actor and Routine run <id> as the revision summary. This also keeps the crash guarantee below simple.

Scheduling, crashes and the fence

  • When it checks. Every 30 s, at the exact due time when that is sooner, at startup, and on powerMonitor resume.
  • Missed runs. Missed due times run once, labelled Missed, run on wake. The next due time moves on before a run starts, so a crash never repeats one.
  • Killed mid-run. The next start marks a run left running as interrupted and never re-runs it. If its page revision had already been written, it is recorded as completed with that revision. The run id is the page write's idempotency key, so no revision is ever written twice.
  • The fence. Only the process that started a run may finish it. Deleting the routine, or quitting Modex, mid-run leaves the run interrupted, and a reply that arrives later writes nothing.
  • Limits. A run is stopped after 30 minutes. A prevent-app-suspension power-save blocker is held while a run works, so App Nap can't suspend a windowless Modex.
  • Unreadable file. If app/routines.json can't be read it is left untouched, and the view says so.

iPhone companion

  • The snapshot carries the last 10 ended runs (routine name, status, end time, thread) and names routine threads. It never carries instructions or page content.
  • The app shows one banner for runs that ended since it last looked, with a link to the thread. Pairing never replays old runs.
  • Refused routine approvals read "Refused automatically · routine run".

Also in this PR

  • A thread created in main now appears in an open window: the runner emits a thread event for it, and the renderer adds threads it didn't know.
  • Policy refusals in the transcript read "Refused: …" instead of the rule wording.

Exit tests

Exit test Where
With the window closed, the routine still runs, and reopening shows it in Activity e2e/routines.spec.ts (closes the macOS window, waits for the run, activate, checks Activity, opens the thread)
Killing the app mid-run leaves the run interrupted on restart, with no duplicate page revision e2e/routines.spec.ts (SIGKILL while the reply streams, relaunch, Activity shows Interrupted with no page, the next run writes revision 1) and test/routines.test.ts (crash before and after the page write)
A routine's turns are confirmed read-only on both CLIs test/routines.test.ts runs routines through the runner on Claude and Codex and checks each turn's real options with ClaudeBackend.args and CodexBackend.policy. Every approval is refused. e2e/routines.spec.ts shows a refused edit and an untouched checkout.

There are 20 unit tests in all, covering scheduling, missed runs, the fence, failures, resume, the unreadable file and the companion snapshot. CompanionModelTests covers the banner.

Fixed from an independent review

  • A turn stopped mid-run was saved as a completed page. It is now an interrupted run: the runner reports whether the turn completed, and only a completed turn writes.
  • Auto routing could override the routine's provider and model. Routine threads now run with Auto off.
  • Daily routines drifted an hour across daylight saving. Days are now local calendar days.
  • The 30-minute limit now ends the run at once and stops the CLI twice.
  • Nothing runs before the scheduler starts, and start never interrupts its own runs.
  • Recovery that can't read the notes no longer disables routines for the session.
  • A save or run start whose write fails rolls back cleanly.
  • A routine moved mid-run writes to the project the run worked in.
  • "Missed" now means only a due time that no check saw.
  • The phone announces a Mac's first runs.

Verification

  • pnpm build && pnpm test, rebased on main with Ask Jev through one decision service #257: all packages pass (desktop 1,465 passed, 0 failed).
  • pnpm --filter @modex/desktop test:e2e before the rebase onto Ask Jev through one decision service #257: 314 passed, 3 skipped (the real Open Knowledge tests). After it, the routines, approvals, approval-policy and notes specs: 11 passed.
  • iOS native unit tests on an iPhone 16 Pro simulator: 45 passed, 0 failed.

Coven-Harness: Claude Code / claude-opus-5-5

Routines Phase 1. A routine runs a read-only Chat or Plan turn in one
project, once or every N minutes, hours or days, while Modex is running
with or without a window, and writes the reply to a Space page.

- routines.ts: app/routines.json storage, validation (Chat or Plan only,
  5-minute minimum), grid scheduling (days in local calendar days) with a
  30 s check, a precise next-due timer and a check on wake. Missed due
  times run once and the next due time moves on before a run starts, so a
  crash never repeats one. A run checks its routine again when it starts,
  holds a fence so only its owner may finish it, ends failed after 30
  minutes, and on the next start a run left running is marked
  interrupted, or completed when its page revision was already written.
  The run id is the page write's idempotency key. A turn that was
  stopped, failed or silent writes no page.
- Pages: the reply becomes a revision of the routine's page in the
  project's notes, under Routines/, written by Modex through the
  revision-checked notes store, because a read-only turn's Pages tools
  are read-only.
- Runner: createRoutineThread (Chat, Plan when asked, Auto off, marked
  with the run), sendUnattended (refuses a thread that is not read-only,
  answers every approval "no" with a policy:routine receipt, and reports
  whether the turn completed), addNotice for transcript receipts. A
  thread made in main reaches an open window as a thread event.
- Routines in the rail: create, edit, pause, delete and run now, plus an
  Activity list with each run's trigger, times, status, thread and page
  revision. A power-save blocker is held while a run works.
- iPhone companion: the snapshot lists recently ended runs and names
  routine threads; the app shows one banner for runs that ended since
  it last looked, and labels refused routine approvals.

Exit tests: e2e/routines.spec.ts runs a routine with the window closed
and finds it in Activity on reopening, kills Modex mid-run and finds the
run interrupted with no page revision, and shows a refused edit with an
untouched checkout. test/routines.test.ts checks the routine turns' real
options on both CLIs against their read-only mappings.

Coven-Harness: Claude Code / claude-opus-5-5
@vercel

vercel Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
modex Ready Ready Preview Oct 16, 2026 9:07am UTC

Request Review

@github-code-quality

Copy link
Copy Markdown

Code coverage overview

Languages: TypeScript

TypeScript / code-coverage-agent

main 79c5e2c routines-phase1 3721eb1 +/-
61% 61% 0%
View coverage of the 10 most impacted files.
File main 79c5e2c routines-phase1 3721eb1 +/-
apps/desktop/sr...ngine/runner.ts 99% 99% 0%
apps/desktop/sr...ne/companion.ts 97% 97% 0%
apps/desktop/sr...kends/claude.ts 97% 97% 0%
apps/desktop/sr...ckends/codex.ts 95% 95% 0%
apps/desktop/sr.../notes-store.ts 98% 98% 0%
apps/desktop/sr...outinesView.tsx 0% 0% 0%
apps/desktop/sr...red/routines.ts 0% 0% 0%
apps/desktop/sr...shared/types.ts 100% 100% 0%
apps/store-desk...rc/main/demo.ts 94% 95% +1%
apps/desktop/sr...ine/routines.ts 0% 99% +99%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@BunsDev
BunsDev merged commit 9668924 into main Oct 16, 2026
13 checks passed
@BunsDev
BunsDev deleted the routines-phase1 branch October 16, 2026 09:37
BunsDev added a commit that referenced this pull request Oct 19, 2026
… and the routines spec (#310)

v0.2.0 was published on 2026-10-18 (23:14Z) from the signed tag on 01b1b8a. This
follows Val's status layout (#290):

- Shipped gains a v0.2.0 row linking its release and its review.
- The 13 "On main, unreleased" items move unchanged to a new "Status summary"
  at the end of the v0.2.0 review, along with the old In flight entry. Each one
  was introduced by a commit in the tag (#248, #253, #254, #257 to #261, #263,
  #264, #266, #267, #269). The CF slices and #283's Markdown parser came after
  the tag, so they stay.
- In flight keeps a short follow-ups entry for the gates no receipt records yet:
  the independent download checks, the banner upgrade on the release Mac, and
  the Companion 0.2.0 (7) TestFlight upload.
- The routines spec and the README now say Phase 1, and most of Phase 0, ship
  from v0.2.0.

Unchanged: the website's static fallback (apps/site/release.json) and the
release evidence, which stay with the release owner. Claimed on #290.

Coven-Harness: Claude Code / claude-opus-5-5

This branch was successfully deployed

1 active deployment
Preview — 3721eb13 Deployed Oct 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant