Skip to content

Commit 6e0d779

Browse files
fix: automatically log out on corrupted auth.json (#195)
1 parent 7080ea7 commit 6e0d779

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/CodexAcpServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export class CodexAcpServer implements acp.Agent {
218218
}
219219

220220
async handleError(e: Error){
221-
if (e.message.includes("log out")) {
221+
if (e.message.includes("log out") || e.message.includes("cloud requirements")) {
222222
await this.runWithProcessCheck(() => this.codexAcpClient.logout());
223223
throw RequestError.internalError(`${(e.message)}\n\nYou have been logged out. Please try again.`);
224224
}

src/__tests__/CodexACPAgent/new-session-logout.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,23 @@ describe("New session logout handling", () => {
2020
});
2121
expect(logoutSpy).toHaveBeenCalledOnce();
2222
});
23+
24+
it("recovers when newSession fails with a failed to reload config error", async () => {
25+
const fixture = createCodexMockTestFixture();
26+
const codexAcpAgent = fixture.getCodexAcpAgent();
27+
const codexAcpClient = fixture.getCodexAcpClient();
28+
const codexAppServerClient = fixture.getCodexAppServerClient();
29+
vi.spyOn(codexAcpClient, "authRequired").mockResolvedValue(false);
30+
31+
const errorMessage = `Internal error: "failed to reload config: Failed to load cloud requirements (workspace-managed policies)."`;
32+
vi.spyOn(codexAppServerClient, "threadStart").mockRejectedValue(new Error(errorMessage));
33+
34+
const logoutSpy = vi.spyOn(codexAcpClient, "logout").mockResolvedValue();
35+
36+
await expect(codexAcpAgent.newSession({cwd: "", mcpServers: []}))
37+
.rejects.toMatchObject({
38+
data: expect.stringContaining("You have been logged out. Please try again."),
39+
});
40+
expect(logoutSpy).toHaveBeenCalledOnce();
41+
});
2342
});

0 commit comments

Comments
 (0)