Skip to content

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

Drop a feed connection that stops reading

Fei24119ddebbb14740
diff --git a/ds-bot/src/host/feed.js b/ds-bot/src/host/feed.js
index 982a457e..98719a3f 100644
--- a/ds-bot/src/host/feed.js
+++ b/ds-bot/src/host/feed.js
@@ -11,6 +11,9 @@ export const FEED_ROUTE = `${ROUTE}/feed`
const KEEPALIVE_MS = 20_000
// Status changes come in bursts (a turn starts several Sessions); one notice covers them.
const LIVE_DELAY_MS = 150
+// A window that stops reading is dropped once this many events wait for it; it
+// reconnects and catches up from `hello`.
+const MAX_QUEUED = 512
export function install(rt) {
const { ctx, state } = rt
@@ -18,6 +21,10 @@ export function install(rt) {
/** @type {Set<ReadableStreamDefaultController<Uint8Array>>} */
const clients = new Set()
const send = (controller, chunk) => {
+ if ((controller.desiredSize ?? 0) < -MAX_QUEUED) {
+ leave(controller)
+ return
+ }
try { controller.enqueue(chunk) } catch { clients.delete(controller) }
}
const publish = (event, data) => {
diff --git a/ds-bot/test/feed.test.js b/ds-bot/test/feed.test.js
index 94639983..2ef7b4d1 100644
--- a/ds-bot/test/feed.test.js
+++ b/ds-bot/test/feed.test.js
@@ -122,6 +122,20 @@ test('the live feed tells a window about saves, new chat entries and the reply b
assert.equal(await next(), undefined)
})
+test('a window that stops reading the feed is dropped', { timeout: 10_000 }, async (t) => {
+ const { ctx, call, stop, routes } = start()
+ t.after(stop)
+ await call('state')
+ const response = await routes['/api/bot/feed'].fetch(new Request('http://localhost/api/bot/feed'))
+ const onEvent = ctx.listeners.get('session/event').at(-1)
+ for (let index = 0; index < 1000; index += 1) onEvent({ id: 'm1c' }, userMessage(`line ${index}`, index))
+ // What was queued before the drop still arrives, then the stream ends.
+ const next = reader(response)
+ let count = 0
+ while (await next() !== undefined) count += 1
+ assert.equal(count > 1 && count < 1000, true)
+})
+
test('the chat endpoint pages a Bot\'s own chat from the newest part back', async (t) => {
const record = (event, seq) => ({ event: { ...event, seq } })
const { call, stop } = start({