Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-11-20-bot-triggers-connectors-boards.md
2026-11-20-bot-triggers-connectors-boards.md: 22f55840296afee0879cc7fc4859707aacb76e9b
2026-11-20-bot-triggers-connectors-boards.zh.md: ced5608e1458ac08fd73b2c223bdace5785ae871
2026-11-20-bot-triggers-connectors-boards.md: 1fe308f9a3592d798691bfc0c5c5176408fb677d
2026-11-20-bot-triggers-connectors-boards.zh.md: e4b1d5ed742c801480fbd4a2ad11da2479867e5d
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ A bot definition had one schedule plus an optional inbound webhook, every run mo

## Decision

- `AutomationDefinition.triggers` replaces `schedule`. A trigger is `schedule`, `webhook` (at most one, with `idempotency: sender | none`), `event` (`mail` or `github`, with a filter), or `bot` (`from`, `mode: wait | dispatch`). A run records `triggerIndex`; an occurrence id hashes the bot, the trigger index, and the cause, so a redelivered event, a repeated idempotency key, or a retried handoff names one run. Each schedule trigger keeps its own watermark in `lastAdmittedAt`.
- `AutomationDefinition.triggers` replaces `schedule`. A trigger is `schedule`, `webhook` (at most one, with `idempotency: sender | none`), `event` (`mail` or `github`, with a filter), or `bot` (`from`, `mode: wait | dispatch`; `from` is a sender list that joins per chain since [run outcomes, calendar triggers, and joins](2026-11-23-bot-run-outcomes-calendar-joins.md)), and `calendar` since that note. A run records `triggerIndex`; an occurrence id hashes the bot, the trigger index, and the cause, so a redelivered event, a repeated idempotency key, or a retried handoff names one run. Each schedule trigger keeps its own watermark in `lastAdmittedAt`.
- `overlap: skip | queue | parallel`, default `skip`, decides what admission does with work in flight; `queue` is bounded by `queueDepth` and `drain` starts queued runs of a non-parallel bot one at a time, oldest first.
- `connectors: 'all' | ConnectorId[]`, default `all`, is enforced by the run's tool guard (`connectorOf` maps `mcp__<provider>_<id>__*` and `mail_*`) and also read by account integrations through `ctx.automations.connectorBinding(sessionId)`, so a run mounts only the bound connectors.
- A saved grant gets `expiresAt` from `grantLifetimeDays`; an expired grant answers nothing and a new answer replaces it. `/bots` revokes a grant through the `grant-revoke` endpoint.
- GitHub events arrive at `/automation-webhook/<id>/github`, verified with the bot's own key as the GitHub secret. This replaces routing a deployment-wide `webhook-github` source to accounts, which would have needed an owner mapping per source and is not composed in any shipped profile.
- Mail events come from a cursor poller over `ctx.mail.search`: one envelope search per watched account every `mailPollSeconds`, no model turn, and a first check that only records the inbox.
- A handoff is a durable `Handoff` record in the definition domain and the account's synced document. Any Host that may run the receiver admits it under the receiver's claim, so handoffs work between cloud and desktop bots without a request path of their own. `wait` settles the sender's run and hands the result back as a new handoff with `replyTo`, rather than holding the sender's run slot.
- A board is a named member list with an optional budget (`maxConcurrentRuns`, `maxTokensPerDay`). Admission refuses a run that would exceed it, with the ceiling as the run error and the handoff reason. A run records `usage` summed from its `assistant/message` events.
- Run conversations get `bot_handoff` only when some receiver names their bot, and `board_tasks` / `board_task_update` only for board members. The `automation_*` and `ask_user` guard is unchanged, so a run still cannot create a bot, a trigger, an edge, a connector binding, a grant, or a board.
- Every run conversation gets the outcome tools of [run outcomes, calendar triggers, and joins](2026-11-23-bot-run-outcomes-calendar-joins.md). Run conversations get `bot_handoff` only when some receiver names their bot, and `board_tasks` / `board_task_update` only for board members. The `automation_*` and `ask_user` guard is unchanged, so a run still cannot create a bot, a trigger, an edge, a connector binding, a grant, or a board.
- The domain stays at version 3. Storage domains have no migration, so a version bump would refuse every existing store at open; instead the definition schema reads a stored `schedule` as the first trigger with `connectors: all` and `overlap: skip`, which keeps existing bots running unchanged.

