fix(desktop): resolve local media linked from remote threads #10619
main fromrefs/pull/10619/head·merged by maria-rcks View on GitHubremote threads try to load desktop images and recordings from the remote server, where the files may not exist. desktop now retries eligible missing absolute media paths against its local server. remote files retain priority; relative paths and authorization failures do not fall back. previews refresh when the local server reconnects.
validation: 74 focused signing/rpc/asset/query tests passed before simplification; 46 focused asset/query tests, client-runtime/web typechecks, and scoped lint passed on this head. github checks pass.
e2e: real linux electron client, two independently authenticated servers, and a seeded remote conversation. filesystem permissions made the media inaccessible to the remote server and readable by the desktop server. image rendering and full-size preview, eight-second video playback, seeking to four seconds, and retry after restoring a missing video passed. checked light/dark appearance and 1100×780 / 1200×1100 viewports. the mac-specific setup remains untested.
before: base client asset wiring, same thread and files.

after: current head, image loaded and video seeked to 0:04.


model: gpt-6. harness: codex.
Note
Fix local media resolution for remote threads via local environment fallback#
- Adds direct asset URL issuance for absolute media-file paths in the
assetsCreateUrlwebsocket RPC handler in ws.ts, so absolute media can be served without resolving a workspace for the referenced thread. - Updates
createAssetEnvironmentAtomsin assets.ts to retry eligible absolute media-file requests against a distinct configured local environment after asset-not-found, asset-inspection, or workspace-context errors, rewriting the result against the local HTTP base URL. - Supplies the connected primary Electron environment as the local media fallback in assets.ts, and refreshes media queries when that fallback context changes.
- Adds integration tests in server.test.ts and parameterized fallback tests in assets.test.ts.
- Behavioral Change: media URL queries now perform an additional local-environment retry for absolute paths with recognized media extensions when the target environment returns specific workspace-resolution failures; non-media and relative paths are unaffected.
Summary by CodeRabbit#
- Bug Fixes
- Media assets using absolute paths now generate valid URLs even when no local thread workspace is available.
- Improved media URL resolution across local, remote, reconnecting, and foreign-thread environments.
- PNG and MP4 assets now return the expected content types and file data.
- Relative media paths continue to report clear workspace-context errors when required context is unavailable.
- Added support for Windows-style absolute media paths and filenames containing literal special characters.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -2390,5 +2391,7 @@23902391 observeRpcEffect(23912392 WS_METHODS.assetsCreateUrl,23922393 Effect.gen(function* () {2394+ const path = yield* Path.Path;2395+ // An absolute media path can be linked from a thread on another environment.23932396 if (23942397 input.resource._tag === "attachment" ||
🔴 Critical
src/ws.ts:2397A caller with only
AuthOrchestrationReadScopecan mint a signed URL for an arbitrary absolute host path without a local thread, so fabricated resources like{ threadId: "anything", path: "/host/private-report.pdf" }expose that file. The absolutemedia-filebranch bypasses the thread/project lookups below; route absolute media through those authorization checks instead.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/ws.ts around line 2397: A caller with only `AuthOrchestrationReadScope` can mint a signed URL for an arbitrary absolute host path without a local thread, so fabricated resources like `{ threadId: "anything", path: "/host/private-report.pdf" }` expose that file. The absolute `media-file` branch bypasses the thread/project lookups below; route absolute media through those authorization checks instead.Note
Written by
gpt-6on behalf of Mariathe rpc authorization still runs before this handler (
observeRpcEffect, ws.ts:640-641). the removed thread/project lookups only establish workspace context; they do not enforce a thread or project acl. before this change,issueAssetUrlalready ignored the workspace root for absolute media paths and allowed the same host file with any existing thread id.orchestration:readalso permits listing threads and reading host files through the existing read endpoints.this change lets that existing host-media capability work when the thread belongs to another environment. restoring a local-thread existence requirement would reproduce the reported failure. the signed exact-file validation and rpc scope check remain in place.
- packages/client-runtime/src/state/assets.ts lines 23 to 24OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -14,4 +20,5 @@1420 import * as Schema from "effect/Schema";1521 import { AsyncResult, Atom } from "effect/unstable/reactivity";162217-import type { EnvironmentRegistry } from "../connection/registry.ts";23+import { EnvironmentRegistry } from "../connection/registry.ts";24+import { EnvironmentSupervisor } from "../connection/supervisor.ts";
state/assets.ts:24These are Effect service boundaries, so preserve each service module namespace rather than importing its tag directly. Please use namespace imports (for example,
import * as EnvironmentRegistry from "../connection/registry.ts") and update the runtime type/acquisition sites toEnvironmentRegistry.EnvironmentRegistryandyield* EnvironmentRegistry.EnvironmentRegistry(likewise forEnvironmentSupervisor). This requires corresponding edits at the usage sites, so no single-hunk suggested diff applies.No longer relevant as of 8616ceff53f343c4dd067ccfcfea9da26560b27d
Note
Written by
gpt-6on behalf of Mariaupdated both service imports and their type/acquisition sites to use module namespaces in 8616ceff53. client-runtime/web typechecks, scoped lint, and asset tests pass.
Effect Service Conventions found one blocking issue:
Posted via Macroscope — Effect Service Conventionspackages/client-runtime/src/state/assets.tsimports Effect services directly instead of preserving their module namespaces. An inline review comment includes the expected fix.Approvability#
Verdict: Approved at
20bd171Macroscope's review found this PR approvable — This is a narrowly scoped asset-resolution bug fix: remote-thread media failures can retry against the connected local Electron server, while relative paths, authorization failures, and existing successful paths remain unchanged. The production changes reuse the existing signed asset endpoint and are backed by focused fallback, reconnect, and server integration tests.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Team
Run ID:
7120bb80-5c06-446c-aa67-d7b90cf2ef32📥 Commits
Reviewing files that changed from the base of the PR and between 8616ceff53f343c4dd067ccfcfea9da26560b27d and 20bd171350f2d0026f262ddc8fce4b80ae6c4f67.
📒 Files selected for processing (4)
apps/web/src/state/assets.tspackages/client-runtime/src/state/assets.test.tspackages/client-runtime/src/state/assets.tspackages/client-runtime/src/state/runtime.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough#
The change adds direct server handling for absolute media paths and client fallback through a local media environment. It wires the web state to the primary Electron connection and adds integration and parameterized coverage.
Changes#
Media asset URL resolution
Layer / File(s) Summary Server absolute-path handling
apps/server/src/ws.ts,apps/server/src/server.test.tsassetsCreateUrlissues URLs directly for absolutemedia-filepaths. Tests cover PNG and MP4 responses, file contents, and relative-path errors.Client media fallback
packages/client-runtime/src/state/runtime.ts,packages/client-runtime/src/state/assets.ts,packages/client-runtime/src/state/assets.test.tsAsset URL queries inspect request results, retry eligible media requests through a local environment, and re-evaluate after reconnects. Tests cover environment selection, fallback, and error cases. Web local environment wiring
apps/web/src/state/assets.tsThe web state derives a local media environment from the primary Electron connection and passes it to asset environment atoms. Estimated code review effort: 3 (Moderate) | ~25 minutes
Merge Risk: ⚪ Minimal · up to
20bd1Desktop media previews now retry eligible missing absolute paths through the local server while preserving remote success, relative-path behavior, and authorization failures. No concrete merge-blocking risk remains.
Sequence Diagram(s)#
sequenceDiagram participant Client participant RemoteEnvironment participant EnvironmentRegistry participant LocalEnvironment Client->>RemoteEnvironment: Request assetsCreateUrl RemoteEnvironment-->>Client: Return URL or workspace error Client->>EnvironmentRegistry: Select fallback environment EnvironmentRegistry->>LocalEnvironment: Request assetsCreateUrl LocalEnvironment-->>Client: Return local-origin URLSuggested reviewers:
juliusmarminge,stienswout,t3dotgg🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly and concisely describes the primary change: resolving local media for remote threads in the desktop client. Description check ✅ Passed The description clearly explains what changed, why it changed, fallback behavior, validation results, UI evidence, and known test limitations. It does not use the template headings or include the chec… - Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Comment `@coderabbitai help` to get the list of available commands.macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
maria-rcks merged thisa01b227
maria-rcks closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed