Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(cli): stop removing workspaces from config on 401

Genera2e69ec55ef2
diff --git a/src/cli/daemon/daemon.test.ts b/src/cli/daemon/daemon.test.ts
index 17b832ad0..5d70c3c9a 100644
--- a/src/cli/daemon/daemon.test.ts
+++ b/src/cli/daemon/daemon.test.ts
@@ -1208,6 +1208,75 @@ describe("daemon workspace eviction", () => {
});
});
+describe("daemon 401 handling (no config removal)", () => {
+ beforeEach(() => {
+ signalHandlers.clear();
+ intervalTimers.length = 0;
+ clearedTimers.length = 0;
+ spawnedChildren.length = 0;
+ nextPid = 50000;
+ vi.clearAllMocks();
+ mockProcessExit.mockImplementation((() => {}) as any);
+ });
+
+ afterEach(() => {
+ for (const t of intervalTimers) realClearInterval(t);
+ });
+
+ it("does not remove workspace from config on startup 401", async () => {
+ vi.mocked(loadCLIConfigForProfile).mockReturnValue({
+ server_url: "",
+ watched_workspaces: [
+ { id: "ws1", name: "Good", token: "al_tok_ws1" },
+ { id: "ws2", name: "Bad Token", token: "al_tok_ws2" },
+ ],
+ });
+
+ mockClientInstance.register.mockImplementation(async (token: string) => {
+ if (token === "al_tok_ws2") throw new Error("HTTP 401 Unauthorized");
+ return { runtimes: [{ id: "rt1" }] };
+ });
+ mockClientInstance.poll.mockResolvedValue({ tasks: [], evicted: false });
+
+ await startDaemon();
+ await new Promise((r) => setTimeout(r, 50));
+
+ // Config should NOT have been saved to remove ws2
+ expect(saveCLIConfigForProfile).not.toHaveBeenCalled();
+ // Daemon should still be running (ws1 registered successfully)
+ expect(mockProcessExit).not.toHaveBeenCalled();
+ });
+
+ it("does not evict workspace on poll 401, continues polling", async () => {
+ vi.mocked(loadCLIConfigForProfile).mockReturnValue({
+ server_url: "",
+ watched_workspaces: [
+ { id: "ws1", name: "Personal", token: "al_tok_ws1" },
+ { id: "ws2", name: "Team", token: "al_tok_ws2" },
+ ],
+ });
+
+ let registerCall = 0;
+ mockClientInstance.register.mockImplementation(async () => {
+ registerCall++;
+ return { runtimes: [{ id: `rt${registerCall}` }] };
+ });
+
+ mockClientInstance.poll.mockImplementation(async (token: string) => {
+ if (token === "al_tok_ws2") throw new Error("HTTP 401 Unauthorized");
+ return { tasks: [], evicted: false };
+ });
+
+ await startDaemon();
+ await new Promise((r) => setTimeout(r, 50));
+
+ // Config should NOT have been saved (no eviction)
+ expect(saveCLIConfigForProfile).not.toHaveBeenCalled();
+ // Daemon should NOT shut down — ws1 still active, ws2 just had a transient 401
+ expect(mockProcessExit).not.toHaveBeenCalled();
+ });
+});
+
describe("daemon restart via update", () => {
it("handleCliUpdate is called when pending_update is in poll response", async () => {
vi.clearAllMocks();
diff --git a/src/cli/daemon/daemon.ts b/src/cli/daemon/daemon.ts
index 42a0ec269..f78769736 100644
--- a/src/cli/daemon/daemon.ts
+++ b/src/cli/daemon/daemon.ts
@@ -185,16 +185,7 @@ export async function startDaemon(
});
} catch (e) {
if (e instanceof Error && e.message.startsWith("HTTP 401")) {
- log.warn(`Workspace ${ws.id} token invalid — removing from config`);
- try {
- const cfg = loadCLIConfigForProfile(profile);
- cfg.watched_workspaces = (cfg.watched_workspaces || []).filter(
- (w) => w.id !== ws.id,
- );
- saveCLIConfigForProfile(profile, cfg);
- } catch {
- // best-effort
- }
+ log.warn(`Workspace ${ws.id} token invalid — skipping (run '${cmdPrefix()} register --token <token>' to fix)`);
} else {
log.error(`Failed to register workspace ${ws.id}, skipping`, e);
}
@@ -274,7 +265,7 @@ export async function startDaemon(
// Best-effort — config write failure must not block eviction
}
- log.info(`Workspace ${workspaceId} evicted — runtimes removed server-side`);
+ log.info(`Workspace ${workspaceId} deleted server-side — removed from config`);
}
// Staggered per-workspace polling
@@ -324,7 +315,7 @@ export async function startDaemon(
}
} catch (e) {
if (e instanceof Error && e.message.startsWith("HTTP 401")) {
- evictedIds.push(ws.workspaceId);
+ log.warn(`Workspace ${ws.workspaceId} poll returned 401 — will retry next cycle`);
} else {
log.debug("Poll error", e);
}
diff --git a/src/cli/package.json b/src/cli/package.json
index b4d085a75..b27106ffd 100644
--- a/src/cli/package.json
+++ b/src/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@alook/cli",
- "version": "0.0.15",
+ "version": "0.0.16",
"description": "Alook CLI — register and run always-on AI coding agents.",
"license": "Apache-2.0",
"homepage": "https://github.com/alookai/alook#readme",