## Alternatives considered
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ Bot 定义只有一个计划和一个可选的入站 webhook,每次执行都

## 决策

- `AutomationDefinition.triggers` 取代 `schedule`。触发器是 `schedule`、`webhook`(最多一个,带 `idempotency: sender | none`)、`event`(`mail` 或 `github`,带过滤条件)或 `bot`(`from`、`mode: wait | dispatch`)。执行记录 `triggerIndex`;发生 ID 对 Bot、触发器索引和起因做哈希,因此重新投递的事件、重复的幂等键或重试的交接只对应一次执行。每个计划触发器在 `lastAdmittedAt` 中保留自己的水位。
- `AutomationDefinition.triggers` 取代 `schedule`。触发器是 `schedule`、`webhook`(最多一个,带 `idempotency: sender | none`)、`event`(`mail` 或 `github`,带过滤条件)或 `bot`(`from`、`mode: wait | dispatch`;自[执行结果、日历触发器与汇合](2026-11-23-bot-run-outcomes-calendar-joins.zh.md)起,`from` 是按链汇合的发送方列表),以及自该文起的 `calendar`。执行记录 `triggerIndex`;发生 ID 对 Bot、触发器索引和起因做哈希,因此重新投递的事件、重复的幂等键或重试的交接只对应一次执行。每个计划触发器在 `lastAdmittedAt` 中保留自己的水位。
- `overlap: skip | queue | parallel`(默认 `skip`)决定准入如何处理执行中的工作;`queue` 受 `queueDepth` 限制,`drain` 对非并行 Bot 的排队执行按时间顺序逐个启动。
- `connectors: 'all' | ConnectorId[]`(默认 `all`)由执行的工具守卫强制执行(`connectorOf` 映射 `mcp__<provider>_<id>__*` 与 `mail_*`),账户集成也通过 `ctx.automations.connectorBinding(sessionId)` 读取它,因此执行只挂载绑定的连接器。
- 已保存的批准根据 `grantLifetimeDays` 获得 `expiresAt`;过期的批准不再作答,新的回答会取代它。`/bots` 通过 `grant-revoke` 端点撤销批准。
- GitHub 事件到达 `/automation-webhook/<id>/github`,以 Bot 自己的密钥作为 GitHub secret 校验。这取代了把部署级 `webhook-github` 来源路由到账户的做法:那需要为每个来源维护所有者映射,而且没有任何发布的配置组合了它。
- 邮件事件来自基于 `ctx.mail.search` 的游标轮询:每 `mailPollSeconds` 对每个被关注账户做一次信封搜索,不启动模型轮次,第一次检查只记录收件箱。
- 交接是定义域与账户同步文档中的持久 `Handoff` 记录。任何可以运行接收方的 Host 都在接收方的占用下准入它,因此云端与桌面 Bot 之间的交接不需要专门的请求通道。`wait` 让发送方的执行结束,再把结果作为带 `replyTo` 的新交接交回,而不是占用发送方的执行槽位。
- 看板是一个命名的成员列表,带可选预算(`maxConcurrentRuns`、`maxTokensPerDay`)。准入会拒绝超出预算的执行,并把上限写入执行错误和交接原因。执行记录由其 `assistant/message` 事件累加得到的 `usage`。
- 只有某个接收方指定了其 Bot 时,执行对话才获得 `bot_handoff`;只有看板成员才获得 `board_tasks` / `board_task_update`。`automation_*` 与 `ask_user` 守卫保持不变,因此执行仍不能创建 Bot、触发器、边、连接器绑定、批准或看板。
- 每个执行对话都获得[执行结果、日历触发器与汇合](2026-11-23-bot-run-outcomes-calendar-joins.zh.md)中的结果工具。只有某个接收方指定了其 Bot 时,执行对话才获得 `bot_handoff`;只有看板成员才获得 `board_tasks` / `board_task_update`。`automation_*` 与 `ask_user` 守卫保持不变,因此执行仍不能创建 Bot、触发器、边、连接器绑定、批准或看板。
- 定义域保持版本 3。存储域没有迁移机制,升级版本会让所有已有存储在打开时被拒绝;因此定义模式把已保存的 `schedule` 读作第一个触发器,并使用 `connectors: all` 与 `overlap: skip`,已有 Bot 照常运行。

