Skip to content

A team of long-lived bots for DeepSeek Harness, with main bots, bot-to-bot messages and group chats.

Pause a group's Bot relays instead of capping each member

Fei24115537bf643ade
diff --git a/ds-bot/client.js b/ds-bot/client.js
index db0dde94..b51099a7 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -247,6 +247,8 @@ var ZH = {
"Who answers": "谁来回答",
"Choose an admin first": "先选一个管理员",
"@mentions always pick who answers.": "@提及总是指定由谁回答。",
+ "Pause Bot relays after": "Bot 接力几次后暂停",
+ "Counted since your last message in this group.": "从你在群里的上一条消息算起。",
Notice: "群公告",
"Shared instructions every member reads before speaking…": "每位成员发言前都会读到的共同说明…",
"Group notice": "群公告",
@@ -559,8 +561,8 @@ var ZH = {
"{name} looked up its own chat for “{text}”": "{name} 在自己的对话里查找「{text}」",
"{name} is typing…": "{name} 正在输入…",
"{name} didn't answer in time": "{name} 没有及时回应",
- "{names} not called: the per-member limit for this round is reached": "没叫到 {names}:这一轮每人的次数用完了",
- "The group went quiet: @ mentions in late replies call nobody until you write here": "群进入安静模式:之后迟到回复里的 @ 不再叫人,你在群里说句话就恢复",
+ "Paused after {count} Bot relays. Waiting: {names}": "Bot 之间已接力 {count} 次,先停下了。还在等:{names}",
+ "Continue": "继续",
"{name} paused for your approval": "{name} 停下来等你批准",
"{name} started on it": "{name} 开始做了",
"You stopped {name}'s work": "你停下了 {name} 的工作",
@@ -1486,6 +1488,7 @@ function teamActions({ call: call2, after, partFor, roster, ui: ui2, live, cards
setPrefs: (prefs) => after(call2("set-prefs", prefs)),
setMain: (id, main = true, options = {}) => after(call2("set-main", { id, main, ...options })),
updateRoom: (id, patch) => after(call2("update-room", { id, ...patch })),
+ continueRoom: (roomId) => after(call2("room-continue", { roomId })),
send: (sessionId, text) => after(call2("send", { sessionId: partFor(sessionId), text })),
answerQuestion: (sessionId, questionId, answer) => after(call2("answer-question", { sessionId: partFor(sessionId), questionId, answer })),
dismissQuestion: (sessionId) => after(call2("dismiss-question", { sessionId })),
@@ -5692,11 +5695,13 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
if (reply.kind === "missed") {
return (0, import_react9.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} didn't answer in time", { name: bot.name }));
}
- if (reply.kind === "dropped") {
- return (0, import_react9.createElement)("div", { key: `dropped-${index}`, className: "bt-event" }, t("{names} not called: the per-member limit for this round is reached", { names: (reply.names ?? []).join(t(" and ")) }));
- }
- if (reply.kind === "quiet") {
- return (0, import_react9.createElement)("div", { key: `quiet-${index}`, className: "bt-event" }, t("The group went quiet: @ mentions in late replies call nobody until you write here"));
+ if (reply.kind === "paused") {
+ return (0, import_react9.createElement)(
+ "div",
+ { key: `paused-${index}`, className: "bt-event" },
+ (0, import_react9.createElement)("span", null, t("Paused after {count} Bot relays. Waiting: {names}", { count: reply.count, names: (reply.names ?? []).join(t(" and ")) })),
+ room2?.paused?.length > 0 ? (0, import_react9.createElement)("button", { type: "button", className: "bt-soft bt-soft-sm", onClick: () => actions.continueRoom(sessionId) }, t("Continue")) : null
+ );
}
if (reply.kind === "resumed") {
return (0, import_react9.createElement)("div", { key: `${reply.botId}-${index}`, className: "bt-event" }, t("{name} was cut off by a restart and picked its work back up", { name: bot.name }));
@@ -10484,6 +10489,44 @@ function roomSubtitle(room2, roster) {
const admin = roster.byId[room2.admin];
return [t("{count} members", { count: room2.members.length }), admin ? t("Admin {name}", { name: admin.name }) : t("No admin")].join(" · ");
}
+function RelayLimitRow({ room: room2, update }) {
+ const [draft, setDraft] = (0, import_react27.useState)(room2.relayLimit ?? "");
+ (0, import_react27.useEffect)(() => setDraft(room2.relayLimit ?? ""), [room2.relayLimit]);
+ const save = () => {
+ const text = String(draft).trim();
+ if (text === "") {
+ if (room2.relayLimit !== void 0) update({ relayLimit: null });
+ return;
+ }
+ const limit = Number(text);
+ if (!Number.isInteger(limit) || limit < 1 || limit > 200 || limit === room2.relayLimit) {
+ setDraft(room2.relayLimit ?? "");
+ return;
+ }
+ update({ relayLimit: limit });
+ };
+ return (0, import_react27.createElement)(
+ Row,
+ { label: t("Pause Bot relays after"), hint: t("Counted since your last message in this group.") },
+ (0, import_react27.createElement)("input", {
+ className: "bt-bs-input",
+ type: "number",
+ min: 1,
+ max: 200,
+ placeholder: String(room2.relayLimitDefault ?? ""),
+ value: draft,
+ "aria-label": t("Pause Bot relays after"),
+ onChange: (event) => setDraft(event.target.value),
+ onBlur: save,
+ onKeyDown: (event) => {
+ if (event.key === "Enter") {
+ event.preventDefault();
+ event.currentTarget.blur();
+ }
+ }
+ })
+ );
+}
function GroupPermission({ room: room2, catalog, update }) {
if (!catalog?.options?.length) return null;
const shared2 = room2.permission !== void 0;
@@ -10575,7 +10618,8 @@ function GroupSettingsForm({ room: room2, roster, actions, run, onDeleted }) {
}
}, t(label)))),
(0, import_react27.createElement)("span", { key: mode, className: "bt-set-hint bt-veil" }, `${t(modeHint)} ${t("@mentions always pick who answers.")}`)
- )
+ ),
+ (0, import_react27.createElement)(RelayLimitRow, { room: room2, update })
),
(0, import_react27.createElement)(
Card,
diff --git a/ds-bot/src/client/cells.js b/ds-bot/src/client/cells.js
index 87d1bc5c..3a62a407 100644
--- a/ds-bot/src/client/cells.js
+++ b/ds-bot/src/client/cells.js
@@ -745,11 +745,10 @@ function GroupReplies({ sessionId, callId, done, content, roster, actions, useUi
if (reply.kind === 'missed') {
return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t("{name} didn't answer in time", { name: bot.name }))
}
- if (reply.kind === 'dropped') {
- return h('div', { key: `dropped-${index}`, className: 'bt-event' }, t('{names} not called: the per-member limit for this round is reached', { names: (reply.names ?? []).join(t(' and ')) }))
- }
- if (reply.kind === 'quiet') {
- return h('div', { key: `quiet-${index}`, className: 'bt-event' }, t('The group went quiet: @ mentions in late replies call nobody until you write here'))
+ if (reply.kind === 'paused') {
+ return h('div', { key: `paused-${index}`, className: 'bt-event' },
+ h('span', null, t('Paused after {count} Bot relays. Waiting: {names}', { count: reply.count, names: (reply.names ?? []).join(t(' and ')) })),
+ room?.paused?.length > 0 ? h('button', { type: 'button', className: 'bt-soft bt-soft-sm', onClick: () => actions.continueRoom(sessionId) }, t('Continue')) : null)
}
if (reply.kind === 'resumed') {
return h('div', { key: `${reply.botId}-${index}`, className: 'bt-event' }, t('{name} was cut off by a restart and picked its work back up', { name: bot.name }))
diff --git a/ds-bot/src/client/group-settings.js b/ds-bot/src/client/group-settings.js
index 8d20ac6d..76c78b95 100644
--- a/ds-bot/src/client/group-settings.js
+++ b/ds-bot/src/client/group-settings.js
@@ -21,6 +21,33 @@ export function roomSubtitle(room, roster) {
return [t('{count} members', { count: room.members.length }), admin ? t('Admin {name}', { name: admin.name }) : t('No admin')].join(' · ')
}
+// The one guard a group keeps: how many Bot turns may answer Bot calls since the
+// user last wrote in it, after which the group pauses until the user goes on or
+// writes. Empty means the default, three relays per member.
+function RelayLimitRow({ room, update }) {
+ const [draft, setDraft] = useState(room.relayLimit ?? '')
+ useEffect(() => setDraft(room.relayLimit ?? ''), [room.relayLimit])
+ const save = () => {
+ const text = String(draft).trim()
+ if (text === '') {
+ if (room.relayLimit !== undefined) update({ relayLimit: null })
+ return
+ }
+ const limit = Number(text)
+ if (!Number.isInteger(limit) || limit < 1 || limit > 200 || limit === room.relayLimit) { setDraft(room.relayLimit ?? ''); return }
+ update({ relayLimit: limit })
+ }
+ return h(Row, { label: t('Pause Bot relays after'), hint: t('Counted since your last message in this group.') },
+ h('input', {
+ className: 'bt-bs-input', type: 'number', min: 1, max: 200,
+ placeholder: String(room.relayLimitDefault ?? ''), value: draft,
+ 'aria-label': t('Pause Bot relays after'),
+ onChange: event => setDraft(event.target.value),
+ onBlur: save,
+ onKeyDown: event => { if (event.key === 'Enter') { event.preventDefault(); event.currentTarget.blur() } },
+ }))
+}
+
// One preset for every member in the group, or each member's own. Turning it on starts
// from DSH's default preset.
function GroupPermission({ room, catalog, update }) {
@@ -75,7 +102,8 @@ export function GroupSettingsForm({ room, roster, actions, run, onDeleted }) {
title: id === 'admin' && !admin ? t('Choose an admin first') : undefined,
onClick: () => { if (mode !== id) void update({ mode: id }) },
}, t(label)))),
- h('span', { key: mode, className: 'bt-set-hint bt-veil' }, `${t(modeHint)} ${t('@mentions always pick who answers.')}`))),
+ h('span', { key: mode, className: 'bt-set-hint bt-veil' }, `${t(modeHint)} ${t('@mentions always pick who answers.')}`)),
+ h(RelayLimitRow, { room, update })),
h(Card, { title: t('Working folder') },
h('div', { className: 'bt-set-row bt-bs-row' },
h('span', { className: 'bt-set-copy' }, h('span', { className: 'bt-bs-label' }, t('Folder'))),
diff --git a/ds-bot/src/client/i18n.js b/ds-bot/src/client/i18n.js
index da2ad63f..9085fa43 100644
--- a/ds-bot/src/client/i18n.js
+++ b/ds-bot/src/client/i18n.js
@@ -214,6 +214,8 @@ const ZH = {
'Who answers': '谁来回答',
'Choose an admin first': '先选一个管理员',
'@mentions always pick who answers.': '@提及总是指定由谁回答。',
+ 'Pause Bot relays after': 'Bot 接力几次后暂停',
+ 'Counted since your last message in this group.': '从你在群里的上一条消息算起。',
Notice: '群公告',
'Shared instructions every member reads before speaking…': '每位成员发言前都会读到的共同说明…',
'Group notice': '群公告',
@@ -503,8 +505,8 @@ const ZH = {
'{name} looked up its own chat for “{text}”': '{name} 在自己的对话里查找「{text}」',
'{name} is typing…': '{name} 正在输入…',
"{name} didn't answer in time": '{name} 没有及时回应',
- '{names} not called: the per-member limit for this round is reached': '没叫到 {names}:这一轮每人的次数用完了',
- 'The group went quiet: @ mentions in late replies call nobody until you write here': '群进入安静模式:之后迟到回复里的 @ 不再叫人,你在群里说句话就恢复',
+ 'Paused after {count} Bot relays. Waiting: {names}': 'Bot 之间已接力 {count} 次,先停下了。还在等:{names}',
+ 'Continue': '继续',
'{name} paused for your approval': '{name} 停下来等你批准',
'{name} started on it': '{name} 开始做了',
"You stopped {name}'s work": '你停下了 {name} 的工作',
diff --git a/ds-bot/src/client/team-actions.js b/ds-bot/src/client/team-actions.js
index dbed528f..0ae389d8 100644
--- a/ds-bot/src/client/team-actions.js
+++ b/ds-bot/src/client/team-actions.js
@@ -66,6 +66,7 @@ export function teamActions({ call, after, partFor, roster, ui, live, cards, hel
setPrefs: prefs => after(call('set-prefs', prefs)),
setMain: (id, main = true, options = {}) => after(call('set-main', { id, main, ...options })),
updateRoom: (id, patch) => after(call('update-room', { id, ...patch })),
+ continueRoom: roomId => after(call('room-continue', { roomId })),
send: (sessionId, text) => after(call('send', { sessionId: partFor(sessionId), text })),
answerQuestion: (sessionId, questionId, answer) => after(call('answer-question', { sessionId: partFor(sessionId), questionId, answer })),
dismissQuestion: sessionId => after(call('dismiss-question', { sessionId })),
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index d7817225..9451b1f5 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -2,6 +2,7 @@
import { randomUUID } from 'node:crypto'
import { createUserMessage } from '@deepseek-ai/dsh-llm'
import { questionReply, viewReply } from './parts.js'
+import { defaultRelayLimit } from './groups.js'
import { validateViewAnswer } from '../shared/views.js'
import { COLORS, EXTRA_COLORS, ROUTE } from './constants.js'
@@ -42,10 +43,10 @@ export function install(rt) {
...bot, sessionId: rt.chatOf(bot.id), parts: (segments ?? []).map(segment => segment.sessionId), ...(kickoff ? { waiting: true } : {}),
})),
// `parts`: the members' hidden group Sessions and their earlier segments, for usage.
- rooms: Object.values(state.rooms).map(({ log, seen, lateRounds, sessions, segments, ...room }) => {
+ rooms: Object.values(state.rooms).map(({ log, seen, lateRounds, relays, sessions, segments, ...room }) => {
const parts = [...Object.values(sessions ?? {}), ...Object.values(segments ?? {}).flat().map(segment => segment.sessionId)]
const last = (log ?? []).filter(line => line.kind === undefined).at(-1)
- return { ...room, parts, ...(last ? { preview: last.who === 'User' ? last.text : `${last.who}:${last.text}` } : {}) }
+ return { ...room, relayLimitDefault: defaultRelayLimit(room), parts, ...(last ? { preview: last.who === 'User' ? last.text : `${last.who}:${last.text}` } : {}) }
}),
exchangeTurns: state.exchangeTurns,
questions: state.questions,
@@ -229,9 +230,15 @@ export function install(rt) {
remove: Array.isArray(body.remove) ? body.remove : undefined,
workDir: body.workDir,
permission: body.permission,
+ relayLimit: body.relayLimit,
})
return ok({ room: view().rooms.find(entry => entry.id === room.id), changes })
}
+ case 'room-continue': {
+ await rt.load()
+ await rt.continueRoom(body.roomId)
+ return ok(view())
+ }
case 'folders':
case 'folder-pick':
case 'folder-list':
diff --git a/ds-bot/src/host/constants.js b/ds-bot/src/host/constants.js
index 3b56db8e..e67dbb9b 100644
--- a/ds-bot/src/host/constants.js
+++ b/ds-bot/src/host/constants.js
@@ -69,9 +69,6 @@ export const TEAM_TOOLS = [
'list_capabilities', 'save_capability', 'delete_capability',
'attach_capability', 'detach_capability',
]
-// Answers a group gives to what members post after the round moved on (their finished
-// work, mostly), before the user speaks there again.
-export const ROOM_LATE_ROUNDS = 10
// A member still at work this long after its first tool call lets the round go on; it
// posts its reply when the work is done.
export const ROOM_WORK_GRACE_MS = 15_000
diff --git a/ds-bot/src/host/groups.js b/ds-bot/src/host/groups.js
index d9ab9242..48c4962c 100644
--- a/ds-bot/src/host/groups.js
+++ b/ds-bot/src/host/groups.js
@@ -8,7 +8,9 @@
// moved on, and nobody has to count lines to know who went before. A plain message
// goes to every member in roster order, admin first, or to the admin alone in admin
// mode; "@Name" picks members. A reply that @mentions a member calls that member
-// next, bounded per member and per round; the admin's calls reach further.
+// next, and the user's own messages are always answered. Bots calling each other
+// count against the group's relay limit, at which the group pauses — nothing is
+// dropped — until the user continues it or writes here.
//
// Work does not hold a round up: a member that is still busy with tools a little after
// it started, or that is called while still at earlier work, lets the round go on. Its
@@ -20,7 +22,7 @@ import { readFile, rm } from 'node:fs/promises'
import { join } from 'node:path'
import { createUserMessage } from '@deepseek-ai/dsh-llm'
import { defineTool } from '@deepseek-ai/dsh-tools'
-import { GROUP_LINE_READ, ROOM_LATE_ROUNDS, ROOM_REPLY_TIMEOUT_MS, ROOM_STEP_GAP_MS, ROOM_WORK_GRACE_MS, SOURCE_KIND, TEAM_TOOLS, TEXT_KEPT } from './constants.js'
+import { GROUP_LINE_READ, ROOM_REPLY_TIMEOUT_MS, ROOM_STEP_GAP_MS, ROOM_WORK_GRACE_MS, SOURCE_KIND, TEAM_TOOLS, TEXT_KEPT } from './constants.js'
import { escapeRegExp, headOf, splitRef, textOf } from './text.js'
import { mentionSpans, speakerOf } from '../shared/mentions.js'
import { GROUP_REF, output } from './tools.js'
@@ -30,10 +32,12 @@ const ROOM_LOG_MAX = 60
const ROOM_FIRST_LOOK = 12
const ROOM_DELTA_MAX = 24
const ROOM_EARLIER_MAX = 8
-const ROOM_EXTRA_TURNS = 4
-const ROOM_ADMIN_EXTRA_TURNS = 4
-const ROOM_TURNS_EACH = 2
-const ROOM_ADMIN_TURNS_EACH = 4
+
+// The only bound on a group: how many Bot turns may answer Bot calls since the user
+// last wrote in it, after which the group pauses rather than going on alone. The
+// user sets it per group; unset, it follows the member count.
+export const defaultRelayLimit = room => 3 * (room?.members?.length ?? 0)
+const relayLimit = room => room.relayLimit ?? defaultRelayLimit(room)
// Logs written before rooms were versioned get sequence numbers in place.
const ensureRoomLog = (room) => {
@@ -55,12 +59,8 @@ const unseenLines = (room, memberId) => {
// when it is read, so old entries still say what happened when the wording or the
// constants move on.
const noticeText = (line) => {
- if (line.reason === 'cap') {
- const via = line.admin !== undefined ? ` @${line.admin} can pass it on, or` : ''
- return `@${(line.names ?? []).join(' and @')} was not called: this round's per-member turn limit (${line.cap}) is reached, so the message is in the log but reaches nobody.${via} end this turn and call again in the next round.`
- }
if (line.reason === 'missed') return `${(line.names ?? []).join(' and ')} did not answer within ${line.minutes} minutes, so this round moved on without it. If it is still working, it posts its result later as a late reply; if it is urgent, the user can write here or the admin can follow up.`
- if (line.reason === 'quiet') return `The group is in quiet mode: late replies after work have reached the ${ROOM_LATE_ROUNDS}-round limit, so @ names in later posts call nobody, though the messages still reach the log. The user can reset it by writing here, or the current work can finish.`
+ if (line.reason === 'paused') return `Paused: Bots have called each other ${line.limit} times since the user last wrote here. The calls to @${(line.names ?? []).join(' and @')} wait until the user continues or writes here; do not call them again.`
return line.text ?? ''
}
// `text` is what to show of a message line, by default what the log keeps of it.
@@ -371,22 +371,16 @@ export function install(rt) {
}
// A called member moves up if it is still waiting, or gets one more turn if it
- // already spoke; either way it goes right after slot `index`. `cap` is the caller's
- // per-member turn bound for the round; `by` is the calling member, if a member called.
- function callMembers(round, turns, index, callees, note, cap, by) {
+ // already spoke; either way it goes right after slot `index`. `origin` is who the
+ // call answers to: 'user' for the user's own messages, 'bot' for a member's calls.
+ // `by` is the calling member, if a member called.
+ function callMembers(round, index, callees, note, by, origin) {
let next = index + 1
for (const peer of callees) {
- if ((turns.get(peer.id) ?? 0) >= cap) {
- // The bound drops the call in silence: the caller's "@Name" sits in the log
- // and reads as a hand-off, while the member never hears of it. Keep the drop
- // in the round, so the group is told once (noteDropped).
- round.dropped ??= []
- round.dropped.push({ name: peer.name, cap })
- continue
- }
const waiting = round.slots.findIndex((other, at) => at > index && other.id === peer.id && other.status === 'waiting')
const called = waiting === -1 ? { id: peer.id, name: peer.name, status: 'waiting' } : round.slots.splice(waiting, 1)[0]
called.note = note
+ called.origin = origin
if (by === undefined) delete called.by
else called.by = by
round.slots.splice(next, 0, called)
@@ -394,25 +388,22 @@ export function install(rt) {
}
}
- // Calls the per-member turn bound dropped, told to the group once per batch of
- // calls: the drop is found while the caller's own reply is handled, so the group
- // hears of it with that reply and not at the end of the round — a round may see
- // several batches, one for the user's message and one for each member's reply.
- // The log already shows the "@Name" that went out, so without this the hand-off
- // looks done while nobody was called: the round moved on and the caller waits for
- // an answer that never starts. The admin can carry the message on, or the round
- // ends and the next one calls again.
- const noteDropped = (room, round) => {
- const dropped = round.dropped ?? []
- if (dropped.length === 0) return
- round.dropped = []
- const names = [...new Set(dropped.map(item => item.name))]
- const admin = rt.botOf(room.admin)
- appendRoom(room, { who: 'DS Bot', kind: 'notice', reason: 'cap', names, cap: dropped[0].cap, ...(admin === undefined ? {} : { admin: admin.name }) })
- // The user's half of the same event: the round's replies carry one line, so the
- // silence after the "@Name" it just saw is not read as a finished hand-off.
- round.replies.push({ kind: 'dropped', names, cap: dropped[0].cap, time: Date.now() })
- void rt.save().catch(() => {})
+ // Calls the relay limit parked wait for the user: the group paused at its limit,
+ // and the user writing here or pressing Continue releases them. Each waits again
+ // as a Bot call at the end of the round's slots, after the speakers the user
+ // picked; one still waiting later in the round is not queued twice.
+ const resumePaused = (room, round) => {
+ const paused = room.paused ?? []
+ if (paused.length === 0) return
+ for (const entry of paused) {
+ if (round.slots.some(slot => slot.id === entry.id && slot.status === 'waiting')) continue
+ round.slots.push({
+ id: entry.id, name: entry.name, status: 'waiting', origin: 'bot',
+ ...(entry.note !== undefined ? { note: entry.note } : {}),
+ ...(entry.by !== undefined ? { by: entry.by } : {}),
+ })
+ }
+ room.paused = []
}
// The user's messages waiting in the group Session's inbox while a round runs, from
@@ -434,39 +425,34 @@ export function install(rt) {
// Messages the user sent while this round is running post into the log before the
// next speaker, so everyone still to speak sees them. The members the message's own
// round would open with answer it next, inside this round. Each message leaves the
- // Session's inbox, so it does not open another round when this one ends. Returns
- // the number of turns added, which the round's limit allows for.
- function drainRoomInbox(room, round, turns, index, agent) {
+ // Session's inbox, so it does not open another round when this one ends; each also
+ // restarts the relay count, and calls parked at the limit resume after the members
+ // the user called.
+ function drainRoomInbox(room, round, index, agent) {
// The greeting's prompt tells the admin the user has not written yet.
- if (round.kickoff) return 0
+ if (round.kickoff) return
const lines = waitingLines(agent).filter(line => agent.inbox.remove(line.id))
- if (lines.length === 0) return 0
- const before = round.slots.length
+ if (lines.length === 0) return
const members = room.members.map(rt.botOf).filter(Boolean)
for (const line of lines) {
appendRoom(room, { who: 'User', text: line.text })
round.replies.push({ kind: 'user', text: line.text, time: Date.now() })
const { all, found } = mentionsIn(line.text, members)
const note = all || found.length > 0 ? 'the user mentioned you' : 'new message from the user'
- callMembers(round, turns, index - 1, openingSpeakers(room, { text: line.text }), note, ROOM_ADMIN_TURNS_EACH)
- noteDropped(room, round)
+ callMembers(round, index - 1, openingSpeakers(room, { text: line.text }), note, undefined, 'user')
}
- // The user spoke in this room, so late results may call members again.
- room.lateRounds = 0
- room.quietNoticed = false
- room.quietShown = false
+ // The user spoke in this room, so Bot relays count afresh and the paused run.
+ room.relays = 0
+ resumePaused(room, round)
void rt.save().catch(() => {})
- return round.slots.length - before
}
async function runRound(room, round, signal, agent) {
- let limit = round.slots.length + ROOM_EXTRA_TURNS + (room.admin ? ROOM_ADMIN_EXTRA_TURNS : 0)
- const turns = new Map()
// The inbox check keeps a message sent during the last speaker's turn inside
// this round: it drains at the loop's head even once the slots ran out.
- for (let index = 0; (index < round.slots.length || waitingLines(agent).length > 0) && round.turns < limit; index += 1) {
+ for (let index = 0; index < round.slots.length || waitingLines(agent).length > 0; index += 1) {
if (signal.aborted) break
- limit += drainRoomInbox(room, round, turns, index, agent)
+ drainRoomInbox(room, round, index, agent)
if (index >= round.slots.length) break
const slot = round.slots[index]
const member = rt.botOf(slot.id)
@@ -475,10 +461,27 @@ export function install(rt) {
slot.status = 'left'
continue
}
+ if (slot.origin === 'bot') {
+ // The group's one guard: Bots calling each other can go on only so long
+ // without the user. Past the limit the call is parked, not dropped — the
+ // user releases it by writing here or pressing Continue.
+ if ((room.relays ?? 0) >= relayLimit(room)) {
+ slot.status = 'paused'
+ const paused = (room.paused ??= [])
+ if (!paused.some(entry => entry.id === slot.id)) {
+ paused.push({
+ id: slot.id, name: slot.name,
+ ...(slot.note !== undefined ? { note: slot.note } : {}),
+ ...(slot.by !== undefined ? { by: slot.by } : {}),
+ })
+ }
+ if (!(round.parked ??= []).includes(slot.name)) round.parked.push(slot.name)
+ continue
+ }
+ room.relays += 1
+ }
slot.status = 'speaking'
round.speaking = member.id
- round.turns += 1
- turns.set(member.id, (turns.get(member.id) ?? 0) + 1)
let session
try {
session = await groupSessionFor(room, member)
@@ -540,8 +543,15 @@ export function install(rt) {
const { all, found: named } = mentionsIn(spoken.join('\n\n'), everyone)
const found = named.filter(other => other.id !== member.id)
const callees = leads && all ? [...found, ...others.filter(other => !found.includes(other))] : found
- callMembers(round, turns, index, callees, `${member.name} mentioned you`, leads ? ROOM_ADMIN_TURNS_EACH : ROOM_TURNS_EACH, member.id)
- noteDropped(room, round)
+ callMembers(round, index, callees, `${member.name} mentioned you`, member.id, 'bot')
+ }
+ // A round that ended with parked calls says so once, to the group and to the
+ // user: the log's "@Name" lines are real calls that wait, not drops in silence.
+ if (round.parked !== undefined) {
+ const limit = relayLimit(room)
+ appendRoom(room, { who: 'DS Bot', kind: 'notice', reason: 'paused', names: round.parked, limit })
+ round.replies.push({ kind: 'paused', names: round.parked, count: limit, time: Date.now() })
+ await rt.save()
}
}
@@ -566,7 +576,7 @@ export function install(rt) {
// late failure, its work picked up after a restart, its work the user stopped, or
// the end of work whose result it already posted is an event of the round.
const event = item => item.failed || item.resumed || item.stopped || item.done
- for (const post of posts.filter(item => !item.kickoff && !event(item) && item.logged === undefined)) {
+ for (const post of posts.filter(item => !item.kickoff && !item.resume && !event(item) && item.logged === undefined)) {
// Image readings go into the log only; `@` names are picked from what the user typed.
// A file stays with its line and reaches each member the line is shown to.
const readings = post.images === undefined ? [] : await rt.imagesForGroup(post.images, room.id)
@@ -577,14 +587,11 @@ export function install(rt) {
...(post.files === undefined ? {} : { files: post.files }),
})
}
- // The user wrote here, so late results may call members again and the quiet
- // notice may be told again: the count and the notice reset together, as they
- // do for a message that waited in the inbox (drainRoomInbox).
- if (posts.some(post => !post.botId && !post.kickoff)) {
- room.lateRounds = 0
- room.quietNoticed = false
- room.quietShown = false
- }
+ // The user wrote here — or pressed Continue, which opens the same round
+ // without a line of its own — so Bot relays count afresh and the calls the
+ // limit parked run after the speakers this message picks.
+ const releases = posts.some(post => post.resume === true || (!post.botId && !post.kickoff))
+ if (releases) room.relays = 0
await rt.save()
// An event post, and a member post that calls nobody, never pick the speakers
// over a message queued with them.
@@ -601,12 +608,12 @@ export function install(rt) {
...(references.length > 0 ? { references, shown: [] } : {}),
slots: openingSpeakers(room, opener).map(member => ({
id: member.id, name: member.name, status: 'waiting',
+ origin: opener.botId === undefined ? 'user' : 'bot',
...(opener.kickoff ? { note: 'the group was just created' } : {}),
...(named.includes(member) ? { by: opener.botId } : {}),
...(opener.done ? { note: `${opener.name ?? 'a member'} finished the work you asked for` } : {}),
})),
speaking: null,
- turns: 0,
replies: [],
passed: [],
failed: [],
@@ -627,7 +634,7 @@ export function install(rt) {
round.replies.push({ kind, botId: post.botId, name, color: bot?.color, time: Date.now() })
}
if (posts.some(post => post.resumed || post.stopped || post.done)) await rt.save()
- if (posts.some(post => post.quiet === true)) showQuiet(room, round)
+ if (releases) resumePaused(room, round)
rt.roomProgress.set(exec.callId, round)
try {
await runRound(room, round, exec.signal, exec.agent)
@@ -743,6 +750,8 @@ export function install(rt) {
const members = everyone.filter(bot => bot.id !== opener.botId)
const admin = members.find(bot => rt.isAdminOf(room, bot.id))
if (opener.kickoff) return admin ? [admin] : []
+ // A Continue opens a round whose speakers are the calls the limit parked.
+ if (opener.resume) return []
if (opener.quiet) return []
if (opener.done) return members.filter(bot => bot.id === opener.askedBy)
const { all, found: named } = mentionsIn(opener.text, everyone, opener.references)
@@ -779,7 +788,6 @@ export function install(rt) {
const line = [text, ...files.map(fileLine)].filter(Boolean).join('\n')
appendRoom(room, { who: sender.name, botId: sender.id, text: line, ...(files.length > 0 ? { files } : {}) })
running.replies.push({ botId: sender.id, name: sender.name, color: sender.color, text: line, time: Date.now() })
- if (extra.quiet === true) showQuiet(room, running)
logged = room.seq
}
await rt.save()
@@ -793,32 +801,12 @@ export function install(rt) {
}
rt.postToRoom = postToRoom
- // Past the late-round limit every later post is quiet: its "@" names call nobody,
- // while the log still shows them. Members would keep handing work to a room that
- // no longer answers, so the group is told once when the limit is reached; the
- // user's next message resets the count (drainRoomInbox) and it may be told again.
- const noteQuiet = (room) => {
- if (room.quietNoticed === true) return
- room.quietNoticed = true
- appendRoom(room, { who: 'DS Bot', kind: 'notice', reason: 'quiet' })
- void rt.save().catch(() => {})
- }
-
- // The user's half of the same event: one line in the replies of the round the
- // quiet post reaches, shown once per quiet stretch the way the notice is.
- const showQuiet = (room, round) => {
- if (room.quietNoticed !== true || room.quietShown === true || round === undefined) return
- room.quietShown = true
- round.replies.push({ kind: 'quiet', time: Date.now() })
- void rt.save().catch(() => {})
- }
-
// A member the round moved on from (it went on working, went quiet or waited for an
// approval) posts what its turn ended with. The member that asked for it and anyone
- // it names answer; past the late round limit nobody does, so late posts cannot keep a
- // group talking. Work whose result already went out as a step line (`shown`) and
- // that ends with nothing more to say still tells the member that asked for it, which
- // answers the result: where the result sits in the turn decides nothing.
+ // it names answer, counted into the same relays to the group's pause as the calls
+ // inside a round. Work whose result already went out as a step line (`shown`) and
+ // that ends with nothing more to say still tells the member that asked for it,
+ // which answers the result: where the result sits in the turn decides nothing.
async function lateRoomReply(sessionId, info, reply, { shown = false } = {}) {
const owner = rt.groupOwners.get(sessionId)
const room = rt.roomOf(owner?.roomId ?? info.roomId)
@@ -827,11 +815,7 @@ export function install(rt) {
const text = stripOwnName(member.name, reply)
const done = isPass(text) && shown && info.askedBy !== undefined
if (isPass(text) && !done) return
- const quiet = (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDS
- if (quiet) noteQuiet(room)
- else room.lateRounds = (room.lateRounds ?? 0) + 1
- await rt.save()
- await postToRoom(room, member, done ? '' : text, { late: true, ...(done ? { done: true } : {}), ...(info.askedBy ? { askedBy: info.askedBy } : {}), ...(quiet ? { quiet: true } : {}) })
+ await postToRoom(room, member, done ? '' : text, { late: true, ...(done ? { done: true } : {}), ...(info.askedBy ? { askedBy: info.askedBy } : {}) })
.catch(error => rt.warn('ds-bot: late group reply from %s failed: %s', member.name, error))
}
rt.lateRoomReply = lateRoomReply
@@ -846,8 +830,8 @@ export function install(rt) {
// What a member says while it works, into the group. While the member holds its place
// in a round, it joins that round. Later, it joins whatever round runs in the group, or
- // posts on its own. Only the members it calls with @ answer it, and not past the late
- // round limit; the member that asked for the work answers the result.
+ // posts on its own. Only the members it calls with @ answer it, each a relay toward
+ // the group's pause; the member that asked for the work answers the result.
async function postStep(sessionId, info, text) {
const waiter = info?.role === 'room' ? rt.roomWaiters.get(info.exchangeId) : undefined
if (waiter !== undefined) return waiter.say(text)
@@ -856,15 +840,11 @@ export function install(rt) {
ensureRoomLog(room)
const calls = callsIn(room, member, text)
const running = [...rt.roomProgress.values()].find(round => round.roomId === room.id)
- const limited = (room.lateRounds ?? 0) >= ROOM_LATE_ROUNDS
- if (limited) noteQuiet(room)
if (!calls && running !== undefined) {
postInRound(room, running, member, text)
- if (limited) showQuiet(room, running)
return
}
- const quiet = !calls || limited
- if (!quiet) room.lateRounds = (room.lateRounds ?? 0) + 1
+ const quiet = !calls
await rt.save()
await postToRoom(room, member, text, { progress: true, ...(quiet ? { quiet: true } : {}) })
}
@@ -947,6 +927,23 @@ export function install(rt) {
}
rt.greetRoom = greetRoom
+ // The Continue of a group paused at its relay limit: the parked calls run in a
+ // round of their own, opened by the same relay a user message opens.
+ async function continueRoom(roomId) {
+ const room = rt.roomOf(roomId)
+ if (room === undefined) throw new Error('Unknown group chat')
+ if ((room.paused ?? []).length === 0) return
+ room.relays = 0
+ await rt.save()
+ const agent = await rt.resolveAgent(room.id)
+ agent.followup(createUserMessage({
+ content: [{ type: 'text', text: '[Continue]' }],
+ source: { kind: SOURCE_KIND, form: 'relay', role: 'resume', exchangeId: randomUUID(), senderName: 'You', roomId: room.id },
+ }))
+ await ctx.sessions.flush(agent.session)
+ }
+ rt.continueRoom = continueRoom
+
async function reportRound(room, post, round) {
const lines = round.replies.filter(reply => reply.kind === undefined).map(reply => `${reply.name}: ${reply.text}`)
const waiting = round.replies.filter(reply => reply.kind === 'approval').map(reply => reply.name)
diff --git a/ds-bot/src/host/roster.js b/ds-bot/src/host/roster.js
index c2cca82a..7c8dc690 100644
--- a/ds-bot/src/host/roster.js
+++ b/ds-bot/src/host/roster.js
@@ -408,10 +408,19 @@ export function install(rt) {
// A Bot's own permissions are the user's to set, so a group's are too.
if (patch.permission !== undefined && actorId !== undefined) throw new Error(`Only the user can set the permissions of "${room.name}"`)
const permission = patch.permission === undefined ? undefined : rt.cleanRoomPermission(patch.permission)
+ // The relay limit is the user's guard against a group that never stops; it is
+ // not a member's to move, whatever its role.
+ if (patch.relayLimit !== undefined && actorId !== undefined) throw new Error(`Only the user can set the relay limit of "${room.name}"`)
+ let relayLimit
+ if (patch.relayLimit === null) relayLimit = null
+ else if (patch.relayLimit !== undefined) {
+ if (!Number.isInteger(patch.relayLimit) || patch.relayLimit < 1 || patch.relayLimit > 200) throw new Error('Relay limit must be a whole number from 1 to 200')
+ relayLimit = patch.relayLimit
+ }
// The second run is the last check before the change is written, so no other change
// can take the name in between.
const name = patch.name === undefined ? undefined : cleanRoomName(patch.name, room.id)
- return { members, admin, name, notice, permission }
+ return { members, admin, name, notice, permission, relayLimit }
}
// `actorId` is the Bot asking, or undefined for the user. Returns what changed, in words.
@@ -424,7 +433,7 @@ export function install(rt) {
// No await from here until every change is written.
const room = rt.roomOf(id)
if (room === undefined) throw new Error('Unknown group chat')
- const { members, admin, name, notice, permission } = planRoomChange(room, patch, actorId)
+ const { members, admin, name, notice, permission, relayLimit } = planRoomChange(room, patch, actorId)
const changes = []
const names = ids => ids.map(member => rt.botOf(member)?.name).filter(Boolean).join(', ')
@@ -445,6 +454,11 @@ export function install(rt) {
room.mode = patch.mode
changes.push(patch.mode === 'admin' ? 'plain messages now go to the admin first' : 'every member now replies in turn')
}
+ if (relayLimit !== undefined && relayLimit !== (room.relayLimit ?? null)) {
+ if (relayLimit === null) delete room.relayLimit
+ else room.relayLimit = relayLimit
+ changes.push(relayLimit === null ? 'Bots pause at the default relay count again' : `Bots now pause after ${relayLimit} relays`)
+ }
if (notice !== undefined && notice !== (room.notice ?? '')) {
room.notice = notice
changes.push(notice ? 'updated the notice' : 'cleared the notice')
diff --git a/ds-bot/src/host/store.js b/ds-bot/src/host/store.js
index ea6658b6..74a494c9 100644
--- a/ds-bot/src/host/store.js
+++ b/ds-bot/src/host/store.js
@@ -167,6 +167,15 @@ export function install(rt) {
delete room.botRounds
migrated = true
}
+ // LEGACY: the late-round limit went with the round caps; a group counts relays to
+ // its pause now.
+ for (const room of Object.values(state.rooms)) {
+ if (room.lateRounds === undefined && room.quietNoticed === undefined && room.quietShown === undefined) continue
+ delete room.lateRounds
+ delete room.quietNoticed
+ delete room.quietShown
+ migrated = true
+ }
// Groups from before group settings existed reply in turn, led by a Main Bot member.
for (const room of Object.values(state.rooms)) {
if (room.admin !== undefined && ROOM_MODES.includes(room.mode)) continue
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index d1bc6d53..a78b9637 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -452,6 +452,8 @@ export function install(rt) {
})
} else if (source?.kind === SOURCE_KIND && source.role === 'kickoff' && rt.roomOf(id)) {
queueRoomMessage(id, { text: '', kickoff: true })
+ } else if (source?.kind === SOURCE_KIND && source.role === 'resume' && rt.roomOf(id)) {
+ queueRoomMessage(id, { text: '', resume: true })
} else if (source?.kind === SOURCE_KIND) {
if (entry.turn === undefined) entry.pending = source
else if (!opened) claimTrigger(id, entry, source)
diff --git a/ds-bot/test/group-work.test.js b/ds-bot/test/group-work.test.js
index ec391b44..eea9c588 100644
--- a/ds-bot/test/group-work.test.js
+++ b/ds-bot/test/group-work.test.js
@@ -5,7 +5,7 @@ import { join } from 'node:path'
import { test } from 'node:test'
import { apply } from '../index.js'
import { fakeAttachments, fakeContext } from './fake-ctx.js'
-import { MESSAGE_INLINE_MAX, ROOM_LATE_ROUNDS, ROOM_STEP_GAP_MS, ROOM_WORK_GRACE_MS } from '../src/host/constants.js'
+import { MESSAGE_INLINE_MAX, ROOM_STEP_GAP_MS, ROOM_WORK_GRACE_MS } from '../src/host/constants.js'
// Chief, the admin of group 'r1', speaks there from 'ga'; Writer from 'gb'; Tester from 'gc'.
const seed = (room = {}, extraRooms = {}) => ({
@@ -363,17 +363,17 @@ test('work inside a PTC program lets the round go on after the grace', async (t)
assert.deepEqual(kinds(result()), [['working', 'Writer']])
})
-test('work the user asked for is left for the user to read, and the user\'s message resets the late limit', async (t) => {
+test('work the user asked for is left for the user to read, and the user\'s message resets the relay count', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] })
- const host = await start(t, { lateRounds: ROOM_LATE_ROUNDS - 1 })
+ const host = await start(t, { relays: 5 })
const first = host.round('c1', host.say('@Writer 整理文档'))
await settle(() => host.agentOf('gb').calls.length === 1)
host.begin('gb')
host.emit('gb', 'tool/call', { callId: 'k1', name: 'write', arguments: '{}' })
t.mock.timers.tick(ROOM_WORK_GRACE_MS)
await settle(() => first() !== undefined)
- // The user's message resets the limit.
- assert.equal(JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).rooms.r1.lateRounds, 0)
+ // The user's message resets the count.
+ assert.equal(JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).rooms.r1.relays, 0)
host.finish('gb', '好了。')
await settle(() => host.agentOf('r1').calls.length === 1)
const post = host.takePost()
@@ -384,13 +384,36 @@ test('work the user asked for is left for the user to read, and the user\'s mess
assert.deepEqual([host.agentOf('ga').calls.length, host.agentOf('gc').calls.length], [0, 0])
})
-test('the late round limit makes a late post quiet', async (t) => {
- const host = await start(t, { lateRounds: ROOM_LATE_ROUNDS })
+test('a late post that calls a member counts into the relays, and parks past the limit', async (t) => {
+ // Three members, so the default relay limit is 9: the eighth relay still runs.
+ const host = await start(t, { relays: 8 })
host.emit('gb', 'turn/start', { turn: 1 })
- host.emit('gb', 'user/message', { content: [{ type: 'text', text: 'go' }], source: { kind: 'bot', role: 'room', exchangeId: 'x1', roomId: 'r1', hop: 0, askedBy: 'a' } })
- host.finish('gb', '做完了。')
+ host.emit('gb', 'user/message', { content: [{ type: 'text', text: 'go' }], source: { kind: 'bot', role: 'room', exchangeId: 'x1', roomId: 'r1', askedBy: 'a' } })
+ host.finish('gb', '@Tester 看看这个')
+ await settle(() => host.agentOf('r1').calls.length === 1)
+ const post = host.takePost()
+ assert.deepEqual([post.source.late, post.source.quiet], [true, undefined])
+ const first = host.round('c2', post)
+ await settle(() => host.agentOf('gc').calls.length === 1)
+ host.begin('gc')
+ host.finish('gc', '[PASS]')
+ await settle(() => first() !== undefined)
+ assert.equal(JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).rooms.r1.relays, 9)
+
+ // The next late call parks: the group pauses instead of running it, and nothing
+ // is dropped — the Tester just gets no turn until the user goes on.
+ host.emit('gb', 'turn/start', { turn: 2 })
+ host.emit('gb', 'user/message', { content: [{ type: 'text', text: 'more' }], source: { kind: 'bot', role: 'room', exchangeId: 'x2', roomId: 'r1', askedBy: 'a' } })
+ host.finish('gb', '@Tester 再看一个')
await settle(() => host.agentOf('r1').calls.length === 1)
- assert.equal(host.takePost().source.quiet, true)
+ const second = host.round('c3', host.takePost())
+ await settle(() => second() !== undefined)
+ const saved = JSON.parse(readFileSync(join(host.home, 'state.json'), 'utf8')).rooms.r1
+ assert.equal(saved.relays, 9, 'the parked call did not run')
+ assert.deepEqual(saved.paused.map(entry => [entry.id, entry.name]), [['c', 'Tester']])
+ assert.equal('lateRounds' in saved, false)
+ assert.equal(host.agentOf('gc').calls.length, 1, 'the parked call never reached the Tester')
+ assert.deepEqual(second().replies.filter(reply => reply.kind === 'paused').map(reply => [reply.names, reply.count]), [[['Tester'], 9]])
})
// #198: a post during a running round waited for the round's own relay before
diff --git a/ds-bot/test/roster.test.js b/ds-bot/test/roster.test.js
index 03a51925..d9e47c6d 100644
--- a/ds-bot/test/roster.test.js
+++ b/ds-bot/test/roster.test.js
@@ -871,3 +871,42 @@ test('a photo that cannot be read changes nothing, and a non-Main Bot cannot set
assert.match(await ctx.registeredTools.get('update_bot').execute({ avatar: notes }, mine), /^Could not update the Bot: The avatar must be a PNG/)
assert.equal((await call('state', {})).value.bots.find(bot => bot.id === writer.id).avatar.image, PNG_DATA_URL)
})
+
+test('a group\'s relay limit is a user setting the state view shows, and old late-round fields load away', async (t) => {
+ const { call, stop, home } = start({
+ version: 1,
+ mainBotIds: ['chief'],
+ bots: { chief: { id: 'chief', name: 'Chief' }, writer: { id: 'writer', name: 'Writer' } },
+ rooms: {
+ r1: {
+ id: 'r1', name: 'Ops', members: ['chief', 'writer'], mode: 'admin', admin: 'chief', named: true,
+ log: [], seq: 0, seen: {}, lateRounds: 7, quietNoticed: true, quietShown: true,
+ },
+ },
+ })
+ t.after(stop)
+ const shown = (await call('state', {})).value.rooms.find(room => room.id === 'r1')
+ // The released late-round fields load away, and the live relay count never shows.
+ assert.equal('lateRounds' in shown, false)
+ assert.equal('quietNoticed' in shown, false)
+ assert.equal('quietShown' in shown, false)
+ assert.equal('relays' in shown, false)
+ assert.equal(shown.relayLimit, undefined)
+ assert.equal(shown.relayLimitDefault, 6, 'the default is three relays per member')
+ assert.equal('lateRounds' in JSON.parse(readFileSync(join(home, 'state.json'), 'utf8')).rooms.r1, false)
+
+ const set = await call('update-room', { id: 'r1', relayLimit: 4 })
+ assert.equal(set.ok, true)
+ assert.equal(set.value.room.relayLimit, 4)
+ assert.match(set.value.changes.join(' '), /Bots now pause after 4 relays/)
+ const cleared = await call('update-room', { id: 'r1', relayLimit: null })
+ assert.equal(cleared.ok, true)
+ assert.match(cleared.value.changes.join(' '), /Bots pause at the default relay count again/)
+ assert.equal((await call('state', {})).value.rooms.find(room => room.id === 'r1').relayLimit, undefined)
+
+ for (const bad of [0, 2.5, 201, 'six']) {
+ const result = await call('update-room', { id: 'r1', relayLimit: bad })
+ assert.equal(result.ok, false, JSON.stringify(bad))
+ assert.match(result.error.message, /Relay limit must be a whole number from 1 to 200/)
+ }
+})
diff --git a/ds-bot/test/rounds.test.js b/ds-bot/test/rounds.test.js
index aabe076d..e82f542e 100644
--- a/ds-bot/test/rounds.test.js
+++ b/ds-bot/test/rounds.test.js
@@ -628,135 +628,199 @@ test('a long post goes to the group as a file, and reaches the member with its p
assert.equal(line.length, undefined, 'the line is short; no file of its own')
})
-// The per-member turn bound, the late-round quiet limit and the reply timeout drop
-// group hand-offs in silence: the log shows the "@Name" that went out, the called
-// member never hears of it, and the round moves on. Each drop is told to the group
-// instead, so a caller learns its hand-off did not land.
-test('a call past the per-member turn limit is dropped, and the group is told once', async (t) => {
- const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()
+// #395: the per-member and per-round turn bounds dropped calls in silence — a
+// "@Name" the user sent mid-round could vanish the same way. Now a member's turns
+// are not capped and every user message is answered; the only bound is the group's
+// relay limit, at which calls the Bot-to-Bot chain would make park instead of
+// dropping, until the user continues or writes in the group.
+test('a user @ mid-round reaches a member however often it already spoke', async (t) => {
+ const { call, emit, userMessage, compose, relay, answer, stop, sent, rt } = start()
+ t.after(stop)
+ const room = await team(call, sent)
+ await call('update-room', { id: room.id, mode: 'admin', relayLimit: 20 })
+ const writer = Object.values(rt.state.bots).find(bot => bot.name === 'Writer')
+
+ await emit(room.id, userMessage('Start'))
+ const running = relay(room.id, 'relay')
+
+ // The admin and the Writer trade calls ten times: nothing caps a member's turns
+ // any more, so each speaks as often as the relay limit leaves room for.
+ const spoken = []
+ let turn = await turnFor(sent)
+ for (let step = 0; step < 10; step += 1) {
+ spoken.push(turn)
+ await answer(turn.sessionId, turn.message.source.exchangeId, `${step % 2 === 0 ? '@Writer' : '@Chief'} volley ${step + 1}`, step + 1)
+ turn = await turnFor(sent, ...spoken)
+ }
+ const writerSession = rt.state.rooms[room.id].sessions[writer.id]
+ assert.equal(sent.filter(entry => entry.sessionId === writerSession && entry.message.source.role === 'room').length,
+ 5, 'the Writer answered five calls in one round; the old cap would have dropped the fifth')
+
+ // While the admin answers its sixth turn the user @s the Writer. The user's own
+ // calls never park: the Writer hears it right after the admin.
+ await compose(room.id, '@Writer your take?')
+ await answer(turn.sessionId, turn.message.source.exchangeId, 'Done.', 11)
+ const called = await turnFor(sent, ...spoken, turn)
+ assert.equal(called.sessionId, writerSession)
+ assert.match(called.message.content[0].text, /@Writer your take\?/)
+ assert.match(called.message.content[0].text, /the user mentioned you/)
+ await answer(called.sessionId, called.message.source.exchangeId, 'Here.', 12)
+ const result = JSON.parse(await running)
+ assert.equal(result.replies.filter(reply => reply.kind === 'paused').length, 0)
+})
+
+test('calls past the relay limit park until the user goes on, and the group is told once', async (t) => {
+ const { call, emit, userMessage, relay, answer, stop, sent, rt, home } = start()
t.after(stop)
const chief = (await call('state', {})).value.mainBotId
const writer = (await call('create-bot', { name: 'Writer' })).value
const editor = (await call('create-bot', { name: 'Editor' })).value
const room = (await call('create-room', { name: 'R1', members: [chief, writer.id, editor.id] })).value
- await call('update-room', { id: room.id, mode: 'everyone' })
+ await call('update-room', { id: room.id, mode: 'admin', relayLimit: 2 })
sent.length = 0
await emit(room.id, userMessage('Start'))
const running = relay(room.id, 'relay')
-
- // Everyone mode, admin first: the three opening turns weave @ calls between them.
const first = await turnFor(sent)
await answer(first.sessionId, first.message.source.exchangeId, '@Writer one', 1)
const second = await turnFor(sent, first)
- await answer(second.sessionId, second.message.source.exchangeId, '@Editor one', 2)
+ await answer(second.sessionId, second.message.source.exchangeId, '@Chief back', 2)
const third = await turnFor(sent, first, second)
- await answer(third.sessionId, third.message.source.exchangeId, '@Writer back', 3)
- const fourth = await turnFor(sent, first, second, third)
- await answer(fourth.sessionId, fourth.message.source.exchangeId, '@Editor two', 4)
- // Editor's second turn calls Writer a third time: Writer already spoke twice, so
- // the call is dropped. The log must say so, not show a hand-off that never starts.
- const fifth = await turnFor(sent, first, second, third, fourth)
- await answer(fifth.sessionId, fifth.message.source.exchangeId, '@Writer again', 5)
- await running
-
- const notices = rt.state.rooms[room.id].log.filter(line => line.kind === 'notice')
- assert.equal(notices.length, 1, 'one notice for the dropped call, not one per message')
- assert.deepEqual({ reason: notices[0].reason, names: notices[0].names, cap: notices[0].cap, admin: notices[0].admin },
- { reason: 'cap', names: ['Writer'], cap: 2, admin: rt.state.bots[rt.state.rooms[room.id].admin]?.name })
- assert.match(lineText(notices[0]), /@Writer was not called: this round's per-member turn limit \(2\) is reached/)
- // The round the user watched shows the same drop as one line of its replies.
+ // The next calls would be the third relay, past the limit: both wait instead of
+ // running, and the log does not show a hand-off that never starts.
+ await answer(third.sessionId, third.message.source.exchangeId, '@Writer again, @Editor too', 3)
const result = JSON.parse(await running)
- assert.deepEqual(result.replies.filter(reply => reply.kind === 'dropped').map(reply => [reply.names, reply.cap]), [[['Writer'], 2]])
- const writerSession = rt.state.rooms[room.id].sessions[writer.id]
- const writerTurns = sent.filter(entry => entry.sessionId === writerSession && entry.message.source.role === 'room')
- assert.equal(writerTurns.length, 2, 'Writer was called twice, and the third call never reached it')
+
+ const state = rt.state.rooms[room.id]
+ assert.equal(sent.filter(entry => entry.message.source.role === 'room').length, 3, 'the parked calls never reached their members')
+ const notices = state.log.filter(line => line.kind === 'notice')
+ assert.equal(notices.length, 1, 'one notice for the pause, not one per parked call')
+ assert.deepEqual({ reason: notices[0].reason, names: notices[0].names, limit: notices[0].limit },
+ { reason: 'paused', names: ['Writer', 'Editor'], limit: 2 })
+ assert.match(lineText(notices[0]), /Paused: Bots have called each other 2 times since the user last wrote here/)
+ assert.match(lineText(notices[0]), /@Writer and @Editor wait/)
+ // The round the user watched shows the same pause as one line of its replies —
+ // and nothing is marked dropped.
+ assert.deepEqual(result.replies.filter(reply => reply.kind === 'paused').map(reply => [reply.names, reply.count]),
+ [[['Writer', 'Editor'], 2]])
+ const saved = JSON.parse(readFileSync(join(home, 'state.json'), 'utf8')).rooms[room.id]
+ assert.deepEqual(saved.paused.map(entry => [entry.id, entry.name, entry.note, entry.by]),
+ [[writer.id, 'Writer', 'Chief mentioned you', chief], [editor.id, 'Editor', 'Chief mentioned you', chief]])
})
-test('the quiet mode past the late-round limit is told to the group once, and the user resets it', async (t) => {
- const { call, emit, userMessage, compose, relay, answer, stop, sent, rt } = start()
+test('Continue runs the parked calls in a round of their own, and a free group ignores it', async (t) => {
+ const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()
t.after(stop)
const room = await team(call, sent)
- await call('update-room', { id: room.id, mode: 'admin' })
- const chief = rt.state.mainBotIds[0]
+ await call('update-room', { id: room.id, mode: 'admin', relayLimit: 2 })
+ const writer = Object.values(rt.state.bots).find(bot => bot.name === 'Writer')
+ const state = rt.state.rooms[room.id]
+
+ // Nothing parked yet: Continue is a no-op and sends no relay.
+ sent.length = 0
+ await call('room-continue', { roomId: room.id })
+ assert.equal(sent.filter(entry => entry.message.source?.role === 'resume').length, 0)
- // One round, so the admin has a group Session to post from.
await emit(room.id, userMessage('Start'))
const running = relay(room.id, 'relay')
- const turn = await turnFor(sent)
- await answer(turn.sessionId, turn.message.source.exchangeId, 'Ready.', 1)
+ const first = await turnFor(sent)
+ await answer(first.sessionId, first.message.source.exchangeId, '@Writer one', 1)
+ const second = await turnFor(sent, first)
+ await answer(second.sessionId, second.message.source.exchangeId, '@Chief back', 2)
+ const third = await turnFor(sent, first, second)
+ await answer(third.sessionId, third.message.source.exchangeId, '@Writer again', 3)
await running
- const groupSession = rt.state.rooms[room.id].sessions[chief]
- const state = rt.state.rooms[room.id]
+ assert.equal(state.paused.length, 1)
+ assert.equal(state.paused[0].id, writer.id)
- // Late replies after work have reached the limit: the next post is quiet, and the
- // group hears why its @ names stop calling anybody.
- state.lateRounds = 10
+ // Continue: the count restarts and a resume relay runs the parked call.
sent.length = 0
- await rt.roomStepText(groupSession, {}, '@Writer still with me?', false)
- await waitFor(() => state.log.some(line => line.kind === 'notice'))
- const notices = state.log.filter(line => line.kind === 'notice')
- assert.equal(notices.length, 1, 'one notice when the limit is reached')
- assert.equal(notices[0].reason, 'quiet')
- assert.match(lineText(notices[0]), /quiet mode/)
- assert.match(lineText(notices[0]), /10-round limit/)
- assert.equal(state.lateRounds, 10, 'a quiet post does not push the count further')
- assert.equal(state.quietNoticed, true)
-
- // A second quiet post says nothing new.
- await rt.roomStepText(groupSession, {}, '@Writer again?', false)
- await waitFor(() => sent.length > 0)
- assert.equal(state.log.filter(line => line.kind === 'notice').length, 1, 'the notice is not repeated')
-
- // The user writes in the group: the count resets, so later posts call members again.
- await compose(room.id, 'carry on')
- const reset = relay(room.id, 'relay-2')
- const after = await turnFor(sent)
- await answer(after.sessionId, after.message.source.exchangeId, 'On it.', 2)
- await reset
- assert.equal(state.lateRounds, 0)
- assert.equal(state.quietNoticed, false)
-
- await rt.roomStepText(groupSession, {}, '@Writer one more', false)
- await waitFor(() => state.lateRounds === 1)
- assert.equal(state.log.filter(line => line.kind === 'notice').length, 1, 'no notice once the group talks again')
+ assert.equal((await call('room-continue', { roomId: room.id })).ok, true)
+ assert.equal(state.relays, 0)
+ const resume = sent.find(entry => entry.sessionId === room.id && entry.message.source?.role === 'resume')
+ assert.ok(resume, 'Continue sends a resume relay to the group Session')
+ await emit(room.id, { type: 'user/message', data: { source: resume.message.source, content: resume.message.content } })
+ const running2 = relay(room.id, 'relay-2')
+ const turn = await turnFor(sent)
+ assert.equal(turn.sessionId, state.sessions[writer.id], 'the parked call runs')
+ await answer(turn.sessionId, turn.message.source.exchangeId, 'Back on it.', 4)
+ await running2
+ assert.deepEqual(state.paused, [])
})
-test('the quiet mode names itself once in the replies the user sees', async (t) => {
+test('a user message after a pause answers the user first, then runs the parked call', async (t) => {
const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()
t.after(stop)
const room = await team(call, sent)
- await call('update-room', { id: room.id, mode: 'admin' })
+ await call('update-room', { id: room.id, mode: 'admin', relayLimit: 2 })
const chief = rt.state.mainBotIds[0]
+ const writer = Object.values(rt.state.bots).find(bot => bot.name === 'Writer')
+ const state = rt.state.rooms[room.id]
await emit(room.id, userMessage('Start'))
const running = relay(room.id, 'relay')
- const turn = await turnFor(sent)
- await answer(turn.sessionId, turn.message.source.exchangeId, 'Ready.', 1)
+ const first = await turnFor(sent)
+ await answer(first.sessionId, first.message.source.exchangeId, '@Writer one', 1)
+ const second = await turnFor(sent, first)
+ await answer(second.sessionId, second.message.source.exchangeId, '@Chief back', 2)
+ const third = await turnFor(sent, first, second)
+ await answer(third.sessionId, third.message.source.exchangeId, '@Writer again', 3)
await running
+ assert.equal(state.paused.length, 1)
+
+ sent.length = 0
+ await emit(room.id, userMessage('@Chief one more question'))
+ const next = relay(room.id, 'relay-2')
+ const own = await turnFor(sent)
+ assert.equal(own.sessionId, state.sessions[chief], 'the member the user called answers first')
+ await answer(own.sessionId, own.message.source.exchangeId, 'Yes?', 4)
+ const parked = await turnFor(sent, own)
+ assert.equal(parked.sessionId, state.sessions[writer.id], 'the parked call runs after the user\'s speaker')
+ await answer(parked.sessionId, parked.message.source.exchangeId, 'On it.', 5)
+ await next
+ assert.equal(state.relays, 1, 'the count restarted with the user\'s message; the parked call counts into it')
+ assert.deepEqual(state.paused, [])
+})
+
+test('a user message mid-round restarts the relay count for the calls after it', async (t) => {
+ const { call, emit, userMessage, compose, relay, answer, stop, sent, rt } = start()
+ t.after(stop)
+ const room = await team(call, sent)
+ await call('update-room', { id: room.id, mode: 'admin', relayLimit: 3 })
const state = rt.state.rooms[room.id]
- // In quiet mode — the notice already went to the log — a quiet post opens a round,
- // and the round's replies name the mode once.
- state.lateRounds = 10
- state.quietNoticed = true
- rt.roomInbox.set(room.id, [{ text: '@Writer still there?', botId: chief, late: true, quiet: true }])
- const first = JSON.parse(await relay(room.id, 'relay-2'))
- assert.equal(first.replies.filter(reply => reply.kind === 'quiet').length, 1)
- assert.equal(state.quietShown, true)
-
- // The next quiet post opens a round too, but the line is not drawn again.
- rt.roomInbox.set(room.id, [{ text: '@Writer?', botId: chief, late: true, quiet: true }])
- const second = JSON.parse(await relay(room.id, 'relay-3'))
- assert.equal(second.replies.filter(reply => reply.kind === 'quiet').length, 0)
-
- // The user writing in the group resets it: the next quiet stretch says it again.
- await emit(room.id, userMessage('carry on'))
- const third = relay(room.id, 'relay-4')
- const again = await turnFor(sent, turn)
- await answer(again.sessionId, again.message.source.exchangeId, 'On it.', 2)
- await third
- assert.equal(state.quietShown, false)
+ await emit(room.id, userMessage('Start'))
+ const running = relay(room.id, 'relay')
+ const first = await turnFor(sent)
+ await answer(first.sessionId, first.message.source.exchangeId, '@Writer one', 1)
+ const second = await turnFor(sent, first)
+ await answer(second.sessionId, second.message.source.exchangeId, '@Chief back', 2)
+ const third = await turnFor(sent, first, second)
+
+ // Two relays spent of three. While the admin answers, the user writes; its
+ // message restarts the count, so the call the Writer then makes does not park.
+ await compose(room.id, '@Writer hold on')
+ await answer(third.sessionId, third.message.source.exchangeId, 'Done.', 3)
+ const fourth = await turnFor(sent, first, second, third)
+ await answer(fourth.sessionId, fourth.message.source.exchangeId, '@Chief last', 4)
+ const fifth = await turnFor(sent, first, second, third, fourth)
+ assert.ok(fifth, 'the Writer\'s call runs: the count restarted at the user\'s message')
+ await answer(fifth.sessionId, fifth.message.source.exchangeId, 'All done.', 5)
+ const result = JSON.parse(await running)
+ assert.equal(result.replies.filter(reply => reply.kind === 'paused').length, 0)
+ assert.equal(state.relays, 1)
+})
+
+test('the relay limit is the user\'s to set, not a member\'s', async (t) => {
+ const { call, stop, rt } = start()
+ t.after(stop)
+ const writer = (await call('create-bot', { name: 'Writer' })).value
+ const chief = rt.state.mainBotIds[0]
+ const room = (await call('create-room', { name: 'R1', members: [chief, writer.id] })).value
+ // The group's admin and a Main Bot may change its other settings; the limit stays
+ // the user's. A plain member is refused earlier, like for any change.
+ await assert.rejects(rt.updateRoom(room.id, { relayLimit: 4 }, chief), /Only the user can set the relay limit of "R1"/)
+ await assert.rejects(rt.updateRoom(room.id, { relayLimit: 4 }, writer.id), /can change it/)
})
test('a member the reply timeout cut short is told to the group, not left as silence', async (t) => {
@@ -819,11 +883,11 @@ test('a member still at work is shown with the group messages it has not read ye
await second0
})
-test('a user message that opens a round resets the quiet notice, as a queued one does', async (t) => {
+test('a user message that opens a round restarts the relay count, as a queued one does', async (t) => {
const { call, emit, userMessage, relay, answer, stop, sent, rt } = start()
t.after(stop)
const room = await team(call, sent)
- await call('update-room', { id: room.id, mode: 'admin' })
+ await call('update-room', { id: room.id, mode: 'admin', relayLimit: 3 })
await emit(room.id, userMessage('Start'))
const first = relay(room.id, 'relay-1')
@@ -832,18 +896,17 @@ test('a user message that opens a round resets the quiet notice, as a queued one
await first
const state = rt.state.rooms[room.id]
- // The group has gone quiet, and it has been told so.
- state.lateRounds = 10
- state.quietNoticed = true
-
- // The user writes in the group. This message opens a round of its own, rather than
- // waiting in the inbox for one that is running, and the quiet notice has to reset
- // with the count: otherwise the group is told about quiet mode only once, ever.
+ // The Bot chain has already spent its relays. A message the user writes between
+ // rounds opens a round of its own rather than waiting in an inbox, and it has to
+ // restart the count there too.
+ state.relays = 3
await emit(room.id, userMessage('carry on'))
const second = relay(room.id, 'relay-2')
const again = await turnFor(sent, turn)
- await answer(again.sessionId, again.message.source.exchangeId, 'On it.', 2)
+ await answer(again.sessionId, again.message.source.exchangeId, '@Writer go', 2)
+ const writer = await turnFor(sent, turn, again)
+ assert.ok(writer, 'the call runs: the user\'s message restarted the count')
+ await answer(writer.sessionId, writer.message.source.exchangeId, 'On it.', 3)
await second
- assert.equal(state.lateRounds, 0)
- assert.equal(state.quietNoticed, false, 'the quiet notice can be told again later')
+ assert.equal(state.relays, 1)
})
diff --git a/ds-bot/test/tool-cells.test.js b/ds-bot/test/tool-cells.test.js
index fc0e761f..659eeb77 100644
--- a/ds-bot/test/tool-cells.test.js
+++ b/ds-bot/test/tool-cells.test.js
@@ -149,19 +149,29 @@ test('a user message inside a group relay shows its time', () => {
assert.deepEqual(times.map(node => node.props.title), [`Today ${clockOf(today)}`])
})
-// Drops the round kept silent about get a line the user sees: calls past the
-// per-member limit, and the group slipping into quiet mode.
-test('a dropped call and quiet mode show as event lines in the round', () => {
- const replies = [
- { kind: 'dropped', names: ['Writer', 'Coder'], cap: 2, time: at(0, 14, 5) },
- { kind: 'quiet', time: at(0, 14, 6) },
- ]
- const out = show(call('group_relay', 'direct', { content: { replies } }), { sessionId: 'room' })
- const events = findAll(out, node => node.props?.className === 'bt-event').map(text)
- assert.deepEqual(events, [
- 'Writer and Coder not called: the per-member limit for this round is reached',
- 'The group went quiet: @ mentions in late replies call nobody until you write here',
- ])
+// A group paused at its relay limit shows the wait, with a Continue button while
+// the room still parks calls — which calls room-continue with the group's id.
+test('a paused group shows the wait, and Continue releases it while calls are parked', () => {
+ const replies = [{ kind: 'paused', names: ['Writer', 'Coder'], count: 6, time: at(0, 14, 5) }]
+ const relay = call('group_relay', 'direct', { content: { replies } })
+
+ // Nothing parked on the room: the line stands alone, with no button.
+ const plain = show(relay, { sessionId: 'room' })
+ const events = findAll(plain, node => node.props?.className === 'bt-event').map(text)
+ assert.deepEqual(events, ['Paused after 6 Bot relays. Waiting: Writer and Coder'])
+ assert.equal(find(plain, node => node.type === 'button' && text(node) === 'Continue'), undefined)
+
+ const parked = { ...room, paused: [{ id: 'writer', name: 'Writer' }] }
+ const clicked = []
+ const live = show(relay, {
+ sessionId: 'room',
+ roster: team({ rooms: [parked], roomsById: { room: parked } }),
+ actions: { continueRoom: id => clicked.push(id) },
+ })
+ const button = find(live, node => node.type === 'button' && text(node) === 'Continue')
+ assert.ok(button, 'the Continue button is drawn while the room parks calls')
+ button.props.onClick()
+ assert.deepEqual(clicked, ['room'])
})
// The trigger of a post in a group chat carries the event's time, not the post's.