Skip to content

Commit 99dd134

Browse files
committed
fix(gateway): gate session root projections
1 parent b7555d4 commit 99dd134

4 files changed

Lines changed: 53 additions & 4 deletions

File tree

‎src/gateway/session-event-payload.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,26 @@ it("projects session actors and explicitly clears absent attribution", () => {
3737
});
3838
});
3939

40-
it("projects the prepared permission boundary", () => {
40+
it("projects the prepared permission boundary only for an explicit mode", () => {
41+
const ordinary = buildGatewaySessionEventFields({
42+
sessionRow: {
43+
key: "agent:main:ordinary",
44+
kind: "direct",
45+
sessionRoot: "/workspace/private",
46+
updatedAt: 3,
47+
},
48+
});
49+
expect(ordinary).toMatchObject({ permissionMode: null });
50+
expect(ordinary).not.toHaveProperty("sessionRoot");
51+
4152
expect(
4253
buildGatewaySessionEventFields({
4354
sessionRow: {
4455
key: "agent:main:workspace",
4556
kind: "direct",
4657
permissionMode: "workspace",
4758
sessionRoot: "/workspace/project",
48-
updatedAt: 3,
59+
updatedAt: 4,
4960
},
5061
}),
5162
).toMatchObject({ permissionMode: "workspace", sessionRoot: "/workspace/project" });

‎src/gateway/session-event-payload.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export function buildGatewaySessionEventFields(params: {
7070
spawnedWorkspaceDir: sessionRow.spawnedWorkspaceDir,
7171
spawnedCwd: sessionRow.spawnedCwd,
7272
permissionMode: sessionRow.permissionMode ?? null,
73-
sessionRoot: sessionRow.sessionRoot,
73+
...(sessionRow.permissionMode !== undefined && sessionRow.sessionRoot !== undefined
74+
? { sessionRoot: sessionRow.sessionRoot }
75+
: {}),
7476
forkedFromParent: sessionEntryForkedFromParent(sessionRow) ? true : undefined,
7577
spawnDepth: sessionRow.spawnDepth,
7678
subagentRole: sessionRow.subagentRole,

‎src/gateway/session-utils-row.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,9 @@ export function buildGatewaySessionRow(params: {
460460
spawnedWorkspaceDir: entry?.spawnedWorkspaceDir,
461461
spawnedCwd: entry?.spawnedCwd,
462462
permissionMode: entry?.permissionMode,
463-
sessionRoot: entry?.sessionRoot,
463+
...(entry?.permissionMode !== undefined && entry.sessionRoot !== undefined
464+
? { sessionRoot: entry.sessionRoot }
465+
: {}),
464466
worktree: entry?.worktree,
465467
execNode: entry?.execNode,
466468
execCwd: entry?.execCwd,

‎src/gateway/session-utils.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,40 @@ describe("gateway session utils", () => {
17401740
expect(row.execCwd).toBe("/Users/peter/Projects/openclaw");
17411741
});
17421742

1743+
test("buildGatewaySessionRow projects the session root only for an explicit permission mode", () => {
1744+
const cfg = { agents: { list: [{ id: "main", default: true }] } } as OpenClawConfig;
1745+
const ordinaryEntry: SessionEntry = {
1746+
sessionId: "ordinary",
1747+
sessionRoot: "/workspace/private",
1748+
updatedAt: 1,
1749+
};
1750+
const ordinaryRow = buildGatewaySessionRow({
1751+
cfg,
1752+
storePath: "",
1753+
store: { "agent:main:ordinary": ordinaryEntry },
1754+
key: "agent:main:ordinary",
1755+
entry: ordinaryEntry,
1756+
});
1757+
expect(ordinaryRow).not.toHaveProperty("sessionRoot");
1758+
1759+
const permissionEntry: SessionEntry = {
1760+
...ordinaryEntry,
1761+
permissionMode: "workspace",
1762+
sessionId: "permission",
1763+
};
1764+
const permissionRow = buildGatewaySessionRow({
1765+
cfg,
1766+
storePath: "",
1767+
store: { "agent:main:permission": permissionEntry },
1768+
key: "agent:main:permission",
1769+
entry: permissionEntry,
1770+
});
1771+
expect(permissionRow).toMatchObject({
1772+
permissionMode: "workspace",
1773+
sessionRoot: "/workspace/private",
1774+
});
1775+
});
1776+
17431777
test("buildGatewaySessionRow prefers entry.label over origin.label for direct sessions", () => {
17441778
const cfg = { agents: { list: [{ id: "main", default: true }] } } as OpenClawConfig;
17451779
const entry: SessionEntry = {

0 commit comments

Comments
 (0)