Skip to content

feat(sessions): run sessions in existing folders on paired devices - #169722

Merged
obviyus merged 23 commits into
mainfrom
feat/device-existing-folder-sessions
Oct 14, 2026
Merged

obviyus merged 23 commits into
mainfrom
feat/device-existing-folder-sessions

Conversation

@obviyus

@obviyus obviyus commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #136048 (non-Git directory semantics) and #142521 (non-Git worker workspace context; this PR does not implement ephemeral cloud workspaces).

What Problem This Solves

Device-hosted sessions required a Git repository or managed worktree, a constraint inherited from ephemeral cloud sessions, even when a paired personal machine should simply work in an existing non-Git folder.

User Impact

Users can choose Existing folder on device in New Session and run a session directly in an existing folder on a paired session-host device. OpenClaw does not create Git metadata, copy the folder to the Gateway, or sync, reconcile, reset, or delete it.

  • nodeHost.workerRuns.folders is node-local consent: unset allows existing directories, a non-empty list restricts selection to those roots and their descendants, and [] disables the feature and its capability advertisement.
  • The session stays pinned to that device: Auto/cloud dispatch, Move, and Continue on Gateway are refused. Attachment staging and the Gateway Files panel are unavailable for these sessions.
  • Worker HOME stays in private node storage. Files are not locked against external changes.

Why This Change Was Made

  • sessions.create accepts deviceFolder: { deviceId, path } (requires operator.write); the binding is stored on the existing session entry and the device-folder workspace kind reuses the worker execution and lifecycle owners.
  • The node owns folder policy and re-validates on every use: absolute or ~ paths only, realpath resolution (symlinks cannot escape a root), no filesystem root, no overlap with private worker storage, and a dev/ino fence between acquisition and execution. One shared rule in node-workspace-protocol.ts forbids preparing, resetting, transferring, seeding, or quiescing a device folder, for both ingress parsing and direct node execution.
  • Gateway shutdown reads the teardown scope from the durable placement, so stopping an attachment with no in-memory tunnel no longer reaches closed worktree admission.
  • A restored existing-folder create retry is owned by its frozen request; current device capacity or runtime no longer blocks it.
  • Attachments are refused for device-folder sessions before anything is persisted: chat.send rejects them with a clear message, New Session blocks Send while attachments are attached, and worker media preparation never restages historical attachments into a device folder, so one refused file cannot make later turns fail.
  • Security tradeoff: a session-host node already runs operator-directed agents with exec, so the allow-all default does not widen that boundary. The folder list is a selection guardrail, not an exec sandbox or a boundary against a compromised Gateway. Deployments that contain operator.write with tools.fs.workspaceOnly should also set a root list; the docs say so.
  • Control UI selection/path input, plus docs for node configuration, session hosting, operator scopes, and workspace behavior.

Screenshots

Synthetic mocked-Gateway captures (no real paths or tokens).

Before — only the managed/new-workspace choice

Before: no existing-device-folder option

After — desktop existing-folder input

After: existing folder on device, desktop

After — mobile layout

After: existing folder on device, mobile

Evidence

  • Cross-machine E2E on the final feature code: a disposable Gateway on one Mac (tailnet TLS, token auth, QA mock model) and a session-host node on a second Mac, both on the same exact head, with folders unset and an existing non-Git target folder on the second Mac. Pairing and capability advertisement; create + explicit dispatch (active, workspace = the device folder); hosted exec wrote pwd and hostname into the folder, confirmed by independent readback on that Mac; node restart and an unclean Gateway restart, then a second turn appended to the same file; ~ and a Gateway-only path rejected; reclaim + delete left the folder, sentinel, and absence of .git unchanged with no copy in Gateway state.
  • Isolated single-host E2E (25 checks, all pass): missing/root/file/relative/private-storage rejections; auto-dispatch rejection; node restarts; clean Gateway shutdown with a live tunnel and with a durable attachment but no tunnel; Gateway restart and resume; symlink escape and outside-root rejection under a root list; [] disables the capability.
  • Attachment refusal, live: on the isolated Gateway, a chat.send with a text attachment to a device-folder session returns the refusal, the attachment never enters history, and the next text turn and later turns after node and Gateway restarts complete in the folder.
  • Authority, live (real Gateway WebSocket, no mocks): an operator client granted only operator.read + operator.sessions.write sends sessions.create with deviceFolder and gets FORBIDDEN / missingScope: operator.write; no session row exists afterwards and a debugger logpoint on the node records no workspace command for that request. The full operator.write client creates and dispatches the same folder (active).
  • Device revocation during awaited admission, live: with the node process tree stopped (SIGSTOP) while sessions.create and sessions.dispatch wait on it, devices remove succeeds, then SIGCONT. Create fails with Selected device changed during folder validation; retry and leaves no row; dispatch fails with Device worker installation connection is no longer current; the node is then disconnected and its old token is rejected. Known bounded behavior: the read-only folder validation request already delivered to the stopped node still runs once on resume (1 ms after removal) before the close frame arrives; its result is discarded, nothing is persisted, and no session command runs. Unit coverage also revokes the caller (real captureGatewayDeviceRevocation capture) and the device during validation.
  • Requesting-operator revocation during awaited admission, live: separate signed operator devices with operator.write, real paired node stopped with SIGSTOP. Removing the operator while sessions.create waits on folder validation: the client gets gateway closed (4001): device removed, sessions.describe returns {"session":null}, the key is absent from sessions.list, and the node trace has no worker execution command. Removing a different operator while sessions.dispatch waits: the session moves from provisioning to {"state":"failed","terminalReason":"Gateway requester authority changed"}, hasActiveRun is false, and no worker command runs. As with device revocation, one already-delivered read-only folder validation runs on resume and its result is discarded.
  • Inline initial turns are refused: sessions.create with deviceFolder plus message, task or attachments is rejected before node I/O; the UI already sends the first message through sessions.send after dispatch. The three new cases fail with the validator removed (3 failed | 12 passed) and pass with it (25 passed).
  • Upgrade compatibility, live: the main merge-base build created a plain session and an explicit-cwd session (turn ok); the PR build on the same state dir lists and describes both with their original IDs, a new turn on the old session completes ok, and Doctor exits 0 with no session-row load errors.
  • Upgrade from stable v2026.10.3, live: the stable build created a plain session with a completed turn, an explicit-cwd session, a custom model alias and a non-default thinkingDefault. Direct startup on the new build exits 78 with "uses schema version 24; … run openclaw doctor --fix" on both this PR and the plain main merge base (inherited). After openclaw doctor --fix --non-interactive (v24 -> v26), the PR Gateway starts, both old sessions list and describe with their original IDs, both settings read back unchanged, a new turn on the old session returns ok, and a new device-folder session created after the upgrade dispatches and runs a turn in the folder. One session-event publication warning about an unsettled worker-environment mutation appeared during that dispatch; the turn still succeeded.
  • Focused tests: device-folder node, tunnel, create, protocol, media, submit-gate and draft-state suites pass; the restored-retry and history-restage regressions fail before their fixes.
  • Hosted CI: on the exact head 364a000, every job passes on the first attempt, and so does the Security Review, except checks-ui-e2e (8/9). That job runs plugins-lifecycle.e2e.test.ts, which also fails the same way on plain main (see the maintainer override comment). Earlier heads hit flaky qa-lab E2E tests and main-side ratchet failures that plain main also reproduces.

Merge Danger

Additive optional protocol field and session-entry JSON field; no SQL schema change. Older Gateways reject the new sessions.create parameter; older nodes do not advertise the capability, so the option is not offered. Revert removes the feature; existing device-folder sessions would then be unrecognized but their folders are untouched.

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: XL labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR lets sessions run directly in existing folders on explicitly selected paired devices.

Example: Start a session on paired-runner in the existing non-Git folder /srv/existing project.

  • Before: Device-hosted sessions use an OpenClaw-managed workspace rather than that existing device folder.
  • After: The worker runs in /srv/existing project, stays bound to paired-runner, and leaves the folder intact when the session is deleted.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Useful, coherent feature work with shipped-path behavior, authority, and upgrade evidence and no identified actionable defect; pending CI remains a landing gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Supplied real Gateway and paired-node evidence exercises creation, explicit dispatch, hosted execution, restart recovery, attachment refusal, folder preservation, scope denial, and caller/device revocation before worker execution; inspected screenshots cover desktop and mobile presentation.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Feature · Worth it: Yes · Fix scope: Complete
User problem: Users cannot run a complete hosted session directly in an existing non-Git folder on their paired device.
Reason: The maintainer-authored direction supplies a concrete device workflow, reuses existing execution owners, and explicitly documents its consent and lifecycle tradeoffs.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR adds a useful capability absent from current main, and no definite introduced defect was found; current-head CI remains pending.

