Skip to content

Commit bd8a7f1

Browse files
committed
feat(sessions): add agent lifecycle batch parity
1 parent 262cf17 commit bd8a7f1

21 files changed

Lines changed: 1338 additions & 272 deletions

‎docs/concepts/session-tool.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ Use [`sessions_search`](/concepts/session-search) for exact full-text recall acr
6060

6161
The owner-gated `sessions` tool exposes bounded self-service surfaces:
6262

63-
- `action: "patch"` changes the current session by default, or another visible session selected by `sessionKey`. It can set the label, sidebar icon, pin/archive state, model, and thinking level.
63+
- `action: "patch"` changes the current session by default, or another visible session selected by `sessionKey`. It can set the label, sidebar icon, pin/archive state, model, and thinking level. Single-session archive/restore patches are generation-fenced.
64+
- `action: "archive"` archives one visible `sessionKey` or an ordered `sessionKeys` batch of up to eight targets. Pass `dryRun: true` to return `would_archive`, `already_archived`, `not_found`, or `failed` outcomes without mutation. Result indexes map to input order, and a batch continues after target failures. To archive the session currently running the tool, use `patch` with `archived: true`; OpenClaw defers that self-archive until the run settles.
6465
- `action: "reset"` resets another visible session selected by `sessionKey`.
65-
- `action: "delete"` first archives and then deletes the exact same generation of another visible session selected by `sessionKey`. By default its transcript is retained as a deleted archive; pass `deleteTranscript: false` to leave the transcript state untouched. Resetting or deleting the session currently running the tool is rejected.
66+
- `action: "delete"` first archives and then deletes the exact same generation of one visible `sessionKey` or an ordered `sessionKeys` batch of up to eight targets. Pass `dryRun: true` to preview without mutation. By default its transcript is retained as a deleted archive; pass `deleteTranscript: false` to leave the transcript state untouched. A current-session target is reported as an item failure without aborting valid siblings; reset still rejects the current session.
6667
- `group_list`, `group_set`, `group_rename`, and `group_delete` manage the global ordered session-group catalog. `group_set` replaces the ordered name list rather than patching one entry.
6768

6869
Use `sessions_spawn` with `visible: true` to create a persistent dashboard session. This keeps session creation on the controlled spawn path, which enforces the parent's tool policy, sandbox, concurrency limits, and run timeout.

‎docs/gateway/config-tools.md‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ Local onboarding defaults new local configs to `tools.profile: "coding"` when un
3131

3232
### Tool groups
3333

34-
| Group | Tools |
35-
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
36-
| `group:runtime` | `exec`, `process`, `code_execution` (`bash` is accepted as an alias for `exec`) |
37-
| `group:fs` | `read`, `write`, `edit`, `apply_patch` |
38-
| `group:sessions` | `sessions`, `sessions_list`, `sessions_history`, `sessions_search`, `conversations_list`, `conversations_send`, `conversations_turn`, `sessions_send`, `sessions_spawn`, `sessions_yield`, `subagents`, `session_status`, `spawn_task`, `dismiss_task` |
39-
| `group:memory` | `memory_search`, `memory_get` |
40-
| `group:web` | `web_search`, `x_search`, `web_fetch` |
41-
| `group:ui` | `browser`, `screen`, `terminal`, `canvas`, `show_widget` |
42-
| `group:automation` | `heartbeat_respond`, `cron`, `gateway` |
43-
| `group:messaging` | `message` |
44-
| `group:nodes` | `nodes`, `computer` |
45-
| `group:agents` | `agents_list`, `get_goal`, `create_goal`, `update_goal`, `update_plan`, `ask_user`, `skill_workshop` |
46-
| `group:media` | `image`, `image_generate`, `music_generate`, `video_generate`, `tts` |
47-
| `group:openclaw` | All built-in tools above except `read`/`write`/`edit`/`apply_patch`/`exec`/`process`/`canvas` (excludes plugin tools) |
48-
| `group:plugins` | Tools owned by loaded plugins, including configured MCP servers exposed through `bundle-mcp` |
34+
| Group | Tools |
35+
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
36+
| `group:runtime` | `exec`, `process`, `code_execution` (`bash` is accepted as an alias for `exec`) |
37+
| `group:fs` | `read`, `write`, `edit`, `apply_patch` |
38+
| `group:sessions` | `sessions`, `sessions_list`, `sessions_history`, `sessions_search`, `conversations_list`, `conversations_send`, `conversations_turn`, `sessions_send`, `sessions_spawn`, `agents_wait`, `sessions_yield`, `subagents`, `session_status`, `spawn_task`, `dismiss_task` |
39+
| `group:memory` | `memory_search`, `memory_get` |
40+
| `group:web` | `web_search`, `x_search`, `web_fetch` |
41+
| `group:ui` | `browser`, `screen`, `dashboard`, `terminal`, `canvas`, `show_widget` |
42+
| `group:automation` | `heartbeat_respond`, `cron`, `gateway` |
43+
| `group:messaging` | `message` |
44+
| `group:nodes` | `nodes`, `computer`, `mobile_ui` |
45+
| `group:agents` | `agents_list`, `get_goal`, `create_goal`, `update_goal`, `update_plan`, `ask_user`, `skill_workshop` |
46+
| `group:media` | `image`, `image_generate`, `music_generate`, `video_generate`, `tts` |
47+
| `group:openclaw` | All built-in tools above except `read`/`write`/`edit`/`apply_patch`/`exec`/`process`/`canvas` (excludes plugin tools) |
48+
| `group:plugins` | Tools owned by loaded plugins, including configured MCP servers exposed through `bundle-mcp` |
4949

