Skip to content

feat(bots): park routine questions and approvals - #1385

Merged
nixuuu merged 1 commit into
devfrom
feat/bot-parked-interactions
Nov 28, 2026
Merged

nixuuu merged 1 commit into
devfrom
feat/bot-parked-interactions

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

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

@nixuuu
nixuuu added this pull request to stack #1388 November 28, 2026 01:07
@nixuuu nixuuu changed the title feat/bot parked interactions feat(bots): park routine questions and approvals Nov 28, 2026
@nixuuu
nixuuu marked this pull request as ready for review November 28, 2026 01:08
@nixuuu
nixuuu force-pushed the feat/bot-parked-interactions branch 3 times, most recently from 072fcf7 to 3de6476 Compare November 28, 2026 02:04
A question or an approval in a routine run no longer blocks the bot's
queue. The card stays with the owner, the run ends, and the decision
starts a continuation of the routine that runs an approved action first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu force-pushed the feat/bot-parked-interactions branch from 3de6476 to 8221dcd Compare November 28, 2026 02:14
@nixuuu
nixuuu merged commit 63a8b8c into dev Nov 28, 2026
44 of 47 checks passed
@nixuuu
nixuuu deleted the feat/bot-parked-interactions branch November 28, 2026 06:31
nixuuu added a commit that referenced this pull request Nov 28, 2026
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](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]>
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