Skip to content

feat(automations): run automations on new activities, with limits, budgets and runs - #462

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-sxrerj
Oct 16, 2026
Merged

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

Conversation

@adeelahmad

Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: automations could be saved and switched on, but nothing ran them.

After: a switched-on automation reacts to new activities in its namespaces. When its If passes it runs its event workflow as the person who made it, within its limits and budgets, and each run is kept with what every node did, its log, its cost and what its actions did, asked or wait to do. Runs appear in the stream as automation.ran. Over the API you can list an automation's runs, read one, find the runs an activity started, try an automation (saved or a draft) on an activity or a kind's sample without keeping or sending anything, run it now, decide a run held over budget, and see when it runs next. Settings → Automations switches them all off and sets how deep chains may go, how many runs a minute Lens allows and how long runs are kept.

How: a thread named automations follows the stream where the notifier and routines run. automations.fire(...) is the one way every trigger starts a run: it checks the person still may act, the If, the automation's cooldown and hourly limit, the minute-wide cap and budgets (automation:<id> is now a budget resource), then runs the graph inside an activity-ledger scope. Activities an automation makes carry their run as the cause, so chains stop at automations.max_depth and an automation ignores other automations' activities unless a trigger says from_automations. Each (automation, trigger, activity) is claimed once through the event log's claims, so the API and a worker can both follow. An action that asks first becomes an approval in the inbox (approvals.ask, #447, with the activity that caused it) and one that waits becomes a timer (timers.later, #452, its timer and time kept on the intent); both report back through update_intent, and the inbox's Always calls set_policy. approvals now reads the run's activity from the fields runs keep (event_ids). Schedule and at triggers run when their timers fire (#450 calls fire with a clock.tick activity), a relative trigger's matching activity sets its timer (timers.relative), and GET /automations/{id}/upcoming lists what it has waiting. A webhook trigger runs on webhook.received calls to its own hook (#442), and purging a deleted automation revokes its hooks. The new source automations (app/domain/events_automations.py) emits automation.ran and automation.limited, and a recording's actor names the automation that brought it.

Motivation and Context

Workflow studio, module M6 (automation engine), part 3 of 5: the dispatcher, runs, limits and budgets. Next come the MCP and assistant tools, then drafting from a sentence.

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: automations now run; merged on green CI.
  • Agents: everything is in the API; the MCP and assistant tools are the next PR.
  • Zero setup: on by default with safe limits; the thread starts with the existing background work.
  • Fewest clicks and keystrokes: n/a, API only until the builder (M11); the settings are four fields with defaults.
  • Configurable: automations.enabled, max_depth (3), max_runs_per_minute (60) and keep_runs_days (30) in Settings → Automations.
  • Light: one polling thread that sleeps when no automation is on; no new dependency.
  • Private and secure: runs act only as their maker, checked again before every run; threat model gains the automations entry point, P-AUTOMATION-ACTOR (acting for its creator) and P-AUTOMATION-LOOP (loop amplification).
  • Cost: runs count in the activity ledger under automation:<id>; budgets on the automation, its workflow and namespaces hold or skip a run; the If is checked before anything is spent.
  • User decides: actions that reach outside Lens still ask first; a run held over budget waits for the person's pick; switching one on never replays the past.
  • Upgrades: new automation_run, automation_intent and automation_limit tables (DEFINE TABLE IF NOT EXISTS, safe to run twice) and four keys added to the automations settings section next to catch_up and approval_days, with defaults; no existing data changes.
  • Honest: docs label running built (schedules, times and webhook calls included) and joins and the studio planned.
  • Tests (tests/domain/test_automation_runs.py, including a schedule's timer firing a real run and re-arming, an approval and a waiting action carried out for real, and a saved variable counting across real runs (feat(automations): saved variables, kept between runs and set by the set_variable action #460); tests/api/test_automations.py), docs (automations, api, budgets, configuration, activity, telemetry) and the generated client (make openapi) updated.
  • Open standards: runs appear as Activity Streams activities; no new dependencies.
  • Result reported with evidence; "refine later" items written in docs/automations.md.

Checked locally: full backend suite (1321 passed; 1328 with the next two PRs on top), ruff, mypy, the threat model check and mkdocs build --strict.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCAZ9NEmBJNovqdzxvK3qi


Generated by Claude Code

…dgets and runs

A thread follows the stream for the kinds switched-on automations listen
for and runs each one a new activity matches, once, as the person who
made it. A run checks that person still may act where it works, its If,
its cooldown and hourly limit and the global per-minute limit, and its
budgets (held for the person's pick, as routines are), then runs its
event workflow and keeps a run with its trace, log and intents. Runs
show in the stream as automation.ran; chains stop at max_depth.

The API tries an automation (saved or a draft) without keeping
anything, runs one now, pages its runs, lists what an activity caused
and decides a held run. Settings → Automations switches them off and
sets the limits and how long runs are kept.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCAZ9NEmBJNovqdzxvK3qi
@adeelahmad adeelahmad self-assigned this Oct 16, 2026
@adeelahmad
adeelahmad merged commit 7a82549 into main Oct 16, 2026
11 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-sxrerj branch October 16, 2026 03:12
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