Skip to content

Commit a151c1e

Browse files
authored
refactor(exec): retire legacy session execSecurity/execAsk; doctor migrates to permission modes (#132740)
* refactor(exec): retire legacy session exec policy Remove persisted execSecurity and execAsk from session resolution, protocol patches, runtime contexts, and reset/recovery carry-forwards. Keep placement and sandbox state unchanged and reserve the retired names. Route security and ask directives only to their message, with truthful acknowledgements. Migrate restrictive historical policy through doctor into permission modes without ever granting full-mode approval bypass. Regenerate Swift protocol models, update operator docs, and cover schema rejection, migration/reopen/idempotency, run-only overrides, and slot reservation. Production changes remain net-negative. * fix(doctor): keep every-command approval when retiring legacy exec policy Legacy execAsk=always required approval for every command. No permission mode encodes that (guarded prompts only on allowlist misses), so migrating those rows to guarded would let analyzed allowlisted commands run unprompted. Retire them to read-only with an explicit operator notice. * fix(exec): preserve migration restrictions and v4 patch compatibility Resolve partial legacy session policy against global and per-agent config, using the stricter base when sandbox availability is unknown. Keep deny and inherited approval-on-every-command restrictions during doctor migration. Retain the retired session patch fields in protocol v4, but reject them with permissionMode and per-run /exec guidance before applying any mutations. Regenerate Swift models and document the retirement contract. Refs #132740
1 parent 2c87f91 commit a151c1e

36 files changed

Lines changed: 745 additions & 440 deletions

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,7 @@ src/auto-reply/reply/exec/directive.ts 1
21952195
src/auto-reply/reply/followup-delivery-payloads.ts 1
21962196
src/auto-reply/reply/followup-turn-execution.ts 1
21972197
src/auto-reply/reply/get-reply-directives.ts 8
2198-
src/auto-reply/reply/get-reply-exec-overrides.ts 3
2198+
src/auto-reply/reply/get-reply-exec-overrides.ts 1
21992199
src/auto-reply/reply/get-reply-fast-path.ts 1
22002200
src/auto-reply/reply/get-reply-inline-actions.ts 5
22012201
src/auto-reply/reply/get-reply-native-slash-fast-path.ts 1

‎docs/gateway/permission-modes.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ New sessions, including managed worktree sessions, inherit the configured global
3232

3333
## Policy precedence and clamping
3434

35-
An explicit session mode takes precedence over the session's legacy `execSecurity` and `execAsk` overrides. When the mode is unset, those fields and the normal global or per-agent configuration continue to work as before.
35+
Session-wide exec policy belongs to the permission mode. When the mode is unset, normal global or per-agent configuration applies. `/exec security=... ask=...` applies only to its message and can only tighten an explicit session mode; `host` and `node` remain session placement defaults. See [Exec session overrides](/tools/exec#session-overrides-exec).
3636

37-
An explicit `full` mode is the admin-authorized exception to host approval-file floors: its OpenClaw exec policy remains `full` with approvals off. Approval-file floors continue to tighten config-driven exec policy, legacy session overrides, unset modes, and every non-full session mode. Sandbox restrictions and tool allow/deny policy remain independent, and a harness may clamp an unsupported mode to a compatible safer policy tuple. Codex also continues to honor externally enforced `requirements.toml` constraints.
37+
Before resuming sessions after upgrading a store with legacy session exec policy, run `openclaw doctor --fix`; the runtime no longer reads that policy. Missing policy values inherit the layered global and per-agent exec policy. When historical sandbox availability is unknown, migration uses the stricter sandbox base for automatic host selection. Restrictive policies migrate without broadening exec access to `read-only` or `guarded`. Existing permission modes remain unchanged. Legacy full-access policy is removed with a notice so configuration applies, never converted into a `full` permission grant.
38+
39+
The retired `execSecurity` and `execAsk` fields remain in the protocol v4 schemas for `sessions.patch` and `sessions.patchMany`. Requests containing either field, including `null`, are rejected with `INVALID_REQUEST` and guidance to set `permissionMode` (`read-only`, `guarded`, `workspace`, or `full`) or use `/exec` for one run. Neither field is stored as runtime session policy.
40+
41+
An explicit `full` mode is the admin-authorized exception to host approval-file floors: its OpenClaw exec policy remains `full` with approvals off unless a turn-scoped override tightens it. Approval-file floors continue to tighten config-driven exec policy, unset modes, and every non-full session mode. Tightening a full session's security restores those floors; tightening only `ask` does not. Sandbox restrictions and tool allow/deny policy remain independent, and a harness may clamp an unsupported mode to a compatible safer policy tuple. Codex also continues to honor externally enforced `requirements.toml` constraints.
3842

3943
For the independent sandbox, tool-policy, and elevated-exec controls, see [Sandbox vs tool policy vs elevated](/gateway/sandbox-vs-tool-policy-vs-elevated).

‎docs/tools/exec.md‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Example:
132132
| `auto` | `allowlist` | `on-miss` | Allowlist/safe-bin matches run directly; everything else routes through OpenClaw's native auto reviewer before asking a human. |
133133
| `full` | `full` | `off` | No approval gate. |
134134

135-
Per-session `/exec ask=always` still asks a human every time regardless of the persisted mode.
135+
Use `/exec ask=always` with a message to require human approval for that run. It does not persist to later messages. Use [session permission modes](/gateway/permission-modes) for session-wide policy.
136136

137137
Auto-review approval is single-use. On the gateway, OpenClaw supplies the resolved executable path to the reviewer and pins execution to that same path. An enforceable command chain or pipeline can be reviewed as one request when every executable resolves and OpenClaw can rebuild the complete command with those exact paths. Commands that cannot be reduced to one enforceable execution plan—such as heredocs, shell expansions, or unsupported wrapper quoting—fall back to human approval even if the model would otherwise allow them.
138138

@@ -162,15 +162,20 @@ Control UI: the **Devices** page includes a small "Exec node binding" panel for
162162

163163
## Session overrides (`/exec`)
164164

165-
Use `/exec` to set **per-session** defaults for `host`, `security`, `ask`, and `node`. Send `/exec` with no arguments to show the current values.
165+
Send `/exec host=... node=...` on its own to set **per-session** placement defaults. `security` and `ask` apply to the **current message only**; include them with the task you want to run. Send `/exec` with no arguments to show the resolved defaults.
166166

167167
Example:
168168

169169
```text
170-
/exec host=auto security=allowlist ask=on-miss node=mac-1
170+
/exec host=node node=worker-1
171+
/exec security=allowlist ask=always inspect the build output
171172
```
172173

173-
`/exec` is only honored for **authorized senders** through channel allowlists/pairing and access groups. Access-group enforcement is always on. It updates **session state only** and does not write config. Authorized external channel senders may set these session defaults. Internal gateway/webchat clients need `operator.admin` to persist them.
174+
`/exec` is only honored for **authorized senders** through channel allowlists/pairing and access groups. Access-group enforcement is always on. It does not write config. Authorized external channel senders may persist placement defaults; internal gateway/webchat clients need `operator.admin` to do so. Turn-scoped `security` and `ask` do not require that persistence permission.
175+
176+
A standalone `/exec security=deny` acknowledges the run-only setting but starts no agent run and does not affect the next message. Use [session permission modes](/gateway/permission-modes) to keep a policy across messages.
177+
178+
The `execSecurity` and `execAsk` fields in `sessions.patch` and `sessions.patchMany` are retired. They remain in the protocol v4 wire schema, but requests containing either field (including `null`) are rejected with `INVALID_REQUEST` and replacement guidance. Set `permissionMode` (`read-only`, `guarded`, `workspace`, or `full`) for session-wide policy, or use `/exec` with a message for a single run.
174179

175180
When a session has a permission mode, per-turn `/exec` overrides can only tighten its security and approval policy. For example, `/exec security=deny` blocks exec for that turn even in a full-access session; an override requesting looser security or fewer approvals leaves the session mode's limits unchanged. Full-access sessions bypass host approval-file floors only while effective security remains `full`. Tightening `ask` alone still applies the requested approval level without restoring those floors.
176181

‎docs/tools/slash-commands.md‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ command handling is enabled for the surface.
2626
<Card title="Directives" icon="sliders">
2727
`/think`, `/fast`, `/verbose`, `/trace`, `/reasoning`, `/elevated`,
2828
`/exec`, `/model`, `/queue` — stripped from the message before the model
29-
sees it. Persist session settings when sent alone; act as inline hints
30-
when sent with other text.
29+
sees it. Most persist session settings when sent alone; `/exec` security
30+
and approval options apply only to their message.
3131
</Card>
3232
<Card title="Inline shortcuts" icon="bolt">
3333
`/help`, `/commands`, `/status`, `/whoami` — run immediately and are
@@ -44,6 +44,10 @@ command handling is enabled for the surface.
4444
are removed. Text with no recognized directive is unchanged.
4545
- In **directive-only** messages (the message is only directives), they
4646
persist to the session and reply with an acknowledgement.
47+
`/exec security=... ask=...` is the exception: these options apply only
48+
to the current message and never change later turns. Include them with
49+
the task; use [session permission modes](/gateway/permission-modes) for
50+
session-wide policy. `/exec host=... node=...` still persists placement.
4751
- In **normal chat** messages with other text, they act as inline hints and
4852
do **not** persist session settings.
4953
Model selection is the exception: an authorized inline `/model` or
@@ -207,7 +211,7 @@ plugins.
207211
| `/fast [status\|auto\|on\|off\|default]` | Show, set, or clear fast mode |
208212
| `/reasoning [on\|off\|stream]` | Toggle reasoning visibility. Alias: `/reason` |
209213
| `/elevated [on\|off\|ask\|full]` | Toggle elevated mode. Alias: `/elev` |
210-
| `/exec host=<auto\|sandbox\|gateway\|node> security=<deny\|allowlist\|full> ask=<off\|on-miss\|always> node=<id>` | Show or set exec defaults |
214+
| `/exec host=<auto\|sandbox\|gateway\|node> security=<deny\|allowlist\|full> ask=<off\|on-miss\|always> node=<id>` | Show resolved exec defaults; persist host/node placement, apply security/ask to this message only. See [Session permission modes](/gateway/permission-modes) |
211215
| `/login [codex\|openai\|openai-codex]` | Pair Codex/OpenAI login from a private chat or Web UI session. Owner/admin only |
212216
| `/model [name\|default\|list\|status] [-s\|--session\|-a\|--agent\|-g\|--global]` | Show or select a model. `-s` changes only this session; owner/admin `-a` and `-g` also update configured defaults |
213217
| `/models [provider] [page] [limit=<n>\|all]` | List configured/auth-available providers or models |

‎extensions/codex/src/conversation-binding.test.ts‎

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,73 +2505,6 @@ describe("codex conversation binding", () => {
25052505
expect(request).not.toHaveBeenCalled();
25062506
});
25072507

2508-
it("ignores legacy session exec overlays when no canonical permission mode exists", async () => {
2509-
const sessionFile = path.join(tempDir, "session.jsonl");
2510-
const storePath = path.join(tempDir, "sessions.json");
2511-
await writeTestConversationBinding(sessionFile, { threadId: "thread-1", cwd: tempDir });
2512-
await upsertSessionEntry({
2513-
storePath,
2514-
sessionKey: "agent:main:session-1",
2515-
entry: {
2516-
sessionId: "session-1",
2517-
updatedAt: Date.now(),
2518-
execSecurity: "full",
2519-
execAsk: "off",
2520-
},
2521-
});
2522-
const request = vi.fn(async () => {
2523-
throw new Error("unexpected native turn");
2524-
});
2525-
sharedClientMocks.getSharedCodexAppServerClient.mockResolvedValue({
2526-
request,
2527-
addNotificationHandler: vi.fn(() => () => undefined),
2528-
addRequestHandler: vi.fn(() => () => undefined),
2529-
});
2530-
2531-
const result = await handleCodexConversationInboundClaim(
2532-
{
2533-
content: "continue the task",
2534-
channel: "discord",
2535-
isGroup: true,
2536-
commandAuthorized: true,
2537-
sessionKey: "agent:main:session-1",
2538-
},
2539-
{
2540-
channelId: "discord",
2541-
sessionKey: "agent:main:session-1",
2542-
pluginBinding: {
2543-
bindingId: "binding-1",
2544-
pluginId: "codex",
2545-
pluginRoot: tempDir,
2546-
channel: "discord",
2547-
accountId: "default",
2548-
conversationId: "channel-1",
2549-
boundAt: Date.now(),
2550-
data: {
2551-
kind: "codex-app-server-session",
2552-
version: 1,
2553-
sessionFile,
2554-
workspaceDir: tempDir,
2555-
agentId: "main",
2556-
},
2557-
},
2558-
},
2559-
{
2560-
timeoutMs: 50,
2561-
config: {
2562-
session: { store: storePath },
2563-
tools: { exec: { mode: "ask" } },
2564-
} as never,
2565-
},
2566-
);
2567-
2568-
expect(result?.handled).toBe(true);
2569-
expect(result?.reply?.text).toContain(
2570-
"OpenClaw native Codex conversation binding cannot route interactive approvals yet",
2571-
);
2572-
expect(request).not.toHaveBeenCalled();
2573-
});
2574-
25752508
it("blocks bound Codex CLI node turns when the current OpenClaw session is sandboxed", async () => {
25762509
const resumeCodexCliSessionOnNode = vi.fn();
25772510

@@ -2913,8 +2846,6 @@ describe("codex conversation binding", () => {
29132846
entry: {
29142847
sessionId: "destination-session",
29152848
updatedAt: Date.now(),
2916-
execSecurity: "full",
2917-
execAsk: "off",
29182849
},
29192850
});
29202851
codexRequirementsTomlMock.mockReturnValue(

‎packages/gateway-protocol/src/index.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ describe("lazy protocol validators", () => {
208208
responseUsage: "full",
209209
elevatedLevel: "on",
210210
execHost: "gateway",
211-
execSecurity: "allowlist",
212-
execAsk: "on-miss",
213211
execNode: "node-1",
214212
model: "openai/gpt-5.6-luna",
215213
completionOwnerSessionKey: "agent:main:main",
@@ -254,6 +252,15 @@ describe("lazy protocol validators", () => {
254252
]);
255253
});
256254

255+
it.each(["execSecurity", "execAsk"])("accepts retired v4 session policy field %s", (field) => {
256+
for (const value of ["deny", "always", null]) {
257+
expectAccepted(validateSessionsPatchParams, [sessionPatch({ [field]: value })]);
258+
expectAccepted(validateSessionsPatchManyParams, [
259+
{ targets: [{ key: "agent:main:main" }], patch: { [field]: value } },
260+
]);
261+
}
262+
});
263+
257264
it("validates sparse session tool overrides", () => {
258265
expectAccepted(validateSessionsPatchParams, [
259266
sessionPatch({

‎packages/gateway-protocol/src/schema/sessions-patch.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ const SessionsPatchMutationProperties = {
5656
),
5757
elevatedLevel: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
5858
execHost: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
59+
// Retired v4 fields stay wire-valid so the applier can explain their replacement.
60+
// Remove them only with the next owner-approved protocol version bump.
5961
execSecurity: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
6062
execAsk: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),
6163
execNode: Type.Optional(Type.Union([NonEmptyString, Type.Null()])),

‎src/agents/cli-runner/execute-plugin.test.ts‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -458,27 +458,6 @@ describe("plugin-owned CLI execution host boundary", () => {
458458
expect(cleanup).toHaveBeenCalledOnce();
459459
});
460460

461-
it("applies restrictive session policy even when global policy permits execution", async () => {
462-
const { context } = await createExecution({
463-
config: { tools: { exec: { security: "full", ask: "off" } } },
464-
sessionEntry: { sessionId: "sdk-session", updatedAt: 1, execSecurity: "deny" },
465-
});
466-
let decision: CliBackendToolPermissionResult | undefined;
467-
468-
await runPlugin(context, async function* (execution) {
469-
decision = await requestNativeTool(execution);
470-
yield SUCCESS_RESULT;
471-
});
472-
473-
expect(decision).toEqual(
474-
expect.objectContaining({
475-
behavior: "deny",
476-
message: expect.stringContaining("security=deny"),
477-
}),
478-
);
479-
expect(mockCallGatewayTool).not.toHaveBeenCalled();
480-
});
481-
482461
it.each([
483462
{
484463
name: "full policy releases the exact original input",
@@ -572,7 +551,7 @@ describe("plugin-owned CLI execution host boundary", () => {
572551
config,
573552
nativeTools: ["WebFetch"],
574553
runId: "plugin-approval-restricted",
575-
sessionEntry: { sessionId: "sdk-session", updatedAt: 1, execSecurity: "deny" },
554+
sessionEntry: { sessionId: "sdk-session", updatedAt: 1, permissionMode: "read-only" },
576555
});
577556
await runPlugin(restricted.context, async function* (execution) {
578557
await expect(

‎src/agents/cli-runner/mcp-grant-context.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ function buildCliMcpExecSession(
2121
: permissionMode;
2222
const execSession = {
2323
execHost: normalizeOptionalMcpContextValue(sessionEntry?.execHost),
24-
execSecurity: normalizeOptionalMcpContextValue(sessionEntry?.execSecurity),
25-
execAsk: normalizeOptionalMcpContextValue(sessionEntry?.execAsk),
2624
execNode: normalizeOptionalMcpContextValue(sessionEntry?.execNode),
2725
...(effectivePermissionMode ? { permissionMode: effectivePermissionMode } : {}),
2826
};

‎src/agents/cli-runner/prepare.test.ts‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3317,8 +3317,6 @@ describe("prepareCliRunContext", () => {
33173317
runId: "run-test-room-event-tools",
33183318
sessionEntry: {
33193319
execHost: "node",
3320-
execSecurity: "allowlist",
3321-
execAsk: "on-miss",
33223320
execNode: "mac-a",
33233321
} as never,
33243322
execOverrides: {
@@ -3391,8 +3389,6 @@ describe("prepareCliRunContext", () => {
33913389
nodeExecAllowed: true,
33923390
execSession: {
33933391
execHost: "node",
3394-
execSecurity: "allowlist",
3395-
execAsk: "on-miss",
33963392
execNode: "mac-a",
33973393
},
33983394
execOverrides: {

0 commit comments

Comments
 (0)