Skip to content

Commit 6325814

Browse files
fix(session-catalog): preserve explicit agent ownership across UI and CLI (#123899)
* fix(session-catalog): preserve explicit agent ownership across UI and CLI * fix(session-catalog): repair owner routing regressions * Fix-session-catalog-CI-checks * test(ui): split chat catalog pane coverage Co-authored-by: IWhatsskill <[email protected]> * refactor(session-catalog): bind Codex homes per request Co-authored-by: IWhatsskill <[email protected]> * refactor(session-catalog): centralize owner resolution Co-authored-by: IWhatsskill <[email protected]> * fix(codex): resolve session fork against the adopted home Co-authored-by: IWhatsskill <[email protected]> * refactor(ui): extract chat session discussion * test(sessions): stabilize archive worker responsiveness check --------- Co-authored-by: IWhatsskill <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 0134c78 commit 6325814

67 files changed

Lines changed: 3827 additions & 1690 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5135,6 +5135,7 @@ public struct SessionCatalogPullRequestSummary: Codable, Sendable {
51355135

51365136
public struct SessionCatalogSession: Codable, Sendable {
51375137
public let threadid: String
5138+
public let sourcehomeid: String?
51385139
public let name: String?
51395140
public let cwd: String?
51405141
public let status: String
@@ -5156,6 +5157,7 @@ public struct SessionCatalogSession: Codable, Sendable {
51565157

51575158
public init(
51585159
threadid: String,
5160+
sourcehomeid: String? = nil,
51595161
name: String? = nil,
51605162
cwd: String? = nil,
51615163
status: String,
@@ -5176,6 +5178,7 @@ public struct SessionCatalogSession: Codable, Sendable {
51765178
canopenterminal: Bool? = nil)
51775179
{
51785180
self.threadid = threadid
5181+
self.sourcehomeid = sourcehomeid
51795182
self.name = name
51805183
self.cwd = cwd
51815184
self.status = status
@@ -5198,6 +5201,7 @@ public struct SessionCatalogSession: Codable, Sendable {
51985201

51995202
private enum CodingKeys: String, CodingKey {
52005203
case threadid = "threadId"
5204+
case sourcehomeid = "sourceHomeId"
52015205
case name
52025206
case cwd
52035207
case status
@@ -5385,19 +5389,25 @@ public struct SessionsCatalogReadParams: Codable, Sendable {
53855389
public let catalogid: String
53865390
public let hostid: String
53875391
public let threadid: String
5392+
public let agentid: String?
5393+
public let sourcehomeid: String?
53885394
public let limit: Int?
53895395
public let cursor: String?
53905396

53915397
public init(
53925398
catalogid: String,
53935399
hostid: String,
53945400
threadid: String,
5401+
agentid: String? = nil,
5402+
sourcehomeid: String? = nil,
53955403
limit: Int? = nil,
53965404
cursor: String? = nil)
53975405
{
53985406
self.catalogid = catalogid
53995407
self.hostid = hostid
54005408
self.threadid = threadid
5409+
self.agentid = agentid
5410+
self.sourcehomeid = sourcehomeid
54015411
self.limit = limit
54025412
self.cursor = cursor
54035413
}
@@ -5406,6 +5416,8 @@ public struct SessionsCatalogReadParams: Codable, Sendable {
54065416
case catalogid = "catalogId"
54075417
case hostid = "hostId"
54085418
case threadid = "threadId"
5419+
case agentid = "agentId"
5420+
case sourcehomeid = "sourceHomeId"
54095421
case limit
54105422
case cursor
54115423
}
@@ -5445,21 +5457,29 @@ public struct SessionsCatalogContinueParams: Codable, Sendable {
54455457
public let catalogid: String
54465458
public let hostid: String
54475459
public let threadid: String
5460+
public let agentid: String?
5461+
public let sourcehomeid: String?
54485462

54495463
public init(
54505464
catalogid: String,
54515465
hostid: String,
5452-
threadid: String)
5466+
threadid: String,
5467+
agentid: String? = nil,
5468+
sourcehomeid: String? = nil)
54535469
{
54545470
self.catalogid = catalogid
54555471
self.hostid = hostid
54565472
self.threadid = threadid
5473+
self.agentid = agentid
5474+
self.sourcehomeid = sourcehomeid
54575475
}
54585476

54595477
private enum CodingKeys: String, CodingKey {
54605478
case catalogid = "catalogId"
54615479
case hostid = "hostId"
54625480
case threadid = "threadId"
5481+
case agentid = "agentId"
5482+
case sourcehomeid = "sourceHomeId"
54635483
}
54645484
}
54655485

@@ -5481,24 +5501,32 @@ public struct SessionsCatalogArchiveParams: Codable, Sendable {
54815501
public let catalogid: String
54825502
public let hostid: String
54835503
public let threadid: String
5504+
public let agentid: String?
5505+
public let sourcehomeid: String?
54845506
public let confirmnootherrunner: Bool
54855507

54865508
public init(
54875509
catalogid: String,
54885510
hostid: String,
54895511
threadid: String,
5512+
agentid: String? = nil,
5513+
sourcehomeid: String? = nil,
54905514
confirmnootherrunner: Bool)
54915515
{
54925516
self.catalogid = catalogid
54935517
self.hostid = hostid
54945518
self.threadid = threadid
5519+
self.agentid = agentid
5520+
self.sourcehomeid = sourcehomeid
54955521
self.confirmnootherrunner = confirmnootherrunner
54965522
}
54975523

54985524
private enum CodingKeys: String, CodingKey {
54995525
case catalogid = "catalogId"
55005526
case hostid = "hostId"
55015527
case threadid = "threadId"
5528+
case agentid = "agentId"
5529+
case sourcehomeid = "sourceHomeId"
55025530
case confirmnootherrunner = "confirmNoOtherRunner"
55035531
}
55045532
}

‎docs/plugins/codex-supervision.md‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,17 @@ Enable the `codex` plugin and its supervision capability in `openclaw.json`:
8787
If `plugins.allow` is present, include `codex`. Restart the Gateway after
8888
changing plugin activation.
8989

90-
With no explicit `appServer` connection settings, supervision uses a separate
91-
managed stdio supervision connection against the native user Codex home. The
92-
ordinary Codex harness remains agent-scoped by default. This makes native
93-
sessions visible in both apps without making ordinary OpenClaw turns share
94-
native Codex state. Set `appServer.homeScope: "user"` explicitly if the harness
95-
should share that state too. Supervision honors explicit `appServer` connection
96-
settings instead of replacing them with its local user-home default.
90+
With no explicit `appServer` connection settings, supervision uses managed
91+
stdio connections for the available local Codex stores. The catalog combines
92+
the process user's `CODEX_HOME` with existing `codex-home` stores under configured
93+
OpenClaw agent directories, deduplicates canonical paths, and assigns each store
94+
an opaque local host id. Each store gets its own App Server connection; its path
95+
is never exposed in the catalog. List, read, continue, archive, adoption, and
96+
terminal resume keep the selected source while retaining the explicit OpenClaw
97+
route agent as owner. The ordinary Codex harness remains agent-scoped by default.
98+
Set `appServer.homeScope: "user"` explicitly if the harness should share native
99+
Codex state too. Supervision honors explicit `appServer` connection settings
100+
instead of replacing them with its local user-home default.
97101

98102
A Chat adopted from the **Codex** sidebar group is not an ordinary harness session.
99103
Its private supervision binding uses the supervision connection for source
@@ -166,29 +170,31 @@ The terminal CLI exposes the same non-archived catalog and Gateway-local branch
166170
and archive actions:
167171

168172
```bash
169-
openclaw codex sessions [--search <text>] [--host <id>] [--limit <count>] [--cursor <cursor>] [--json] [--url <url>] [--token <token>] [--timeout <ms>] [--expect-final]
170-
openclaw codex continue <thread-id> [--json] [--url <url>] [--token <token>] [--timeout <ms>] [--expect-final]
171-
openclaw codex archive <thread-id> --confirm-no-other-runner [--json] [--url <url>] [--token <token>] [--timeout <ms>] [--expect-final]
173+
openclaw codex sessions [--agent <id>] [--search <text>] [--host <id>] [--limit <count>] [--cursor <cursor>] [--json] [--url <url>] [--token <token>] [--timeout <ms>] [--expect-final]
174+
openclaw codex continue <thread-id> [--agent <id>] [--host <id>] [--json] [--url <url>] [--token <token>] [--timeout <ms>] [--expect-final]
175+
openclaw codex archive <thread-id> --confirm-no-other-runner [--agent <id>] [--host <id>] [--json] [--url <url>] [--token <token>] [--timeout <ms>] [--expect-final]
172176
```
173177

174178
`openclaw codex sessions` options:
175179

180+
- `--agent <id>` selects the OpenClaw owner in a multi-agent Gateway.
176181
- `--search <text>` searches session titles case-insensitively.
177182
- `--host <id>` limits the response to one stable catalog host, such as
178-
`gateway:local` or `node:<node-id>`.
183+
`gateway:local`, an opaque `gateway:local:<source-id>`, or `node:<node-id>`.
179184
- `--limit <count>` sets 1 through 100 rows per host; the default is 50.
180185
- `--cursor <cursor>` continues one host page and therefore requires `--host`.
181186
- `--json` prints the structured Gateway response.
182187

183-
All three commands inherit `--url`, `--token`, and `--timeout <ms>` from the
188+
All three commands accept `--agent <id>` and inherit `--url`, `--token`, and `--timeout <ms>` from the
184189
Gateway client. Session listing defaults to 75,000 ms so cold paired-node
185190
catalogs can complete; continue and archive default to 30,000 ms. They also expose the shared
186191
`--expect-final` switch, which does not change these unary supervision RPCs.
187192
Each command requires the `operator.write` Gateway scope.
188193
Standard `-h, --help` output is available on each subcommand.
189194
There is no archived or include-archived option. `sessions` can list paired
190-
hosts, but `continue` and `archive` always target `gateway:local`; paired rows
191-
are list-only. Archive always requires `--confirm-no-other-runner`.
195+
hosts. `continue` and `archive` default to `gateway:local`; pass the listed
196+
opaque local `--host` id to target another local Codex store. Paired rows remain
197+
list-only. Archive always requires `--confirm-no-other-runner`.
192198

193199
These shell commands are distinct from the in-chat `/codex` runtime commands.
194200
`/codex threads [filter]` lists App Server threads available to the current

‎extensions/acpx/lazy-import.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ describe("acpx Pi session catalog lazy imports", () => {
5353
expect(nodeCommands).toHaveLength(3);
5454
expect(nodePolicies).toHaveLength(1);
5555

56-
await expect(catalogs[0]?.list({})).resolves.toEqual([]);
57-
await expect(catalogs[0]?.list({})).resolves.toEqual([]);
56+
await expect(catalogs[0]?.list({ agentId: "main" })).resolves.toEqual([]);
57+
await expect(catalogs[0]?.list({ agentId: "main" })).resolves.toEqual([]);
5858
await expect(nodeCommands[0]?.handle()).resolves.toBe("[]");
5959
await expect(nodeCommands[0]?.handle()).resolves.toBe("[]");
6060
expect(runtimeImports).toBe(1);
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
2+
import { describe, expect, it, vi } from "vitest";
3+
import { registerPiSessionCatalog } from "./pi-session-catalog-plugin.js";
4+
import {
5+
bindTestCatalogOwner,
6+
type TestSessionCatalogProvider,
7+
} from "./pi-session-catalog.test-support.js";
8+
9+
const PI_SESSIONS_LIST_COMMAND = "acpx.pi.sessions.list.v1";
10+
const PI_SESSION_READ_COMMAND = "acpx.pi.sessions.read.v1";
11+
12+
describe("Pi paired-node session catalog", () => {
13+
it("bridges list and read requests without undefined transport fields", async () => {
14+
let provider: TestSessionCatalogProvider | undefined;
15+
const invoke = vi
16+
.fn()
17+
.mockResolvedValueOnce({
18+
payloadJSON: JSON.stringify({
19+
sessions: [
20+
{
21+
threadId: "pi-remote",
22+
status: "stored",
23+
source: "pi-cli",
24+
archived: false,
25+
canContinue: false,
26+
canArchive: false,
27+
},
28+
],
29+
}),
30+
})
31+
.mockResolvedValueOnce({
32+
payloadJSON: JSON.stringify({
33+
threadId: "pi-remote",
34+
items: [{ type: "agentMessage", text: "remote answer" }],
35+
}),
36+
});
37+
const api = {
38+
pluginConfig: {},
39+
runtime: {
40+
nodes: {
41+
list: vi.fn().mockResolvedValue({
42+
nodes: [
43+
{
44+
nodeId: "node-1",
45+
displayName: "Remote",
46+
connected: true,
47+
commands: [PI_SESSIONS_LIST_COMMAND, PI_SESSION_READ_COMMAND],
48+
},
49+
],
50+
}),
51+
invoke,
52+
},
53+
},
54+
registerSessionCatalog: (
55+
value: Parameters<OpenClawPluginApi["registerSessionCatalog"]>[0],
56+
) => {
57+
provider = bindTestCatalogOwner(value);
58+
},
59+
registerNodeHostCommand: vi.fn(),
60+
registerNodeInvokePolicy: vi.fn(),
61+
} as unknown as OpenClawPluginApi;
62+
63+
registerPiSessionCatalog(api);
64+
const catalog = provider;
65+
expect(catalog).toBeDefined();
66+
await catalog!.list({ hostIds: ["node:node-1"] });
67+
await catalog!.read({ hostId: "node:node-1", threadId: "pi-remote" });
68+
69+
expect(invoke).toHaveBeenNthCalledWith(1, {
70+
nodeId: "node-1",
71+
command: PI_SESSIONS_LIST_COMMAND,
72+
params: {},
73+
timeoutMs: 20_000,
74+
scopes: ["operator.write"],
75+
});
76+
expect(invoke).toHaveBeenNthCalledWith(2, {
77+
nodeId: "node-1",
78+
command: PI_SESSION_READ_COMMAND,
79+
params: { threadId: "pi-remote" },
80+
timeoutMs: 20_000,
81+
scopes: ["operator.write"],
82+
});
83+
84+
invoke.mockResolvedValueOnce({
85+
payloadJSON: JSON.stringify({
86+
sessions: [
87+
{
88+
threadId: 123,
89+
status: "stored",
90+
archived: false,
91+
canContinue: false,
92+
canArchive: false,
93+
},
94+
],
95+
}),
96+
});
97+
await expect(catalog!.list({ hostIds: ["node:node-1"] })).resolves.toEqual([
98+
expect.objectContaining({
99+
error: { code: "NODE_INVOKE_FAILED", message: expect.any(String) },
100+
}),
101+
]);
102+
103+
invoke.mockResolvedValueOnce({
104+
payloadJSON: JSON.stringify({
105+
sessions: [
106+
{
107+
threadId: "--help",
108+
status: "stored",
109+
archived: false,
110+
canContinue: false,
111+
canArchive: false,
112+
},
113+
],
114+
}),
115+
});
116+
await expect(catalog!.list({ hostIds: ["node:node-1"] })).resolves.toEqual([
117+
expect.objectContaining({
118+
error: { code: "NODE_INVOKE_FAILED", message: expect.any(String) },
119+
}),
120+
]);
121+
122+
invoke.mockResolvedValueOnce({
123+
payloadJSON: JSON.stringify({
124+
threadId: "pi-remote",
125+
items: [{ type: "invalid", text: "bad" }],
126+
}),
127+
});
128+
await expect(catalog!.read({ hostId: "node:node-1", threadId: "pi-remote" })).rejects.toThrow(
129+
"invalid transcript page",
130+
);
131+
132+
invoke.mockClear();
133+
await expect(
134+
catalog!.read({ hostId: "node:node-1", threadId: "pi-remote", cursor: "" }),
135+
).rejects.toThrow("cursor is invalid");
136+
await expect(
137+
catalog!.list({
138+
hostIds: ["node:node-1"],
139+
cursors: { "node:node-1": "" },
140+
}),
141+
).resolves.toEqual([
142+
expect.objectContaining({
143+
error: { code: "NODE_INVOKE_FAILED", message: expect.any(String) },
144+
}),
145+
]);
146+
expect(invoke).not.toHaveBeenCalled();
147+
148+
invoke.mockResolvedValueOnce({
149+
payloadJSON: JSON.stringify({ sessions: [], nextCursor: " wrapped " }),
150+
});
151+
await expect(catalog!.list({ hostIds: ["node:node-1"] })).resolves.toEqual([
152+
expect.objectContaining({
153+
error: { code: "NODE_INVOKE_FAILED", message: expect.any(String) },
154+
}),
155+
]);
156+
invoke.mockResolvedValueOnce({
157+
payloadJSON: JSON.stringify({
158+
threadId: "pi-remote",
159+
items: [],
160+
nextCursor: " wrapped ",
161+
}),
162+
});
163+
await expect(catalog!.read({ hostId: "node:node-1", threadId: "pi-remote" })).rejects.toThrow(
164+
"invalid cursor",
165+
);
166+
167+
const exactCursor = Buffer.from(JSON.stringify({ offset: 1 }), "utf8").toString("base64url");
168+
invoke.mockResolvedValueOnce({ payloadJSON: JSON.stringify({ sessions: [] }) });
169+
await catalog!.list({
170+
hostIds: ["node:node-1"],
171+
cursors: { "node:node-1": exactCursor },
172+
});
173+
expect(invoke).toHaveBeenLastCalledWith(
174+
expect.objectContaining({ params: { cursor: exactCursor } }),
175+
);
176+
invoke.mockResolvedValueOnce({
177+
payloadJSON: JSON.stringify({ threadId: "pi-remote", items: [] }),
178+
});
179+
await catalog!.read({
180+
hostId: "node:node-1",
181+
threadId: "pi-remote",
182+
cursor: exactCursor,
183+
});
184+
expect(invoke).toHaveBeenLastCalledWith(
185+
expect.objectContaining({ params: { threadId: "pi-remote", cursor: exactCursor } }),
186+
);
187+
});
188+
});

0 commit comments

Comments
 (0)