Repository navigation
feat(automations): schedule, at and relative triggers as timers - #450
Merged
Merged
Conversation
timers.schedule_automation sets one timer per schedule trigger (its next time, re-armed as it fires, DST as schedule.py has it) and per at trigger still to come, leaves timers a trigger still wants alone so they can catch up, calls off the rest, and cancels everything when the automation is off. timers.relative sets a relative trigger's timer per automation, trigger and object, so a moved calendar event moves its timer; past times are skipped with a note. When they fire, automations.fire gets a clock.tick activity (a new kind, never stored) or the activity that set the timer. timers.upcoming lists what an automation has waiting, in words, and schedule.describe reads weekdays, single days and days of the month. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KfD6cia42GiEZakbs74jxY
This was referenced Oct 16, 2026
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.
Requested by Adeel · project thread
Description
Before: Lens could keep timers (#446), but nothing turned an automation's "every weekday at 07:00", "at 18:00 on Friday" or "30 minutes before the event starts" into one.
After:
app/domain/timers.pysets, moves and calls off the timers behind an automation's schedule,atandrelativetriggers, and lists what an automation has coming in words ("Every weekday at 07:00: next on Fri 16 Oct at 07:00 (Europe/London)"). When one fires, the automation fires with aclock.tickactivity (a new kind, never stored) or with the activity that set the timer. Workflow studio M4, part 2 of 3. Nothing changes for an install until automations are stored (M6), which calls these on save.How:
schedule_automation(db, automation)runs on save, switch-on and switch-off. It sets one timer per schedule trigger (sched-<id>-<as>, kindschedule.next, re-armed in its claim throughschedule.next_after, so DST works as routines have it). It also sets one perattrigger that is still to come (at-<id>-<as>). A waiting timer whose trigger is unchanged is left alone, so an overdue one can still catch up. Changed ones are set anew and the rest are cancelled. Switched off, everything is cancelled.relative(db, automation, alias, activity, field, offset)keys its timer by automation, trigger and the activity's object (rel-<id>-<as>-<object id>), so a moved calendar event moves its timer rather than adding a second one. A time more than 5 minutes past is skipped and returns anotefor the run log.upcoming(db, automation, n)andclock_state(db, automation)serve M6's API and the builder.untrustedmarks a description that quotes outside text (an event title).schedule.describenow reads weekdays, weekends, single days and days of the month ("at 09:00 on the 20th of every month"), so the existingGET /api/v1/routines/schedulepreview gets better too.automations.fireis reached through an import guard (_provided), since M6 isn't merged. Until then a fired trigger records "automations aren't built yet" onlast.error, and a schedule still re-arms.Defaults I picked (reversible):
fieldvalue is midnight UTC; the person's time zone is under Refine later.clock.tickis noisy and never stored, so it reaches automations without filling the timeline.Motivation and Context
Workflow studio M4 (
/mnt/project-files/workflow-studio/briefs/M4.md, plan section 3.10). M6 callsschedule_automationon save andrelativefrom its trigger matcher, and exposesupcoming. Part 3 adds actions that wait (later).Types of changes
!in the title)Checklist:
make hookschecks it on commit).docs/accordingly.## UnreleasedinCHANGELOG.md. (n/a: nothing reaches people until M6 stores automations)Done questions (AGENTS.md)
upcomingand the automation API;clock.tickshows inGET /api/v1/activities/kindsfor agents writing triggers; the schedule preview is already in the API.untrusted. Threat model n/a.docs/automations.mdlabels the timers built and says automations set them once they are stored; waiting actions planned.tests/domain/test_timer_triggers.pycovers schedule re-arm and catch-up, DST,atonce, relative moves/skips/cancels, saving again, switch-off, upcoming, clock_state and describe. Docs:docs/automations.md(Time, kinds table, Refine later). Run on embedded SurrealDB and a 3.2.4 server. No generated files change.docs/automations.md.🤖 Generated with Claude Code
https://claude.ai/code/session_01KfD6cia42GiEZakbs74jxY
Generated by Claude Code