Skip to content

feat(bots): bound unattended approvals and let scheduled calls wait for Send - #1403

Merged
bvsr365 merged 40 commits into
masterfrom
scheduled-run-approvals
Nov 17, 2026
Merged

bvsr365 merged 40 commits into
masterfrom
scheduled-run-approvals

Conversation

@bvsr365

@bvsr365 bvsr365 commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Scheduled bots could not wait for approval before making a call. Unattended work could also create many identical approval cards by splitting one task into pieces.

Change

Scheduled runs now park for approval and continue in the same thread with the stored outcome. Later occurrences of that schedule skip while the card waits or its run finishes. Cards expire after one schedule gap, with an hour minimum. Schedule edits invalidate the old review; removal and expiry withdraw pending calls and preserve the run's report.

Unattended work and schedules share refusal history per bot and tool. Owner-started work keeps its own history. To decide who started work, Mousse follows its saved link to the starting conversation turn: an owner's message or tapped answer counts as owner-started; creation, wakes, default answers and another bot's messages do not. Automatic reminder work is unattended. An unknown start is refused rather than guessed.

An identical open card prevents another card for the same call, regardless of origin. Stored outcomes join ordered unread updates and are confirmed when the model outputs or completes. Adjacent expired cards from one schedule show as one quiet line; stored rows and unread counts remain. The experimental switch stays off.

How to review

Start with the approval wait rule and the explicit same-schedule skip check in BotEngine. Then read BotActions' origin scope, duplicate check and lifecycle, the schedule revision and edit hook, and the chat row fold.

Verification

  • Real engine, scheduler and temporary-store tests cover both direct and use_tool holds, exact arguments, duplicate suppression, unattended fan-out, owner limits, switch-off parity, skips, expiry, restart, schedule edits, removal and final reports.
  • The continuation matrix uses stored action rows from real scheduled activations. Captured master fixtures are unchanged. Mounted chat tests cover adjacent expiry folds and separation at an older-chat summary.
  • The unchanged authority parity test, held-call, app-tool, registry and automation checks pass. Both typechecks pass.
  • Seven inherited queue-era cases fail: one each in botScheduleDowntime, botScheduleExpiryCompletion and botScheduleInbox, two in botSchedules, and two in botWorkReplay. The same cases fail on master. Master command: flock /tmp/mousse-heavy.lock npx vitest run --configLoader runner tests/bots/botScheduleDowntime.test.ts tests/bots/botScheduleExpiryCompletion.test.ts tests/bots/botScheduleInbox.test.ts tests/bots/botSchedules.test.ts tests/bots/botWorkReplay.test.ts --maxWorkers=2.
  • Real-provider sends and phone rendering were not checked. Card details, opening folded calls, action names and screenshots follow with feat(bots): review and answer held calls in chat #1390. No process lane or installed app was run.

Notes

No database version change. The schedule file and bot database remain separate stores; stale-Send validation and restart reconciliation fence interrupted edits.

Refs #1335

@bvsr365 bvsr365 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An adversarial pass on unattended runs. No call is made without Send:

  • an edit withdraws the card;
  • removal raced with a Send that waits on its refresh leaves the card withdrawn with 0 calls;
  • only one run per schedule parks, and the others are skipped;
  • thread and subagent tools are refused after a hold.

Over 72 hourly occurrences the owner is shown 3 cards per tool, whether they never answer or always say Not now; after that the runs report instead. Open:

Should fix

  1. A scheduled run can reset its schedule's repeat rules by recreating its own schedule. The "declined exactly this" and three-unsent rules for a run are scoped by scheduleId, and a scheduled run may call bot_schedule_remove and bot_schedule_add (both allowed in a scheduled run's authority, as is schedule_done). After three unsent cards, a run that read a hostile page can remove its schedule and add it back: the new scheduleId has no history, so three more cards per tool, without the owner writing, as often as it likes. That removes the only bound on cards from an unattended schedule. Fix: for scheduled runs, count both rules per bot and tool across all of the bot's schedules since the owner last wrote. That also covers a second schedule doing the same thing.

Minor

  1. Changing an automation's Tell me level or "can wake me" withdraws its waiting card. The schedule revision hashes tellMe and the whole job.bot. Fix: hash only what the run executes under: prompt, timing and until, model or pick, enabled.
  2. The fold hides what an unattended run tried. An expired schedule card is drawn only as "Expired · not sent", with no way to open the folded cards, yet for a run that may have read outside text, the arguments it tried to send are what the owner most needs. Fix: let the folded line open its cards read-only. As built, each expired run's report also sits between its card and the next, so cards of one schedule are seldom adjacent and rarely fold.

@bvsr365 bvsr365 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review at 134591aea: needs changes, 2 should fix and 5 minor, no blockers. Parking through C1's table, the skip check through the real scheduler, card life, removal and until with the last report, restart, the per-schedule refusals and the soon telling all behave as the spec says. With the switch off a scheduled run is as on master. All bot unit files plus the scheduler, automation, bridge and chat files (131) pass, and both typechecks are clean. The failing cases below come from throwaway tests built on scheduledCall.

