Skip to content

[feat] assets: Import media by reference #473

Todo

Description

@FayeSpica

Related: Desktop RFC #362 and canvas roadmap #262.

Example scenario

A travel vlogger returns with dozens of camera and drone clips stored on an external drive or a mounted NAS share. Individual clips can be as large as 10 GB. Copying the entire batch into each project takes time and consumes extra disk space. The editor selects Reference in place for the batch, then browses, seeks, and cuts the clips directly from their existing storage.

Goal and scope

Let desktop users import large local media without duplicating the source file. Offer Copy into project and Reference in place when importing a local file. Keep copying as the default and retain the browser upload flow.

User flow and rules

  • The desktop host obtains read-only access to the file selected by the user. Keep its location and content fingerprint in host-managed storage. The canvas, timeline, and Agent use the same project asset ID.
  • If the file moves or a drive disconnects, show the asset as offline and retain its timeline edits and references. Let the user relink a matching file by SHA-256 without changing the asset ID. If the bytes differ, require an explicit replacement and preserve earlier execution records.
  • Read the linked source for preview, editing, generation, and export through shared media services. Apply the existing model input limits when submitting generation.
  • Let users copy linked media into the project for portable archives. Identify offline files before creating a self-contained archive. Removing a linked asset leaves the original file on disk.

Proposed reference structure

  • Project asset. Keep the existing asset ID, immutable fingerprint, verified media metadata and provenance. Canvas nodes, timeline clips and Agent operations keep referencing the same project asset. Today the Asset schema requires a project-relative assets/{id} path. Extend the storage contract to distinguish managed bytes from a desktop link, and resolve both through the shared media service.
  • Desktop file binding. Store the authorized file location in a Host-local record keyed by project and asset ID. An authorized root plus a relative path can support batch relinking when a drive letter, mount point or NAS share changes. Keep machine-specific paths and grants out of portable archives. A project opened elsewhere can retain its asset records and ask the user to bind the files again.
  • Availability and identity. Derive availability from the current binding and access checks. Distinguish an unavailable source from a source whose bytes changed. Use filename, size and folder layout to find candidates. Verify SHA-256 before accepting a candidate as the same asset. Relinking changes the binding only. Replacing different bytes requires explicit adoption of a new immutable asset and preserves existing execution records.
  • Read and export. Resolve by asset ID under the current project authorization and stream or seek through the Host. Verify source identity at the execution boundary. Operations that require durable inputs, such as accepted generation jobs, need a validated snapshot or must report that the source cannot be safely used. An explicit portable archive copies verified bytes into managed storage and reports unavailable assets before export.

References and trade-offs

  • Final Cut Pro informs the import choice and the workflow for reconnecting source media. Apple media management guide
  • Adobe Premiere informs one-file and batch relinking when the folder structure is intact. Use these matches to find candidates and verify their content before reconnecting. Adobe relinking guide
  • OpenTimelineIO separates a clip's media reference from its available time range. OpenDirector also needs Host-local authorization and immutable content identity. OpenTimelineIO schema

Decisions to confirm

  • For large batches, propose registering links with an explicit verification state and computing full SHA-256 in the background with bounded concurrency. Decide when unverified files may be previewed and how generation and export wait for verification. Measure first-preview latency and NAS reads using the 10 GB case.
  • Start with file selection and an explicit folder selection for batch relinking. Confirm which platform access grants survive restart and how the app requests access again.

Acceptance criteria

  • Import a batch of dozens of clips by reference from an external drive and repeat on a mounted NAS share. Include a 10 GB clip in each run. Verify that the project creates no full-size copies of the source clips. Reopen the project, seek in the large clip, add it to the timeline, and reference it from the Agent.
  • Move the file or disconnect its drive. Verify the offline state, then relink an identical file and confirm the asset ID, nodes, and timeline edits survive.
  • Change the contents at the original path. Verify that the project requires explicit replacement before using the new bytes.
  • Export a timeline that uses linked media. Copy the media into the project, archive it, and verify playback on another machine without access to the source path.
  • Remove a linked asset and verify the source file remains intact. Verify import and recovery flows in English and Chinese.

