Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) => ({
Expand All @@ -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);
}
Expand Down
28 changes: 28 additions & 0 deletions src/__tests__/CodexACPAgent/list-sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
Expand Down