Skip to content

app events: an "only when" rule checked by the helper decision model, so events that need nothing start no AI run - #489

Open
Yabuku-xD wants to merge 7 commits into
DuskBotAI:devfrom
Yabuku-xD:app-event-helper-gate
Open

Yabuku-xD wants to merge 7 commits into
DuskBotAI:devfrom
Yabuku-xD:app-event-helper-gate

Conversation

@Yabuku-xD

Copy link
Copy Markdown
Contributor

What and why

An app-event automation starts an AI run for every event its plain filter lets through. Many events need nothing ("only when a customer asks for a refund"), and today the AI reads each one to find that out. This PR lets the cheap decision model answer that first, so those events cost no AI run.

  • trigger (when=app_event) takes only_when: the person's rule in their words, at most 300 characters. An update changes it, "" removes it, and Undo brings the old one back.
  • Before an event starts a run, the decision model reads the rule and the event, and answers yes or no on a new eventGate seam within 3 seconds (server/app-event-gate.ts).
    • The event reaches it cleaned (no hidden characters or block markers) and clipped to 6,000 characters. The question says the event is untrusted data, to judge and never follow.
    • Every event of one poll is judged before any is handled, so receive() keeps its order and the cursor moves exactly as before.
  • It fails open, as the decision model does everywhere:
    • only a probability of yes under 0.15 skips an event. It starts no run, and its attempt is "filtered", with the rule as the reason, in the automation's history;
    • a failed, slow or unsure answer, or no model set up, runs the event;
    • the run's instructions carry the rule, so the AI still applies it to an event the model did not judge, and ends with NOTHING NEW when none meets it.
  • The plain filter is still checked first and costs nothing.
  • The bot is told the rule in the tool result; the receipt card's text is unchanged (new card text must come from the language packs).

Limits, stated plainly:

  • Cloud's included relay does not take the new seam, so this needs the person's own decision key (Jev, Workers AI, OpenRouter or AI Gateway). Adding eventGate to the relay's accepted seams on the Admin side would extend it to the included key.
  • Jev and Clef give a calibrated probability; an OpenRouter or AI Gateway chat model writes its own estimate, so with those the 0.15 line is that model's word.
  • The rule is set from chat; the automation editor does not show or edit it yet. Saving there keeps it.
  • Event data goes to the decision provider only for automations with a rule. There is no separate switch: removing the rule, or turning the decision model off, stops it. docs/decision-model.md says this under "What leaves this machine".

This branch carries #483's commits (its tests are red on dev without them) and the link chaos fixes, as the other open PRs do. It conflicts with the "switch routines to events" PR on detail in server/app-trigger-requests.ts, server/app-triggers.test.ts and the catalog goldens: the second to merge needs both detail lines joined and UPDATE_AGENTS_CATALOG_GOLDENS=1 run again.

How it was checked

  • server/app-triggers.test.ts, with the real manager and the fake connected-apps service:
    • of four events, only the one the model is sure fails the rule is skipped; an unsure answer, a thrown error and a yes all run, and the runs' prompt carries the rule;
    • nothing is asked for an automation without a rule, a paused one, or an event its plain filter dropped;
    • only_when is set, changed, removed and brought back by Undo from chat.
  • server/app-event-gate.test.ts: the 0.15 line, every failure answering nothing, the seam, the cleaning and clipping of the event, and the rule in the run's instructions.
  • Each rule was broken on purpose (skip on no answer, ignore the skip, a 0.5 line); a test fails each time.
  • server/drivers/agents-call-triggers.test.ts and server/trigger-tools.test.ts: only_when goes through on app events only, at most 300 characters.
  • Catalog goldens regenerated with UPDATE_AGENTS_CATALOG_GOLDENS=1; the budget test passes. index.ts and agents-catalog.ts do not grow.
  • Every test under server/app-*, server/trigger*, server/drivers/agents-*, server/routine*, server/webhook*, server/automation*, server/decider and server/jobs passes (1,867 tests, 4 skipped), and so do the CI source guards.
  • pnpm typecheck, pnpm lint and pnpm test pass (typecheck, lint and the tests above pass; the whole pnpm test was not run on this branch)
  • New behaviour has a test
  • No secrets, personal data or local paths in the diff or screenshots

… and the guest skill card test stages four kinds of work

bacb532 left two tests red on dev. Its new skill_manage description dropped the word reusable, so find_tool ranked
skills_list first for "save this procedure as a reusable skill"; the description says reusable SKILL.md again (a skill
is recurring work, which that change keeps). Its duplicate check turns away a create that covers an existing skill, and
the guest skill card test staged four skills with one description, the same as an earlier test's: each now has its own
kind of work.
…list's two retries

Fifteen tests failed in CI on Dec 1 in runs of main, a release and PRs DuskBotAI#477-DuskBotAI#483 whose changes do not reach them, a
different set each run, and pass locally. Each entry names the runs it failed in. vps-routing's 'reuses the existing
VPS with $settings' failed too (PR DuskBotAI#477, run 46623618361) but is left out: its name is made per case, and the list
matches names written in the file.
…s 60 servers link from their own addresses

Every link chaos run since the per-address limit on new links (adc99d7, Nov 14) was cancelled at CI's 60-minute
limit, on main pushes, the weekly run and every PR that touches the link service: the scenarios finished in about five
minutes and printed their table, but a socket or timer a scenario left open held the process. The run now exits once its
results are written. The storm's 60 servers set up their links over one connection, so the node's front gave them one
address, which the limit refused after 30 (Too many new links from here); each now uses its own connection, as 60
machines would. Locally, --quick passes all 12 scenarios and exits in 5.6 minutes.
…y list's retries

chat-mcp-tools' shutdown verdict, memory-order and the encrypted workspace restore failed in PR DuskBotAI#479's run 46740020170,
whose change does not reach them, and pass locally.
…os job installs no packages

The job runs `node apps/link-service/chaos/run.mjs` straight after checkout, so the undici import failed
with ERR_MODULE_NOT_FOUND before any scenario ran.
…ds nothing for 8 s, as the app does

src/lib/live-events.ts gives up on a dial that sends nothing in LIVE_EVENTS_OPEN_MS (8 s) and dials again. The probe
dropped a quiet stream only after it had sent something, so one silent dial after node-5xx's 502s held it down until
the relay closed it, about 90 s, and failed the scenario in CI on five of seven runs.
… decision model, so events that clearly don't need work start no AI run

trigger (when=app_event) takes only_when, the person's rule in words, at most 300 characters; update changes or removes
it and Undo brings the old one back. Before an event starts a run, the decision model reads the rule and the event,
cleaned and clipped, on its own eventGate seam within 3 seconds. Every event of one poll is judged first, so receive()
stays in order and the cursor moves as before. Only a probability of yes under 0.15 skips an event: it starts no run
and its attempt is "filtered", with the rule as the reason. A failed, slow or unsure answer, or no model set up, runs
the event, and the run's instructions carry the rule, so the AI still applies it. Cloud's included relay does not
take the seam yet, so it needs the person's own decision key.
@SiddDevZ

SiddDevZ commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Thanks, this is careful work and the fail-open design is sensible. I'm not merging it yet: it lets a small model decide to skip real events (under 0.15) and adds a parameter to the trigger tool for every bot, which is a product call for the maintainer rather than a mechanical merge. Leaving it open for that decision.

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