Skip to content

feat(bots): run bots on matching canopy events - #1386

Merged
nixuuu merged 1 commit into
feat/bot-parked-interactionsfrom
feat/bot-event-triggers
Nov 28, 2026
Merged

nixuuu merged 1 commit into
feat/bot-parked-interactionsfrom
feat/bot-event-triggers

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Part 2 of 3 of the bot event triggers stack (#1385 → #1386 → #1387). The stack merges at once.

What changes

Event triggers: a bot runs in the background when a Canopy event it subscribed to happens.

  • A trigger is a bot_routines row with kind = 'trigger'. Its event type, atomic filter, scope and revision live in migration 0229. Its scope rows (bot_trigger_scopes) exist only while it can match.
  • Event types:
    • thread events (0230): turn finished, request opened;
    • CI results of watched pull requests;
    • schedule runs;
    • provider usage limits: a gte threshold crossing per worker, profile, window and reset, deduplicated by receipts;
    • memory habits (0231).
  • Filter (packages/domain/src/bot-triggers): one event type, concrete resource ids the owner can see, conditions on catalogue fields, exclude_own, a quiet window and an hourly limit.
  • Recording: PostgreSQL source triggers call bot_trigger_record, one statement that checks module eligibility, candidates and a module generation stamp. An owner without matching scopes costs one index lookup and writes nothing.
  • Matcher (locks candidates in id order):
    • excludes the bot's own work (watches, started threads, steers);
    • holds events of a bot frozen by an undecided move;
    • drops events of an older module generation.
  • Batches: matched events coalesce into a batch. The hourly limit holds a batch with check_after. Three consecutive saturated hours pause the trigger.
  • Rechecks before the run starts: the run reports only events that are still current. It checks again at claim, under its lease before the first worker command, and before the first send. A command refused unsent is retired: the run restarts with the remaining events or ends without a model call.
  • Pinned workers: a trigger run waits for its pinned worker's bot link on any gateway.
  • Read policy for trigger runs: no threads, schedules, requests or files from external conversations, and no threads of other computers.
  • Tools: create_trigger, update_trigger (needs revision; only enabled=true resumes a trigger), preview_trigger, list_triggers, delete_trigger and list_trigger_event_types. Only a private owner message can change triggers. A frequent or unestimated trigger needs an approval card with a 7-day estimate.
  • Consolidation and moves:
    • events, batches, generations and receipts are local-only;
    • scopes are imported from 0229, and project ids are rewritten on merge;
    • source triggers are fenced during import;
    • the new move_bot_triggers_v1 capability is required to move a bot with triggers.
  • Shared harness fixes this work needed (all bot turns):
    • a runBotTurn handed to a link is recorded as attempted before the frame leaves;
    • a capability refusal comes only from the worker's current registration, for a command never attempted (BOT_WORKER_OUTDATED);
    • a turn waiting for a worker that was archived or revoked ends with a configuration error (BOT_WORKER_REMOVED), including while it waits for an interrupt acknowledgement.

The gateway API for the next layer is included: BotApproval.routine_kind (proto field 1115) and the trigger views.

Docs: docs/bots.md ("Wyzwalacze zdarzeń"), docs/linked-computers.md (move capability), docs/copy.md (glossary: event trigger).

Verification

Ran locally on the stack tip, rebased on the current dev:

  • gateway, domain and mobile typecheck; web svelte-check;
  • oxlint and oxfmt check on the changed files;
  • bun run gen: no diff;
  • migrations 0001–0231 applied to a fresh database;
  • integration tests, run one file at a time:
Test file Passed
bot-event-triggers 10
bot-event-trigger-sources 6
bot-parked-interactions 8
bots-harness 26
bots-harness-regressions 12
bots-harness-approvals 14
bots-harness-errors 7
bots-harness-context 2
bots-harness-defaults 2
bots-remote 8
bot-files 9
bot-routines 11
bot-background-continuations 11
bot-handoff 10
bot-module-suspension 5
bot-deletion 3
computer-moves 10
consolidation-preflight 1
worker-configuration-compatibility 2
packages/db schema test 26

Left to CI: these tests need psql, which this machine doesn't have:

  • apps/gateway/test/consolidation-import
  • apps/gateway/test/consolidation-projection
  • gateway-relocation

Test gateway (fresh database, real PostgreSQL source triggers): a failed turn in a watched project was recorded, matched and coalesced into an open batch. Answering a parked trigger question queued its parked: continuation with the trigger's instructions.

Reviewed by GPT 6.2 Astra over 11 rounds. The final verdict was ACCEPT.

🤖 Generated with Claude Code

@nixuuu
nixuuu added this pull request to stack #1388 November 28, 2026 01:07
@nixuuu
nixuuu marked this pull request as ready for review November 28, 2026 01:08
@nixuuu
nixuuu force-pushed the feat/bot-event-triggers branch 3 times, most recently from 19ebecc to 886ae5c Compare November 28, 2026 02:04
Event triggers let a bot run in the background when a Canopy event it
subscribed to happens: thread turns and requests, CI results, schedule
runs, usage limits and memory habits. Each trigger filters by event
type, concrete resources and field conditions; matched events are
coalesced, rate limited and checked again before the run starts, and a
noisy trigger pauses itself.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu force-pushed the feat/bot-event-triggers branch from 886ae5c to de2fc96 Compare November 28, 2026 02:14
@nixuuu
nixuuu merged commit 03e6ca6 into dev Nov 28, 2026
24 checks passed
@nixuuu
nixuuu deleted the feat/bot-event-triggers branch November 28, 2026 06:31
nixuuu added a commit that referenced this pull request Nov 28, 2026
Part 1 of 3 of the bot event triggers stack (#1385 → #1386 → #1387). The
stack merges at once.

## What changes

A question (`ask_user`) or an approval card raised by a **background
run** no longer blocks the bot's FIFO queue:

- Routine runs, verified reminders (`wakeup:<id>`) and verified
continuations (`parked:<id>`) **park** the card
(`bot_approvals.parked`). The model gets `status: parked`, the run ends,
and the private chat stays free. Conversation and bot-to-bot turns never
park.
- The owner's answer, a decline or 24-hour expiry enqueues a
**continuation** turn `parked:<card>`. An approved action runs **once**
in the gateway before the model reads the continuation
(`bot_turns.resume_approval_id`, migration 0228). The approved proposal
(`proposed_bot`) and the restricted destination are kept.
- The continuation input is bounded: the card prompt is clipped to 8000
characters, and the owner's answer (≤ 32 000) is kept whole. The asking
run's final note is attached when the continuation starts, even if the
owner answered before that run ended.
- Bot workspace (file) tools are **not** parked. A background run waits
for them as it does on `dev`, because a continuation gets a new
workspace without the run's files.
- Locks follow one order (module → bot → turn → card) in answer, expiry
and routine disable. A disabled routine discards its pending parked
cards.
- Bot moves carry continuations: the target restores
`resume_approval_id` after approvals, and validation rejects references
outside the moved cards.

Docs: `docs/bots.md`, section "Parkowane pytania i zgody rutyn".

## Verification

Ran locally on this layer: gateway typecheck, web `svelte-check`, mobile
typecheck, oxlint on the changed files, and these integration tests:
`bot-parked-interactions` (7), `computer-moves` (10),
`bots-harness-approvals` (14). CI runs the full gate.

Reviewed with the next layers by GPT 6.2 Astra over 11 rounds. The final
verdict was **ACCEPT**. Accepted limitation: file-tool approvals in
background runs still wait, as on `dev`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
nixuuu added a commit that referenced this pull request Nov 28, 2026
Part 3 of 3 of the bot event triggers stack (#1385 → #1386 → #1387). The
stack merges at once.

## What changes

Bot details on web, desktop and mobile:
- **Event triggers**: each trigger shows its plain filter description,
last 7 days' counts ("1 event · 2 runs in 7 days"), last run and pause
state ("Paused after running too often"). The owner can pause, resume or
delete it.
- **Waiting for you**: parked questions and approvals ("Your answer or
decision starts a new background run."). "Show in chat" scrolls to the
card; on narrow layouts it closes the overlay first.
- Cards and rows name their origin: "From event trigger “…”", "From
routine “…”", or "from a reminder" when a card has no routine.
- Parked cards say "Your answer starts a new run" or "Your decision
starts a new run".
- The countdown switches to hours ("Expires in 19 hours").
- A background status line names a trigger run "Event trigger “…”"
instead of "Routine “…”".

## Copy audit (docs/copy.md §8)

1. One idea per sentence, sentence case, active voice: pass. Long origin
lines were split with ` · `.
2. Glossary: pass. Added "event trigger"; "routine" and "reminder" are
unchanged.
3. Verbs: pass ("Show in chat", "Pause", "Resume", "Delete").
4. Errors: pass. "Update this worker to run bots, or pick another
worker." and "This bot's worker was removed. Pick another worker in Runs
on." each say what happened and what to do.
5. Empty states: pass. Both sections are hidden when empty.
6. Repetition: pass. The section description isn't repeated in each row;
origin labels stay because they tell trigger, routine and reminder cards
apart.
7. External gaps: none.
8. "Soul" sentences: none.
9. Short, typical and long values: pass. Checked a long trigger title
and description, at 1440 px and in a narrow window.
10. Colour/icon-only cues: pass. Pause state and origin are text.

## Verification

Ran locally: web `svelte-check`, mobile typecheck, oxlint and oxfmt
check on the changed files.

Checked in a real browser on the test gateway with the shared web
renderer:
- the "Waiting for you" section and the cards and their origins;
- the trigger list, with a long title and the paused state;
- answering a parked question, then the follow-up activity and the
status line;
- a desktop width and a narrow window.

Not checked on a native mobile device: only the mobile typecheck ran.

Reviewed with the lower layers by GPT 6.2 Astra. The final verdict was
**ACCEPT**.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
nixuuu added a commit that referenced this pull request Nov 28, 2026
…1402)

A workspace with a GitHub App installation could show pull requests in
the PR panel while the new-thread composer found nothing for the same
repository. The composer only consulted project-granted MCP accounts.

The gateway now searches the GitHub account selected for the workspace
remote. A number such as `#1386` looks up the issue or pull request
directly, including closed and merged items. The picker also supports
text, links and recent open items. GitHub results share the existing
reference format, and sending the message checks current access to the
workspace repository. A GitHub MCP connector may still provide its own
results. When both return the same PR, the picker shows the repository
account's result once.

## Verification

- All 17 focused tests passed across the GitHub App, linked-computer
mentions and provider suites. They cover delivery to the worker, removal
of installation access, repository boundaries and duplicate results.
- Gateway and integration-test typechecks passed, along with edited-file
lint and formatting.
- On the new-thread page in Chromium, typing `#1386` and choosing the PR
inserted the expected chip at 1440 × 900 and 390 × 844 with fixture
responses at the HTTP boundary.
- Live GraphQL queries by number and title both found the merged
`#1386`.
- Repository-wide verification runs in CI.

## Copy audit

The empty state previously directed users only to Settings → Connectors.
It now points to both GitHub repository access and connector access.
Read failures and unavailable references give a next action. Reviewed
the changed English copy against §8 and verified wrapping at both
browser widths.

Fixes: #1176
nixuuu added a commit that referenced this pull request Nov 28, 2026
GitHub now has one default connection flow on web, desktop and mobile.
Adding GitHub in Connectors opens Settings → GitHub. Existing MCP
accounts retain their reconnect action and grants. Advanced connections
supports a PAT, an OAuth app and custom MCP servers.

At each installed repository, the owner chooses projects and bots. They
can read text files, issues and pull requests. Enabling **Allow changes
on GitHub** also permits creating issues, posting comments and opening
pull requests between branches of that repository, subject to the thread
or bot approval policy.

The gateway binds every grant to the account and immutable repository
ID. It checks the current grant before a call and before returning
private results. The same project grant can confirm an exact merge
during worktree cleanup. GitHub credentials and native grants remain on
their home gateway. Previously saved grants can still be removed after
an uninstall.

### Verification

- Schema, grant RPC, linked-home routing, consolidation, legacy
connector and bot settings, worker and bot dispatch, revocation during
reads, uncertain writes, replay, and worktree cleanup passed focused
tests against local PostgreSQL and a GitHub API fixture.
- Chromium at 1440 and 390 px exercised setup, grant editing, stale
revisions, revocation, advanced connections, and switching homes. An
Android emulator exercised local and linked-home grants, revocation,
PAT, reconnect and long names with controlled RPC responses.
- In the same two Chromium viewports, the composer showed the distinct
GitHub and Jira/Linear setup guidance with no clipping. Bot Connections
rendered the scoped repository and linked to GitHub settings.
- Gateway, integration-test, web and mobile typechecks and edited-file
lint were checked locally. The full repository gate runs in CI.
- The repository tool request builder and result parser handled three
live public GitHub reads in `itsoltech/canopy` by numeric repository ID.
PR #1386 returned its merged state and canonical link, listing closed
PRs returned three items, and reading `README.md` from `dev` returned
the file text. Private data and writes were tested using fixtures.
- The new linked-computer capability follows the original protocol-1
entries. Seven focused cases for older desktop peers and GitHub routing
passed locally.

### Copy audit

The previous Add GitHub entry presented a second authorization flow. It
now opens the common GitHub setup. The grant editor names files, issues
and pull requests before a user selects recipients. “Allow changes on
GitHub” makes writes a separate choice. Advanced options name their
credentials explicitly. Error actions, accessible control labels, narrow
layouts and long repository names were checked against docs/copy.md §8.

Second part of the GitHub unification stack, based on #1405.
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.

1 participant