Repository navigation
feat(automations): join triggers with all, count, absent and batch - #543
Merged
Merged
Conversation
match.join_step completes joins as the stream brings each trigger's activities: all within a window on a key, count of one trigger, absent (a timer the missing trigger calls off) and batch (a timer that runs once with what it collected). What a join waits on is kept in automation_state, capped, expiring, and written with a version so two processes lose nothing. Join timers register with timers.py, and one that ends without firing drops what it waited on. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AjJqXgjj1cNdKGRQbX5frb
17 of 23 tasks
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: an automation with several triggers could only run on each of them as it came (the join
any); every other join was refused when the automation was saved, as coming soon, so "when the school's email and the calendar event both arrive", "three failed logins in five minutes" and "no reply within two days" could not be said.After: an automation's join waits for its triggers together.
allruns it when every trigger has an activity within a window of the others, on a key ("for the same sender");countwhen one trigger came so many times within a window;absentwhen a window passes after one trigger with no second one on the same key (a reply in time calls it off);batchonce, with everything one trigger collected over a window. The If and the graph see every trigger's activity inevents({{ events.mail.object.subject }}), andeventis the last. What a join waits on outlasts a restart, and switching the automation off drops it.Workflow studio module M5, part 3 of 5 (plan section 5, M5 item 3).
How:
match.join_step(db, cfg, automation, alias, activity): given each activity a trigger matched (after its guards and claim), completes the join and gives the list of completions;automations.firesends a claimed activity there first when the join isn'tany, and fires the automation for each completion.automation_state, kindjoin: small copies of the activities (long text cut, at most 500 in a batch), written with a version so two processes at once lose nothing, expiringwithinafter the newest activity (a day after a timer's time forabsentandbatch).absentandbatchset timers throughtimers.py(absent-<automation>-<key>,batch-<automation>), whose handlersjoin.absentandjoin.batch(match.TIMER_HANDLERS) fire the automation. A timer that ends without firing drops what it waited on; one that can't be set (the automation already has 1000 waiting) drops it too, with a log line. Switching the automation off or deleting it calls its join timers off with its schedules.match.describe_joinreads a join in words (mail, then no reply within 2 days), andautomation_specno longer refuses joins other thanany.docs/requirements.md; a line under## UnreleasedinCHANGELOG.md.Motivation and Context
Adeel asked for conditions joined from several sources ("the school emails and the calendar", "if I haven't replied") and for them to survive restarts.
Types of changes
!in the title)Checklist:
make hookschecks it on commit).docs/accordingly.## UnreleasedinCHANGELOG.md.Done questions (AGENTS.md)
automations.catch_up.anybehaves as before; the other joins were refused until now, so no saved automation changes.automation_statetable, no stored shape changes.docs/requirements.md; drafts from a sentence still say they can't make a join (refine later).tests/domain/test_match_joins.py,tests/domain/test_automation_conditions.py;docs/automations.mdJoins.allwait across off and on, sequences of three) are in the docs.timers.py,automation_state, the stream's claims andautomations.fire.Generated by Claude Code