Let a bot answer its sessions side by side, and show a due reply in each

Replies were locked per bot, so a long reply in one session held up every
other session's reply with nothing shown. The lock is now per session. A
chat shows the thinking row whenever the user has the last word, rather
than from the bot's face (one per user, shared by every session), so it
shows even while the bot works elsewhere. A task waiting for its busy
computer says so, and a job finishing while another still runs puts back
the running one's face.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-19 16:09:21 +01:00
co-authored by Claude Opus 5.5
parent e157863cfb
commit 4ee81d6127
8 changed files with 122 additions and 19 deletions
+15
View File
@@ -65,4 +65,19 @@ describe("createKeyLock", () => {
expect(failed).rejects.toThrow("boom");
expect(await next).toBe("ok");
});
test("is busy while a task with the key is running", async () => {
const lock = createKeyLock();
expect(lock.busy({ key: 1 })).toBe(false);
const running = lock.run({ key: 1, task: () => wait(10) });
expect(lock.busy({ key: 1 })).toBe(true);
expect(lock.busy({ key: 2 })).toBe(false);
await running;
expect(lock.busy({ key: 1 })).toBe(false);
});
});
+9 -1
View File
@@ -28,5 +28,13 @@ export default function createKeyLock() {
}
}
return { run, size: () => tails.size };
/**
* Whether a task with this key is running or queued, so a caller can
* say it's waiting before it joins the line.
*/
function busy({ key }: { key: string | number }) {
return tails.has(String(key));
}
return { run, busy, size: () => tails.size };
}