Let bots take in messages sent while they reply

A reply read the session once at the start, so a message sent while it
ran was never seen, and the follow-up reply queued for it then finished
silently: the message was saved before the reply, so the thread ended
with the bot. Those messages went unanswered.

The text loop now reads new user messages after every round of tools and
before an answer goes out, and the bot decides from what each one means
whether it changes the work (folded in, or the unsent answer redrafted)
or is a separate request, which it acknowledges at once with the new
send_message tool and does after the current work. Messages sent that
way are marked interim, so the thinking row stays up while the bot
works. A reply job records the newest user message it read, and a queued
reply only stays silent when a finished reply already read everything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-25 04:49:10 +01:00
co-authored by Claude Opus 5.5
parent c13b9ea826
commit b0fe619ae8
25 changed files with 754 additions and 20 deletions
@@ -13,6 +13,10 @@ type Params = {
workspace_id?: number | null;
text: string;
needs_you?: boolean;
/**
* Sent mid-reply (`send_message`): the reply is still being worked on.
*/
interim?: boolean;
/**
* Files the bot saved and sent with it (`media` ids): a PDF it made, a
* generated image, a document it wrote.
@@ -30,10 +34,12 @@ export default async function insertBotMessage({
workspace_id,
text,
needs_you,
interim,
media_ids = [],
}: Params): Promise<BUN_SQLITE_COBBLE_BOT_MESSAGES> {
const now = Date.now();
const needs_you_flag = needs_you ? 1 : 0;
const interim_flag = interim ? 1 : 0;
const res = await BunSQLite.insert<
BUN_SQLITE_COBBLE_BOT_MESSAGES,
@@ -48,6 +54,7 @@ export default async function insertBotMessage({
author: "bot",
text,
needs_you: needs_you_flag,
interim: interim_flag,
},
],
});
@@ -78,6 +85,7 @@ export default async function insertBotMessage({
author: "bot",
text,
needs_you: needs_you_flag,
interim: interim_flag,
created_at: now,
updated_at: now,
};