Skip to content

An open-source, faster Devin alternative

TypeScript

managed-agents: recover a session log the host never wrote (#1081)

opencomputer-app[bot]ed8935980fad
diff --git a/services/managed-agents/src/computer/session-log.ts b/services/managed-agents/src/computer/session-log.ts
index 8ad400cf..2ed99979 100644
--- a/services/managed-agents/src/computer/session-log.ts
+++ b/services/managed-agents/src/computer/session-log.ts
@@ -364,7 +364,9 @@ export class SessionLogDurableObject extends DurableObject<SessionLogEnv> implem
return this.exclusive(async (): Promise<RecoverResult> => {
this.claim(input);
const m = this.meta;
- if (input.epoch !== m.logEpoch + 1) return { ok: false, reason: "stale_epoch", logEpoch: m.logEpoch, ack: m.ack };
+ // Any newer epoch, not only logEpoch + 1: a log the host never wrote is at 0 while its row starts at 1,
+ // so the recover comes at 2. A lagging row's recover (epoch <= logEpoch) is still refused.
+ if (input.epoch <= m.logEpoch) return { ok: false, reason: "stale_epoch", logEpoch: m.logEpoch, ack: m.ack };
const result = await this.store(input.epoch, this.recoveryEvents(input));
return result.ok ? { ...result, tail: await this.tailOf() } : result;
});
diff --git a/services/managed-agents/test/session-log.test.ts b/services/managed-agents/test/session-log.test.ts
index bfe7a5fb..483ee623 100644
--- a/services/managed-agents/test/session-log.test.ts
+++ b/services/managed-agents/test/session-log.test.ts
@@ -220,7 +220,7 @@ describe("SessionLog recover", () => {
const log = open();
await log.stub.append(log.identity, 1, busyLog(log));
const at = "2026-10-26T10:00:00.000Z";
- expect(await log.stub.recover({ ...log.identity, epoch: 3, at })).toMatchObject({ ok: false, reason: "stale_epoch", logEpoch: 1 });
+ expect(await log.stub.recover({ ...log.identity, epoch: 1, at })).toMatchObject({ ok: false, reason: "stale_epoch", logEpoch: 1 });
const result = await log.stub.recover({ ...log.identity, epoch: 2, at });
expect(result).toMatchObject({ ok: true, ack: 13 });
@@ -270,6 +270,17 @@ describe("SessionLog recover", () => {
expect(await log.stub.append(log.identity, 1, [log.ev(15, "x.y", null, {})])).toMatchObject({ ok: false, reason: "stale_epoch", logEpoch: 3 });
});
+ it("recovers a log the host never wrote, at the row's next epoch", async () => {
+ // A new row is at epoch 1 but its log is at 0 until the host's first append, so the recover comes at 2.
+ const log = open();
+ const result = await log.stub.recover({ ...log.identity, epoch: 2, at: "2026-10-26T10:00:00.000Z" });
+ expect(result).toMatchObject({ ok: true, summary: { logEpoch: 2, status: "suspended" } });
+ // Settled: the same recover again is refused, and so is the lost writer at the row's old epoch.
+ expect(await log.stub.recover({ ...log.identity, epoch: 2, at: "2026-10-26T10:00:00.000Z" })).toMatchObject({ ok: false, reason: "stale_epoch", logEpoch: 2 });
+ if (!result.ok) throw new Error("refused");
+ expect(await log.stub.append(log.identity, 1, [log.ev(result.ack + 1, "x.y", null, {})])).toMatchObject({ ok: false, reason: "stale_epoch", logEpoch: 2 });
+ });
+
it("with nothing open records the suspension only", async () => {
const log = open();
await log.stub.append(log.identity, 1, busyLog(log).slice(0, 2));