Repository navigation
feat(bots): bound unattended approvals and let scheduled calls wait for Send - #1403
Conversation
bvsr365
left a comment
There was a problem hiding this comment.
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
withdrawnwith 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
- 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 callbot_schedule_removeandbot_schedule_add(both allowed in a scheduled run's authority, as isschedule_done). After three unsent cards, a run that read a hostile page can remove its schedule and add it back: the newscheduleIdhas 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
- Changing an automation's Tell me level or "can wake me" withdraws its waiting card. The schedule revision hashes
tellMeand the wholejob.bot. Fix: hash only what the run executes under: prompt, timing anduntil, model or pick,enabled. - 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
left a comment
There was a problem hiding this comment.
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
- Editing a schedule leaves a card that can never be sent. After an edit, Send is refused with
bot_action_changed, but the card staysopen(two Sends refused, row still open). It is withdrawn only when something else runswithdrawChanged, or when the gap ends. With C4's live buttons the owner can keep tapping. RunwithdrawChanged(botId)in the transaction that saves a schedule edit, or haveanswerwithdraw a row thatobsolete()reports instead of answeringchanged. - A held call after
schedule_doneis refused with the wrong reason. The run callsschedule_done, then the tool, and is told "This tool changed. Carry on without it.": the schedule is gone, sobindingreturns 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):
bvsr365
left a comment
There was a problem hiding this comment.
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:
- 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.
- 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 throwawaywait: falsequestion 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. - 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.
|
Re-check at Four small points, all with asks first on:
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. |
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
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.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