5050
`spawn_task` lets a coding agent propose confirmed follow-up work without starting it. The suggestion's project directory must be a git checkout; invalid suggestions, including a non-git directory or blank prompt, are rejected when the tool records them. The Control UI shows the title and summary as an actionable chip; a Gateway-backed TUI shows an equivalent interactive prompt. Accepting either creates a fresh managed-worktree session and sends the full prompt there while the current turn continues. `dismiss_task` withdraws a still-pending suggestion by the ephemeral `task_id` returned from `spawn_task`.
5151

‎extensions/policy/src/tool-policy-conformance.test.ts‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import { expandPolicyToolRequirement, toolListCoversTool } from "./tool-policy-c
33

44
describe("policy tool group conformance", () => {
55
it("keeps computer control in both node and OpenClaw policy groups", () => {
6-
expect(expandPolicyToolRequirement("group:nodes")).toEqual(
7-
expect.arrayContaining(["computer", "mobile_ui"]),
8-
);
6+
expect(expandPolicyToolRequirement("group:nodes")).toEqual(["nodes", "computer", "mobile_ui"]);
97
expect(expandPolicyToolRequirement("group:openclaw")).toEqual(
108
expect.arrayContaining(["computer", "mobile_ui"]),
119
);
@@ -19,6 +17,32 @@ describe("policy tool group conformance", () => {
1917
"web_fetch",
2018
"x_search",
2119
]);
20+
expect(toolListCoversTool(["cron"], "automations")).toBe(true);
21+
expect(expandPolicyToolRequirement("group:sessions")).toEqual([
22+
"sessions",
23+
"sessions_list",
24+
"sessions_history",
25+
"sessions_search",
26+
"conversations_list",
27+
"conversations_send",
28+
"conversations_turn",
29+
"sessions_send",
30+
"sessions_spawn",
31+
"agents_wait",
32+
"sessions_yield",
33+
"subagents",
34+
"session_status",
35+
"spawn_task",
36+
"dismiss_task",
37+
]);
38+
expect(expandPolicyToolRequirement("group:ui")).toEqual([
39+
"browser",
40+
"screen",
41+
"dashboard",
42+
"terminal",
43+
"canvas",
44+
"show_widget",
45+
]);
2246
});
2347

2448
it("matches wildcard tool requirements", () => {

‎extensions/policy/src/tool-policy-conformance.ts‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,40 @@ const POLICY_TOOL_GROUPS: Record<string, readonly string[]> = {
77
"x_search",
88
"memory_search",
99
"memory_get",
10+
"sessions",
1011
"sessions_list",
1112
"sessions_history",
13+
"sessions_search",
14+
"conversations_list",
15+
"conversations_send",
16+
"conversations_turn",
1217
"sessions_send",
1318
"sessions_spawn",
19+
"agents_wait",
1420
"sessions_yield",
1521
"subagents",
1622
"session_status",
23+
"spawn_task",
24+
"dismiss_task",
1725
"browser",
26+
"screen",
27+
"dashboard",
28+
"terminal",
29+
"show_widget",
1830
"message",
1931
"heartbeat_respond",
20-
"cron",
32+
"automations",
2133
"gateway",
2234
"nodes",
2335
"computer",
2436
"mobile_ui",
2537
"agents_list",
38+
"get_goal",
39+
"create_goal",
40+
"update_goal",
2641
"update_plan",
42+
"ask_user",
43+
"skill_workshop",
2744
"image",
2845
"image_generate",
2946
"music_generate",
@@ -35,19 +52,35 @@ const POLICY_TOOL_GROUPS: Record<string, readonly string[]> = {
3552
"group:web": ["web_search", "web_fetch", "x_search"],
3653
"group:memory": ["memory_search", "memory_get"],
3754
"group:sessions": [
55+
"sessions",
3856
"sessions_list",
3957
"sessions_history",
58+
"sessions_search",
59+
"conversations_list",
60+
"conversations_send",
61+
"conversations_turn",
4062
"sessions_send",
4163
"sessions_spawn",
64+
"agents_wait",
4265
"sessions_yield",
4366
"subagents",
4467
"session_status",
68+
"spawn_task",
69+
"dismiss_task",
4570
],
46-
"group:ui": ["browser", "canvas"],
71+
"group:ui": ["browser", "screen", "dashboard", "terminal", "canvas", "show_widget"],
4772
"group:messaging": ["message"],
48-
"group:automation": ["heartbeat_respond", "cron", "gateway"],
73+
"group:automation": ["heartbeat_respond", "automations", "gateway"],
4974
"group:nodes": ["nodes", "computer", "mobile_ui"],
50-
"group:agents": ["agents_list", "update_plan"],
75+
"group:agents": [
76+
"agents_list",
77+
"get_goal",
78+
"create_goal",
79+
"update_goal",
80+
"update_plan",
81+
"ask_user",
82+
"skill_workshop",
83+
],
5184
"group:media": ["image", "image_generate", "music_generate", "video_generate", "tts"],
5285
} as const;
5386

@@ -80,6 +113,9 @@ function normalizePolicyToolName(value: string): string {
80113
if (normalized === "apply-patch") {
81114
return "apply_patch";
82115
}
116+
if (normalized === "cron") {
117+
return "automations";
118+
}
83119
return normalized;
84120
}
85121

‎src/agents/agent-tools.create-openclaw-coding-tools.test.ts‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,17 @@ function createToolsForStoredSession(storeTemplate: string, sessionKey: string)
118118

119119
function expectNoSubagentControlTools(tools: ReturnType<typeof createOpenClawCodingTools>) {
120120
const names = new Set(tools.map((tool) => tool.name));
121+
expect(names.has("sessions")).toBe(false);
121122
expect(names.has("sessions_spawn")).toBe(false);
122123
expect(names.has("sessions_list")).toBe(false);
123124
expect(names.has("sessions_history")).toBe(false);
124125
expect(names.has("subagents")).toBe(false);
125126
}
126127

128+
function expectNoSessionLifecycleTool(tools: ReturnType<typeof createOpenClawCodingTools>) {
129+
expect(tools.map((tool) => tool.name)).not.toContain("sessions");
130+
}
131+
127132
function applyRuntimeToolsAllow<T extends { name: string }>(tools: T[], toolsAllow: string[]) {
128133
const allowSet = new Set(toolsAllow.map((name) => normalizeToolName(name)));
129134
return tools.filter((tool) => allowSet.has(normalizeToolName(tool.name)));
@@ -1834,6 +1839,7 @@ describe("createOpenClawCodingTools", () => {
18341839

18351840
const restrictedTools = createToolsForStoredSession(storeTemplate, "agent:main:acp:plain");
18361841
const restrictedNames = new Set(restrictedTools.map((tool) => tool.name));
1842+
expect(restrictedNames.has("sessions")).toBe(false);
18371843
expect(restrictedNames.has("sessions_spawn")).toBe(true);
18381844
expect(restrictedNames.has("subagents")).toBe(true);
18391845

@@ -1844,6 +1850,52 @@ describe("createOpenClawCodingTools", () => {
18441850
}
18451851
});
18461852

1853+
it("hard-denies session lifecycle mutations for leaf, orchestrator, and ACP inventories", async () => {
1854+
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-lifecycle-policy-"));
1855+
try {
1856+
const storeTemplate = path.join(tmpDir, "sessions-{agentId}.json");
1857+
const entries = {
1858+
"agent:main:subagent:leaf": {
1859+
sessionId: "leaf-session",
1860+
updatedAt: Date.now(),
1861+
spawnDepth: 2,
1862+
subagentRole: "leaf",
1863+
subagentControlScope: "none",
1864+
},
1865+
"agent:main:subagent:orchestrator": {
1866+
sessionId: "orchestrator-session",
1867+
updatedAt: Date.now(),
1868+
spawnDepth: 1,
1869+
subagentRole: "orchestrator",
1870+
subagentControlScope: "children",
1871+
},
1872+
"agent:main:acp:child": {
1873+
sessionId: "acp-session",
1874+
updatedAt: Date.now(),
1875+
spawnDepth: 1,
1876+
subagentRole: "orchestrator",
1877+
subagentControlScope: "children",
1878+
spawnedBy: "agent:main:subagent:orchestrator",
1879+
},
1880+
};
1881+
await writeSessionStore(storeTemplate, "main", entries);
1882+
1883+
const leaf = createToolsForStoredSession(storeTemplate, "agent:main:subagent:leaf");
1884+
const orchestrator = createToolsForStoredSession(
1885+
storeTemplate,
1886+
"agent:main:subagent:orchestrator",
1887+
);
1888+
const acp = createToolsForStoredSession(storeTemplate, "agent:main:acp:child");
1889+
1890+
expectNoSessionLifecycleTool(leaf);
1891+
expectNoSessionLifecycleTool(orchestrator);
1892+
expectNoSessionLifecycleTool(acp);
1893+
expect(toolNameList(orchestrator)).toContain("sessions_spawn");
1894+
} finally {
1895+
await fs.rm(tmpDir, { recursive: true, force: true });
1896+
}
1897+
});
1898+
18471899
it("applies leaf tool policy for cross-agent subagent sessions when spawnDepth is missing", async () => {
18481900
const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cross-agent-subagent-"));
18491901
try {

‎src/agents/agent-tools.policy.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ describe("resolveSubagentToolPolicyForSession", () => {
320320
const sessionKeys = {
321321
leaf: "agent:main:subagent:hard-deny-leaf",
322322
orchestrator: "agent:main:subagent:hard-deny-orchestrator",
323+
acp: "agent:main:acp:hard-deny",
323324
} as const;
324325
await writeSessionEntries(storePath, {
325326
[sessionKeys.leaf]: {
@@ -336,6 +337,13 @@ describe("resolveSubagentToolPolicyForSession", () => {
336337
subagentRole: "orchestrator",
337338
subagentControlScope: "children",
338339
},
340+
[sessionKeys.acp]: {
341+
sessionId: "hard-deny-acp",
342+
updatedAt: Date.now(),
343+
spawnDepth: 1,
344+
subagentRole: "orchestrator",
345+
subagentControlScope: "children",
346+
},
339347
});
340348
const hardDeniedTools = [
341349
"gateway",
@@ -344,6 +352,7 @@ describe("resolveSubagentToolPolicyForSession", () => {
344352
"automations",
345353
"cron",
346354
"message",
355+
"sessions",
347356
"sessions_send",
348357
"conversations_list",
349358
"conversations_send",

‎src/agents/agent-tools.policy.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const SUBAGENT_TOOL_DENY_ALWAYS = [
5454
AUTOMATIONS_TOOL_NAME,
5555
// Direct user/session sends - subagents communicate through announce chain
5656
"message",
57+
"sessions",
5758
"sessions_send",
5859
"conversations_list",
5960
"conversations_send",

0 commit comments

Comments
 (0)