Repository navigation
fix(bots): held calls withdraw, expire and stay declined until new input - #1392
Conversation
bvsr365
left a comment
There was a problem hiding this comment.
An adversarial pass on three questions:
- Can a dead call still run? No, in every path I tried: Stop, the work ending,
/clear,/reset, delete, forget history, a grant or tool change, Forget, expiry, Send racing Stop (nothing sent), and the owner's pause. - Is anything left behind? Yes: see the second point below.
- Can the bot get around "a declined call does not come back"? Only by changing the arguments: see the third point.
Open points:
Should fix
-
A passing MCP hiccup or a slow start withdraws every open card for good.
withdrawChanged()runs on every listing change (fillMcpAsks), onapprove, and inreconcileafterrefresh. It withdraws any row whosevalid()fails, andvalid()fails wheneverBotMcp.bindingisundefined, which also happens while a server is starting, failing or not listed yet.- A server whose tools drop out of one listing and come back: the card is
withdrawnand stays so. - A restart before MCP has listed: every open card is withdrawn.
The PR's "server" case uses
bindingreturningundefined, so it can't tell removal from a blip. Fix: withdraw only on positive evidence: the server removed or changed perwhere(), the tool missing from a successful listing, or the grant dropping or lowering the pair. Keep the card onundefined; Send already re-checks the binding. - A server whose tools drop out of one listing and come back: the card is
-
Forget of the card, or of the owner's request, leaves the call's content in the row and the export. The chat row is redacted and
exec_argscleared. Butargs_json(recipients, subject, body) stays inbot_actions, andBotMemoryStore.actions()exports it. Fix: write forget history's tombstone toargs_json,card_json,bot_noteandresult_jsonof the rowsforgetMessagetouches, settled rows of that card included. Incard_json, keepownerSeqandnoteSeq. -
Trivially changed calls after Not now are unlimited (decide). With one more trailing space in the body each time and Not now each time, 20 rounds gave 20 cards, each looking like the last, and nothing refuses the 21st. Key order is caught;
"a@x"against["a@x"], a trailing space, another tool, or a new work are not, and a digest can't be made to see "the same email". Suggestion: reuse the wake rule's number with its reason. AfterMAX_SAME_WAKES(3) declined cards for the same tool in the same work since the owner last wrote, refuse further calls of that tool there without a card ("Your owner said no three times. Tell them what you need and wait for them to write."), lifting when the owner writes.
Minor
- Any owner row lifts the refusal, including a tap on an unrelated question. So a bot can ask "Shall I carry on?" and use the tap. Bot messages, wakes and notes from turns the owner didn't start don't count. Worth a sentence in the docs.
- After forget history,
args_digeststill confirms a guessed email offline. It is an unsalted SHA-256 of the forgotten arguments, readable by anyone who readsbots.db. Nothing needs it then: works are ended, and re-execution is stopped bycall_key. Tombstone it too. - Any grant change withdraws every open card of the bot. Allowing the web for a bot ends its open email card, because the binding holds the whole manifest's digest. Binding on the pair's level would keep it.
bvsr365
left a comment
There was a problem hiding this comment.
Review at 956344705: needs changes, 4 should fix and 4 minor, no blockers. With the switch off nothing changes. All 14 withdrawal paths are atomic, and the rollback test really aborts half way. Forget history keeps the run-once record, and expiry fires on the engine's timer and survives restart and sleep. Every bot unit file and both typechecks pass. The failing cases below come from throwaway engine tests built on botActions' own setup.
Should fix
- The repeat refusal is stored as an owner's note.
holdwrites "Your owner declined exactly this…" tobot_work_notes. After Not now and the same call again, the running turn is steered with "[Mousse] The owner added this to your job while you work: - Your owner declined exactly this…". When that turn completes, the pending note setsnoted(BotEngine.ts:4796) and starts another dispatch: "The owner added something while you worked; what you had so far was already sent to them … Your last message is your updated report". That is an extra turn, an extra report, and a false claim that the owner wrote. Give the refusal its own timed update with its own told marker, like waits and settled calls, rather than a work note. The matrix row feeds a raw event, so it doesn't catch this. - Forget ends parked work outside the engine's end path. The
forgetMessagehook moves the workblocked → cancelleddirectly, so there is norun_endjournal row and noafterEnd(cleanup of scratch, browser, progress and chip;changed; pump). Forgetting the card also ends the work, saying "its request was forgotten". End throughendWaitingInTxplusafterEndafter commit. For a forgotten card, either continue the work told "withdrawn", or end it with words about the card. - An unrelated grant change leaves a card that can't be sent or withdrawn. While a card is open, the owner allows "use your threads" from a chat ask. The card stays
openand the work stays parked, but every Send is refused with "This changed since you saw it" until the 48 hours run out.withdrawChangedruns only fromnarrowGrant,fillMcpAsksand restart. Run it wherever a grant is approved. - Slightly different arguments aren't limited. Six rounds of Not now, each followed by the same email plus one trailing space, give seven cards and seven notifications. Following #1311's wake rule with the tool as "the same thing": after 3 cards for the same tool in the same work are declined or expired since the owner last wrote or noted, refuse further cards for that tool until they do. Spec point 6 asks for a pinned rule.
Minor
approvedrows expire:expireDueexpires them too, so a Send just before the deadline can lose to the timer whilerunApprovedawaitsrefresh(). Expire onlyopenrows, or skipexecutingones.- Rows left from switch-on are never cleaned up: with the switch turned off, existing held rows never expire or withdraw. After Stop, the row stays
openwithexec_args. Cleanup could run regardless of the switch, with only new holds gated. - Engine state in the memory table: the note counter and the wait-loop cursor live in
bot_memory_state(cursor:action-*) and outlive the work. Check they are purged with the bot and stay out of the memory export. - Refusal codes: a Send while paused and a Send after expiry are refused as
bot_action_changed, which C4 shows as "This changed since you saw it". Give each its own code or text.
On the three decisions:
- Pause keeps the card: agree.
- Expiry from
expires_at: agree. One deadline, it doesn't spin, and the source is gated by the switch. An open card keepsisIdlefalse, as questions already do; that comes from C3a. - No fixed cap: see finding 4.
With C4 (#1390): both touch BotActions.ts, BotEngine.ts, docs/bots.md and botActions.test.ts; only the docs and the test file conflict. C4 should:
- draw the forget-history tombstone (
card_jsonbecomes the string"[forgotten]"); - keep its projection off C3b's
ownerSeq/noteSeq; - show the pause and expiry refusals separately (finding 8);
- add nudges beside the expiry source in
dueAt.
Not checked: the running app and a phone.
|
Re-check 2 at Should fix (small)
Merge with master (trial merge with
Docs nit:
|
Problem
Held calls can outlive their work, request or permission. Old cards retain executable arguments and never expire, while Not now can become repeated cards for the same job. Passing MCP failures could also kill live cards, and Forget left call content in the export.
Change
Held calls withdraw with ended work, forgotten requests or cards, cleared history, reset, bot deletion and relevant tool or permission changes. Settlement clears executable arguments and updates the chat row together. Running calls retain their run-once record and recover as uncertain. The default-off switch gates only new holds; existing rows still settle, withdraw, expire and forget their content after it is turned off. Send still works on a card left from when the switch was on. A profile with no action rows keeps its existing behavior.
Open cards expire 48 hours from creation, including restart and sleep. The due timer reads that original deadline, and Send checks it before accepting approval. A timely Send commits approval before asynchronous tool refresh, then rechecks its execution binding. An accepted call must start dispatch within
APPROVED_SEND_WINDOW_MS(ten minutes) ofanswered_at, independent of the original card expiry: a tap one second before that expiry still gets ten minutes. The due timer includes this deadline even with no tools listing. Restart inside the window can recover it; restart or sleep past it settles it immediately without sending. The transport fence also checks the window before dispatch.Past the accepted window, the row becomes
failed, clearsexec_args, and storesresult_json.notSentInTime = truewith<Service> couldn't be reached, so nothing was sent.The card message has that sentence too. Its outcome joins ordered unread updates and is confirmed on output/completion; the work can decide to ask again. This is neither a declined nor expired card, so it does not count toward the three-unsent rule or identical-call refusal. Stop, Forget, owner pause, relevant grant changes and delete can withdraw it earlier. A pause keeps an open card; an accepted call still waiting for service is withdrawn immediately on owner pause. Running calls settle or become uncertain after restart, as before.C4: waiting versus sending
status = approved: dispatch has not begun. DrawWaiting for <service>…; the stored message already has this text.card_json.serverNamesupplies the service name andanswered_at + APPROVED_SEND_WINDOW_MSsupplies the deadline.status = running: execution has been claimed and may have left Mousse. Draw “Sending…”. The message changes at that transition.status = failedwithresult_json.notSentInTime = true: dispatch never happened within the window. Draw the stored service-unreachable sentence.card_json.settledAtrecords the outcome time.Withdrawal needs positive evidence: a server removed, disabled or changed in configuration, a tool absent from a successful server listing, a changed schema, or a relevant permission change. Starting, failing and cold catalogues keep live cards. Intact approved calls wait for their listing to return; malformed, oversized or stale calls cannot use that retry path. Every grant approval and revocation checks only that bot’s held pairs inside its transaction, including permissions allowed from chat. A failing card belonging to another bot cannot undo its Allow or Remove.
Forget of a card or its request, including settled calls, and forget history use the same tombstone: display arguments, argument digest, card text, bot note and result are erased. Card metadata retains fixed tombstone text and the owner-message/work-note numbers used by refusal rules. A settled tool-error outcome keeps only its error-category flag (
card_json.toolReportedError), so both the work and C4 can retain the outcome label without the answer. An owner-removed pending card also retains a boolean removal marker and numeric input snapshots; these contain no call content or digest. The call key, target, status and timestamps remain. Running executable arguments clear on settlement; late results cannot restore forgotten content or replace the forgotten message. Exports contain tombstones. Forgotten rows no longer match real argument digests in repeat detection or C4's identical-call lookup; the call key still prevents another execution.Forgetting an open card, or an accepted call still waiting for its service, withdraws and forgets it, then tells the work “Your owner removed this request. Do not ask for it again unless they write.” Further calls of that tool in that work, including changed arguments, are refused without a card or action row until owner input. Another tool is unaffected. Forgetting an already settled card only removes its content: it adds no block, leaves status unchanged and still tells an unread outcome as sent, not sent, tool error or uncertain. No
[forgotten]text or forgotten details reach the work. This content-free rule needs no digest. Forgetting the owner's request still ends the work throughendWaitingInTxandafterEnd, releasing scratch, browser, progress and live status, with an end journal entry.An identical declined or expired call needs later owner input before another card. After
MAX_SAME_WAKES(three) cards for the same tool in the same work were declined or expired since its owner last wrote, even changed calls are refused without a card or action row. The sentence says three cards were not sent, without treating expiry as a refusal by the owner. Another tool is independent. Any owner message row, including a tapped question answer, or an owner work note lifts the rule, as for wake loops. Forgetting cannot erase the three-card loop. Send and Not now reset wait history as owner answers do.Refusals are Mousse updates, never owner notes: they neither steer the work as owner words nor start another turn or report. Refusals, withdrawals, expiry, waits, notes and answers join the same ordered update list and count as told only on model output or completion. The matrix stores refusals and reads them through the engine’s real update path, and covers accepted-window timeout and owner-removal outcomes. Captured master cells are unchanged.
Approval binding
asks_firstor allowed)Unrelated permissions and revision bumps preserve a sendable card. Removing or changing the pair's level withdraws it; re-granting it never revives the old card. Ordinary bot authority checks retain their grant rules. Cards held under #1340’s whole-grant binding are withdrawn on upgrade rather than silently upgraded, including old accepted cards. These are development profiles only; this fails safe.
Refusals exposed to C4
The chat service preserves each code through the protocol. Only a changed binding/review uses
bot_action_changed.bot_action_expiredbot_action_withdrawnbot_action_changedbot_action_settledbot_action_gonebot_action_pausedResume <bot> to send this.bot_action_unreachable<Service> couldn't be reached, so nothing was sent.Private engine state
bot_memory_stateholdscursor:action-note:<work>andcursor:action-owner:<work>so owner-input and wait-loop facts survive restart without a database-version change. Both are deleted in the work-ending transaction. Refusal updates usecursor:action-refusal:<work>:…, with carrying ids inprompt.workRefusalIds; output/completion removes confirmed entries, while untold entries survive resumable interruptions and waits. The transaction that changes work todone,failedorcancelleddeletes its refusal entries, because terminal work can no longer be told. Startup removes older entries for ended or missing work, and the bot’s 30-day purge removes them in any case. Historical carrying dispatches keep their delivery ids. None of these keys is exported as memory, and bot purge deletes them. Tombstones keep the numericownerSeq/noteSeqfacts in the action row.How to review
Start with
BotActions.tsfor withdrawal, tombstones, refusal rules and accepted-call recovery.BotEngine.tssupplies pair authority and the shared ordered update path;BotStore.tsowns grant-change transactions and confirmation.BotChatService.tspreserves refusal codes. Tests observe actual transport calls, record/export contents, rollback, normal ending and cleanup, no extra report, chat Allow, restart, sleep, timely/late Send and confirmed delivery. The continuation matrix reads persisted Mousse updates.Integration with master
Master
8e30e499bc56353ec3a6b86998b4072ddeab9d95is merged in192394dc3a3bee9f8b93bcc55f999cc030500c15, without rebase or force-push. There were no textual conflicts.BotEngine.tsanddocs/bots.mdauto-merged; review retained both C3b’s binding/lifecycle/delivery paths and master’s new behavior:askCallNoteremain in the ask/wall paths. Other changes retained in the touched engine include terminal/running read tools, watcher output, running-list helpers and wake ids.On untouched master the four inherited
integration thread actionscases fail because they assume subagents have no thread actions before the hold. The tests now assert master’s granted rights before a hold and refusal after it, for both callers and switch states. No production permission rule was weakened to make them pass.Verification
All final-head commands below passed on
2339cdf21a50d7d9cbb4cf2e080f1874aa2a68f9. Every bot unit file is included except process-lanebotSupervisor; each batch uses at most ten named files and two workers under the shared lock. The three required integration files and node typecheck are included.Untouched-master baseline — four expected failures, before updating the stale tests
On master
8e30e499bc56353ec3a6b86998b4072ddeab9d95, in a clean detached worktree:flock /tmp/mousse-heavy.lock npx vitest run tests/bots/botActions.test.ts -t 'integration thread actions' --maxWorkers=2Each work/subagent × switch-state case fails at the old pre-hold assertion,
expected undefined to be truthy. The final merged-head batches pass all four updated cases.Batch 01 — passed
Batch 02 — passed
Batch 03 — passed
Batch 04 — passed
Batch 05 — passed
Batch 06 — passed
Batch 07 — passed
Batch 08 — passed
Batch 09 — passed
Batch 10 — passed
Batch 11 — passed
Batch 12 — passed
Batch 13 — passed
Batch 14 — passed
Node typecheck — passed
Fake MCP transports record calls and exact arguments; provider events are scripted. Settled-card tests cover a later different call, an untold sent outcome, declined outcomes, tool errors and uncertain results, with no forgotten content. Pending-card removal still blocks re-asking. No live external send, full suite, process lane, development app run or phone check. C4 rendering remains separate. No database-version change; no captured master matrix cells changed.
Notes
C4 (#1390), scheduled cards (C5) and rollout (C6) remain separate. C4 should keep a forgotten settled outcome’s label without its details, using the preserved error-category fact when needed. External catalogue configuration is outside the bot database; withdrawal, card settlement and parked-work readiness commit together when the change is observed.
Refs #1335