## 考虑过的替代方案
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
# side as of the last confirmed-consistent state. Both languages carry equal authority;
# after editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write .agents/notes/implemented/architecture/2026-11-23-bot-run-outcomes-calendar-joins.md
2026-11-23-bot-run-outcomes-calendar-joins.md: 3322a4d5f8227133b956d6c5d6d46563338fe7de
2026-11-23-bot-run-outcomes-calendar-joins.zh.md: 83975e78248e13bf908cc0e6a2b6fd95d65a1dae
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Agent Note: Bot runs report their outcome, calendar events and jitter wake bots, and handoffs join per chain

Status: implemented

English | [中文](2026-11-23-bot-run-outcomes-calendar-joins.zh.md)

## Problem

Three gaps were left after [the trigger list and handoffs](2026-11-20-bot-triggers-connectors-boards.md). A run that completed its turn always read `succeeded` and replaced the bot's last result, so a polling bot reported "nothing new" all day and a run that could not do its task looked finished ([#752](https://github.com/Aeven-AI/Aeven/issues/752)). Schedules could not express "15 minutes before each meeting" or "around 7", and every bot of every account fired at the same minute ([#753](https://github.com/Aeven-AI/Aeven/issues/753)). A handoff went from one bot to one bot, so "the editor writes once the researcher and the analyst have both finished" could not be built, and a failed step left nothing that would skip the rest ([#754](https://github.com/Aeven-AI/Aeven/issues/754)).

## Decision

### Run outcomes

- Every run conversation gets `bot_no_update`, `bot_report_failure` (`reason`), and `bot_pause` from `registerRunTools`; the root conversation never does. The calls set fields on the in-memory `ActiveRun`, and `execute` reads them once, when the run settles.
- A completed turn after `bot_report_failure` settles `failed` with the reason as `error`; the handoffs the run carried fail with it, and a `wait` reply carries the reason.
- `bot_no_update` makes a `succeeded` run `quiet: true` unless the log holds an `approval/decided` other than `allowed-once` or a successful `tool/call` whose `presentCall` is a diff card or a generic card of kind `edit`, `delete`, or `move`. `list` sets `lastRun` to the latest run that is not quiet, and `/bots` folds two or more consecutive quiet runs of one bot into one row.
- `bot_pause` pauses the bot only when the run settles `succeeded`, and stores `pausedBy: { runId, scheduledFor }` on the definition. The owner's own pause or resume clears it. Pausing narrows what the bot does, so the `automation_*` guard is unchanged.

### Calendar triggers and jitter