Priority: P2
Reviewed head: 364a0000a69b09b9a51defa90e69cababc077829

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Control UI submits a device and folder to Gateway session creation; the paired node validates its local folder policy, and existing placement and worker lifecycle owners execute turns without transferring the folder.

flowchart LR
  A[Control UI] --> B[Gateway session creation]
  B --> C[Session entry]
  B --> D[Paired node folder validation]
  C --> E[Worker placement]
  E --> F[Node worker supervisor]
  F --> G[Existing user folder]
  F --> H[Private worker HOME]
Loading

Technical review

Best possible solution:

Land the device-bound workspace mode through the existing worker owners while preserving node-local consent and user-folder lifecycle guarantees.

Do we have a high-confidence way to reproduce the issue?

This is a feature addition: current-main source lacks the new creation parameter, and supplied live evidence exercises the proposed device-folder flow.

Is this the best way to solve the issue?

The implementation fits the existing placement and worker lifecycle owners and keeps user-owned folders outside Gateway transfer and reconciliation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f4f0255bc773.

Provenance checked

  • Paired-worker workspace transport keeps the original intent (438d035: The original paired-worker launch implementation deliberately used node-owned workspaces; subsequent transfer work supported Gateway-owned inputs and reconciliation.)
  • Worker lifetime and teardown keeps the original intent (e4d602c: Existing lifecycle owners preserve background processes and retain exact environment cleanup responsibility; this PR adds folder-specific cleanup without replacing those owners.)
  • New Session picker and retry state keeps the original intent (bcafd72: Picker changes preserve submitted selections, accepted-session ownership, and concurrent preferences; device-folder recovery likewise retains its frozen request.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Pinned introduction and current-main boundary: The pinned base-to-head diff adds deviceFolder to sessions.create; the fetched main schema still has no such field. GitHub confirms the reviewed head is open, non-draft, and mergeable. (packages/gateway-protocol/src/schema/sessions-create.ts:104, 364a0000a69b)
  • Caller and device authority: Creation composes current requester authority with the validated device connection before commit; private node dispatch rechecks authorization and pairing immediately before sending the command. (src/gateway/server-methods/sessions-create.ts:186, 364a0000a69b)
  • Node-owned folder policy: The node resolves existing directories, rejects filesystem roots and private-storage overlap, applies configured roots, and checks directory identity again before execution. (src/node-host/node-worker-device-folder.ts:87, 364a0000a69b)
  • Lifecycle preserves user files: Device-folder completion and reclaim bypass workspace reconciliation; node retention collects namespaced private HOME rather than the existing user folder. (src/gateway/worker-environments/placement-reclaim.ts:127, 364a0000a69b)
  • Supplied behavior and authority proof: The body and obviyus's discussion record real Gateway/node execution across two Macs, restart recovery, independent file readback, attachment refusal, scope denial, and requester/device revocation with no worker execution or persisted session after rejection. (364a0000a69b)
  • Visual proof inspected: Prepared screenshots visibly show the previous workspace choice and the new desktop/mobile device-folder input, including /srv/existing project; these are explicitly mocked-Gateway UI captures. (ui/src/pages/new-session/target-controls-view.tsx:327, 364a0000a69b)

Likely related people:

  • Peter Steinberger: Raw commit 438d035 adds src/gateway/worker-environments/node-worker-tunnel.ts:70 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 438d0358857b; files: src/gateway/worker-environments/node-worker-tunnel.ts)

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
New configuration option 1: nodeHost.workerRuns.folders Unset permits existing directories, a non-empty list restricts roots, and an empty list disables the capability.
Persisted workspace binding 1 optional session-entry field; no SQL schema change deviceFolder retains the canonical device/path binding through reset, recovery, and row publication.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A useful optional device-session capability with a limited, explicitly selected execution surface.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (20 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-13T18:18:44.160Z sha 49a83f2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T19:45:59.343Z sha 49a83f2 :: needs changes before merge. :: none
  • reviewed 2026-10-13T20:45:42.502Z sha f354d35 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-13T22:44:40.607Z sha 73b0fc1 :: needs changes before merge. :: none
  • reviewed 2026-10-14T00:38:13.510Z sha e7db547 :: needs changes before merge. :: none
  • reviewed 2026-10-14T00:48:30.838Z sha e7db547 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-14T01:27:17.253Z sha 12a2d82 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-14T01:37:41.454Z sha bea786c :: needs maintainer review before merge. :: none

Reviewed October 13, 2026, 11:08 PM ET / October 14, 2026, 03:08 UTC (Revision 21).

@clawsweeper clawsweeper Bot added the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Oct 12, 2026
@obviyus
obviyus force-pushed the feat/device-existing-folder-sessions branch from 2a2e365 to f7a2353 Compare October 12, 2026 07:59
@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. and removed proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Oct 12, 2026
@obviyus
obviyus force-pushed the feat/device-existing-folder-sessions branch from f7a2353 to 764c666 Compare October 12, 2026 17:46
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Oct 12, 2026
@obviyus

obviyus commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

Runtime-eligibility repair — inspected UI evidence

Synthetic before/after captures for the follow-up to the exact-head review. Switching an existing-folder draft to a runtime without worker-turn support now disables submission, explains the compatible-runtime requirement, and keeps the folder path. Returning to a compatible runtime restores submission.

Before (incompatible runtime still allowed submission):
Before: incompatible runtime leaves submission enabled

After desktop:
After: incompatible runtime blocks submission and preserves the path

After mobile:
After mobile: explanation and retained folder path

Disabled workspace choice:
Incompatible runtime disables existing-folder selection

Verification: 69 focused UI tests and two browser E2E tests passed; UI typecheck passed. The browser scenarios cover switching runtimes, blocked Enter/no creation, preserved path, compatible recovery, and pending-placement restoration. Final source publication and exact-head re-review follow separately.

@obviyus

obviyus commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Oct 12, 2026
@obviyus
obviyus force-pushed the feat/device-existing-folder-sessions branch from 9650b1d to 754fdbe Compare October 13, 2026 00:31
@obviyus
obviyus marked this pull request as ready for review October 13, 2026 00:32
@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 14, 2026
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the only red job on head 12a2d823b06a229facfe2d04e1f23b5f1b6f59b2 comes from main, not from this PR.

  • checks-fast-baseline-ratchets (job 115623631257): the mock-exports ratchet reports src/gateway/worker-environments/worker-turn-launcher.lazy.test.ts:212: ./worker-turn-execution.js.
    • This PR does not touch that test file, worker-turn-execution.ts or config/test-mock-exports-baseline.txt.
    • On plain origin/main (9583134a7d2, without this PR), scripts/check-test-mock-exports.mts --base <this PR's merge base> reports the same violation at the same line. It comes from main commit a1ac97b ("fix(gateway): retain placement facts for required worker turns"), which changed that test after this branch's merge base.
    • On this PR's head with --base origin/main, the ratchet passes: "Mock factory ratchet OK".
  • All other CI jobs pass on the first attempt, and the Security Review passes. openclaw/ci-gate is red only because of the job above.

@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

…folder-sessions

# Conflicts:
#	ui/src/pages/new-session/target-controls-view.tsx
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override for head bea786ce92558055494151cbf3979f60a7180805: the remaining red is inherited from main and from a GitHub API failure. This PR does not cause it.

  • checks-node-compact-small-7: plugin-sdk-surface-report.mts --check fails with public exports 3759 > 3758 and public callable exports 2194 > 2193 (first run, rerun).
    • This PR does not touch src/plugin-sdk or packages/plugin-sdk.
    • Plain main at f183f386715 (the main side of this merge, without this PR) fails the same check locally with the same numbers.
  • openclaw/ci-gate / Security Review: the Security Review passed on this exact head on the first CI attempt (run 38497483928, success). After the flaky-job rerun, it now fails only because GET /actions/runs/38496137643/attempts/2/jobs?per_page=100 times out on GitHub's side (run 38503044466).
    • From a maintainer shell, the same endpoint returns HTTP 502 for every attempt-2 run with per_page=100, but per_page=50 answers.
  • On the first attempt, three other jobs failed. All passed on the rerun:
    • checks-node-changed-6: skill-library-worker-wire.e2e.test.ts, which passes 2 of 2 times locally on this head;
    • checks-ui (3/3): chat-pane-parent-session.test.ts, which passes locally;
    • android-access-native: this PR changes no Android code.
  • ClawSweeper state is ready on this exact head.

@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override for head 364a0000a69b09b9a51defa90e69cababc077829: the only red job is inherited from main. This PR does not cause it.

  • checks-ui-e2e (8/9) (job 115657761235): ui/src/pages/plugins/plugins-lifecycle.e2e.test.ts > "retains uninstall feedback through during inspection" fails with AssertionError: expected 'Claw planner depends on calendar-plus…' to contain 'Configuration reload failed after rem…'.
    • On plain main at 72ccf6ff929 (the main side of this merge, without this PR), with a fresh install, the same file fails 2 of 2 times locally with the same test and the same assertion.
    • On this head it also fails locally in the same way, so the failure does not depend on this PR.
    • This PR changes nothing under ui/src/pages/plugins.
  • Every other CI job passes on the first attempt. The Security Review passes (run 38505347701). openclaw/ci-gate is red only because of the job above.
  • ClawSweeper state is ready on this exact head.

@obviyus
obviyus merged commit 2c87e33 into main Oct 14, 2026
186 of 189 checks passed
@obviyus
obviyus deleted the feat/device-existing-folder-sessions branch October 14, 2026 03:27
@obviyus

obviyus commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 2c87e33 (squash of head 364a000). ClawSweeper was ready on that head. The red checks-ui-e2e (8/9) job is inherited: plugins-lifecycle.e2e.test.ts fails the same way on plain main (see the maintainer override comment).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 14, 2026
…penclaw#169722)

Related: openclaw#136048 (non-Git directory semantics) and openclaw#142521 (non-Git worker workspace context; this PR does not implement ephemeral cloud workspaces).

## What Problem This Solves

Device-hosted sessions required a Git repository or managed worktree, a constraint inherited from ephemeral cloud sessions, even when a paired personal machine should simply work in an existing non-Git folder.

## User Impact

Users can choose **Existing folder on device** in New Session and run a session directly in an existing folder on a paired session-host device. OpenClaw does not create Git metadata, copy the folder to the Gateway, or sync, reconcile, reset, or delete it.

- `nodeHost.workerRuns.folders` is node-local consent: unset allows existing directories, a non-empty list restricts selection to those roots and their descendants, and `[]` disables the feature and its capability advertisement.
- The session stays pinned to that device: Auto/cloud dispatch, Move, and Continue on Gateway are refused. Attachment staging and the Gateway Files panel are unavailable for these sessions.
- Worker HOME stays in private node storage. Files are not locked against external changes.

## Why This Change Was Made

- `sessions.create` accepts `deviceFolder: { deviceId, path }` (requires `operator.write`); the binding is stored on the existing session entry and the `device-folder` workspace kind reuses the worker execution and lifecycle owners.
- The node owns folder policy and re-validates on every use: absolute or `~` paths only, realpath resolution (symlinks cannot escape a root), no filesystem root, no overlap with private worker storage, and a dev/ino fence between acquisition and execution. One shared rule in `node-workspace-protocol.ts` forbids preparing, resetting, transferring, seeding, or quiescing a device folder, for both ingress parsing and direct node execution.
- Gateway shutdown reads the teardown scope from the durable placement, so stopping an attachment with no in-memory tunnel no longer reaches closed worktree admission.
- A restored existing-folder create retry is owned by its frozen request; current device capacity or runtime no longer blocks it.
- Attachments are refused for device-folder sessions before anything is persisted: `chat.send` rejects them with a clear message, New Session blocks Send while attachments are attached, and worker media preparation never restages historical attachments into a device folder, so one refused file cannot make later turns fail.
- Security tradeoff: a session-host node already runs operator-directed agents with exec, so the allow-all default does not widen that boundary. The folder list is a selection guardrail, not an exec sandbox or a boundary against a compromised Gateway. Deployments that contain `operator.write` with `tools.fs.workspaceOnly` should also set a root list; the docs say so.
- Control UI selection/path input, plus docs for node configuration, session hosting, operator scopes, and workspace behavior.

## Screenshots

Synthetic mocked-Gateway captures (no real paths or tokens).

**Before — only the managed/new-workspace choice**

![Before: no existing-device-folder option](https://github.com/user-attachments/assets/b9697664-c8ed-414f-95e3-e34f987051d8)

**After — desktop existing-folder input**

![After: existing folder on device, desktop](https://github.com/user-attachments/assets/b721aeec-7e23-495a-b454-d85d97af8c79)

**After — mobile layout**

![After: existing folder on device, mobile](https://github.com/user-attachments/assets/2f2ff9fe-0c1f-4a85-9db7-9a1d9a5e534b)

## Evidence
- **Cross-machine E2E on the final feature code:** a disposable Gateway on one Mac (tailnet TLS, token auth, QA mock model) and a session-host node on a second Mac, both on the same exact head, with `folders` unset and an existing non-Git target folder on the second Mac. Pairing and capability advertisement; create + explicit dispatch (`active`, workspace = the device folder); hosted exec wrote `pwd` and `hostname` into the folder, confirmed by independent readback on that Mac; node restart and an unclean Gateway restart, then a second turn appended to the same file; `~` and a Gateway-only path rejected; reclaim + delete left the folder, sentinel, and absence of `.git` unchanged with no copy in Gateway state.
- **Isolated single-host E2E (25 checks, all pass):** missing/root/file/relative/private-storage rejections; auto-dispatch rejection; node restarts; clean Gateway shutdown with a live tunnel and with a durable attachment but no tunnel; Gateway restart and resume; symlink escape and outside-root rejection under a root list; `[]` disables the capability.
- **Attachment refusal, live:** on the isolated Gateway, a `chat.send` with a text attachment to a device-folder session returns the refusal, the attachment never enters history, and the next text turn and later turns after node and Gateway restarts complete in the folder.
- **Authority, live (real Gateway WebSocket, no mocks):** an operator client granted only `operator.read` + `operator.sessions.write` sends `sessions.create` with `deviceFolder` and gets `FORBIDDEN` / `missingScope: operator.write`; no session row exists afterwards and a debugger logpoint on the node records no workspace command for that request. The full `operator.write` client creates and dispatches the same folder (`active`).
- **Device revocation during awaited admission, live:** with the node process tree stopped (`SIGSTOP`) while `sessions.create` and `sessions.dispatch` wait on it, `devices remove` succeeds, then `SIGCONT`. Create fails with `Selected device changed during folder validation; retry` and leaves no row; dispatch fails with `Device worker installation connection is no longer current`; the node is then disconnected and its old token is rejected. Known bounded behavior: the read-only folder validation request already delivered to the stopped node still runs once on resume (1 ms after removal) before the close frame arrives; its result is discarded, nothing is persisted, and no session command runs. Unit coverage also revokes the caller (real `captureGatewayDeviceRevocation` capture) and the device during validation.
- **Requesting-operator revocation during awaited admission, live:** separate signed operator devices with `operator.write`, real paired node stopped with `SIGSTOP`. Removing the operator while `sessions.create` waits on folder validation: the client gets `gateway closed (4001): device removed`, `sessions.describe` returns `{"session":null}`, the key is absent from `sessions.list`, and the node trace has no worker execution command. Removing a different operator while `sessions.dispatch` waits: the session moves from `provisioning` to `{"state":"failed","terminalReason":"Gateway requester authority changed"}`, `hasActiveRun` is false, and no worker command runs. As with device revocation, one already-delivered read-only folder validation runs on resume and its result is discarded.
- **Inline initial turns are refused:** `sessions.create` with `deviceFolder` plus `message`, `task` or `attachments` is rejected before node I/O; the UI already sends the first message through `sessions.send` after dispatch. The three new cases fail with the validator removed (`3 failed | 12 passed`) and pass with it (`25 passed`).
- **Upgrade compatibility, live:** the `main` merge-base build created a plain session and an explicit-cwd session (turn `ok`); the PR build on the same state dir lists and describes both with their original IDs, a new turn on the old session completes `ok`, and Doctor exits 0 with no session-row load errors.
- **Upgrade from stable `v2026.10.3`, live:** the stable build created a plain session with a completed turn, an explicit-cwd session, a custom model alias and a non-default `thinkingDefault`. Direct startup on the new build exits 78 with "uses schema version 24; … run openclaw doctor --fix" on both this PR and the plain `main` merge base (inherited). After `openclaw doctor --fix --non-interactive` (`v24 -> v26`), the PR Gateway starts, both old sessions list and describe with their original IDs, both settings read back unchanged, a new turn on the old session returns `ok`, and a new device-folder session created after the upgrade dispatches and runs a turn in the folder. One session-event publication warning about an unsettled worker-environment mutation appeared during that dispatch; the turn still succeeded.
- **Focused tests:** device-folder node, tunnel, create, protocol, media, submit-gate and draft-state suites pass; the restored-retry and history-restage regressions fail before their fixes.
- **Hosted CI:** on the exact head `364a000`, every job passes on the first attempt, and so does the Security Review, except `checks-ui-e2e (8/9)`. That job runs `plugins-lifecycle.e2e.test.ts`, which also fails the same way on plain `main` (see the maintainer override comment). Earlier heads hit flaky qa-lab E2E tests and `main`-side ratchet failures that plain `main` also reproduces.

## Merge Danger

Additive optional protocol field and session-entry JSON field; no SQL schema change. Older Gateways reject the new `sessions.create` parameter; older nodes do not advertise the capability, so the option is not offered. Revert removes the feature; existing device-folder sessions would then be unrecognized but their folders are untouched.

Co-authored-by: Ayaan Zaidi <[email protected]>
obviyus added a commit that referenced this pull request Oct 16, 2026
…ns (#174713)

Related: #169722

## What Problem This Solves

**Existing folder on device** sessions require you to type an absolute path on the paired device. The **Browse folders** picker lists only the Gateway host, so it cannot help you find the folder on the device.

## User Impact

Admins can choose **Browse folders on <device>** in the New Session project menu, open folders on the selected paired device, and click **Use this folder** to fill the device path. Writers still type the path, because node folder listing is admin-only.

## Why This Change Was Made

- The Gateway already routes `fs.listDir` with `nodeId` to the node's directory listing (#105114). #126187 removed that route from New Session together with legacy `execNode` sessions, so the picker cannot reach it now.
- This change reuses the same picker and Gateway route for device-folder sessions only. The menu item appears when all of these are true:
  - device folders are available for the selected device
  - the operator is an admin
  - the device can invoke `fs.listDir`
- Device listings skip Gateway-only side effects: folder approval, the Git checkout probe and project registration.
- The Gateway now keeps a node's `INVALID_REQUEST` folder errors (for example `ENOENT`) as request errors. Before, it reported them as `UNAVAILABLE`. With this change, a stale or partly typed device path opens the device home folder, the same as the Gateway picker does.
- There is no protocol, schema or config change. The listing is not limited to `nodeHost.workerRuns.folders` roots. The device still checks the chosen folder when the session is created. The docs say this.

## Evidence

**Live, isolated Gateway + separate session-host node (both from this branch), real Control UI:**
- Selected the paired node, chose **Browse folders on Synthetic laptop**, and opened `projects/`. The listing showed the node's own home, not the Gateway's.
- Picked `device-only-tries`. The path field filled, and `sessions.create` stored that `deviceFolder`.
- The session dispatched to the device. A turn ran `pwd > proof.txt`, and the file appeared in the picked folder on the node.
- Typed `/nope/missing-on-device`, then chose browse. The picker opened the device home with no error.

| Before (`main`) | After |
| --- | --- |
| ![before menu](https://github.com/user-attachments/assets/2e713cae-3bc6-47af-b378-d67e86b82beb) | ![after menu](https://github.com/user-attachments/assets/b9cdae9e-e0ba-4766-98fd-7cbaece41774) |

| Device listing | Picked folder | Missing typed path falls back |
| --- | --- | --- |
| ![device listing](https://github.com/user-attachments/assets/99f21484-e711-478b-9b91-07d676f08c6b) | ![picked](https://github.com/user-attachments/assets/ff604832-d78e-4f2d-a70f-4109a00371db) | ![fallback](https://github.com/user-attachments/assets/f8de3452-59a6-4c5d-b43c-a0291673d63c) |

**Focused tests:**
- `new-session-page.device-folder.e2e.test.ts`: 4 passed, including the new browse-and-create case and the writer case (no browse item).
- `new-session-page.places` and `operator-scopes` e2e: 19 passed, so Gateway browsing still works.
- `draft-place-browser.test.ts`: 33 passed.
- `src/gateway/server-methods/fs.test.ts`: 16 passed. The new node error-code case fails without the `fs.ts` change.
- `tsgo:ui`, oxlint and oxfmt on the changed files, `ui:i18n:verify`.

**Gap:** the live node ran on the same host as the Gateway. A cross-machine device uses the same node WebSocket path, but I did not exercise one.

**Merge danger:** two-way door. A revert removes the menu item and the error-code change, and no state, config or contract changes. Blast radius: admin operators in New Session with a device-folder-capable paired device. Other `fs.listDir` node callers now see `INVALID_REQUEST` instead of `UNAVAILABLE` for node path errors.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. scripts Repository scripts security-sensitive-changed size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant