Skip to content

fix(composer): reference pasted disk files with sizes - #2316

Merged
vastsa merged 4 commits into
vastsa:mainfrom
Linuxdazhao:codex/pasted-file-references-2314-20261113
Nov 13, 2026
Merged

vastsa merged 4 commits into
vastsa:mainfrom
Linuxdazhao:codex/pasted-file-references-2314-20261113

Conversation

@Linuxdazhao

@Linuxdazhao Linuxdazhao commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Pasting a disk-backed file larger than 64 MiB currently fails after reading its bytes into the renderer. Native clipboard files now become live path references with byte sizes, so attaching them does not allocate, transfer, copy, hash, or upload their contents.

Main consumes the existing sender-bound selection token and records the canonical source/project with an opaque reference id. Composer displays the size; drafts, queued input, transcript storage, input history and runtime replay retain the metadata. Dispatch checks the registered path/project, rejects missing or redirected sources, and refreshes size. Subsequent reads use normal tool permissions, including outside-project approval.

Disk-backed images also use this lazy reference flow; an Agent can read them through normal tools. Screenshots and generated clipboard payloads retain the existing scratch/image transport. Native picker and drop behavior remain unchanged. The ADR, IPC/permission specs and E2E scenario describe the additive contract and live-file semantics.

Fixes #2314.

Validation

Base: 82823a6c0122a95d5cc3bb21e530d4b8522c61b1 (fresh origin/main). Electron: lockfile-pinned 43.6.0, macOS arm64. All fixtures use synthetic files and paths.

All six GitHub checks passed at 047748de868b58f336a6a9d8ffe2eebe94c19fd4: Docs, latest-base ancestry, JS build/typecheck/lint/architecture/tests, Rust format/lint/tests, Windows transcript-cache E2E, and trusted-extensions Electron E2E. The PR merge candidate d174a4728860c2edb8bd1ff09a4cb7d6afa2a26d has the same executable tree as this validated head.

  • Desktop dependency builds and Desktop typecheck passed.
  • 120 targeted Desktop tests passed, including actual native selection IPC callback → registered reference → prompt preparation, sparse 64 MiB + 1 byte files, metadata-only image references, sender/project/path checks, symlink rejection, changed/deleted sources, card size/removal, draft/history and screenshot controls. The history test explicitly restores only path, size and reference metadata for a missing source, without a snapshot.
  • Runtime live-input/history-replay regression passed.
  • Both Rust canonical attachment roundtrip tests passed, including the new file-reference metadata case.
  • Targeted Biome lint, diff whitespace checks and PR-base ancestry check passed.
  • Full documentation checks passed (621 pages and 89 English/Chinese pairs); cargo fmt --all -- --check passed.
  • node scripts/e2e-composer-paste.mjs --screenshot-only passed, including four draft-race cases and screenshot/native-image compatibility controls.
  • Full node scripts/e2e-composer-paste.mjs passed twice after correcting preview focus restoration, including keyboard/image compatibility, undo/redo, native files, session races and history restoration in a second Electron process.
  • node scripts/e2e-composer-paste.mjs --file-references-only passed, exercising real disk-backed Electron File objects, React Composer hooks, preload IPC, native clipboard parsing, sender-bound selection tokens, persisted registration and prompt preparation. Sparse 64 MiB + 1 byte and small outside-project files never read bytes into the renderer or use the scratch byte writer. The test verifies card size, refreshed dispatch size after editing the source, metadata-only history recall, remount and recovery/send in a second Electron process.
  • Three preview-focus regression tests passed, covering selection-before-control focus ordering and stale session/project restoration guards. Desktop typecheck, targeted lint, whitespace and docs checks passed again after this correction.

Compatibility correction

Full paste validation exposed an existing image-preview focus ordering defect, also reproducible on the unchanged base. Restoring a saved selection after focusing the original control can refocus the editing host. This PR restores the selection first and the original control last, with a deterministic regression and the strict Electron focus check retained.

The Electron fixture controls clipboard URI-list metadata at the native OS boundary and controls external provider delivery; it does not automate a manual Finder copy gesture or make a live external provider call. Original files remain live: later reads observe edits, and moved/deleted files require a new reference.

Avoid copying native clipboard files through renderer memory and session scratch. Keep trusted selection records and current byte sizes while deferring content access to normal tool permissions.

Preserve reference metadata through drafts, queues, transcript storage and runtime replay; keep generated clipboard payloads on the existing byte path.

Fixes vastsa#2314
Index the accepted decision and format the attachment fixture for the documentation and Rust gates. Verify that history restores live reference metadata without opening or snapshotting the source.
Exercise large and small disk references across real Composer hooks, preload IPC, selection records, dispatch and history restart. Verify metadata-only transport and refreshed source sizes.

Restore the preview assertion to the actual pre-open focus target because Chromium can retain the editing host as activeElement for a nested chip.
Installing the saved selection can focus its editing host and override
the original attachment control. Restore control focus last and cover
the ordering plus stale-session and stale-project guards.

Keep the Electron assertion strict while waiting for preview disposal
and focus restoration to finish.
@Linuxdazhao
Linuxdazhao marked this pull request as ready for review November 13, 2026 06:20
@Linuxdazhao

Copy link
Copy Markdown
Contributor Author

Validation completed at 047748de868b58f336a6a9d8ffe2eebe94c19fd4; all six current-head GitHub checks passed. The PR integration candidate d174a4728860c2edb8bd1ff09a4cb7d6afa2a26d matches the validated head tree and contains base 82823a6c0122a95d5cc3bb21e530d4b8522c61b1.

Local Electron validation now covers the full paste suite plus --file-references-only: a sparse 64 MiB + 1 byte disk file, no renderer byte reads/scratch writes, card/remount metadata, changed-source size refresh, input-history recall and registry/history recovery in a second process. The full suite also exposed the base's selection/focus ordering bug; the minimal correction and three focused regressions are included, and the full suite passed twice afterward. Typecheck, targeted lint and documentation checks passed.

The fixture controls native clipboard URI-list metadata and external provider delivery. Manual Finder copy gestures and live external model calls were not performed. Marked Ready for review; not merged.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 047748de868b58f336a6a9d8ffe2eebe94c19fd4 against current main 82823a6c0.

Independently reproduced the existing production byte-paste rejection for a 64 MiB + 1 byte payload. The metadata path addresses that cost without raising transfer limits or broadening the ordinary attachment-root validator. Reviewed sender-bound one-shot selection consumption, canonical source/project registration, dispatch refresh/rejection, draft/message propagation and runtime replay. The small selection/focus ordering correction has focused coverage and passes the full paste suite.

Independent validation in an isolated worktree using reused dependencies and this candidate's freshly built shared package:

  • Shared TypeScript build and whitespace check passed.
  • 38 targeted reference/draft/history/directory/focus tests passed.
  • Full runtime.test.ts: 421 tests passed, including live and restored reference metadata.
  • Real Electron file-reference suite passed, including sparse 64 MiB + 1 source, no renderer byte reads, changed-source size refresh and second-process history recovery.
  • Full real Electron paste suite passed, including screenshots/native images, preview focus, undo/redo, multiple files, draft races and second-process history restoration.
  • All six current-head CI checks passed, including clean JS validation and Rust/Windows coverage. Latest main is an ancestor; fetched actual merge candidate and tested head have identical tree c01e0ba1408227cea46d4121329eb536d1abc3a1.

Local Electron tests use controlled native clipboard metadata/provider boundaries. No manual Finder copy gesture, physical Windows UI, or live model request was performed. Initial local setup failures (missing preload and stale donor shared exports) were resolved by building candidate shared/preload; final runs above passed. No contributor source changes were needed.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Reference pasted local files with size metadata instead of copying their contents

2 participants