Skip to content

feat(automations): join triggers with all, count, absent and batch - #543

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-li6m25
Oct 18, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-li6m25

Conversation

@adeelahmad

Copy link
Copy Markdown
Owner

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. all runs it when every trigger has an activity within a window of the others, on a key ("for the same sender"); count when one trigger came so many times within a window; absent when a window passes after one trigger with no second one on the same key (a reply in time calls it off); batch once, with everything one trigger collected over a window. The If and the graph see every trigger's activity in events ({{ events.mail.object.subject }}), and event is 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.fire sends a claimed activity there first when the join isn't any, and fires the automation for each completion.
  • What a join waits on is a row per automation (and key) in automation_state, kind join: 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, expiring within after the newest activity (a day after a timer's time for absent and batch).
  • absent and batch set timers through timers.py (absent-<automation>-<key>, batch-<automation>), whose handlers join.absent and join.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_join reads a join in words (mail, then no reply within 2 days), and automation_spec no longer refuses joins other than any.
  • README: the built list's automations bullet names joins and the studio line loses them, with the checks in docs/requirements.md; a line under ## Unreleased in CHANGELOG.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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly.
  • Users need more than the title to understand it, so I wrote it under ## Unreleased in CHANGELOG.md.

Done questions (AGENTS.md)

  • Goal: the four joins, running on the stream and on timers; merged on green CI.
  • Agents: the join is part of the automation agents save over the API, MCP and the assistant.
  • Zero setup: nothing to install or configure.
  • Fewest clicks: n/a, no UI here (the builder is M11).
  • Configurable: n/a, no new settings; the catch-up window is the existing automations.catch_up.
  • Light: one small state row per waiting join, capped at 500 activities a batch and 1000 timers an automation.
  • Private and secure: a join's rows hold cut-down copies of activities the automation's person already sees, in the database like everything else; nothing leaves Lens.
  • Cost: no model calls.
  • User decides: any behaves as before; the other joins were refused until now, so no saved automation changes.
  • Upgrades: new rows in the existing automation_state table, no stored shape changes.
  • Honest: docs and README label joins built, with their checks in docs/requirements.md; drafts from a sentence still say they can't make a join (refine later).
  • Tests and docs: tests/domain/test_match_joins.py, tests/domain/test_automation_conditions.py; docs/automations.md Joins.
  • Open: n/a.
  • Reported in the project thread; refine-later items (drafting joins, keeping an all wait across off and on, sequences of three) are in the docs.
  • Reuse: timers.py, automation_state, the stream's claims and automations.fire.

Generated by Claude Code

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
@adeelahmad adeelahmad self-assigned this Oct 18, 2026
@adeelahmad
adeelahmad merged commit 3ef3a17 into main Oct 18, 2026
11 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-li6m25 branch October 18, 2026 02:49
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.

2 participants