Skip to content

Commit 7819130

Browse files
authored
improve: stream native sessions as hosts finish (#110211)
* perf: stream native session catalogs by host * fix: satisfy session catalog CI contracts * fix: retain changed-session refresh timing * fix: keep catalog refresh helpers private
1 parent 6903ab3 commit 7819130

26 files changed

Lines changed: 1717 additions & 222 deletions

‎apps/shared/OpenClawKit/Sources/OpenClawProtocol/GatewayModels.swift‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,6 +3370,7 @@ public struct SessionCatalogTranscriptItem: Codable, Sendable {
33703370
public struct SessionsCatalogListParams: Codable, Sendable {
33713371
public let catalogid: String?
33723372
public let agentid: String?
3373+
public let progressid: String?
33733374
public let search: String?
33743375
public let limitperhost: Int?
33753376
public let hostids: [String]?
@@ -3378,13 +3379,15 @@ public struct SessionsCatalogListParams: Codable, Sendable {
33783379
public init(
33793380
catalogid: String? = nil,
33803381
agentid: String? = nil,
3382+
progressid: String? = nil,
33813383
search: String? = nil,
33823384
limitperhost: Int? = nil,
33833385
hostids: [String]? = nil,
33843386
cursors: [String: AnyCodable]? = nil)
33853387
{
33863388
self.catalogid = catalogid
33873389
self.agentid = agentid
3390+
self.progressid = progressid
33883391
self.search = search
33893392
self.limitperhost = limitperhost
33903393
self.hostids = hostids
@@ -3394,6 +3397,7 @@ public struct SessionsCatalogListParams: Codable, Sendable {
33943397
private enum CodingKeys: String, CodingKey {
33953398
case catalogid = "catalogId"
33963399
case agentid = "agentId"
3400+
case progressid = "progressId"
33973401
case search
33983402
case limitperhost = "limitPerHost"
33993403
case hostids = "hostIds"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
7e717544b401b5ca3447d5383e241f678b6c343c089b3f430c2fc48244f1b3c8 plugin-sdk-api-baseline.json
2-
0b4bc1cfc71177b5f5e0d146c48d86d48ff0eea1a075358adb7583ee35af54b9 plugin-sdk-api-baseline.jsonl
1+
5e2ce14f9b24efbaa43886bc2f82226f6ca83ba1e02520dc8812da839fa20e2f plugin-sdk-api-baseline.json
2+
62a3c8c10295440d956d257b4e8cb981b0ed37a16f9976b9417ac3227fed9242 plugin-sdk-api-baseline.jsonl

‎docs/plugins/codex-supervision.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ closed instead of risking the node or Gateway connection.
137137
Open the **Codex** group in the normal sessions sidebar. It lists the same sessions
138138
grouped by host. **Load more sessions** appends the next page from each host that
139139
has older rows, and those appended rows survive the sidebar's periodic refresh.
140+
Each host appears as soon as its own native listing settles. The visible page
141+
reconciles after node-connectivity changes, when it regains focus, and at most
142+
every 30 seconds; a changed result gets a faster follow-up pass. Sessions created
143+
in Codex Desktop, the CLI, or another native client therefore appear without a
144+
full page reload. The first page follows Codex's own most-recently-updated order,
145+
so a newly created native session is eligible immediately.
140146
Each returned search page scans a bounded number of native pages per host rather
141147
than sending the query to App Server, because native search can also match
142148
transcript previews.

‎docs/plugins/sdk-entrypoints.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ export default definePluginEntry({
147147
`openclaw/plugin-sdk/session-catalog` and
148148
`api.registerSessionCatalog({ id, label, list, read, continueSession?, archive? })`.
149149
Core owns the `sessions.catalog.*` Gateway methods; providers return host,
150-
session, and normalized transcript projections without registering RPCs.
150+
session, and normalized transcript projections without registering RPCs. A
151+
list provider should call the optional `onHost(host)` callback as each host
152+
settles; the returned host array remains required as the final compatibility
153+
snapshot.
151154
- `kind` is deprecated: declare an exclusive slot (`"memory"` or
152155
`"context-engine"`) in the `openclaw.plugin.json` manifest `kind` field
153156
instead. Runtime-entry `kind` remains only as a compatibility fallback for

‎docs/providers/anthropic.md‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,15 @@ is bundled and enabled by default; a native macOS node advertises the read-only
217217
Claude session commands when the local `~/.claude/projects/` directory exists.
218218
Approve the node pairing upgrade when those commands first appear.
219219

220-
The sidebar groups rows by their Gateway or paired-node host, starts with the
221-
newest bounded page from each host, and refreshes on the normal 30-second
222-
cadence. Use **Load more sessions** below a catalog group to append the next page
223-
for every host that has more history; appended rows stay visible and are
224-
re-fetched to the same depth across refreshes. Catalog clients use
225-
`sessions.catalog.list`; opening a row uses `sessions.catalog.read`.
220+
The sidebar groups rows by their Gateway or paired-node host and shows each
221+
host's newest bounded page as soon as that computer answers. It reconciles again
222+
after host-connectivity changes, when the page regains focus, and at most every
223+
30 seconds while visible, so Claude sessions created outside OpenClaw appear
224+
without a reload. A changed catalog gets a faster follow-up pass. Use **Load more
225+
sessions** below a catalog group to append the next page for every host that has
226+
more history; appended rows stay visible and are re-fetched to the same depth
227+
across refreshes. Catalog clients use `sessions.catalog.list`; opening a row uses
228+
`sessions.catalog.read`.
226229

227230
Terminal takeover resolves `claude` from the owning host user's login-shell
228231
PATH before the service/daemon PATH. This keeps app-launched sessions aligned

‎docs/specs/codex-supervision.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ local App Server does not erase healthy hosts from the page. Connectivity is a
150150
host property, not a thread status: a failed host result contains no fresh
151151
session rows and does not project `offline` onto native threads.
152152

153+
The Control UI requests progressive catalog updates. Each local or paired host
154+
appears when its own App Server listing settles; the aggregate response remains
155+
the compatibility and recovery snapshot. The visible page reconciles after
156+
connectivity changes, on focus, and at most every 30 seconds, with a faster pass
157+
after changes. Native Codex sessions created in another client are therefore
158+
eventually discovered without importing them into OpenClaw storage.
159+
153160
Catalog discovery is passive. Listing or reading metadata must not call
154161
`thread/resume`, subscribe the OpenClaw client to live thread requests, or
155162
answer an approval.

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ A **Search** field at the top of the sidebar opens the command palette (⌘K). C
201201
- Channels: built-in plus bundled/external plugin channels status, QR login, and per-channel config (`channels.status`, `web.login.*`, `config.patch`).
202202
- Channel probe refreshes keep the previous snapshot visible while slow provider checks finish, and label partial snapshots when a probe or audit exceeds its UI budget.
203203
- Sessions (a settings page under **Agents & Tools**, `/settings/sessions`): list configured-agent sessions by default, pin frequent sessions, rename them, archive or restore inactive sessions, fall back from stale unconfigured agent session keys, and apply per-session model/thinking/fast/verbose/trace/reasoning overrides (`sessions.list`, `sessions.patch`). Pinned sessions sort above recent unpinned sessions; archived sessions live in the Sessions page's archived view and keep their transcripts. Rows show an unread dot for sessions with activity since their last read, with mark-unread/mark-read actions (`sessions.patch { unread }`), and a Fork action that branches the transcript into a new session (`sessions.create { parentSessionKey, fork: true }`). Overview tiles above the table summarize the loaded roster (session count, live runs, unread sessions, total tokens), each row carries a kind glyph with a live-run dot, status renders as a plain dot plus label, and the Tokens column shows a context-window usage meter when the session reports token and context sizes. Row management actions live in a per-row menu (kebab button or right-click) mirroring the sidebar's session menu, and the row drawer carries the agent runtime and run duration alongside the other session details.
204+
- Native Claude and Codex sidebar catalogs stream one host at a time, then reconcile after node connectivity changes, on page focus, and at most every 30 seconds while visible. Catalog changes trigger a faster follow-up pass, so sessions created in the native tools appear without reloading the Control UI.
204205
- Session grouping: a Group by control organizes the sessions table into sections by custom groups, channel, kind, agent, or date. Custom groups persist per session via `sessions.patch` (`category`), so sessions started from message channels (Discord, Telegram, WhatsApp, ...) can be categorized too; assign groups by dragging rows onto a section, or with the per-row group selector, and create groups with the New group action.
205206
- Memory (a tab on the Agents page, scoped to the selected agent): dreaming status, enable/disable toggle, and Dream Diary reader (`doctor.memory.status`, `doctor.memory.dreamDiary`, `config.patch`).
206207
- Import Memory (a settings page under **Agents & Tools**, `/settings/memory-import`): preview and copy local Claude Code auto-memory, Codex consolidated memory, or Hermes memory files into the selected agent workspace (`migrations.memory.plan`, `migrations.memory.apply`).

‎extensions/anthropic/session-catalog.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,64 @@ describe("Claude session catalog", () => {
15591559
}
15601560
});
15611561

1562+
it("publishes a paired-node page that finishes after the fail-soft response", async () => {
1563+
vi.useFakeTimers();
1564+
try {
1565+
let resolveInvoke!: (value: unknown) => void;
1566+
const invokeResult = new Promise<unknown>((resolve) => {
1567+
resolveInvoke = resolve;
1568+
});
1569+
const invoke = vi.fn<PluginRuntime["nodes"]["invoke"]>(async () => await invokeResult);
1570+
const provider = captureCatalogProvider({
1571+
nodes: {
1572+
list: vi.fn().mockResolvedValue({
1573+
nodes: [
1574+
{
1575+
nodeId: "slow-node",
1576+
displayName: "Slow node",
1577+
connected: true,
1578+
commands: [CLAUDE_SESSIONS_LIST_COMMAND],
1579+
},
1580+
],
1581+
}),
1582+
invoke,
1583+
},
1584+
} as unknown as PluginRuntime);
1585+
const onHost = vi.fn();
1586+
const pending = provider.list({ hostIds: ["node:slow-node"], onHost });
1587+
1588+
await vi.advanceTimersByTimeAsync(8_000);
1589+
await expect(pending).resolves.toEqual([
1590+
expect.objectContaining({ error: expect.objectContaining({ code: "NODE_INVOKE_FAILED" }) }),
1591+
]);
1592+
expect(onHost).not.toHaveBeenCalled();
1593+
1594+
resolveInvoke({
1595+
payloadJSON: JSON.stringify({
1596+
sessions: [
1597+
{
1598+
threadId: "late-thread",
1599+
status: "stored",
1600+
source: "claude-cli",
1601+
modelProvider: "anthropic",
1602+
archived: false,
1603+
},
1604+
],
1605+
}),
1606+
});
1607+
await vi.advanceTimersByTimeAsync(0);
1608+
1609+
expect(onHost).toHaveBeenCalledWith(
1610+
expect.objectContaining({
1611+
hostId: "node:slow-node",
1612+
sessions: [expect.objectContaining({ threadId: "late-thread" })],
1613+
}),
1614+
);
1615+
} finally {
1616+
vi.useRealTimers();
1617+
}
1618+
});
1619+
15621620
it("starts paired-node discovery while the local catalog is still reading", async () => {
15631621
const home = await createHome();
15641622
process.env.HOME = home;

‎extensions/anthropic/session-catalog.ts‎

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ function parseGatewayQuery(value: unknown): {
993993
async function listClaudeSessionCatalog(params: {
994994
runtime: PluginRuntime;
995995
query?: unknown;
996+
onHost?: (host: ClaudeSessionCatalogHost) => void;
996997
}): Promise<ClaudeSessionCatalogResult> {
997998
const query = parseGatewayQuery(params.query);
998999
const requested = query.hostIds ? new Set(query.hostIds) : undefined;
@@ -1030,6 +1031,11 @@ async function listClaudeSessionCatalog(params: {
10301031
})(),
10311032
]
10321033
: [];
1034+
for (const host of localHosts) {
1035+
if (params.onHost) {
1036+
void host.then(params.onHost).catch(() => undefined);
1037+
}
1038+
}
10331039
const wantsNodes = !requested || query.hostIds?.some((hostId) => hostId.startsWith("node:"));
10341040
if (!wantsNodes) {
10351041
return { hosts: await Promise.all(localHosts) };
@@ -1038,18 +1044,17 @@ async function listClaudeSessionCatalog(params: {
10381044
try {
10391045
nodes = (await params.runtime.nodes.list()).nodes;
10401046
} catch (error) {
1047+
const registryHost: ClaudeSessionCatalogHost = {
1048+
hostId: "node:registry",
1049+
label: "Paired nodes",
1050+
kind: "node",
1051+
connected: false,
1052+
sessions: [],
1053+
error: createNodeListFailedError(error),
1054+
};
1055+
params.onHost?.(registryHost);
10411056
return {
1042-
hosts: [
1043-
...(await Promise.all(localHosts)),
1044-
{
1045-
hostId: "node:registry",
1046-
label: "Paired nodes",
1047-
kind: "node",
1048-
connected: false,
1049-
sessions: [],
1050-
error: createNodeListFailedError(error),
1051-
},
1052-
],
1057+
hosts: [...(await Promise.all(localHosts)), registryHost],
10531058
};
10541059
}
10551060
const eligible = nodes
@@ -1078,14 +1083,16 @@ async function listClaudeSessionCatalog(params: {
10781083
...catalogTerminal.claudeNodeTerminalCapability(node),
10791084
};
10801085
if (node.connected !== true) {
1081-
return Object.assign(common, {
1086+
const host: ClaudeSessionCatalogHost = Object.assign({}, common, {
10821087
sessions: [],
10831088
error: { code: "NODE_OFFLINE", message: "Paired node is offline" },
10841089
});
1090+
params.onHost?.(host);
1091+
return host;
10851092
}
1086-
try {
1087-
const raw = await withTimeout(
1088-
params.runtime.nodes.invoke({
1093+
const eventualHost = Promise.resolve()
1094+
.then(async () => {
1095+
const raw = await params.runtime.nodes.invoke({
10891096
nodeId: node.nodeId,
10901097
command: CLAUDE_SESSIONS_LIST_COMMAND,
10911098
params: {
@@ -1095,13 +1102,30 @@ async function listClaudeSessionCatalog(params: {
10951102
},
10961103
timeoutMs: NODE_INVOKE_TIMEOUT_MS,
10971104
scopes: ["operator.write"],
1098-
}),
1099-
NODE_CATALOG_LIST_RESPONSE_TIMEOUT_MS,
1100-
{ message: "paired node Claude session catalog timed out" },
1105+
});
1106+
return Object.assign({}, common, parseCatalogPage(unwrapNodePayload(raw)));
1107+
})
1108+
.catch(
1109+
(): ClaudeSessionCatalogHost =>
1110+
Object.assign({}, common, {
1111+
sessions: [],
1112+
error: {
1113+
code: "NODE_INVOKE_FAILED",
1114+
message: "Paired node Claude sessions are unavailable",
1115+
},
1116+
}),
11011117
);
1102-
return Object.assign(common, parseCatalogPage(unwrapNodePayload(raw)));
1118+
if (params.onHost) {
1119+
// The fail-soft response can finish first; the original node invoke still
1120+
// publishes its authoritative host page whenever cold discovery completes.
1121+
void eventualHost.then(params.onHost).catch(() => undefined);
1122+
}
1123+
try {
1124+
return await withTimeout(eventualHost, NODE_CATALOG_LIST_RESPONSE_TIMEOUT_MS, {
1125+
message: "paired node Claude session catalog timed out",
1126+
});
11031127
} catch {
1104-
return Object.assign(common, {
1128+
return Object.assign({}, common, {
11051129
sessions: [],
11061130
error: {
11071131
code: "NODE_INVOKE_FAILED",
@@ -1444,8 +1468,15 @@ export function registerClaudeSessionCatalog(api: OpenClawPluginApi): void {
14441468
list: async (query) => {
14451469
const adopted = listBoundClaudeSessions(api);
14461470
const localCliAvailable = catalogTerminal.isClaudeCliAvailable();
1447-
const result = await listClaudeSessionCatalog({ runtime: api.runtime, query });
1448-
return result.hosts.map((host) => toGenericClaudeHost(host, adopted, localCliAvailable));
1471+
const { onHost, ...gatewayQuery } = query;
1472+
const mapHost = (host: ClaudeSessionCatalogHost) =>
1473+
toGenericClaudeHost(host, adopted, localCliAvailable);
1474+
const result = await listClaudeSessionCatalog({
1475+
runtime: api.runtime,
1476+
query: gatewayQuery,
1477+
...(onHost ? { onHost: (host) => onHost(mapHost(host)) } : {}),
1478+
});
1479+
return result.hosts.map(mapHost);
14491480
},
14501481
read: async (request) => {
14511482
const page = await readClaudeSessionTranscript({

‎extensions/codex/src/session-catalog-node-continue.ts‎

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export async function listPairedNode(params: {
8383
node: CatalogNode;
8484
query: CodexSessionCatalogParams;
8585
adoptedSessions: ReadonlyMap<string, AdoptedSessionEntry>;
86+
onHost?: (host: CodexSessionCatalogHost) => void;
8687
}): Promise<CodexSessionCatalogHost> {
8788
const hostId = `node:${params.node.nodeId}`;
8889
const common = {
@@ -93,16 +94,18 @@ export async function listPairedNode(params: {
9394
canContinueCodex: canContinueCodexOnNode(params.node),
9495
};
9596
if (params.node.connected !== true) {
96-
return {
97+
const host = {
9798
...common,
9899
connected: false,
99100
sessions: [],
100101
error: { code: "NODE_OFFLINE", message: "Paired node is offline" },
101102
};
103+
params.onHost?.(host);
104+
return host;
102105
}
103-
try {
104-
const raw = await withTimeout(
105-
params.runtime.nodes.invoke({
106+
const eventualHost = Promise.resolve()
107+
.then(async () => {
108+
const raw = await params.runtime.nodes.invoke({
106109
nodeId: params.node.nodeId,
107110
command: CODEX_APP_SERVER_THREADS_LIST_COMMAND,
108111
params: {
@@ -112,23 +115,40 @@ export async function listPairedNode(params: {
112115
},
113116
timeoutMs: NODE_INVOKE_TIMEOUT_MS,
114117
scopes: ["operator.write"],
115-
}),
118+
});
119+
const page = filterCatalogPageByTitle(
120+
parseCatalogPage(unwrapNodeInvokePayload(raw)),
121+
params.query.search,
122+
);
123+
return {
124+
...common,
125+
connected: true,
126+
...page,
127+
sessions: page.sessions.map((session) => {
128+
const adopted = params.adoptedSessions.get(adoptedSourceKey(hostId, session.threadId));
129+
return adopted
130+
? Object.assign({}, session, { openClawSessionKey: adopted.key })
131+
: session;
132+
}),
133+
};
134+
})
135+
.catch((error: unknown) => ({
136+
...common,
137+
connected: true,
138+
sessions: [],
139+
error: catalogError("NODE_INVOKE_FAILED", error),
140+
}));
141+
if (params.onHost) {
142+
// Keep the 8s aggregate response while allowing cold app-server discovery
143+
// to replace that fail-soft page as soon as the node invoke really settles.
144+
void eventualHost.then(params.onHost).catch(() => undefined);
145+
}
146+
try {
147+
return await withTimeout(
148+
eventualHost,
116149
NODE_CATALOG_LIST_RESPONSE_TIMEOUT_MS,
117150
"paired node Codex session catalog timed out",
118151
);
119-
const page = filterCatalogPageByTitle(
120-
parseCatalogPage(unwrapNodeInvokePayload(raw)),
121-
params.query.search,
122-
);
123-
return {
124-
...common,
125-
connected: true,
126-
...page,
127-
sessions: page.sessions.map((session) => {
128-
const adopted = params.adoptedSessions.get(adoptedSourceKey(hostId, session.threadId));
129-
return adopted ? Object.assign({}, session, { openClawSessionKey: adopted.key }) : session;
130-
}),
131-
};
132152
} catch (error) {
133153
return {
134154
...common,

0 commit comments

Comments
 (0)