Skip to content

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

Keep a failed migration write from poisoning load()

lulu feizhu5de5d689ee0a
diff --git a/ds-bot/src/host/store.js b/ds-bot/src/host/store.js
index 1cea5ddf..9bd6e596 100644
--- a/ds-bot/src/host/store.js
+++ b/ds-bot/src/host/store.js
@@ -161,7 +161,15 @@ export function install(rt) {
if (holder !== undefined) warn('ds-bot: %s', readOnly())
const { migrated, stale } = adopt(await readFileState())
if (holder !== undefined) return
- if (migrated && stuck === undefined && lockError === undefined) await save()
+ if (migrated && stuck === undefined && lockError === undefined) {
+ // A failed write must not poison `loaded`: the migrated state stays in
+ // memory and the next save() writes it.
+ try {
+ await save()
+ } catch (error) {
+ warn('ds-bot: saving the migrated Bot team failed: %s', error)
+ }
+ }
// Not awaited: renaming a session must not hold up the first roster read.
for (const room of stale) void rt.retitleRoom(room)
})()
diff --git a/ds-bot/test/store.test.js b/ds-bot/test/store.test.js
index 44176c18..8c7f9ac7 100644
--- a/ds-bot/test/store.test.js
+++ b/ds-bot/test/store.test.js
@@ -72,6 +72,21 @@ test('a failed state write rejects and leaves the saved file unchanged', async (
assert.deepEqual(fs.readFileSync(statePath), original)
})
+test('a failed migration write warns but load() still resolves', async (t) => {
+ const { rt, statePath, warnings } = runtime(t, { version: 1, mainBotId: 'chief', bots: { chief: { id: 'chief', name: 'Chief' } } })
+ // The migrated team's first write fails: a directory takes the temp file's path.
+ fs.mkdirSync(`${statePath}.${process.pid}.tmp`)
+ await rt.load()
+ assert.equal(rt.readOnly(), undefined)
+ assert.ok(warnings.some(args => /saving the migrated Bot team failed/.test(String(args))))
+ // Once the disk is free the next save() writes the migrated state.
+ fs.rmSync(`${statePath}.${process.pid}.tmp`, { recursive: true })
+ await rt.save()
+ const saved = JSON.parse(fs.readFileSync(statePath, 'utf8'))
+ assert.equal(saved.mainBotId, undefined)
+ assert.ok(saved.mainBotIds.includes('chief'))
+})
+
test('a failed state rename rejects and preserves the saved file', async (t) => {
const { rt, statePath } = runtime(t)
await rt.load()