Repository navigation
Pin an automation to one computer of a device group - #240
Merged
Merged
Conversation
A per-automation Run on setting (routines.run_on: "primary" or a device id, null = any). Every desktop computer runs the scheduler but fires only what belongs to it: pinned automations only on their computer, also while another one stands in; the rest where the group's schedules run. Run now on a pinned automation goes to its computer over the link, or is refused clearly while that computer is offline. Exposed in the REST API, the routine_create/routine_update tools and the automation editor.
…ill save A pinned automation only goes on in a chat that lives on its computer. Run now passed on between computers uses a link-only route, so app requests can't claim the pinned hop. An unchanged pin to a computer that left the group no longer blocks saving.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In a device group, a secondary that stands in for an offline primary fires every schedule itself. Automations that depend on files, folders or browser profiles that only exist on one computer then run on the wrong one and fail or do nothing (missing project folders,
MODULE_NOT_FOUND, a browser profile that isn't there).Change
A per-automation Run on setting:
routines.run_on(migration 103) holds"primary", a device id (the sameGroupDevice.idthe Devices list uses) orNULL= any computer (today's behaviour).runsRoutineHereinremote/group.ts). Pinned automations fire only on their computer, also while another one stands in; unpinned ones fire where the group's schedules run (primary, or a secondary standing in). The stand-in catch-up (runMissedSince) skips pinned automations. The pinned computer catches up a slot it missed while away through the existingcatchUpMissed/ late-tick path, so the existing dedupe (caughtUp,last_run_at,lastScheduledStart) still guarantees one run per slot. On the primary, a pin to a computer that left the group falls back to the primary.next_run_atand repairslast_statusfor automations it fires, so a secondary doesn't overwrite the primary's view of automations it doesn't run (routines replicate as whole rows).sendMessagewould forward the run to the computer the chat lives on.POST /api/routines/:id/run,routine_run): when the automation is pinned elsewhere, the request goes to that computer over a new link-only route,POST /api/link/routines/:id/run(group peers only, refused for the cloud). A secondary sends it to its primary, which passes it on. If that computer can't be reached, the request fails with a 409device_offlinethat names the computer.runOnonRoutine/RoutineInput, in the REST schema, and inroutine_create/routine_update. The value can be "primary", a device id, a computer's name, or the primary's runner id as seen from a secondary; it is normalised to the stored form. Aroutine_updatethat only changesrunOndoesn't make the automation fill-only (like pausing). Saving an unchanged pin to a computer that left the group still works.Notes
last_run_at,last_status) while the primary is up. If the two computers can't reach each other, a run on the secondary can win over an edit made on the primary at the same time. A secondary standing in has the same problem today; per-column merge would be a separate change.Tests
scheduler.test.ts: 10 new tests. They cover: normalising names and ids into the stored pin; a stand-in that never fires or catches up an automation pinned to the primary (and leaves itsnext_run_atalone); a secondary that fires its own pins while not standing in; the primary skipping automations pinned to another computer unless that computer left the group; saving a stale pin; no chat reuse across computers; Run now refused with a clear message while offline; the pinned primary catching up a missed slot exactly once; a secondary catching up only its own pins after a sleep.replica.test.ts: the pin replicates.pnpm -r typecheckis clean. These suites pass: scheduler, routines, replica, mcp, devices-e2e, stand-in-waiting, automations, cloud-scope, remote-link, backup, remote-snapshot.