Should fix

  1. Editing a schedule leaves a card that can never be sent. After an edit, Send is refused with bot_action_changed, but the card stays open (two Sends refused, row still open). It is withdrawn only when something else runs withdrawChanged, or when the gap ends. With C4's live buttons the owner can keep tapping. Run withdrawChanged(botId) in the transaction that saves a schedule edit, or have answer withdraw a row that obsolete() reports instead of answering changed.
  2. A held call after schedule_done is refused with the wrong reason. The run calls schedule_done, then the tool, and is told "This tool changed. Carry on without it.": the schedule is gone, so binding returns nothing. Refuse it with the truth ("This schedule has ended, so this can't wait for your owner. Say in your report what you would have sent."), or bind the ending run's last card to the run.

Minor
3. The revision digest is broader than the docs say. It includes tellMe, name and enabled, so changing only Tell me makes Send refuse; the docs say "instructions and timing".
4. A schedule edit doesn't lift the per-schedule refusals, though the owner acted on exactly this. Either count it as the owner acting, or say so in the docs.
5. The new matrix rows feed continuationPrompt a raw line. Build them from stored action rows of a schedule activation, as the work rows are. Fixtures are untouched.
6. The fold line names neither the schedule nor the action. Two schedules in a row read "2 expired · not sent", then "Expired · not sent".
7. Unread and other devices see six rows. The unread badge counts all six stored rows while one line shows, and phones get six rows plus expiredActionSchedule. Say so in the docs; the phone app needs the fold.

For the merge with master (notes, not findings):

  • #1407: removes turn slots, which parking and the skip check assume.
  • #1420's use_tool: check that the hold still sees the call id and the real pair.
  • #1417/#1418: they change botChatShape.ts, so the expired fold must compose with the digest fold.

@bvsr365 bvsr365 changed the title feat(bots): scheduled calls wait for approval and expired cards fold feat(bots): bound unattended approvals and let scheduled calls wait for Send Nov 17, 2026

@bvsr365 bvsr365 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-check at d3a1d91d1 (adversarial). The limits hold end to end:

  • Recreating the schedule: removed and re-added three times, still 3 cards in all.
  • Twenty pieces of work from one wake turn: 1 card for identical calls, 3 for slightly changed ones, 6 when alternating two tools.
  • Shared scope: a schedule and unattended work share it, and owner-started work keeps its own.
  • Edits: an edit raced with Send in either order, or one made behind the service, makes 0 calls; a no-op edit sends once.
  • After a hold: later tools are refused on both routes.

Open, all minor:

  1. Owner-started work refused as a duplicate never learns the outcome. Unattended work opens card X, then the owner asks in chat for exactly X. The owner's work is told "This exact call is already waiting … carry on without asking again" and reports before the owner presses Send. The one card's result goes only to the unattended work, so the owner's own request reports it wasn't sent while the email is in fact sent. Fix: for owner-started work, name the waiting card in the refusal, or deliver that card's outcome to every work refused as its duplicate.
  2. A tap moves work into owner scope. Work started in an answer: turn counts as owner-started even when an unattended turn asked the question, so a throwaway wait: false question plus the owner's tap gives fresh per-work limits. This is the same "any owner row lifts it" rule as before. Worth a sentence in the docs.
  3. Unchanged from the first pass: the fold hides what an unattended run tried. Expired schedule cards draw only as "N expired · not sent", with no way to open them.

@bvsr365

bvsr365 commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Re-check at d3a1d91d1: clear to merge behind the switch. Every finding from both earlier reviews is closed, decided and documented, or left for the approval card (#1390). With the switch off, the skip check gives master's answers. The same test run on this head and on master: running, offline, blocked for another reason, finished, and an every-minute schedule. The only failures are the 7 queue/slot tests that fail on master with the same assertions. Both typechecks pass, and the branch merges cleanly with current master.

Four small points, all with asks first on:

  1. A stale Send answers as if the card could still be sent. Case: the schedule file is saved but the bot database step fails, so the card stays open; then the owner taps Send. The card is withdrawn, but the answer is bot_action_changed, "This changed since you saw it. Check it again before sending." It can never be sent. A second tap gives the right answer (bot_action_withdrawn, "This changed since you saw it. Nothing was sent."). Use that one the first time too.
  2. The three-unsent refusal is now partly untrue. Open cards count in the shared history. So when one unattended chat starts four pieces of work with different calls, the fourth is told "You had three cards for this tool that were not sent… wait for your owner to write". In fact all three are still waiting, and Send on them lifts the rule without the owner writing. Suggest "Three cards for this tool are waiting for your owner or were not sent."
  3. docs/bots.md says "Editing them makes Send refuse the old call." An edit now withdraws the card when it is saved, and the run is told. Say that.
  4. If the bot database step fails after the schedule file is written, the edit is saved, but the caller gets an error and the updated event never fires. Chat and About keep showing the old schedule until something else changes. Nothing can be sent: Send or a restart withdraws the card. Emitting updated anyway, or a line in the Notes, would do.

PR text: it is long for a teammate. Keep Problem, How to review and the rules in Change. Describe how a work's starter is decided in plain words: a message or tap from the owner, or anything else. Verification fits in a few bullets: what was checked, plus the seven inherited failures with the one master command. The two command lists, the commit-by-commit red-to-green pairs, the head and merge hashes, the paragraph about the previous head's runs and the package.json remark can go.

@bvsr365
bvsr365 merged commit 5a584d1 into master Nov 17, 2026
7 checks passed
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