Skip to content

Commit 90fea43

Browse files
fix: title listed sessions by name, title, summary, then preview (#606)
## Summary The title of a `session/list` row and of a `_session/list/changes` row now follows AIR's native Codex chain (`CodexAppServerProtocol.resolveThreadTitle`): the first non-blank of `Thread.name`, `title`, `summary` and `preview`, collapsed to one line. - Before: `name ?? preview`, cut to 256 characters. A blank (not null) `name` hid the preview. - Current Codex threads carry only `name` and `preview`; `title` and `summary` are read when Codex sends them, as AIR reads them. - Both list paths (with and without `sessionIndex`) and subscription rows share `listedSessionTitle`. ## Decisions - **No cut for listed titles.** The native list does not cut, ACP `SessionInfo.title` has no length limit, and the stdio transport has none either. Codex already sends the whole `preview` to the adapter, so the adapter adds no payload of its own. - **Rename limit unchanged.** `_session/rename` still cuts to 256, so the write queue and validation are unchanged. `session_info_update` titles of loaded sessions keep their 256 cut as well (out of scope). - **`null` fallback, not `Thread <id>`.** ACP `SessionInfo.title` is optional and nullable ("Human-readable title for the session"), and AIR's ACP list (`SessionListRow`) shows the session id for a `null` title. A synthetic `Thread <id8>` would replace that and would count as a real title. ## Test plan - `SessionTitle.test.ts`: chain order, blank fields fall through, `null` when all blank, no cut. - `session-index.test.ts`: `session/list` rows through the chain without a cut; a subscription change carries the uncut name. - `npm run typecheck`, `npm test`, `npm run bundle:all`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a2e74a4 commit 90fea43

6 files changed

Lines changed: 108 additions & 8 deletions

File tree

‎docs/air-extensions.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,13 @@ The request can carry `_meta.jetbrains.air.list`:
10421042
No `cwd` lists every thread.
10431043
- Rows are ordered by last user activity, `lastPromptAt ?? updatedAt`, newest first, ties in the Codex order:
10441044
Codex sorts by `recency_at`, which it moves when a turn starts.
1045+
- `title` is the first non-blank of `Thread.name`, `title`, `summary` and `preview`, collapsed to one line, as AIR's
1046+
native Codex list resolves it. Current Codex threads carry only `name` and `preview`; the other two are read when
1047+
Codex sends them. The title is not cut, as the native list does not cut it, and no transport limit asks for a
1048+
cut: Codex already sends the whole `preview` to the adapter. `_session/rename` still cuts to 256 characters, and so
1049+
does the `title` of `session_info_update` for a loaded session. When
1050+
all four are blank, `title` is `null`, which ACP allows, and the client shows its own fallback: AIR shows the
1051+
session id. A `session/list` without `sessionIndex` and a `_session/list/changes` row use the same title.
10451052
- `updatedAt` is `Thread.updatedAt`, the last activity of any kind: Codex moves it for every rollout write of the
10461053
user or the agent, so it can be later than `lastPromptAt` while the agent works. Every row has it. A rename and
10471054
an archive do not move it, but `thread/unarchive` does: Codex sets the rollout file time to now and copies it

‎src/CodexAcpClient.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import path from "node:path";
3030
import {logger} from "./Logger";
3131
import {isAccountReadAuthFailureError, isAccountReadUnavailableError} from "./CodexThreadErrors";
3232
import {sanitizeMcpServerName} from "./McpServerName";
33-
import {normalizeSessionTitle} from "./SessionTitle";
33+
import {listedSessionTitle} from "./SessionTitle";
3434
import type {
3535
AccountLoginCompletedNotification,
3636
AccountUpdatedNotification,
@@ -1300,7 +1300,7 @@ export class CodexAcpClient {
13001300
const mapThreadToSession = (thread: Thread) => ({
13011301
sessionId: thread.id,
13021302
cwd: thread.cwd,
1303-
title: normalizeSessionTitle(thread.name ?? thread.preview),
1303+
title: listedSessionTitle(thread),
13041304
updatedAt: new Date(thread.updatedAt * 1000).toISOString(),
13051305
});
13061306

‎src/SessionIndex.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {z} from "zod";
1414
import type {ServerNotification} from "./app-server";
1515
import type {Thread, ThreadListParams, ThreadListResponse, ThreadStatus, Turn} from "./app-server/v2";
1616
import {AIR_META_KEY, JETBRAINS_META_KEY, withAirMeta} from "./AirExtension";
17-
import {normalizeSessionTitle} from "./SessionTitle";
17+
import {listedSessionTitle} from "./SessionTitle";
1818
import {logger} from "./Logger";
1919

2020
export const AIR_SESSION_INDEX_KEY = "sessionIndex";
@@ -445,7 +445,7 @@ export function sessionIndexSessionInfo(
445445
return {
446446
sessionId: thread.id,
447447
cwd: thread.cwd,
448-
title: normalizeSessionTitle(thread.name ?? thread.preview),
448+
title: listedSessionTitle(thread),
449449
// Codex moves `Thread.updatedAt` for every rollout write of the user or the agent: the last activity of any
450450
// kind. The list is ordered by `lastPromptAt ?? updatedAt` instead. Known deviation from #2161: Codex also
451451
// moves it on `thread/unarchive`, which sets the rollout mtime to now (thread-store unarchive_thread.rs).

‎src/SessionTitle.ts‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type {Thread} from "./app-server/v2";
2+
13
/** The maximum length of a session title that the adapter publishes, the ellipsis included. */
24
export const MAX_SESSION_TITLE_LENGTH = 256;
35

@@ -6,11 +8,38 @@ export const MAX_SESSION_TITLE_LENGTH = 256;
68
* Returns `null` for a blank title.
79
*/
810
export function normalizeSessionTitle(title: string | null | undefined): string | null {
9-
const normalized = title?.replace(/\s+/g, " ").trim() ?? "";
10-
if (normalized.length === 0) return null;
11-
if (normalized.length <= MAX_SESSION_TITLE_LENGTH) return normalized;
11+
const normalized = collapseSessionTitle(title);
12+
if (normalized === null || normalized.length <= MAX_SESSION_TITLE_LENGTH) return normalized;
1213
let cut = normalized.slice(0, MAX_SESSION_TITLE_LENGTH - 1);
1314
// Do not leave half of a surrogate pair before the ellipsis.
1415
if (/[\uD800-\uDBFF]$/.test(cut)) cut = cut.slice(0, -1);
1516
return `${cut.trimEnd()}…`;
1617
}
18+
19+
/**
20+
* The title fields of a listed thread. The generated `Thread` has only `name` and `preview`; `title` and `summary`
21+
* are read when Codex sends them, as AIR's native Codex list reads them.
22+
*/
23+
export type ListedThreadTitleFields = Pick<Thread, "name" | "preview"> & {
24+
title?: string | null;
25+
summary?: string | null;
26+
};
27+
28+
/**
29+
* The title of a thread's `session/list` row and of its `_session/list/changes` row: the first non-blank of
30+
* `name`, `title`, `summary` and `preview`, collapsed to one line, as AIR's native Codex list resolves it. It is not
31+
* cut, as the native list does not cut it either. `null` when all are blank: the ACP title is optional, and a client
32+
* shows its own fallback, AIR the session id.
33+
*/
34+
export function listedSessionTitle(thread: ListedThreadTitleFields): string | null {
35+
return collapseSessionTitle(thread.name)
36+
?? collapseSessionTitle(thread.title)
37+
?? collapseSessionTitle(thread.summary)
38+
?? collapseSessionTitle(thread.preview);
39+
}
40+
41+
/** Collapses the whitespace of [title] to single spaces and trims it; `null` for a blank title. */
42+
function collapseSessionTitle(title: string | null | undefined): string | null {
43+
const collapsed = title?.replace(/\s+/g, " ").trim() ?? "";
44+
return collapsed.length === 0 ? null : collapsed;
45+
}

‎src/__tests__/CodexACPAgent/session-index.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import path from "node:path";
66
import {createCodexMockTestFixture, createTestModel, deferred, type CodexMockTestFixture} from "../acp-test-utils";
77
import type {Thread, ThreadListParams, ThreadListResponse} from "../../app-server/v2";
88
import {SESSION_LIST_CHANGES_METHOD} from "../../SessionIndex";
9+
import {MAX_SESSION_TITLE_LENGTH} from "../../SessionTitle";
910

1011
const threadId = "01a0637c-5b99-7242-9064-04545d605fdb";
1112
const otherThreadId = "01a0637c-5b99-7242-9064-04545d605fdc";
@@ -299,6 +300,25 @@ describe("session/list", () => {
299300
});
300301
});
301302

303+
it("titles a row by name, title, summary, then preview, without a cut", async () => {
304+
const longPreview = `Investigate ${"x".repeat(MAX_SESSION_TITLE_LENGTH)}\n end`;
305+
const {agent} = await createAgent("sessionIndex", [
306+
createThread({id: "named", name: " Named\n thread ", recencyAt: 50}),
307+
createThread({id: "blank-name", name: " ", preview: longPreview, recencyAt: 40}),
308+
{...createThread({id: "summarized", name: null, recencyAt: 30}), title: null, summary: "Summary"} as Thread,
309+
createThread({id: "untitled", name: null, preview: "", recencyAt: 20}),
310+
]);
311+
312+
const response = await agent.listSessions({cwd: "/repo/project"});
313+
314+
expect(response.sessions.map(({sessionId, title}) => [sessionId, title])).toEqual([
315+
["named", "Named thread"],
316+
["blank-name", `Investigate ${"x".repeat(MAX_SESSION_TITLE_LENGTH)} end`],
317+
["summarized", "Summary"],
318+
["untitled", null],
319+
]);
320+
});
321+
302322
it("merges the unarchived and the archived threads by recency when the client asks for archived ones", async () => {
303323
const {agent, threadList} = await createAgent("sessionIndex");
304324
const row = (id: string, recencyAt: number) => createThread({id, recencyAt});
@@ -730,6 +750,26 @@ describe("_session/list/subscribe", () => {
730750
expect(agent.sessionIndex.subscriptionResources()).toEqual({subscriptions: 0, groups: 0, watching: false, timer: false});
731751
});
732752

753+
it("sends the uncut title of a changed row, by the same chain as the list", async () => {
754+
vi.useFakeTimers();
755+
const {fixture, agent, appServer} = await createAgent("sessionIndex");
756+
const {subscriptionId} = await agent.sessionIndex.subscribeList({cwd: "/repo/project"});
757+
fixture.clearAcpConnectionDump();
758+
const name = `Renamed ${"y".repeat(MAX_SESSION_TITLE_LENGTH)}`;
759+
const renamed = createThread({name, path: "/codex-home/sessions/rollout.jsonl"});
760+
vi.spyOn(appServer, "threadRead").mockResolvedValue({thread: renamed});
761+
762+
fixture.sendServerNotification({method: "thread/name/updated", params: {threadId, threadName: name}});
763+
await vi.advanceTimersByTimeAsync(100);
764+
765+
expect(listChanges(fixture)).toEqual([{
766+
subscriptionId,
767+
sessions: [expect.objectContaining({sessionId: threadId, title: name})],
768+
removed: [],
769+
}]);
770+
agent.sessionIndex.dispose();
771+
});
772+
733773
it("sends removed for a thread that the client deletes", async () => {
734774
vi.useFakeTimers();
735775
const {fixture, agent, appServer} = await createAgent("sessionIndex");

‎src/__tests__/SessionTitle.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {describe, expect, it} from "vitest";
2-
import {MAX_SESSION_TITLE_LENGTH, normalizeSessionTitle} from "../SessionTitle";
2+
import {listedSessionTitle, MAX_SESSION_TITLE_LENGTH, normalizeSessionTitle} from "../SessionTitle";
33

44
describe("normalizeSessionTitle", () => {
55
it("collapses whitespace and returns null for a blank title", () => {
@@ -28,3 +28,27 @@ describe("normalizeSessionTitle", () => {
2828
expect(title).toBe(`${"a".repeat(MAX_SESSION_TITLE_LENGTH - 2)}…`);
2929
});
3030
});
31+
32+
describe("listedSessionTitle", () => {
33+
it("takes the first non-blank of name, title, summary and preview", () => {
34+
const all = {name: "Name", title: "Title", summary: "Summary", preview: "Preview"};
35+
36+
expect(listedSessionTitle(all)).toBe("Name");
37+
expect(listedSessionTitle({...all, name: " \n "})).toBe("Title");
38+
expect(listedSessionTitle({...all, name: null, title: ""})).toBe("Summary");
39+
expect(listedSessionTitle({...all, name: null, title: null, summary: "\t"})).toBe("Preview");
40+
expect(listedSessionTitle({name: null, preview: "Preview"})).toBe("Preview");
41+
});
42+
43+
it("collapses whitespace and returns null when every field is blank", () => {
44+
expect(listedSessionTitle({name: " Fix the flaky\n test ", preview: ""})).toBe("Fix the flaky test");
45+
expect(listedSessionTitle({name: null, title: " ", summary: null, preview: " \n "})).toBeNull();
46+
});
47+
48+
it("does not cut a long title", () => {
49+
const preview = "a".repeat(25_023);
50+
51+
expect(listedSessionTitle({name: null, preview})).toBe(preview);
52+
expect(listedSessionTitle({name: `${"b".repeat(MAX_SESSION_TITLE_LENGTH)} tail`, preview})).toHaveLength(MAX_SESSION_TITLE_LENGTH + 5);
53+
});
54+
});

0 commit comments

Comments
 (0)