Skip to content

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

Restart the activity row when a queued message is steered

Fei24117f7de4de0b7d
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 0c7d9bf8..14f2ed76 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -8049,6 +8049,11 @@ var import_react_dom2 = require("react-dom");
var PHRASE_HOLD_MS = 800;
var drawPhrase = (pool) => t(pool[Math.min(pool.length - 1, Math.floor(Math.random() * pool.length))]);
var rowVisible = ({ running, streaming, tools, relaying, bot, room: room2 }) => running && (!streaming || tools.length > 0) && !relaying && (bot !== void 0 || room2 !== void 0);
+var freshInputAt = (submissions, steeredAt) => Math.max(
+ 0,
+ steeredAt ?? 0,
+ ...(submissions ?? []).filter((sub) => sub.placement !== "queued").map((sub) => sub.time)
+);
var mountMissed = false;
function findHost() {
const node = document.querySelector("[data-chat-flow] [data-chat-running]") ?? document.querySelector("[data-chat-flow]");
@@ -8140,7 +8145,8 @@ function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useLive, us
if (!running) runAt.current = 0;
else if (runAt.current === 0) runAt.current = Date.now();
const liveKey = useLive((state) => JSON.stringify(state[sessionId] ?? {}));
- const pendingInput = useSession((snapshot) => Math.max(0, ...(snapshot?.pendingSubmissions ?? []).filter((sub) => sub.placement !== "queued").map((sub) => sub.time)));
+ const steeredAt = useWork?.((work) => work.steered?.[sessionId]);
+ const pendingInput = useSession((snapshot) => freshInputAt(snapshot?.pendingSubmissions, steeredAt));
const bot = roster.byId[sessionId];
const room2 = roster.roomsById[sessionId];
const moveAt = useWork?.((work) => {
diff --git a/ds-bot/src/client/activity-row.js b/ds-bot/src/client/activity-row.js
index cfaf6c9e..dcc75ce6 100644
--- a/ds-bot/src/client/activity-row.js
+++ b/ds-bot/src/client/activity-row.js
@@ -20,6 +20,11 @@ export { reducedMotion }
export const rowVisible = ({ running, streaming, tools, relaying, bot, room }) =>
running && (!streaming || tools.length > 0) && !relaying && (bot !== undefined || room !== undefined)
+// A queued message waits for the next turn, so only a transcript or steering
+// send counts as fresh input; a steer the host saw counts from when it landed.
+export const freshInputAt = (submissions, steeredAt) => Math.max(0, steeredAt ?? 0,
+ ...(submissions ?? []).filter(sub => sub.placement !== 'queued').map(sub => sub.time))
+
// The shell's running slot can sit under wrappers it adds around the flow, so the
// search is a descendant one; without the slot the row mounts at the flow's tail.
// No flow at all is a mount failure, noted once per page — the observer keeps
@@ -108,10 +113,8 @@ export function ActivityIndicator({ sessionId, useRoster, useSessionStatus, useL
if (!running) runAt.current = 0
else if (runAt.current === 0) runAt.current = Date.now()
const liveKey = useLive(state => JSON.stringify(state[sessionId] ?? {}))
- // A queued message waits for the next turn, so only a transcript or steering
- // send counts as fresh input.
- const pendingInput = useSession(snapshot => Math.max(0, ...(snapshot?.pendingSubmissions ?? [])
- .filter(sub => sub.placement !== 'queued').map(sub => sub.time)))
+ const steeredAt = useWork?.(work => work.steered?.[sessionId])
+ const pendingInput = useSession(snapshot => freshInputAt(snapshot?.pendingSubmissions, steeredAt))
const bot = roster.byId[sessionId]
const room = roster.roomsById[sessionId]
// The one switch the row names: a working-folder move jumps the chat to a fresh
diff --git a/ds-bot/src/host/channel.js b/ds-bot/src/host/channel.js
index 83064f3f..fb0e58c8 100644
--- a/ds-bot/src/host/channel.js
+++ b/ds-bot/src/host/channel.js
@@ -87,7 +87,7 @@ export function install(rt) {
// and per Session, when its running turn began.
const live = () => ({
activity: rt.activityView(),
- work: { bots: rt.workView(), rooms: rt.roomWorkView(), approvals: rt.approvalsView(), waiting: rt.waitingView?.() ?? {}, turns: rt.turnsView?.() ?? {} },
+ work: { bots: rt.workView(), rooms: rt.roomWorkView(), approvals: rt.approvalsView(), waiting: rt.waitingView?.() ?? {}, turns: rt.turnsView?.() ?? {}, steered: rt.steeredView?.() ?? {} },
memoryNews: rt.memoryNews(),
memoryReviews: rt.memoryReviews(),
connectors: rt.connectorsView(),
diff --git a/ds-bot/src/host/turns.js b/ds-bot/src/host/turns.js
index a0e31295..9e563b71 100644
--- a/ds-bot/src/host/turns.js
+++ b/ds-bot/src/host/turns.js
@@ -309,6 +309,12 @@ export function install(rt) {
.filter(([, entry]) => entry.turn !== undefined && entry.since !== undefined)
.map(([id, entry]) => [id, entry.since]))
+ // Per Session, when the user last steered its running turn: the input the
+ // activity row's phrase and clock restart from.
+ const steeredView = () => Object.fromEntries([...live]
+ .filter(([, entry]) => entry.turn !== undefined && entry.steeredAt !== undefined)
+ .map(([id, entry]) => [id, entry.steeredAt]))
+
// Per group, the members whose turn there is running or who move on to a fresh part;
// the round's current speaker is marked, since its round shows it.
const roomWorkView = () => {
@@ -401,6 +407,7 @@ export function install(rt) {
entry.opened = false
entry.joined = []
entry.later = []
+ entry.steeredAt = undefined
if (entry.pending !== undefined) {
claimTrigger(id, entry, entry.pending)
entry.pending = undefined
@@ -507,6 +514,14 @@ export function install(rt) {
}
break
}
+ case 'agent/inbox/spliced':
+ // A message the user steered into the running turn is fresh input, like
+ // a send that never queued.
+ if (event.data?.target === 'next-step' && entry.turn !== undefined
+ && (event.data.inserted ?? []).some(message => message?.source?.kind === 'user')) {
+ entry.steeredAt = event.time ?? Date.now()
+ }
+ break
case 'assistant/message': {
const content = event.data?.message?.content
const text = textOf(content)
@@ -539,6 +554,7 @@ export function install(rt) {
entry.switched = false
entry.joined = []
entry.since = undefined
+ entry.steeredAt = undefined
entry.tool = undefined
entry.calls = undefined
entry.lastText = undefined
@@ -650,5 +666,5 @@ export function install(rt) {
}
})
- Object.assign(rt, { live, liveOf, roomWaiters, roomProgress, roomInbox, activityView, workView, roomWorkView, turnsView, callDetail, doingOf, stopRoomTurn, releaseBot })
+ Object.assign(rt, { live, liveOf, roomWaiters, roomProgress, roomInbox, activityView, workView, roomWorkView, turnsView, steeredView, callDetail, doingOf, stopRoomTurn, releaseBot })
}
diff --git a/ds-bot/test/activity-row.test.js b/ds-bot/test/activity-row.test.js
index ba280329..17700163 100644
--- a/ds-bot/test/activity-row.test.js
+++ b/ds-bot/test/activity-row.test.js
@@ -15,7 +15,7 @@ const { JSDOM } = createRequire(join(process.env.DSH_HARNESS ?? join(PLUGIN, '..
const { outputFiles } = await build({
stdin: {
contents: [
- "export { findHost, rowVisible } from './src/client/activity-row.js'",
+ "export { findHost, rowVisible, freshInputAt } from './src/client/activity-row.js'",
"export { clientErrors } from './src/client/diagnostics.js'",
].join('\n'),
resolveDir: PLUGIN,
@@ -39,7 +39,7 @@ runInNewContext(outputFiles[0].text, {
cancelAnimationFrame: id => clearTimeout(id),
require: name => (name === 'react' ? react : name === 'react-dom' ? { createPortal: node => node } : {}),
})
-const { findHost, rowVisible, clientErrors } = module.exports
+const { findHost, rowVisible, freshInputAt, clientErrors } = module.exports
test('the activity row mounts at the running slot even under an extra wrapper', () => {
dom.window.document.body.innerHTML = '<div data-chat-flow><div class="wrap"><div data-chat-running id="slot"></div></div></div>'
@@ -80,3 +80,19 @@ test('the row shows while a turn runs, also when text streamed before a tool', (
]
for (const [input, expected] of cases) assert.equal(rowVisible(input), expected, JSON.stringify(input))
})
+
+// A queued message waits for the next turn; a transcript or steering send counts
+// as fresh input, and a steer the host saw counts from when it landed.
+test('fresh input ignores queued sends and takes the newest of the rest', () => {
+ const submissions = [
+ { placement: 'queued', time: 300 },
+ { placement: 'steering', time: 100 },
+ { placement: 'transcript', time: 200 },
+ ]
+ assert.equal(freshInputAt(submissions, undefined), 200)
+ assert.equal(freshInputAt(submissions, 400), 400)
+ assert.equal(freshInputAt(submissions, 50), 200)
+ assert.equal(freshInputAt([{ placement: 'queued', time: 300 }], undefined), 0)
+ assert.equal(freshInputAt(undefined, 400), 400)
+ assert.equal(freshInputAt([], undefined), 0)
+})
diff --git a/ds-bot/test/bot-messages.test.js b/ds-bot/test/bot-messages.test.js
index b7afecc0..d6ba13fd 100644
--- a/ds-bot/test/bot-messages.test.js
+++ b/ds-bot/test/bot-messages.test.js
@@ -90,9 +90,9 @@ async function start(seed) {
}
apply(ctx, { home })
let seq = 0
- const emit = (id, type, data) => {
+ const emit = (id, type, data, extra) => {
for (const listener of ctx.listeners.get('session/event') ?? []) {
- if (listener.length >= 2) listener({ id }, { type, seq: ++seq, data })
+ if (listener.length >= 2) listener({ id }, { type, seq: ++seq, data, ...extra })
}
}
// Runs every registered waterfall listener; `next` settles the chain.
@@ -197,6 +197,35 @@ test('a request steered into a running turn is recorded once and answered in a t
assert.deepEqual((await exchanges()).map(entry => entry.role), ['request', 'reply'])
})
+// Issue #580: a queued message the user steers into the running turn restarts
+// the activity row's clock from when it landed, not from the turn's start.
+test('a user message steered into the running steps marks when it landed', async (t) => {
+ const { emit, call, stop } = await start(team())
+ t.after(stop)
+ const steered = async () => (await call('state', {})).value.work.steered ?? {}
+ const userMessage = id => ({ id, role: 'user', content: textBlock('还没好吗'), source: { kind: 'user' } })
+ const spliced = (target, inserted, time, extra = {}) => emit('b', 'agent/inbox/spliced', { target, start: 0, inserted, ...extra }, { time })
+
+ emit('b', 'turn/start', { turn: 1 })
+ // Queued for the next turn first; only moving it into the running steps steers.
+ spliced('next-turn', [userMessage('m1')], 2000)
+ assert.deepEqual(await steered(), {})
+ spliced('next-turn', [], 3000, { removedCount: 1, outcome: 'canceled' })
+ spliced('next-step', [userMessage('m1')], 3001)
+ assert.equal((await steered()).b, 3001)
+ // A Bot's request spliced into the same place is not the user's input.
+ spliced('next-step', [{ ...userMessage('m2'), source: replySource('request') }], 4000)
+ assert.equal((await steered()).b, 3001)
+ emit('b', 'turn/end', { turn: 1, reason: { kind: 'completed' } })
+ assert.deepEqual(await steered(), {})
+
+ // A turn a part switch cut short may see turn/start without a turn/end.
+ emit('b', 'turn/start', { turn: 2 })
+ spliced('next-step', [userMessage('m3')], 5000)
+ emit('b', 'turn/start', { turn: 3 })
+ assert.deepEqual(await steered(), {})
+})
+
test('a request from a name with brackets keeps its body when replayed after the current work', async (t) => {
const seed = team()
seed.bots.a.name = 'R]2'