Skip to content

refactor(components): own attachment transfers with Effect - #707

Draft
zxch3n wants to merge 1 commit into
refactor/attachment-submission-boundaryfrom
refactor/attachment-effect-resources
Draft

zxch3n wants to merge 1 commit into
refactor/attachment-submission-boundaryfrom
refactor/attachment-effect-resources

Conversation

@zxch3n

@zxch3n zxch3n commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Problem / pressure

Attachment transfers and send-path store borrows outlive individual composer mounts, but previously had no shared workspace owner. Image removal did not cancel XHR, and multipart failure cleanup could outlive its caller.

Summary

Stack 2/4, based on #705. Add an internal Effect resource owner with a Promise-facing interface. Landing and continuation file preparation share one pipeline; image uploads forward cancellation to XHR. Workspace shutdown interrupts all owned work and waits for raw IPC and cleanup before releasing its dependencies. Store borrows return references through the existing cache.

Transfer still starts when attachments are added. Persistent submission/recovery and complete draft UX are the next two layers; upload-free local references remain separate.

Visual explanation

Workspace runtime
└─ Effect send scope (disposed before transport/cache)
   ├─ file preparation → existing local handoff or cloud upload
   ├─ image upload → abortable XHR
   └─ session-store borrow → return cache reference in finally

Route unmount: retain tasks
Remove/reset: interrupt selected transfer
Workspace disposal: interrupt all → join cleanup → close dependencies

Before / after

Before After
Image cancellation only removed preview state Cancellation aborts XHR and removes listeners
Multipart cleanup was detached Failure waits for bounded cleanup
New/reply file pipelines duplicated ownership Shared preparation with late-completion cancellation fence
Workspace teardown could race send resources Teardown joins owned work before dependencies close

Test plan

  • Deterministic resource tests cover concurrent cancellation, noncooperative completion, late acquisition release, and sibling failure isolation.
  • Real multipart helper tests distinguish byte progress from response success and verify underlying request cancellation.
  • Landing persistence tests retain transfers across route unmount and cancel them on explicit clear.
  • TMPDIR=/private/tmp NODE_ENV=test pnpm check passes completely, including 478 component files / 3,661 tests.
  • pnpm format and pnpm run docs check completed (zero documentation errors). No packaged-device draft acceptance claimed.

Context handoff

Instructions for reviewing agents

  • Review focus: session-send-resources.ts, the shared file preparation adapter, and workspace disposal order.
  • Decisions to challenge: Cancellation waits for noncooperative IPC; cache ownership never transfers to the send scope.
  • Plausible failures / evidence gaps: Uninterruptible platform IPC can delay shutdown; packaged-device coverage remains outstanding.

Authoring context

  • User goal / directives: Introduce Effect gradually through independently reviewable stacked changes before complete attachment drafts.
  • Constraints / non-goals: No transfer-timing change, Effect upgrade, daemon rewrite, or upload-free local reference feature.
  • Risk-bearing decisions: Workspace owns cancellation; component unmount preserves work. Cancellation never starts fallback transfer.
  • Destructive or irreversible behavior: Existing multipart failure cleanup is now awaited. No stored content migration or deletion added.
  • Deliberately not done or tested: Durable submit outcomes and restart recovery belong to layer 3; complete drafts belong to layer 4.
  • Unknowns / confidence: Behavioral tests establish resource boundaries; they do not establish packaged Electron or private-shell acceptance.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant