diff --git a/src/CodexAcpClient.ts b/src/CodexAcpClient.ts index a780eecd..32c9b240 100644 --- a/src/CodexAcpClient.ts +++ b/src/CodexAcpClient.ts @@ -51,6 +51,8 @@ import type {AuthenticationStatusResponse} from "./AcpExtensions"; */ export const CUSTOM_GATEWAY_PROVIDER_ID = "custom-gateway"; +const SESSION_LIST_PAGE_SIZE = 100; + /** * ACP `LlmProtocol` values Codex can route through the custom gateway, mapped to * the Codex `wire_api`. Codex only supports the OpenAI Responses wire API here. @@ -824,8 +826,12 @@ export class CodexAcpClient { const modelProviders = preferredProvider ? [preferredProvider] : []; const listResponse = await this.codexClient.threadList({ cursor: request.cursor ?? null, + limit: SESSION_LIST_PAGE_SIZE, + sortKey: "updated_at", + sortDirection: "desc", modelProviders: modelProviders, sourceKinds: sourceKinds, + ...(requestedCwd && path.isAbsolute(requestedCwd) ? {cwd: requestedCwd} : {}), }); const mapThreadToSession = (thread: Thread) => ({ @@ -835,7 +841,7 @@ export class CodexAcpClient { updatedAt: new Date(thread.updatedAt * 1000).toISOString(), }); - if (listResponse.data.length === 0) { + if (listResponse.data.length === 0 && !requestedCwd) { const diagnostics = await this.runSessionListDiagnostics(); logger.log("Session list diagnostics", diagnostics); } diff --git a/src/__tests__/CodexACPAgent/list-sessions.test.ts b/src/__tests__/CodexACPAgent/list-sessions.test.ts index 36529576..b6a03179 100644 --- a/src/__tests__/CodexACPAgent/list-sessions.test.ts +++ b/src/__tests__/CodexACPAgent/list-sessions.test.ts @@ -76,6 +76,10 @@ describe("CodexACPAgent - list sessions", () => { const response = await codexAcpAgent.listSessions(params); expect(codexAppServerClient.threadList).toHaveBeenCalledWith(expect.objectContaining({ + cwd: "/repo/project", + limit: 100, + sortKey: "updated_at", + sortDirection: "desc", sourceKinds: [ "cli", "vscode", @@ -89,6 +93,30 @@ describe("CodexACPAgent - list sessions", () => { ); }); + it("does not run global diagnostics for an empty cwd-filtered page", async () => { + const fixture = createCodexMockTestFixture(); + const codexAcpAgent = fixture.getCodexAcpAgent(); + const codexAcpClient = fixture.getCodexAcpClient(); + const codexAppServerClient = fixture.getCodexAppServerClient(); + + codexAcpClient.authRequired = vi.fn().mockResolvedValue(false); + codexAppServerClient.threadList = vi.fn().mockResolvedValue({ + data: [], + nextCursor: null, + }); + + const response = await codexAcpAgent.listSessions({ + cwd: "/repo/project", + cursor: null, + }); + + expect(response).toEqual({ + sessions: [], + nextCursor: null, + }); + expect(codexAppServerClient.threadList).toHaveBeenCalledTimes(1); + }); + it("should prefer the explicit thread name as the session title", async () => { const fixture = createCodexMockTestFixture(); const codexAcpAgent = fixture.getCodexAcpAgent();