Activity

  1. added
    help wanted
    type:feat
    area:assets
    area:desktop
    on Nov 23, 2026
  2. changed the title [-][feat] desktop: Import media by reference[/-] [+][feat] assets: Import media by reference[/+] on Nov 23, 2026
  3. Hniii98 commented on Nov 25, 2026

    @Hniii98

    Hi @FayeSpica , I’d like to work on this feature. I have access to a Synology NAS and can test with a mounted network share.

  4. FayeSpica commented on Nov 26, 2026

    @FayeSpica
    CollaboratorAuthor

    @Hniii98 Assigned, thanks! If you spot any potential bias, let’s discuss how best to address it.

  5. Hniii98 commented on Nov 26, 2026

    @Hniii98

    I'll implement both the external-drive and the mounted-NAS paths. Below are my plan.

    • External drive first. I'll get the full flow working on a USB external drive and report the parameters requested here, using a 10 GB clip plus a batch of dozens of clips:
      • first-preview latency
      • hashing throughput (MB/s)
      • total bytes read (to confirm a restart does not trigger a full re-read)
      • project directory disk increase (to confirm no full-size copies)
    • NAS: limited by the current network. The test NAS (Synology) is not on my LAN. My uplink sits behind carrier-grade NAT, so Tailscale can only reach the NAS through a DERP relay (no direct path, RTT ~365 ms). On this link, That can't support a 10 GB test.
    • Plan for NAS: I'll run the 10 GB NAS case from inside the NAS's LAN via remote access to a machine on that network. Until then I can use the relay link to check behavior that does not need full reads (offline detection, relink, no backend hang on a stalled mount). Every report will state the link conditions (LAN vs relay, RTT, measured throughput), and relay timings won't be presented as performance results.
  6. Hniii98 commented on Nov 27, 2026

    @Hniii98

    Blow are my draft design summary

    Model: three layers. Logical asset (immutable content identity) → storage kind (managed / linked) → host-local binding (which machine, which root, relative path).

    1. Asset storage contract. Extend Asset with storage: ManagedStorage | LinkedStorage (see decision [bugfix] Windows 重命名撞名返回 409 + 清理生成轮询的 abort 监听器 #2 below on whether to keep path: str | None alongside storage or replace path with a format version bump). LinkedStorage holds only machine-independent hints (original name, relative path hint). Linked assets never produce AssetFileWrite/Delete.
    2. Host-local binding. Host SQLite maps (projectId, assetId) to a locator, grant, binding version and verification record. On relink, the Host searches the newly authorized location and updates only the selected bindings whose SHA-256 and expected binding version match. For changes spanning the project and the Host, a stable operation ID joins the prepared binding change to the project command. Recovery completes pending project commits first, then uses their receipts to finish or discard the prepared change. Removal and consolidation retain historical bindings while Undo needs them.
    3. Read-only MediaSourceProvider port. Phase 1 ships managed and local_fs. local_fs covers local disks, external drives, and any OS-mounted NAS (SMB/NFS). The port has no write methods, so "removing a linked asset never deletes the source" is enforced by the type. Remote providers (WebDAV, Synology File Station) are out of scope for this issue.
    4. Availability is derived, not stored: online | offline | changed | unbound | unauthorized, with bilingual error codes, pushed through the existing change channel.
    5. Verification. Under proposed option A, LinkedImport supports preview and Range seeks while a bounded per-root queue computes SHA-256. Registration requires verified bytes. Verification records can be reused after restart under the trust policy in decision 3. Consolidation and archiving verify bytes before publishing. A generation job that transmits linked media requires a durable, verified input before acceptance. Execution, retries and recovery read that same input. Until P3a provides it, users and agents can reference registered assets, and generation submissions requiring those bytes are rejected before a job or remote request is created.
    6. Read path. Capture expected asset and binding versions in a short transaction. Open, probe, read and hash the external source outside the outermost catalog transaction, including generation admission. A short commit rechecks authorization and relevant versions. Preview uses the opened source through a controlled handle or Range endpoint. Per-root concurrency limits, timeouts and circuit breakers isolate stalled mounts.
    7. Commands. source.root.register records the user's desktop selection. UI and Agent share link.import, link.status, link.relink, link.relinkBatch, link.locateCandidates, asset.replaceSource, asset.consolidate, asset.remove and archive.preflight. Replacement creates a new Asset and preserves past executions. Consolidation preserves the Asset ID and fingerprint. Removal leaves the source file intact.
    8. Desktop authorization. Electron sends the exact selected files or explicitly selected directory to the Host over the control pipe. Batching preserves that scope. The renderer receives an opaque grant ID. The Host checks the project and grant for each operation. Staged preview uses the streaming proxy. Browser uploads keep their existing flow.

    Issues found in the current code that must be fixed for the 10 GB / NAS case:

    • Generation admission reads media inside an outer project commit callback. External I/O must move outside that transaction as well as outside the resolver's own lock.
    • Video/audio preview copies the entire file to a temp directory before running ffmpeg.
    • Some open_media callers (library add, tool byte reads) read the whole file into memory.
    • The canvas exporter builds the archive in browser memory. The importer also buffers the archive and rejects ZIP64 entries. Both ends need bounded-memory processing for a 10 GB clip.

    Phasing:

    Phase Scope Acceptance
    P0 Storage contract, managed/local providers, binding registry and recovery protocol, whole-call-chain lock boundaries, bounded reads and preview No regression for managed assets
    P1 Scoped desktop grants, recoverable imports, availability, bilingual UI and Agent tools. Gate generation submissions that need linked bytes Criterion 1. Rejected submissions create no job
    P2 Relink (single/batch), candidates, replaceSource, soft-delete unbind on remove Criteria 2, 3, 5
    P3a Consolidation, archive preflight and verified export. Enable generation with durable inputs prepared before acceptance Criterion 4 (core). Accepted jobs can run and recover with the source disconnected
    P3b Stream ZIP64 portable archives on export and import Criterion 4. On a second machine with no source access, import a 10 GB clip, verify its fingerprint and play the edited timeline
  7. Hniii98 commented on Nov 27, 2026

    @Hniii98

    Decisions I'd like confirmed:

    (I can already start on the decision-independent P0 infrastructure—read-only provider port, moving open_media file opens out of the SQLite transaction lock with timeouts, removing full-file temp copies in preview(), and fixing whole-file stream.read() callers—while waiting for your input.)

    Blocking P0/P1 domain contracts:

    1. Verification model for large batches (10 GB × dozens of clips):
      • Option A (staged import): Register a LinkedImport staging record first; allow preview/seek during background SHA-256 hashing, and create the Asset only after hashing completes. Keeps the AssetRef.fingerprint invariant untouched, but users must wait for full hashing before adding a 10 GB clip to the timeline or referencing it from the Agent.
      • Option B (pending Asset): Register the Asset immediately with an explicit verification: pending state so users can preview and edit on the timeline right away, and gate generation / consolidate / portable archive on verification completion. Better UX for 10 GB batches, but requires relaxing Asset.fingerprint / AssetRef invariants in P0.
      • Which direction do you prefer?
    2. Asset.path contract transition:
      • Option 1: Keep path: str | None (assets/{id} for managed, None for linked) and add storage: ManagedStorage | LinkedStorage (defaulting to managed), so existing project event logs replay cleanly without a hidden migration path.
      • Option 2: Replace path with storage outright and bump the project format version, explicitly rejecting older formats per AGENTS.md.
      • Which approach fits the repository's versioning policy better?

    Needed for P1–P3 (can be confirmed together):

    1. Stat trust window: Once verified, should open_media trust an unchanged (changeToken, size) signature indefinitely until it changes, or add a more conservative re-hash policy for mounts like SMB where only size + mtime may be reliable?
    2. Generation job inputs. Should the job own its snapshot, or can it reuse verified immutable bytes retained for the job's lifetime, including recovery? Both require durable inputs before acceptance.
    3. Archive & provenance details:
      • Allow an optional lightweight "references-only, no bytes" archive, or require portable archives to contain all bytes?
      • For AssetProvenance.source, is adding 'linked' preferred? (Note that 'imported' is already reserved for canvas archive imports and requires importedFrom.)
  8. Hniii98 commented on Nov 27, 2026

    @Hniii98

    Hello @FayeSpica, Could you share your thoughts on the design decisions above when you get a chance? Thanks!

  9. FayeSpica commented on Nov 27, 2026

    @FayeSpica
    CollaboratorAuthor

    @Hniii98, we need a small architecture diagram showing how an asset ID resolves through the shared media service to project files or a Host-local binding, and where preview and generation read their inputs.

  10. Hniii98 commented on Nov 27, 2026

    @Hniii98

    @FayeSpica , Here is the resolution flow through the shared media service, showing how managed vs. linked assets resolve and where preview and generation read their inputs:

    flowchart TD
        subgraph Consumers["Callers (same projectId + assetId)"]
            Range["Playback & Timeline Seek\nGET /assets/{id}/content (HTTP Range)"]
            Prev["Asset Preview (CreationAssets.preview)\nThumbnails / ffmpeg first-frame & 30s audio"]
            GenAccept["Generation Admission\n(accept job & validate model limits)"]
        end
    
        GenExec["Generation Execution & Recovery\n(ProviderMedia -> Model Adapter)"]
        JobSnap[("Verified Job-Private Snapshot\n(for linked references only)")]
    
        Range -->|"stream / seek"| Resolver
        Prev -->|"verify + local_path() to ffmpeg -i\n(no full-file temp copy)"| Resolver
        GenAccept -->|"verify-while-reading"| Resolver
        GenAccept -->|"if storage = linked:\nfreeze verified copy"| JobSnap
        GenExec -->|"linked ref: read frozen copy"| JobSnap
        GenExec -->|"managed ref: open_media"| Resolver
    
        subgraph SharedMedia["Shared Media Service (CreationAssets.open_media / MediaResolver)"]
            Resolver["1. Under catalog lock: pin ProjectSnapshot & Asset\n(fingerprint + storage: managed | linked), then release lock"]
            Verify["2. Outside lock (bounded timeout + circuit breaker):\nstat() vs persisted VerificationRecord -> SHA-256 check if needed"]
            Resolver --> Verify
        end
    
        Verify -->|"storage = managed"| ManagedProv["ManagedMediaSourceProvider"]
        Verify -->|"storage = linked"| Registry[("Host-Local LinkRegistry\nworkspace/state/linked-media.sqlite\n(projectId, assetId) -> (rootId, relPath)")]
    
        ManagedProv --> ProjFiles[("Project Directory\nprojects/{proj}/assets/{assetId}")]
        Registry --> LocalProv["LocalFsMediaSourceProvider\n(read-only, root-scoped)"]
        LocalProv --> ExtFiles[("External Drive / Mounted NAS Share\n(original source file, never modified)")]
    
    Loading

    Key read boundaries

    1. Asset resolution (open_media / MediaResolver):

      • Lock boundary: Inside the SQLite catalog transaction, it only pins the ProjectSnapshot and reads the Asset descriptor (fingerprint and storage.kind), then immediately releases the lock before any filesystem stat/open so a slow or disconnected SMB mount cannot block other project operations.
      • Storage dispatch: managed resolves directly to projects/{proj}/assets/{assetId}; linked looks up (projectId, assetId) -> (rootId, relativePath) in the Host-local LinkRegistry (kept out of project files and portable archives) and opens the file read-only via LocalFsMediaSourceProvider.
      • Identity check: Matches (changeToken, size) against the persisted VerificationRecord in linked-media.sqlite, re-hashing full SHA-256 against Asset.fingerprint only on first verification or when the stat signature changes.
    2. Where Preview reads:

      • Playback / timeline seek (/assets/{id}/content): Calls open_media and serves HTTP Range slices directly from the returned RandomAccessReader (closing the handle as soon as the chunk finishes).
      • Thumbnails / first-frame preview (CreationAssets.preview): Verifies the asset via open_media, then passes provider.local_path() directly to ffmpeg -i (re-checking stat after ffmpeg exits) instead of copying a 10 GB source into a temp directory first. (If Option A staged import is chosen, unverified staging previews read through a separate handle-scoped route before an Asset exists.)
    3. Where Generation reads:

      • managed references: Unchanged—bytes already live permanently in projects/{proj}/assets/{assetId}, so ProviderMedia continues reading through open_media.
      • linked references: Enforces existing model byte/duration limits at job acceptance and copies a verified, job-private snapshot while checking SHA-256. Execution, retries, and crash recovery read from that frozen snapshot rather than the external drive or NAS mount, preserving fixed job inputs even if the drive is later unplugged.
  11. Hniii98 commented on Nov 27, 2026

    @Hniii98

    Also let me know your preferences on decisions #1 and #2 above when convenient!

  12. FayeSpica commented on Nov 28, 2026

    @FayeSpica
    CollaboratorAuthor

    @Hniii98 Thanks for the diagram! Could you open a small draft PR so we can walk through it together? One clip on a mounted NAS / Storage is enough: preview it, seek, add it to the timeline, and reopen the project with the edit intact, without copying the source file.

    Let’s hold off on SHA-256 for now. For the demo, I’d prefer keep the existing managed asset path unchanged and leave the final linked-asset schema open until we’ve tried the workflow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:assetsarea:desktophelp wantedtype:feat

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions