Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Sign-in resume: the app's sign-in and the status read that finds it are one sign-in, whichever comes first
laijsg1d5bdbd7ef564
diff --git a/server/harness/registry.test.ts b/server/harness/registry.test.tsindex 35ea075364..ae98e1a86c 100644--- a/server/harness/registry.test.ts+++ b/server/harness/registry.test.ts@@ -244,9 +244,10 @@ describe("ProviderRegistry", () => {};await read();authenticated = true;- registry.sawSignedIn("a");+ expect(registry.sawSignedIn("a"), "no read had found it signed in yet").toBe(false);await read();expect(heard, "the app told this sign-in itself").toEqual([]);+ expect(registry.sawSignedIn("a"), "the app reporting it again is the same sign-in").toBe(true);authenticated = false;await read();await registry.dispose("a");diff --git a/server/harness/registry.ts b/server/harness/registry.tsindex da8421352d..2ebc6dfe77 100644--- a/server/harness/registry.ts+++ b/server/harness/registry.ts@@ -655,9 +655,12 @@ export class ProviderRegistry {this.signedInListeners.add(listener);}- /** A sign-in the app made and has already told: the next read that finds it signed in tells nothing new. */- sawSignedIn(instanceId: InstanceId): void {+ /** A sign-in the app made and tells itself: the next read that finds it signed in tells nothing new. True when a read+ * had already found it signed in, so it was told then. */+ sawSignedIn(instanceId: InstanceId): boolean {+ const known = this.lastAuth.get(instanceId)?.authenticated === true;this.lastAuth.set(instanceId, { authenticated: true, read: ++this.readsBegun });+ return known;}private saveStatus(): void {diff --git a/server/host/sign-in-resume.test.ts b/server/host/sign-in-resume.test.tsindex 1b5d8dcdab..e35fccb5ca 100644--- a/server/host/sign-in-resume.test.ts+++ b/server/host/sign-in-resume.test.ts@@ -5,7 +5,7 @@ import { afterEach, describe, expect, it, vi } from "vitest";import type { ModelSelection } from "../../shared/wire.ts";import type { Message } from "../store.ts";-import { createSignInResume, RECHECK_MS, RECHECKS_UNANSWERED, RESUME_WINDOW_MS, type SignInResumeDeps, type SignInWait } from "./sign-in-resume.ts";+import { createSignInResume, createSignInResumeHost, RECHECK_MS, RECHECKS_UNANSWERED, RESUME_WINDOW_MS, type SignInResumeDeps, type SignInWait } from "./sign-in-resume.ts";const claude: ModelSelection = { instanceId: "claude", model: "sonnet" };const scratch: string[] = [];@@ -415,6 +415,41 @@ describe("createSignInResume", () => {expect(() => createSignInResume(w.deps)).not.toThrow();});+ it("takes the app's own report of a sign-in the status read already found for the same sign-in", async () => {+ const directory = mkdtempSync(join(tmpdir(), "omb-sign-in-resume-"));+ scratch.push(directory);+ const w = world();+ let readSignedIn = false;+ const listeners: Array<(instanceId: string) => void> = [];+ const instance = { snapshot: async () => ({ state: "available" as const, authenticated: true }) };+ const takeover = { signedIn: vi.fn() };+ const host = createSignInResumeHost({+ ...w.deps, dataDir: directory, takeover, startupRead: null,+ registry: {+ forgetSnapshots: () => {},+ get: () => instance as never,+ onSignedIn: (listener) => { listeners.push(listener); },+ sawSignedIn: () => { const known = readSignedIn; readSignedIn = true; return known; },+ },+ startTurn: async (_botId, text, opts) => { w.sent.push({ wait: { threadId: opts.threadId } as SignInWait, message: { text } as Message }); },+ replyTarget: () => undefined,+ });+ const kai = w.stuck("t-kai");+ host.waiting(kai.wait);+ w.tick(10);+ readSignedIn = true;+ listeners.forEach((listener) => listener("claude"));+ await vi.waitFor(() => expect(w.sent).toHaveLength(1));+ w.tick(5);+ const resent = w.row("t-kai", { role: "user", kind: "text", text: "Draft the plan" });+ await host.waiting({ ...kai.wait, messageId: resent.id, failedAt: 1_015 });+ w.tick(10);+ host.appSignedIn("claude");+ await new Promise((resolve) => setTimeout(resolve, 10));+ expect(w.sent, "the app's report is the sign-in the status read already found").toHaveLength(1);+ expect(takeover.signedIn).toHaveBeenCalledTimes(2);+ });+it("after a restart, asks the AI once and sends what was left waiting", async () => {const directory = mkdtempSync(join(tmpdir(), "omb-sign-in-resume-"));scratch.push(directory);diff --git a/server/host/sign-in-resume.ts b/server/host/sign-in-resume.tsindex 0922281f38..6c83caee78 100644--- a/server/host/sign-in-resume.ts+++ b/server/host/sign-in-resume.ts@@ -279,10 +279,10 @@ export function createSignInResumeHost(deps: Omit<SignInResumeDeps, "file" | "si};registry.onSignedIn(signedIn);void Promise.resolve(deps.startupRead).then(() => resume.resumeSaved());- /** A sign-in made in the app: the status read that later finds it is the same sign-in, not another. */+ /** A sign-in made in the app is one sign-in with the status read that finds it, whichever comes first. */const appSignedIn = (instanceId: string): void => {- registry.sawSignedIn(instanceId);- signedIn(instanceId);+ if (registry.sawSignedIn(instanceId)) deps.takeover.signedIn(instanceId);+ else signedIn(instanceId);};return { ...resume, signedIn, appSignedIn };}