Repository navigation
feat: session permission modes with worktree-scoped defaults - #124909
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 17, 2026, 7:02 AM ET / 11:02 UTC. ClawSweeper reviewWhat this changesAdds session-scoped permission modes and worktree-root enforcement across Gateway sessions, native and Codex harnesses, and the Control UI. Merge readinessKeep open for maintainer review. The local checkout is behind the supplied base and cannot access the PR head or required sibling Codex source, so an exact-head merge verdict would not be evidence-backed. Priority: P1 Review scores
Verification
How this fits togetherGateway stores a session’s mode and root, then passes those facts into native tools and the Codex app-server policy. The Control UI displays and updates the session setting for authorized operators. flowchart LR
UI[Control UI] --> Gateway[Gateway session API]
Gateway --> Stored[Stored mode and session root]
Stored --> Native[Native harness policy]
Stored --> Codex[Codex app-server policy]
Native --> Tools[File and command tools]
Codex --> Sandbox[Codex sandbox and approvals]
Gateway --> UIState[Session change events]
UIState --> UI
Decision needed
Why: Repository policy requires direct inspection of the sibling Codex implementation for this protocol-dependent change, but that checkout and the PR objects are unavailable here. Before merge
Findings
Agent review detailsSecurityNeeds attention: No concrete vulnerability was established, but the required upstream Codex boundary review cannot be completed in this environment. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Have a maintainer with the exact PR head and sibling Codex checkout verify the runtimeWorkspaceRoots enforcement contract and rerun the exact-head security review before merging. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction: the PR body describes live after-fix exercises, but this reviewer could not access the exact head to independently rerun them. Is this the best way to solve the issue? Unclear: the session-owned policy design is coherent, but the exact Codex enforcement contract and final branch state could not be independently inspected. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bbe22082b0d3. LabelsLabel justifications:
EvidenceSecurity concerns:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (18 earlier review cycles; latest 8 shown)
|
3cec523 to
687f6f5
Compare
|
Review findings addressed on [P1] Require operator.admin before persisting full mode — FIXED. [P2] Verify the Codex workspace-root request field — refuted with direct upstream source + live proof. The pinned The security concern and both P1 merge risks are resolved by the fix above; the runtimeWorkspaceRoots merge risk is resolved by the contract evidence above. |
|
|
Merged via squash.
|
…w#124909) * feat(gateway): add session permission modes * feat(agents): enforce session permission policies * test: cover session permission modes * docs: explain session permission modes * fix(agents): preserve apply patch default root * feat(codex): map session permission modes * feat(ui): add session permission controls * test: cover session permission surfaces * fix(agents): enforce session permissions from entry * fix(codex): pass params object to requirements reader * fix(codex): honor session permission modes * fix(codex): preserve exec approval floors * chore: revert changelog edit (release-owned) * test: align full-mode promotion with upstream semantics * chore(protocol): regenerate session permission models * docs: register session permission modes * fix(ui): use shared permission dropdown * fix(sessions): restore permission mode contracts * fix(ci): record session permission startup JS growth in the budget baseline * refactor(agents): prepare session exec mode at dispatch Host dispatch owns permissionMode→exec override preparation; the codex plugin consumes prepared facts and the SDK barrel export is removed, keeping the plugin-sdk surface at its recorded budget. * test: type exec mode fixtures as ExecMode * fix(codex): require admin scope for yolo permissions * test: isolate codex permission command state * ci: refresh PR checks against current main * ci: refresh checks after gateway test repair * test: fix main-fallout CI suites * chore: refresh CI merge ref * fix(worker): fence permission-mode cloud placements * fix(sessions): clear worktree policy on detach * chore(protocol): generate session permission mode enum * test(gateway): type dispatch fixtures from session entries * fix(ui): allow clearing session permission mode * chore: refresh CI merge ref * fix(ci): record permission picker startup growth in the budget baseline * fix(gateway): gate session root projections
`sessions.create` now lstats the requested cwd and rejects one that is absent (openclaw#124909, "session permission modes with worktree-scoped defaults"), so the two cwdOnCreateOnly tests failed on the rebase with `cwd is unavailable: ENOENT` -- they passed fabricated /tmp paths. Switched to `tempDirs.make()`, the auto-cleanup helper the rest of this file already uses for real cwd cases. Also merged a duplicate import of `translator.test-helpers.js` that the rebase surfaced. No production change; the assertions are the same, against paths that exist.
…e default root Session permission modes hard-required a recorded sessionRoot, which only the sessions.create RPC ever records. Channel sessions, pre-#124909 rows, and exec-node sessions are rootless, so runs failed closed with 'session permission mode requires a recorded session root' (rows poisoned before the #128149 guards were permanently bricked) and operators could not set a mode on channel sessions at all. The mode semantics are root-free; every containment consumer already falls back to the workspace, and the remote worker launcher already derives its containment root from placement.remoteWorkspaceDir. Make that the canonical rule: a recorded sessionRoot pins worktree/explicit-cwd boundaries, and a rootless session's boundary is the agent's canonical workspace resolved where the run is prepared. - embedded runner + compaction: default policy root to realpath(workspace) instead of throwing/dropping the mode; bricked rows self-heal - gateway: delete the patch/create/reset rejection guards and session-permission-policy.ts entirely - codex plugin: helpers take a required defaultRoot (agent workspace fact, never a requested thread cwd); delete the four root throws; sandbox context for conversation bindings now derives from the agent workspace - ui: drop the rootless-rejection surface from the permission picker - docs: permission-modes boundary contract updated
…e default root (#129994) * fix(gateway): permission modes work on rootless sessions via workspace default root Session permission modes hard-required a recorded sessionRoot, which only the sessions.create RPC ever records. Channel sessions, pre-#124909 rows, and exec-node sessions are rootless, so runs failed closed with 'session permission mode requires a recorded session root' (rows poisoned before the #128149 guards were permanently bricked) and operators could not set a mode on channel sessions at all. The mode semantics are root-free; every containment consumer already falls back to the workspace, and the remote worker launcher already derives its containment root from placement.remoteWorkspaceDir. Make that the canonical rule: a recorded sessionRoot pins worktree/explicit-cwd boundaries, and a rootless session's boundary is the agent's canonical workspace resolved where the run is prepared. - embedded runner + compaction: default policy root to realpath(workspace) instead of throwing/dropping the mode; bricked rows self-heal - gateway: delete the patch/create/reset rejection guards and session-permission-policy.ts entirely - codex plugin: helpers take a required defaultRoot (agent workspace fact, never a requested thread cwd); delete the four root throws; sandbox context for conversation bindings now derives from the agent workspace - ui: drop the rootless-rejection surface from the permission picker - docs: permission-modes boundary contract updated * fix(agents): split workspace path identity out of the kysely state store Heals main: #116650 made memory-host-sdk/dreaming.ts import resolveWorkspaceStateIdentity from workspace-state-store, statically pulling kysely into the memory-core doctor-contract closure and failing the doctor-contract-closure-guard lane on origin/main. The identity helpers are pure path/crypto code; move them to workspace-state-identity.ts and repoint all importers (dreaming, event-store, onboarding recommendations, workspace migrations, legacy state). * fix(ui): drop the unused permission picker sessionRoot prop and dead i18n keys check-prod-types caught the New Session dialog still passing the removed sessionRoot picker prop; the prop and the permissionControls.rootLabel / sessionRoot strings have had no consumers since #124301. * fix(codex): resolve rootless permission boundaries from agent config, not bind cwd ClawSweeper P1: /codex bind --cwd stores the requested path as the binding workspaceDir, which the previous commit then trusted as defaultRoot — letting a bound thread's requested cwd become (and widen) the rootless permission boundary. resolveConversationAppServerRuntime now owns the fact: it resolves the selected agent's canonical workspace from config (falling back to the plugin's configured default workspace), and the caller-supplied agentWorkspaceDir parameter chain is deleted so no call site can pass a tainted value. Recovery of recorded roots is unchanged (pinned roots stay pinned); the moved-history test now proves the bind-cwd clamp lands on the agent workspace.
…e default root (openclaw#129994) * fix(gateway): permission modes work on rootless sessions via workspace default root Session permission modes hard-required a recorded sessionRoot, which only the sessions.create RPC ever records. Channel sessions, pre-openclaw#124909 rows, and exec-node sessions are rootless, so runs failed closed with 'session permission mode requires a recorded session root' (rows poisoned before the openclaw#128149 guards were permanently bricked) and operators could not set a mode on channel sessions at all. The mode semantics are root-free; every containment consumer already falls back to the workspace, and the remote worker launcher already derives its containment root from placement.remoteWorkspaceDir. Make that the canonical rule: a recorded sessionRoot pins worktree/explicit-cwd boundaries, and a rootless session's boundary is the agent's canonical workspace resolved where the run is prepared. - embedded runner + compaction: default policy root to realpath(workspace) instead of throwing/dropping the mode; bricked rows self-heal - gateway: delete the patch/create/reset rejection guards and session-permission-policy.ts entirely - codex plugin: helpers take a required defaultRoot (agent workspace fact, never a requested thread cwd); delete the four root throws; sandbox context for conversation bindings now derives from the agent workspace - ui: drop the rootless-rejection surface from the permission picker - docs: permission-modes boundary contract updated * fix(agents): split workspace path identity out of the kysely state store Heals main: openclaw#116650 made memory-host-sdk/dreaming.ts import resolveWorkspaceStateIdentity from workspace-state-store, statically pulling kysely into the memory-core doctor-contract closure and failing the doctor-contract-closure-guard lane on origin/main. The identity helpers are pure path/crypto code; move them to workspace-state-identity.ts and repoint all importers (dreaming, event-store, onboarding recommendations, workspace migrations, legacy state). * fix(ui): drop the unused permission picker sessionRoot prop and dead i18n keys check-prod-types caught the New Session dialog still passing the removed sessionRoot picker prop; the prop and the permissionControls.rootLabel / sessionRoot strings have had no consumers since openclaw#124301. * fix(codex): resolve rootless permission boundaries from agent config, not bind cwd ClawSweeper P1: /codex bind --cwd stores the requested path as the binding workspaceDir, which the previous commit then trusted as defaultRoot — letting a bound thread's requested cwd become (and widen) the rootless permission boundary. resolveConversationAppServerRuntime now owns the fact: it resolves the selected agent's canonical workspace from config (falling back to the plugin's configured default workspace), and the caller-supplied agentWorkspaceDir parameter chain is deleted so no call site can pass a tainted value. Recovery of recorded roots is unchanged (pinned roots stay pinned); the moved-history test now proves the bind-cwd clamp lands on the agent workspace.
What Problem This Solves
OpenClaw's agent permission posture is config-only and process-global: Codex sessions run whatever
plugins.entries.codex.config.appServer.*says (commonly YOLO/danger-full-access), the native harness's fs/exec policy is agent-global, and none of it is visible or switchable per session. Operators cannot see what an agent may touch, cannot scope a session to its worktree, and cannot change posture mid-session.Why This Change Was Made
This PR introduces one session-scoped, harness-agnostic permission mode with four values —
read-only,guarded,workspace,full— where the differentiating axis is who reviews escalations: a human (guarded), an LLM reviewer (workspace), or nobody (full). A canonical session root (worktree path → contained cwd → agent workspace, realpath-canonicalized) is recorded atsessions.createand interpreted by the mode.permissionModeon sessions.create/patch/row + event projection (additive, closed literal union; no SQLite DDL — entry_json only).SessionEntry.permissionMode/sessionRootrecorded at creation, preserved across reset, sourced from the entry at the run owner (attempt-execution), never from caller opts.fullrequiresoperator.adminon create and patch. Worktree sessions default toworkspace(deliberate bounded default; called out below).{root, mode}policy; fs tools split resolution-cwd from containment-root (nested worktree cwds work),read-onlyremoves mutating tools, exec maps todeny/ask/auto/fullwith existing allowlist fast-path, LLM auto-review, human fallback, and approvals-file floors.workspaceusesauto_review(guardian subagent) with the existing model-trust downgrade; session modes outrank explicitly configured global exec posture (supervision lock preserved); tuple applies before hook-promotion and trust resolution;thread/resumenow carriescwd./codex permissionspersists the canonical session fact.full, session root pinned in the menu footer), livesessions.patch+sessions.changedround-trip, and guardian transcript notices (muted for approvals, danger-toned for denials/warnings) consuming the existingcodex_app_server.guardianstream.Unset mode = exactly today's behavior; no shipped session changes posture.
User Impact
Sessions show their permission mode in the composer and can switch it mid-session (next turn applies it — Codex re-sends policy per turn). Worktree sessions are contained by default: file tools and the Codex seatbelt sandbox are rooted at the worktree, benign work inside flows freely, escalations get judged by the guardian (
workspace), a human (guarded), or blocked (read-only).auto_review)Screenshots (live gateway):
Composer chip at rest · mode menu with root footer · switched to Guarded:
Evidence
Live-proven on an isolated dev gateway (own
OPENCLAW_STATE_DIR, port 19811, dist build), both harnesses with real model turns:sessions.create {worktree:true}recordspermissionMode:"workspace"+ canonical worktreesessionRoot.Path escapes sandbox root …, actionable next-step copy, no file created); exec in workspace mode forces theallowlist/on-misslane despite globaltools.exec.mode=full; interactive exec approval card → Allow once → command ran (EXEC_RAN Darwin); reviewer model invocation verified via pinned-tracer model fetch./tmp/TMPDIRwritable) denied by seatbelt (Sandbox blocked the write: operation not permitted); explicit escalation request → guardianauto_reviewapproved a benign outside write (GUARDIAN_ALLOWED, file verified then removed).sessions.patch(server row showsguarded) → chip live-updates viasessions.changed.Focused suites (all green): gateway/protocol/runtime 283; native tools/attempts 146; codex policy/conversation/guardian 77+24; UI unit 190; mocked-gateway e2e 11; boundary regressions failed pre-fix for the intended reasons.
pnpm ui:i18n:baselineclean;tsgo:extensionslane green; multiple clean Codex autoreviews per commit plus a final full-branch autoreview.Production LOC (honest ledger vs origin/main): +1276/−157 (net +1119) — UI picker/notices ~+520, codex tuple mapping ~+330, core facts/enforcement ~+270; tests +1022/−41; docs +36. Named follow-ups that recoup surface: retire global
appServer.mode/approvalPolicy/sandbox/approvalsReviewerconfig via doctor migration; remove session-levelexecSecurity/execAskpatch fields; native auto-review transcript notices; New Session dialog mode select; requirements clamp for the legacy global path.Config-surface note (ClawSweeper): adds one session field (
permissionMode) to create/patch/row; no new config keys or env vars; legacy config paths unchanged when mode is unset.Main fallout CI repairs
Current main concurrently landed the canonical provider-provisioning split before the first exact-head watch completed. The initial fallout head
d00bbf633ffcarried a pure replay/recovery move and proved the original 45 tests remained 45/45, but that split became duplicate and was the PR's only merge conflict. Follow-upbfd155bc26removes the duplicate branch delta so the synthetic merge now uses main's canonical focused files:provider-provisioning.test.ts(607 lines),provider-provisioning-node-admission.test.ts(105),provider-provisioning-node.test.ts(105), andprovider-provisioning.replay.test.ts(398). All are below the 1,000-line cap; there is no suppression or baseline change.The untouched Synology loopback deadline test had a real isolation race rather than an external transport flake. Its module-global user-list cache is keyed by the full
user_listURL, while consecutive loopback tests rely on OS-assigned ephemeral ports. Port reuse could therefore return the prior test's cached user before the dripping test contacted its server, producingundefinedinstead of user id 21. The dripping test now adds a UUID token to its URL, preserving the same timeout and stale-cache assertions without sleeps or weakened semantics.Proof: provider suite 45/45 before and after the initial pure split; Synology loopback 9/9; targeted oxlint clean; formatting, core/extension test typechecks, max-lines ratchet, lint, and the complete changed gate green. Two scoped Codex autoreviews reported no accepted/actionable findings.