- `{ kind: 'calendar', calendar?, filter, offsetMinutes }` fires `offsetMinutes` from each matching timed event. `filter` has `title`, `attendee`, `hasExternalAttendee`, and `accepted`. An attendee is external when its domain differs from every domain of the owner's own addresses on the event.
- Automations owns the `CalendarSource` Service Definition and `registerCalendarSource`. Account integrations is the provider: it reads Google Calendar's primary calendar and Microsoft Graph's `calendarView` over REST with each connector's own token, so no MCP process and no model turn take part. The direction matches `connectorBinding`: account integrations already depends on automations.
- The Host that may run the bot reads every `calendarPollSeconds` (300 by default), after a calendar trigger is saved, and after a source registers. A read covers the firings from the misfire grace before now to two read intervals ahead; the scheduler timer fires each one at its instant.
- A calendar occurrence is identified by the bot, the trigger index, and the event id without its start. A moved event therefore fires at its new time while it has not fired, and does not fire a second time after it did. This deliberately departs from #753's "event id plus start" identity, which would admit a moved event twice.
- `jitterMinutes` (1–30) on every schedule kind but `once` delays each occurrence by `sha256(botId, nominal instant) mod jitterMinutes` whole minutes. `nextFiring` and `latestDueFiring` scan at most 64 nominal occurrences around the instant, and the jittered instant is the run's `scheduledFor`, its occurrence id, and its watermark. An interval's jitter must be smaller than its spacing.

### Joins and chains

- A `bot` trigger is `{ from: AutomationId[], join: 'all' | 'any', mode, joinTimeoutMinutes }`. A stored single `from` still reads, as a one-item list with `join: all` and 60 minutes.
- Every handoff and run reference carries `chain`, the run that started it: a run nothing handed work to starts its own chain, and replies inherit the chain.
- Handoffs on an edge with several senders are grouped by receiver, edge, and chain, and are not admitted one by one. `admitJoins` admits `any` on the first open input, and admits `all` once every sender has an input. When a run of a chain settles without handing work to a joining receiver it feeds, `settleRun` records a `failed` input with the reason. Missing senders past `joinTimeoutMinutes` become timed-out inputs.
- The joined run's id hashes receiver, edge, and chain. It carries `join.inputs`, and its notice names every input and every failure. A group with no input that carries work is admitted as one skipped run.
- `stopRun` refuses every open handoff of the run's chain with `CHAIN_STOPPED` and stops the chain's other runs this Host knows. `handOff` and `admitJoins` treat a chain with such a handoff as stopped. A queued run stopped before it started now settles its handoffs as well.
- The board card lists the handoffs of its latest chain, oldest first.

## Alternatives considered

- **A per-bot "only notify on news" setting** for quiet runs: rejected, as #752 says; the model decides per run, which also covers bots that report only sometimes.
- **Pausing at the `bot_pause` call**: rejected, because a run that later reports failure must leave the bot active, and reverting a pause would publish a definition revision that never applied.
- **Reading calendars through the connector MCP tools**: rejected. It needs an agent context and starts the Workspace or Graph MCP process for every read, while a REST listing with the token account integrations already refreshes costs one HTTP request.
- **Exposing a public event-listing method on account integrations for automations to call**: rejected, because automations cannot depend on account integrations without a cycle; the registration keeps the seam on the consumer.
- **Random jitter at fire time**: rejected; two Hosts of one account would admit different instants and the shared watermark could not deduplicate them.
- **Centred jitter (±)**: rejected for delay-only `[0, jitter)`, so a run never starts before the time its owner named.
- **A separate join record type**: rejected; failed inputs are ordinary `Handoff` records, so the join survives restarts and syncs to every Host through the existing handoff entries.

## Consequences

- There is no unread marker in the product, so #752's "does not count as unread" has nothing to change; a quiet run still bumps the Automations workspace in the sidebar.
- Quiet detection only sees file changes a tool presents as such; a file written by a shell command does not block quiet.
- Calendar reads cost one listing per connected calendar per interval while a calendar bot is active; an event removed less than one read interval before its firing still fires.
- Calendar deduplication is per Host, like mail.
- A frequent cron with a long jitter can skip occurrences whose jittered instant falls before an earlier one's.
- A sender that runs outside the receiver's chain never joins it: its input waits until `joinTimeoutMinutes`, and the receiver then runs with the missing senders named as timed out.
- Stopping a chain stops the runs this Host admitted and cloud runs it requested; runs other desktops admitted see only the refused handoffs.
Loading
Loading