Repository navigation
fix(ui): file links outside the session workspace fail to open, HTML previews drop their assets - #163185
Conversation
…preview assets File links in Control UI chat failed with "Failed to load" when the file lived outside the viewing session's workspace root, which is common for links in forwarded/inter-session updates and for agent-workspace scratch files. HTML previews also rendered without their relative images, stylesheets and scripts. - sessions.files.get/list follow the session agent's file-tool read boundary: contained in read-only/guarded/workspace modes, with tools.fs.workspaceOnly, under a sandbox, or when file tools do not run on the Gateway host; otherwise host paths are readable. Out-of-root reads additionally require the caller to pass the real chat.send admission for that session, run inside prepared session facts and rechecked after I/O. Out-of-root previews are read-only; write containment is unchanged. - Links inside messages with a sender session open against that session. - New session read method sessions.files.assets lets the UI inline relative assets into sandboxed HTML previews by source offset (64 refs, 1 MiB per asset, 4 MiB per call; fonts stay unloaded under the unchanged CSP). - canvas.document.preview joins session-reader admission so session-only readers can render HTML previews. - authorizeGatewayRequestPreDispatch moves unchanged into server-methods/request-authorization.ts with a synchronous consumeSessionTurn hook.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: blocked before merge. Reviewed October 2, 2026, 8:26 PM ET / October 3, 2026, 00:26 UTC (Revision 11). ClawSweeper reviewWhat this changesControl UI file previews use the sending session’s file-read permissions and load relative HTML images, stylesheets, and scripts through bounded Gateway reads. Merge readiness⛔ Blocked before merge - 1 item remains This PR remains useful: current main still lacks the corrected preview behavior. No blocking correctness finding remains, and the earlier migration request is unsupported by the additive wire-only changes. Priority: P2 Review scores
Verification
How this fits togetherControl UI turns file links in chat into Gateway requests scoped to the owning session. The Gateway authorizes filesystem access and returns preview bytes, which the UI renders in its existing isolated HTML sandbox. flowchart TD
A[Chat file link] --> B[Resolve owning session]
B --> C[Gateway session read authorization]
C --> D{Outside workspace?}
D -->|Yes| E[Current turn permission and host policy]
D -->|No| F[Bounded file and asset reads]
E --> F
F --> G[Recheck authority and return bytes]
G --> H[Isolated HTML preview]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +1214, Tests +1503, Docs +34. Total +2751 across 62 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Use the canonical session authorization owner for previews, preserve contained writes and sandbox isolation, and keep asset loading bounded with visible partial failures. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main contains previews to the workspace and never fetches relative HTML assets. The supplied before/after and isolated-Gateway evidence demonstrates the affected flow; this reviewer did not execute target code. Is this the best way to solve the issue? Yes. Reusing turn admission avoids a competing authorization policy, while sender-scoped preview identity and bounded asset reads address the two reported failures without persistent-state changes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 23bc4d7bfe86. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (10 earlier review cycles; latest 8 shown)
|
Restore the ordinary pre-dispatch fence to main so mutation commit guards retain handler-entry ordering for plugin contention and ACP cleanup. Session file reads use non-committing request checks, including their borrowed chat.send authorization, without consuming mutation callbacks. Append deferred classic preview scripts after authored HTML in source order. Keep module, async, and blocking scripts in place. Update forwarded message fixtures for current renderer APIs while retaining file ownership assertions. Validation: all 12 requested test files and the HTML preview browser suite; core, UI, UI-test, and source-test type lanes; copy-out oxlint and oxfmt over all 63 branch-changed files; git diff --check. The existing Linux-only non-UTF-8 filename test is skipped on macOS.
The previous commit also special-cased sessions.files.* in the router and swapped their transport commit guard for a new non-committing check. That was not needed: in-root file reads on main already revalidate through retainSessionScopedRead, which runs the request's commit guard, and production guards are caller-currency assertions. The actual regression was only the pre-dispatch tail invoking assertInvocationCurrent for every request, which the previous commit already restored to main. Restore server-methods.ts, session-mutation-guards.ts and the turn-authority test to their reviewed state; the host-read path again revalidates through requestMutationAuthority.assertCurrent(), matching existing reads. Validation: plugins.lifecycle-contention (2/2) and acp spawn (13/13) pass; session-turn-authority, host-read and assets suites pass (23 tests); tsgo:core and tsgo:test:src pass.
Replace the end-of-document append path with in-place inline module trampolines. Each trampoline inserts the original code as an inline classic script, preserving document order with modules, classic globals, retained attributes, and sloppy mode under the existing sandbox CSP and document guard. Escape serialized code and attributes against HTML script termination. Replace the srcdoc-only regression with the real session-file preview path, mocked sessions.files.assets, and the actual sandbox host. Before the fix it produced "undefined true in order"; afterward it produces "ready true in order" and confirms blocking head scripts run before the body exists. Document the script ordering behavior. Validation (wall time): assets 9/9, 3.80s; full HTML preview E2E 3/3, 31.40s; preview element 34/34, 6.92s; tsgo:ui 9.75s; tsgo:test:ui 85.04s. Copy-out oxlint checked all 3 TypeScript files, 0.12s; copy-out oxfmt checked all 4 changed files, 0.34s. git diff --check passed.
…pete/web-ui-wm-clickability-8a43b7 # Conflicts: # ui/src/pages/chat/components/chat-detail-slot.ts
…pete/web-ui-wm-clickability-8a43b7
…pete/web-ui-wm-clickability-8a43b7 # Conflicts: # src/gateway/methods/core-descriptors.ts # src/gateway/server-methods-list.test.ts
…pete/web-ui-wm-clickability-8a43b7 # Conflicts: # ui/src/pages/chat/components/chat-message.forwarded-attribution.test.ts
…pete/web-ui-wm-clickability-8a43b7 # Conflicts: # src/gateway/methods/core-descriptors.ts # src/gateway/server-methods-list.test.ts
…pete/web-ui-wm-clickability-8a43b7 # Conflicts: # src/gateway/server-methods.ts # src/gateway/session-row-prepared-read.test.ts
File preview identities now include the session key. The mocked files response still returned main while the pane used agent:main:main, so the active row could never match after the preview resolved. Match the response to the requested session, preserving the delayed-directory response and both content/selection assertions. No production behavior changes. Remote proof on captured main 06ac4a4 using the native UI E2E owner reproduced the one original failure across 3 tests in 47s; the reviewed correction passed all 3 in 22s. Combined fixture proof used Hetzner lease cbx_0ddfa2afe062, run run_2fdec9b8159f9fdd9a8551bc1b942607. Direct review was clean. Refs #163185, #162920.
…previews drop their assets (openclaw#163185) * fix(ui): open file links outside the session workspace and load HTML preview assets File links in Control UI chat failed with "Failed to load" when the file lived outside the viewing session's workspace root, which is common for links in forwarded/inter-session updates and for agent-workspace scratch files. HTML previews also rendered without their relative images, stylesheets and scripts. - sessions.files.get/list follow the session agent's file-tool read boundary: contained in read-only/guarded/workspace modes, with tools.fs.workspaceOnly, under a sandbox, or when file tools do not run on the Gateway host; otherwise host paths are readable. Out-of-root reads additionally require the caller to pass the real chat.send admission for that session, run inside prepared session facts and rechecked after I/O. Out-of-root previews are read-only; write containment is unchanged. - Links inside messages with a sender session open against that session. - New session read method sessions.files.assets lets the UI inline relative assets into sandboxed HTML previews by source offset (64 refs, 1 MiB per asset, 4 MiB per call; fonts stay unloaded under the unchanged CSP). - canvas.document.preview joins session-reader admission so session-only readers can render HTML previews. - authorizeGatewayRequestPreDispatch moves unchanged into server-methods/request-authorization.ts with a synchronous consumeSessionTurn hook. * fix(gateway): preserve pre-dispatch and preview script scheduling Restore the ordinary pre-dispatch fence to main so mutation commit guards retain handler-entry ordering for plugin contention and ACP cleanup. Session file reads use non-committing request checks, including their borrowed chat.send authorization, without consuming mutation callbacks. Append deferred classic preview scripts after authored HTML in source order. Keep module, async, and blocking scripts in place. Update forwarded message fixtures for current renderer APIs while retaining file ownership assertions. Validation: all 12 requested test files and the HTML preview browser suite; core, UI, UI-test, and source-test type lanes; copy-out oxlint and oxfmt over all 63 branch-changed files; git diff --check. The existing Linux-only non-UTF-8 filename test is skipped on macOS. * fix(gateway): keep session file reads on the existing request guard The previous commit also special-cased sessions.files.* in the router and swapped their transport commit guard for a new non-committing check. That was not needed: in-root file reads on main already revalidate through retainSessionScopedRead, which runs the request's commit guard, and production guards are caller-currency assertions. The actual regression was only the pre-dispatch tail invoking assertInvocationCurrent for every request, which the previous commit already restored to main. Restore server-methods.ts, session-mutation-guards.ts and the turn-authority test to their reviewed state; the host-read path again revalidates through requestMutationAuthority.assertCurrent(), matching existing reads. Validation: plugins.lifecycle-contention (2/2) and acp spawn (13/13) pass; session-turn-authority, host-read and assets suites pass (23 tests); tsgo:core and tsgo:test:src pass. * fix(ui): keep deferred preview scripts in order with module scripts Replace the end-of-document append path with in-place inline module trampolines. Each trampoline inserts the original code as an inline classic script, preserving document order with modules, classic globals, retained attributes, and sloppy mode under the existing sandbox CSP and document guard. Escape serialized code and attributes against HTML script termination. Replace the srcdoc-only regression with the real session-file preview path, mocked sessions.files.assets, and the actual sandbox host. Before the fix it produced "undefined true in order"; afterward it produces "ready true in order" and confirms blocking head scripts run before the body exists. Document the script ordering behavior. Validation (wall time): assets 9/9, 3.80s; full HTML preview E2E 3/3, 31.40s; preview element 34/34, 6.92s; tsgo:ui 9.75s; tsgo:test:ui 85.04s. Copy-out oxlint checked all 3 TypeScript files, 0.12s; copy-out oxfmt checked all 4 changed files, 0.34s. git diff --check passed. * test(agents): stub the moved pre-dispatch authorizer in shared announce mocks openclaw#163513 introduced subagent-announce.requester-settle-dispatch-mocks.test-support.ts with authorizeGatewayRequestPreDispatch stubbed on gateway/server-methods.js. This branch moved that function to server-methods/request-authorization.ts, so the stub stopped intercepting and both announce suites silently ran the real authorizer. Stub it on its owning module, matching the other moved mocks. Validation: requester-settle-dispatch (18) and requester-settle-watch (3) pass; copy-out oxfmt and oxlint clean.
File preview identities now include the session key. The mocked files response still returned main while the pane used agent:main:main, so the active row could never match after the preview resolved. Match the response to the requested session, preserving the delayed-directory response and both content/selection assertions. No production behavior changes. Remote proof on captured main 1311a9c using the native UI E2E owner reproduced the one original failure across 3 tests in 47s; the reviewed correction passed all 3 in 22s. Combined fixture proof used Hetzner lease cbx_0ddfa2afe062, run run_2fdec9b8159f9fdd9a8551bc1b942607. Direct review was clean. Refs openclaw#163185, openclaw#162920.
What Problem This Solves
Fixes: clicking a file link in Control UI chat shows "Failed to load" when the file lives outside the viewing session's workspace. This is common for links in forwarded or inter-session updates, which point into the sending session's workspace, and for scratch files under the agent workspace. HTML files that did open rendered without their relative images, stylesheets, and scripts.
User Impact
User impact: file links in chat open whenever the session's agent could read the file. Links in forwarded messages open in the sending session's workspace. HTML previews such as design concepts now render with their sibling PNGs, CSS, and JS.
Viewers who can only read a session, such as Team guests with view access, still see only files inside that session's workspace. When a link is blocked, the panel now says the file is outside the session's workspace instead of a generic "Failed to load". Session-only readers can now render HTML previews at all.
Why This Change Was Made
The sidebar preview enforced its own rule: it always contained reads to the session root, even when the agent's file tools are unrestricted. It now follows the same boundary the agent uses. Reads stay contained in
read-only,guarded, andworkspacemodes, withtools.fs.workspaceOnly, under a sandbox, and for any session whose tools do not run on the Gateway host. Otherwise any host path is readable, which is the documented default.Reading outside the root also requires that the caller could start a turn in that session right now. This check runs the Gateway's real
chat.sendadmission for that session (scope, sharing role, agent allowlist, role sandbox requirement, incognito/draft rules). It runs inside the prepared session facts and is rechecked after file I/O, before the response is sent. So viewing a session never grants more filesystem access than asking its agent would. Out-of-root previews are read-only, with no edit hash; writes keep their existing root containment.Links inside a message that carries a sender session resolve against that sender's session.
HTML previews load assets through a new session read method,
sessions.files.assets, which applies the same boundary to every asset. The UI inlines the results into the sandboxed preview by source offset, without reserializing the author's document. It skips documents that set their own<base href>.Limits: 64 refs per call, 1 MiB per asset, 4 MiB total per call, which stays well under the 25 MiB frame limit. Fonts are not loaded because the shared sandbox CSP stays unchanged (
font-src 'self'). Missing or oversized assets show a small "Some assets couldn't be loaded (N)" notice.canvas.document.previewjoins the session-reader admission set. It only echoes caller HTML and the sandbox location.To reuse the router fence for this check,
authorizeGatewayRequestPreDispatchmoved, unchanged, fromserver-methods.tsintoserver-methods/request-authorization.ts, gaining a synchronousconsumeSessionTurnhook. Callers and test mocks were updated to the new import path.Update behavior: no config, state, migration, or plugin-loading change.
Compatibility:
packages/gateway-protocol/src/schema/sessions.tsgains only additive wire schema. It adds thesessions.files.assetsrequest/result and an optionalreason: "outside_session_boundary"detail on the existingsession_file_not_founderror. No stored data, migration, or config shape changes. The Control UI ships with its Gateway (ui/AGENTS.md, Gateway Coupling). Native models are generated at build time from this schema (#162251), andprepare-native-protocol.mjs --checkpasses.Release-note context: Control UI file links now open files outside the session workspace when the session's agent could read them and you can send turns in that session. Links in forwarded messages open in the sending session, and HTML previews load relative images, stylesheets, and scripts.
Evidence
HTML preview with relative assets, before and after (synthetic fixture; the after capture includes one deliberately missing asset to show the notice):
Live, on an isolated dev Gateway started from this branch (real Playwright clicks and real Gateway responses, synthetic fixture under
/Users/Shared): an outside-workspace HTML link opens with its sibling PNG and CSS. The file response omitshash, so the preview is read-only. After switching the same session toworkspacemode, the same link is refused with the new message.Focused tests, run with
pnpm test <file> --maxWorkers=1on a heavily loaded host (load average around 55 on 32 cores; most wall time is cold transform):src/gateway/server-methods/sessions-files.host-read.test.ts(new: mode/policy/sandbox/exec-node denial matrix, placement observation, canonicalization, hardlinked host file, post-read recheck, write containment)src/gateway/server-methods.session-turn-authority.test.ts(new: session writer allowed, view-only caller hidden, solo/admin incognito inside prepared authorization, scope/incarnation recheck after I/O)src/gateway/server-methods/sessions-file-assets.test.ts(new)ui/src/pages/chat/components/chat-html-preview-assets.test.ts(new)src/gateway/server-methods/sessions-files.test.tsui/src/pages/chat/components/chat-html-preview-element.test.tsui/src/pages/chat/components/chat-session-workspace.test.tsui/src/pages/chat/components/chat-message.forwarded-attribution.test.tsui/src/pages/chat/components/chat-sidebar.test.tsinternal-facade,method-scopes.own-session,server-methods-list,server-methods.canonical-validation,session-row-prepared-read,main-session-restart-dispatch-start,subagent-announce.requester-settle-dispatch,node-workspace-protocolTwo negative controls failed as intended against the original implementation: host preview rejection and missing sender ownership.
pnpm run tsgo:core,pnpm run tsgo:ui, oxlint, oxfmt,ui:i18n:verify, protocol generation (TS, Swift, Kotlin), andgit diff --checkpass. Independent Codex autoreview found no P0 or P1 findings.Second head (fixes from CI and ClawSweeper on the first head
735a02c82fbf):authorizeGatewayRequestPreDispatchhad also refactored its tail. The tail calledassertInvocationCurrent, and through it the request'ssessionMutationCommitGuard, at the end of pre-dispatch for every request. Mutation commit guards then fired before handlers ran. CI caught it inplugins.lifecycle-contention.test.ts, where a disable succeeded instead of a retryableUNAVAILABLE, and insrc/acp/control-plane/spawn.test.ts, two admission/retirement cases. Both pass on main and failed on this branch locally. The ordinary path is now exactly main's code again: apart from import paths, the only differences are theconsumeSessionTurnparameter and branches that run only when it is set. Contention passes 2/2 and spawn 13/13.<script defer src>droppeddefer. Each deferred classic script is now replaced in place by an inline module trampoline. Inline modules share the browser's single post-parsing queue with deferred and module scripts, in document order. The trampoline inserts the original code as an inline classic script, which keeps classic global and sloppy-mode semantics under the unchanged sandbox CSP. A real-sandbox e2e case (session file preview, mockedsessions.files.assets, actual sandbox host) covers it: a blocking head script runs before#appexists, a module sets state, and two deferred classic scripts then read that state and see the body in order (ready true in order). The case failed before the fix withundefined true in order.chat-message.forwarded-attribution.test.tswas updated to main's current renderer types (CIcheck-test-types).pnpm run tsgo:test:uiandpnpm run tsgo:test:srcpass.After rebasing onto
d4b98b3a5101, every test file this PR adds or modifies passed again, along with the tests main changed in the overlapping files: 613 tests passed, 1 skipped. Typechecks, lint/format,ui:i18n:verify, andnode scripts/prepare-native-protocol.mjs --check(native models are now generated at build time, #162251) pass.Inherited local failure, not caused by this PR:
src/gateway/local-request-context.session-notify.test.ts› "queues an owned-child notification for operator.sessions.write" fails identically on unmodified maind4b98b3a5101on this heavily loaded Mac (statuserrorinstead ofqueued; the other 5 cases pass). The case passes when replayed alone, and main CI is green. This PR changes that path only by importing the moved authorizer from its new module. It is filed for a separate fix.Gap: a forwarded message cannot be produced on a model-less dev Gateway, so sender-session resolution is covered by UI tests rather than a live capture.