Skip to content

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

Settle a Session switch on a timer, not the next DOM batch

Fei24112a7e9e05bde4
diff --git a/ds-bot/client.js b/ds-bot/client.js
index 32c23474..2057b5f0 100644
--- a/ds-bot/client.js
+++ b/ds-bot/client.js
@@ -14309,7 +14309,7 @@ function DetailsDrawer({ sessionId, startRenaming, startTab, hasStrip, roster, a
{ className: "bt-drawer-top", "data-move": side },
bot || room2 ? (0, import_react37.createElement)("button", { type: "button", className: "bt-round", "aria-label": bot ? t("Edit Bot") : t("Group settings"), title: bot ? t("Edit Bot") : t("Group settings"), "data-info-row": "settings", onClick: () => setView("settings") }, (0, import_react37.createElement)(GearIcon)) : null,
bot && roster.browser === true && actions.openBrowser ? (0, import_react37.createElement)("button", { type: "button", className: "bt-round", "aria-label": t("Open browser"), title: t("Open this Bot's browser"), onClick: () => actions.openBrowser(sessionId) }, (0, import_react37.createElement)(GlobeIcon)) : null,
- bot || room2 ? actions.canOpenTerminal?.() ? (0, import_react37.createElement)("button", { type: "button", className: "bt-round", "data-info-row": "terminal", "aria-label": t("New terminal"), title: t("New terminal"), onClick: () => actions.newTerminal() }, (0, import_react37.createElement)(TerminalIcon)) : null : null,
+ (bot || room2) && actions.canOpenTerminal?.() ? (0, import_react37.createElement)("button", { type: "button", className: "bt-round", "data-info-row": "terminal", "aria-label": t("New terminal"), title: t("New terminal"), onClick: () => actions.newTerminal() }, (0, import_react37.createElement)(TerminalIcon)) : null,
bot || room2 ? (0, import_react37.createElement)("button", { type: "button", className: "bt-round", "aria-label": copied ? t("Copied conversation") : t("Share conversation"), title: copied ? t("Copied") : t("Copy conversation as Markdown"), onClick: share }, copied ? (0, import_react37.createElement)("span", { key: "copied", className: "bt-pop-in" }, "✓") : (0, import_react37.createElement)(ShareIcon)) : null,
hasStrip ? null : (0, import_react37.createElement)("button", { type: "button", className: "bt-round", "aria-label": t("Close details"), onClick: close }, (0, import_react37.createElement)(CloseIcon))
);
@@ -16188,6 +16188,20 @@ function columnOpened(drawerOpen, moved) {
if (!drawerOpen) return null;
return moved ? "collapse-column" : "close-drawer";
}
+function createSwitchWindow(settle) {
+ let token = null;
+ return {
+ moved() {
+ const self = token = {};
+ settle(() => {
+ if (token === self) token = null;
+ });
+ },
+ get pending() {
+ return token !== null;
+ }
+ };
+}
// src/client/user-message.js
var import_react40 = require("react");
@@ -16998,7 +17012,13 @@ function apply(ctx) {
const sidebar = ctx.get("sidebarRight");
if (!sidebar) return void 0;
let open = rightColumnOpen(document);
- let moved = false;
+ const switchWindow = createSwitchWindow((done) => {
+ const timer = setTimeout(done, 400);
+ requestAnimationFrame(() => requestAnimationFrame(() => {
+ clearTimeout(timer);
+ done();
+ }));
+ });
const collapseColumn = () => {
try {
if (sidebar.isExpanded()) sidebar.toggleExpanded();
@@ -17006,29 +17026,20 @@ function apply(ctx) {
actions.reportError(error, "right-sidebar");
}
};
- const observer = new MutationObserver((records) => {
- if (!records.some((record) => record.type === "attributes")) {
- moved = false;
- return;
- }
- const inSwitch = moved;
- moved = false;
+ const observer = new MutationObserver(() => {
const next = rightColumnOpen(document);
const opening = next && !open;
open = next;
- const verdict = opening ? columnOpened(ui2.getSnapshot().details !== null, inSwitch) : null;
+ const verdict = opening ? columnOpened(ui2.getSnapshot().details !== null, switchWindow.pending) : null;
if (verdict === "close-drawer") actions.closePanel();
else if (verdict === "collapse-column") collapseColumn();
});
observer.observe(document.documentElement, {
subtree: true,
- childList: true,
attributes: true,
attributeFilter: RIGHTBAR_ATTRIBUTES
});
- const offMounted = sidebar.mounted.subscribe(() => {
- moved = true;
- });
+ const offMounted = sidebar.mounted.subscribe(() => switchWindow.moved());
let drawer = ui2.getSnapshot().details !== null;
const offUi = ui2.subscribe(() => {
const next = ui2.getSnapshot().details !== null;
diff --git a/ds-bot/src/client/details-drawer.js b/ds-bot/src/client/details-drawer.js
index 0ca48d40..b222bc9a 100644
--- a/ds-bot/src/client/details-drawer.js
+++ b/ds-bot/src/client/details-drawer.js
@@ -223,9 +223,9 @@ export function DetailsDrawer({ sessionId, startRenaming, startTab, hasStrip, ro
bot && roster.browser === true && actions.openBrowser
? h('button', { type: 'button', className: 'bt-round', 'aria-label': t('Open browser'), title: t("Open this Bot's browser"), onClick: () => actions.openBrowser(sessionId) }, h(GlobeIcon))
: null,
- bot || room ? (actions.canOpenTerminal?.()
+ (bot || room) && actions.canOpenTerminal?.()
? h('button', { type: 'button', className: 'bt-round', 'data-info-row': 'terminal', 'aria-label': t('New terminal'), title: t('New terminal'), onClick: () => actions.newTerminal() }, h(TerminalIcon))
- : null) : null,
+ : null,
bot || room ? h('button', { type: 'button', className: 'bt-round', 'aria-label': copied ? t('Copied conversation') : t('Share conversation'), title: copied ? t('Copied') : t('Copy conversation as Markdown'), onClick: share }, copied ? h('span', { key: 'copied', className: 'bt-pop-in' }, '✓') : h(ShareIcon)) : null,
hasStrip ? null : h('button', { type: 'button', className: 'bt-round', 'aria-label': t('Close details'), onClick: close }, h(CloseIcon)))
if (!bot && !room) {
diff --git a/ds-bot/src/client/index.js b/ds-bot/src/client/index.js
index e28e0643..7468e032 100644
--- a/ds-bot/src/client/index.js
+++ b/ds-bot/src/client/index.js
@@ -33,7 +33,7 @@ import { noteLeft, setUnread, sharedMap, toggleReaction } from './shared-map.js'
import { freePriority, groupsFor, readMode, surfaceGroups, writeMode } from './surface.js'
import { installLocale, language, t } from './i18n.js'
import { noteClientError, quietly } from './diagnostics.js'
-import { RIGHTBAR_ATTRIBUTES, columnOpened, drawerOpened, rightColumnOpen } from './right-panel.js'
+import { RIGHTBAR_ATTRIBUTES, columnOpened, createSwitchWindow, drawerOpened, rightColumnOpen } from './right-panel.js'
import { ErrorToast, FEEDBACK_CSS } from './feedback.js'
import { ABOUT_CSS } from './about.js'
import { MEMBER_CSS, MemberDock } from './member-status.js'
@@ -647,15 +647,20 @@ export function apply(ctx) {
// The drawer and DSH's right column never share the window: whichever the
// user asked for last wins. The column's state is read off the frame's
// attributes through a MutationObserver. `mounted` moves before the DOM of a
- // Session switch does, so a switch is only marked; the next DOM batch settles
- // it — a batch that touches the column is the switch revealing that Session's
- // own column (the drawer wins and folds it back), while any other batch
- // clears the mark, so a later opening is the user's own (the column wins).
+ // Session switch does, so a switch opens a timed window (createSwitchWindow):
+ // an attribute batch inside it is the switch revealing that Session's own
+ // column — the drawer wins and folds it back — while one outside it is the
+ // user's own opening and takes the space.
ctx.effect(() => {
const sidebar = ctx.get('sidebarRight')
if (!sidebar) return undefined
let open = rightColumnOpen(document)
- let moved = false
+ // Two frames settle the switch's DOM; the fullscreen slide is slower, so a
+ // ~400 ms timer covers it and still ends the window where frames stall.
+ const switchWindow = createSwitchWindow((done) => {
+ const timer = setTimeout(done, 400)
+ requestAnimationFrame(() => requestAnimationFrame(() => { clearTimeout(timer); done() }))
+ })
const collapseColumn = () => {
try {
if (sidebar.isExpanded()) sidebar.toggleExpanded()
@@ -663,21 +668,18 @@ export function apply(ctx) {
actions.reportError(error, 'right-sidebar')
}
}
- const observer = new MutationObserver((records) => {
- if (!records.some(record => record.type === 'attributes')) { moved = false; return }
- const inSwitch = moved
- moved = false
+ const observer = new MutationObserver(() => {
const next = rightColumnOpen(document)
const opening = next && !open
open = next
- const verdict = opening ? columnOpened(ui.getSnapshot().details !== null, inSwitch) : null
+ const verdict = opening ? columnOpened(ui.getSnapshot().details !== null, switchWindow.pending) : null
if (verdict === 'close-drawer') actions.closePanel()
else if (verdict === 'collapse-column') collapseColumn()
})
observer.observe(document.documentElement, {
- subtree: true, childList: true, attributes: true, attributeFilter: RIGHTBAR_ATTRIBUTES,
+ subtree: true, attributes: true, attributeFilter: RIGHTBAR_ATTRIBUTES,
})
- const offMounted = sidebar.mounted.subscribe(() => { moved = true })
+ const offMounted = sidebar.mounted.subscribe(() => switchWindow.moved())
let drawer = ui.getSnapshot().details !== null
const offUi = ui.subscribe(() => {
const next = ui.getSnapshot().details !== null
diff --git a/ds-bot/src/client/right-panel.js b/ds-bot/src/client/right-panel.js
index cbf480ba..4bf91987 100644
--- a/ds-bot/src/client/right-panel.js
+++ b/ds-bot/src/client/right-panel.js
@@ -22,11 +22,29 @@ export function drawerOpened(columnOpen) {
return columnOpen ? 'collapse-column' : null
}
-// The column appeared. `moved` marks a Session switch whose DOM has not settled
-// (mounted moves before the DOM that follows it), so the opening is that
-// Session's own column and the drawer wins; an unmoved opening is the user's
-// own — a file link, a subagent, a shortcut — and takes the space.
+// The column appeared. `moved` marks a Session switch still inside its window
+// (see below), so the opening is that Session's own column and the drawer wins;
+// an unmoved opening is the user's own — a file link, a subagent, a shortcut —
+// and takes the space.
export function columnOpened(drawerOpen, moved) {
if (!drawerOpen) return null
return moved ? 'collapse-column' : 'close-drawer'
}
+
+// A Session switch moves `mounted` well before the DOM that follows it: a seat
+// whose store is not minted yet opens in a passive effect, and a fullscreen
+// panel reports only after its slide, so the attribute flip can land several
+// batches later. The switch is therefore a timed window, not the next DOM
+// batch — `settle(done)` calls `done` once the switch settled (two frames, with
+// a timer for the slide and for hidden tabs whose frames do not run). A newer
+// `moved()` restarts the window; a stale settle is ignored.
+export function createSwitchWindow(settle) {
+ let token = null
+ return {
+ moved() {
+ const self = token = {}
+ settle(() => { if (token === self) token = null })
+ },
+ get pending() { return token !== null },
+ }
+}
diff --git a/ds-bot/test/right-panel.test.js b/ds-bot/test/right-panel.test.js
index 5106f260..ad1bd5dc 100644
--- a/ds-bot/test/right-panel.test.js
+++ b/ds-bot/test/right-panel.test.js
@@ -5,7 +5,7 @@ import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { runInNewContext } from 'node:vm'
import { build } from 'esbuild'
-import { columnOpened, drawerOpened, rightColumnOpen } from '../src/client/right-panel.js'
+import { columnOpened, createSwitchWindow, drawerOpened, rightColumnOpen } from '../src/client/right-panel.js'
// jsdom comes from the harness that test/harness-resolve.mjs found, like the dsh packages.
const PLUGIN = dirname(dirname(fileURLToPath(import.meta.url)))
@@ -43,6 +43,33 @@ test('with no drawer open the column opens on its own', () => {
assert.equal(columnOpened(false, true), null)
})
+// The switch window holds "the Session moved" until `settle` calls back: inside
+// it a column opening is the switch revealing that Session's own column, past
+// it the user's own. A newer move restarts it and a stale settle is ignored.
+test('the switch window steers the verdict while it is open', () => {
+ const ends = []
+ const window = createSwitchWindow(done => ends.push(done))
+ assert.equal(window.pending, false)
+ window.moved()
+ assert.equal(window.pending, true)
+ assert.equal(columnOpened(true, window.pending), 'collapse-column')
+ ends[0]()
+ assert.equal(window.pending, false)
+ assert.equal(columnOpened(true, window.pending), 'close-drawer')
+})
+
+test('a newer Session switch restarts the window and the old settle is stale', () => {
+ const ends = []
+ const window = createSwitchWindow(done => ends.push(done))
+ window.moved()
+ window.moved()
+ ends[0]()
+ assert.equal(window.pending, true)
+ assert.equal(columnOpened(true, window.pending), 'collapse-column')
+ ends[1]()
+ assert.equal(window.pending, false)
+})
+
// The drawer's top row, bundled once and run with a minimal React stand-in; the
// row's components are vnodes, so only the drawer's own body runs.
const bundle = await build({