Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(shared-computers): a computer whose person changed is no longer lent to its former person
Bugfixer 2fbf187e8b6f7
diff --git a/server/shared-computers.test.ts b/server/shared-computers.test.tsindex a3270dcb26..05f6389711 100644--- a/server/shared-computers.test.ts+++ b/server/shared-computers.test.ts@@ -29,6 +29,17 @@ describe("shared computer authority and lifecycle", () => {expect(broker.list("p_lender").map(entry => entry.id)).toEqual([computer.id]);broker.close();});+ it("a computer whose person changed is no longer lent to its former person", () => {+ const dir = mkdtempSync(join(tmpdir(), "omb-lent-rekey-"));+ const lent = new LentComputers(join(dir, "lent.json"));+ const broker = new SharedComputers(id => id === "owner", lent);+ const computer = registration(); broker.register(computer, alice, secret);+ broker.register(computer, { session: alice.session, person: "p_lender" }, secret);+ expect(lent.list(alice.person).map(record => [record.id, record.stoppedAt !== null])).toEqual([[computer.id, true]]);+ expect(lent.list("p_lender").map(record => [record.id, record.stoppedAt])).toEqual([[computer.id, null]]);+ broker.close();+ rmSync(dir, { recursive: true, force: true });+ });it("a poll from a session that is now someone else drops the computer so it connects again", async () => {const broker = new SharedComputers(id => id === "owner");const computer = registration(); broker.register(computer, alice, secret);diff --git a/server/shared-computers.ts b/server/shared-computers.tsindex 1f94886e69..6c1fbd8fdd 100644--- a/server/shared-computers.ts+++ b/server/shared-computers.ts@@ -182,6 +182,8 @@ export class SharedComputers {this.changed();return;}+ // Its person changed: the former person's record of it is no longer lent, not merely away.+ if (old) this.lent?.stopped(old.owner.person, registration.id);this.reap();// A new id from the same session replaces its entry; no other session can reach, replace or squat this key.for (const [stale, entry] of this.computers) {