Skip to content

fix: desktop export download writes a file (#13047) - #17428

Merged
iamwhatever merged 2 commits into
kirodotdev:mainfrom
chenmingwei23:fix/13047-desktop-export-download
Oct 11, 2026
Merged

iamwhatever merged 2 commits into
kirodotdev:mainfrom
chenmingwei23:fix/13047-desktop-export-download

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the desktop app's "Download Export (.zip)" button actually save the zip file to disk.

In the desktop app (Electron), Overview → Portability → Download Export (.zip) shows "Download started" but no file is ever written and no save dialog appears. The backend builds and serves the archive correctly (~16.5 MB per click), and the same button in a normal browser saves the zip fine, so the loss is specific to the Electron shell.

Reproduction

Verified on current origin/main (d5135b9e8). The bug has two halves, both reproduce:

1. No will-download handler (the dominant half):

$ git grep -n "will-download" origin/main -- website/electron/
$ echo $?
1          # no match: no save-path handler anywhere in the electron source

With no handler, a DownloadItem in the WebContentsView/BaseWindow dashboard gets no save path and nothing is written.

2. Synchronous blob-URL revoke — regression test that FAILS on main, PASSES on this branch.

The test PortabilityTab.test.tsx › "does not revoke the export blob URL synchronously after the click (issue #13047)", run against main's handleExport:

FAIL  src/pages/overview/PortabilityTab.test.tsx
AssertionError: expected "vi.fn()" to not be called at all, but actually been called 1 times
  (URL.revokeObjectURL called synchronously after a.click())

The same test against this branch's handleExport (routed through downloadBlob's deferred revoke): PASS.

Why it matters

The portability export is how users back up or migrate their entire Kiro Crew configuration (settings, memory, crons, skills, workspace). Desktop-app users — the primary install channel — have no working path to export their data without the workaround of opening the gateway URL in a separate browser.

Not a goal

  • A renderer-visible failure notification via preload/IPC when a download is interrupted or cancelled (a user-facing listener for failures). This PR makes the file land; surfacing interrupted/cancelled downloads to the UI is a separable enhancement.
  • Fixing the <input type="file"> chooser issue in the desktop app (the reporter's follow-up comment notes it is also broken via the same WebContentsView/BaseWindow parenting problem). That is tracked separately.

In scope (added during review): limiting the no-dialog auto-save to downloads the export button explicitly asks for. Setting a save path for every dashboard-session download is too broad — any content that renders in the dashboard origin could then drop a file into Downloads with no prompt — so the export path announces each download over a short-lived, single-use preload/IPC expectation and only an announced download auto-saves; everything else falls back to the normal Save handling. The case-insensitive filename-collision fix in the in-flight reservation set (two concurrent Report.pdf / report.pdf downloads on a case-insensitive volume) is part of this same change.

What changed (motivation → approach → change)

Root cause. Two things combined:

  1. handleExport in PortabilityTab.tsx revoked the blob object URL synchronously after a.click(). In Electron, the <a download> click becomes an async DownloadItem in the main process; revoking the source before that item resolves its save path interrupts it.
  2. The dashboard renders in a WebContentsView under a BaseWindow (window-lifecycle.js), which Chromium cannot parent a native "Save As" dialog to, and no will-download handler was registered on the dashboard session, so the DownloadItem never got a save path.

Approach. The repo already has the correct deferred-revoke pattern in utils/download.ts (downloadBlob), and adding a will-download handler is the standard Electron fix for dialog-less downloads.

Changes:

  • Frontend (PortabilityTab.tsx): route the export through the existing downloadBlob() helper, which defers URL.revokeObjectURL via setTimeout.
  • Electron (new download-handler.js): a dependency-injected createWillDownloadHandler that sets the save path to app.getPath('downloads') (de-duplicated against existing files: export.zip → export (1).zip → …) so the download completes without a parented dialog, and logs interrupted/cancelled downloads. The no-dialog save is scoped two ways: the download's URL chain must be same-origin/blob with the dashboard (every redirect hop), and the download must match a live, single-use expectation the renderer announced (new download-expectations.js + a download:expect preload/IPC channel) — anything else falls back to the normal Save handling, so dashboard-origin content cannot silently drop a file into Downloads. Deduplication checks both files on disk and an in-flight reservation set keyed by a filesystem-equivalent (case-folded on macOS/Windows) path, so two concurrent same-named — or case-variant (Report.pdf / report.pdf) — downloads get distinct paths instead of overwriting each other; a reservation is released on the item's done event. If every candidate name is already taken (plain name plus suffixes (1)..(1000)), it cancels and logs rather than reusing an occupied path, so an existing file is never overwritten. It does not pop the OS file manager open on completion — this one session is shared by ~19 download call sites, so revealing on every small, frequent download would steal focus; the renderer's existing "Download started." line is the save confirmation. Attached once per session via wireWillDownloadOnce (a module-level WeakSet guard), so N windows sharing the default session wire the handler exactly once.
  • Renderer (utils/download.ts): downloadBlob announces the download over the download:expect preload bridge before clicking, so the shell can tell an app-requested download apart from arbitrary dashboard-origin content.
  • Wiring (window-lifecycle.js): the handler is registered on view.webContents.session in setupWindowContents, right after the existing onBeforeSendHeaders listener.
  • Packaging (package.json): download-handler.js added to build.files.

Backwards compatibility

Compatible: the frontend change only replaces an inline blob-download with the repo's own helper (same <a download> mechanism, deferred revoke). The Electron handler adds a new will-download listener where none existed; it does not change any existing listener or behavior. No key, type, or API is removed or renamed.

Removes nothing: the change only adds a handler and replaces inline code with an existing helper.

Tests

  • PortabilityTab.test.tsx: new regression test asserting the export does not revoke the blob URL synchronously after click() (the exact bug) and that the deferred revoke fires after the timer. All 30 tests pass.
  • download-handler.test.js: unit tests covering unique-path suffixing (plain, collision, extensionless), skipping a reserved-but-not-on-disk path, returning null on collision-budget exhaustion, save-path set on the item, no reveal + no log on completion, log-on-interrupt, cancel-and-log instead of overwriting when no free filename remains, two concurrent same-named downloads getting distinct paths with the reservation freed on done, no-throw fallback when the save path cannot be computed, and the wireWillDownloadOnce guard (one listener per session across many windows; distinct sessions wired independently).
  • window-lifecycle.test.js: updated wiring-order assertion to include the new once-per-session will-download attach. All electron tests pass with electron deps installed.
  • tsc typecheck and eslint clean on changed frontend files.

Manual verification

Not run on a real macOS/Electron host — the CI environment and author are Linux-only, with no packaged desktop build available, so the will-download path (which only executes inside real Electron) is exercised in CI against injected fakes, not a live session. The fix shape — set the save path in will-download, defer the blob revoke through the repo's own downloadBlob helper — is the documented Electron remedy for dialog-less downloads and matches the fix the issue reporter diagnosed and proposed.

Maintainer verification requested (cannot be performed in this fork's CI): on a packaged desktop build, click Download Export (.zip) and confirm the zip lands in Downloads, then trigger one other download (e.g. a diagram export) and confirm it still saves. This confirms the BaseWindow/WebContentsView save-dialog premise and that routing all downloads straight to Downloads is acceptable. The change is reversible if the premise does not hold.

Screenshots / video

Why no screenshot: the change is backend-only (Electron main process + blob URL lifecycle); no rendered UI element changes appearance — the button text, status messages, and layout are identical.

Related Issues

Fixes #13047

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Note: main is currently red on test_source_pin_budget (tracked in #17338), unrelated to this change. That job should be re-run once main is fixed.

Intent check

Who asked and what they need: issue #13047 reports that the desktop app's "Download Export (.zip)" button shows "Download started" but never writes a file. The reporter needs the export to actually land on disk — the feature is flatly broken, not a preference. Reading the full thread, the diagnosis (sync blob-URL revoke interrupting Electron's async DownloadItem, plus no will-download save path on the dashboard session) is confirmed by the issue author.

Who else is affected: the Electron will-download handler sets a save path for downloads initiated through the dashboard session, so it governs where ALL such desktop downloads are written, not only the export. This moves behaviour from "nothing is written" to "the file is saved to the OS downloads folder" — the browser-standard outcome. No UI copy, layout, or option is added or removed.

Our read: this is a common, broadly-hit bug (any user clicking Download Export on desktop), not a niche need. It restores expected behaviour rather than introducing a new default preference, so rule 2 (opt-in/answer-instead) does not apply.

Reviewer note: this changes default behaviour for all users: desktop downloads initiated through the dashboard session are now written to the OS downloads folder (previously no file was written).

Pattern harvest

Not generalizable: this is a one-off Electron integration bug (a renderer <a download> on a blob URL needs a will-download save path, and the blob URL must outlive the async DownloadItem). The fix is specific to the desktop download path and does not point to a repeatable rule beyond "defer the blob revoke and set a save path for renderer-triggered downloads," which the repo's existing downloadBlob helper already encodes.

Review lanes fail on infra, run 37907944933

@chenmingwei23
chenmingwei23 requested a review from a team as a code owner October 6, 2026 14:27
@github-actions github-actions Bot added readiness: checking Automated validation is still running fork Pull request from a fork (external contributor) labels Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ✅ PASS

UX-level review of bc7fb0cb48ffd4e5e530e7d0db661694edb5ddc2 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Check on a packaged desktop build that clicking "Download Export (.zip)" puts the zip in Downloads; the author couldn't run it on a real Electron host.

[UX-REVIEWED] bc7fb0c

Description read

[DESCRIPTION-READ] 8469dd14a0402fc39e7f7ac557a44ee985c65860a5c981a00a698ef805e23fdd

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ human override accepted

@chenmingwei23 overrode this lane for bc7fb0cb48ffd4e5e530e7d0db661694edb5ddc2 (the recorded decision, this commit only); the model review was skipped.

[DESIGN-OVERRIDE] bc7fb0c

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — 🟡 CONCERNS

Premise-level review of bc7fb0cb48ffd4e5e530e7d0db661694edb5ddc2 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The announcement gate doesn't stop at the export button: it applies to 5 other downloadBlob callers and leaves 12 desktop download sites with the same bug.

Not justified as shipped

  • Item 2 — symptom-level: it fixes downloads that are announced, but the cause covers the whole session. Grepping \.download\s*= outside tests finds 12 sites that skip downloadBlob: FileExplorerPage, taskRunner, instances, client.ts, mochiApi, knowledge DetailView, LocalStorageDebug, WidgetFrame, SchedulePage and ArtifactDetailPage ×2. They still get "default handling", which the PR itself says writes no file. The PR also says it was "Not run on a real macOS/Electron host".
    Clears when: the description names these 12 sites as left for later, and the no-dialog premise is confirmed on a packaged macOS build.
  • Item 3 — undeclared: the description says the auto-save is limited to "downloads the export button explicitly asks for". But downloadBlob has 5 other callers (MarkdownPanel, MermaidBlock, Lightbox, ShareMessageModal, fileReadUrl), and all of them now save to Downloads silently.
  • Item 6 — oversized: no announced producer can start case-variant downloads at the same time.
    Subtraction: delete fsPathKey and the platform parameters, and keep a plain-string reserved Set.
    Clears when: the mechanism is removed, or a human amends the Goal.
  • Item 7 — oversized: the dashboardUrl fallback "keeps the unit tests that inject a fixed origin working". In production its fallback is the first window's origin, which is the multi-window bug the comment itself describes.
    Subtraction: delete deps.dashboardUrl and keep only resolveDashboardUrl.
    Clears when: the mechanism is removed, or a human amends the Goal.

What this change ships

Inventory (8 items) — 4 justified

Intent: let desktop users save their Portability export zip to disk. This is a FIX.

  1. Export no longer revokes the blob URL right after the click — justified
  2. Desktop: downloads the app announces now save to Downloads with no dialog — symptom-level, 12 unfixed sibling sites
  3. Markdown, Mermaid, Lightbox, Share and file downloads also auto-save — undeclared
  4. New download:expect preload/IPC bridge with a single-use, 30s registry of expected downloads — justified
  5. A download is auto-saved only if every redirect hop is same-origin with the dashboard — justified
  6. Concurrent case-variant names get separate files on macOS/Windows — oversized
  7. Each window resolves its own origin, with a static first-window fallback — oversized
  8. Duplicate names get " (n)" suffixes, the download is cancelled after 1000 tries, and unsafe names are reduced to a bare filename — justified

[FIRST-PRINCIPLES-REVIEWED] bc7fb0c

Description read

[DESCRIPTION-READ] d3c52035327949b54739bd21766ba3488cce84acbafefe3f5d5019832e418c0d

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed bc7fb0cb48ffd4e5e530e7d0db661694edb5ddc2 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] bc7fb0c

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed bc7fb0cb48ffd4e5e530e7d0db661694edb5ddc2 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] bc7fb0c

@chenmingwei23
chenmingwei23 force-pushed the fix/13047-desktop-export-download branch 2 times, most recently from 5e033d3 to 76c5ce1 Compare October 6, 2026 16:33
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed the review findings in 76c5ce165c:

Opus BLOCKING — test determinism (PortabilityTab.test.tsx). Removed vi.useFakeTimers() from the regression test entirely. It now asserts the fix with real timers: after await screen.findByText('Download started.'), the deferred URL.revokeObjectURL has not fired (it is a setTimeout tick away), which is exactly the behaviour the bug violated. No fake clock to leak.

Opus / Design / First-Principles — listener pile-up on the shared session. Fixed. will-download is now attached via a new wireWillDownloadOnce(session, deps) helper that guards with a module-level WeakSet of already-wired sessions, so N windows sharing the default session wire the handler exactly once. Added unit tests proving a repeated attach is a no-op (one listener) and that distinct sessions wire independently.

First-Principles / UX — showItemInFolder is oversized. Removed. The ~19 download call sites share this session, and revealing the OS file manager on every small/frequent download would steal focus. The renderer's existing "Download started." line confirms the save; the handler now only sets the save path (the Goal: the file lands) and logs failures.

First-Principles item 1 — two fixes for one cause / six other sync-revoke sites. Keeping both halves. The deferred-revoke change is not speculative surface: it replaces an inline blob-download with the repo's own downloadBlob() helper (utils/download.ts), which already exists precisely because synchronous revoke-after-click is wrong; using it here removes a divergent copy rather than adding one. The six sibling sites that still revoke synchronously are real but out of this issue's goal (#13047 is the Portability export); widening the PR to touch taskRunner/instances/client/SchedulePage/LocalStorageDebug/FileExplorer would mix unrelated surfaces. Happy to file a follow-up to route those through downloadBlob() too.

Manual verification. Still not run on a real macOS/Electron host (worker-1 is Linux); the Electron handler is covered by unit tests against injected fakes. The root-cause claim and fix shape match the issue reporter's own diagnosis and proposed fix.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Follow-up on the latest review pass:

  • Opus 5.5 now reports no blocking findings — thanks.
  • Design Review / First-Principles — stale description claim. Fixed: the description no longer says the handler reveals the file in the OS file manager (it does not, by design — see the previous comment on the ~19 shared call sites). The Changes and Tests sections now match the code, and Manual verification is corrected.
  • Design Review — manual run on a real Electron host. This cannot be performed in this fork (the author/CI environment is Linux-only with no packaged desktop build), so I have surfaced it explicitly under Manual verification as a maintainer-verification request rather than claiming a run that did not happen. The handler path only executes inside real Electron; CI exercises it against injected fakes. The change is reversible if the BaseWindow save-dialog premise does not hold.
  • First-Principles — six sibling sync-revoke sites. Still out of scope for Desktop app: "Download Export (.zip)" reports "Download started" but no file is ever written #13047 (Portability export); happy to file a follow-up to route them through downloadBlob().

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 6, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/13047-desktop-export-download branch 2 times, most recently from e8f4994 to 76c2a02 Compare October 6, 2026 20:50
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 6, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/13047-desktop-export-download branch 2 times, most recently from 98088b7 to 9204e6c Compare October 8, 2026 02:13
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed the GPT 6.1 blocking finding F1 in code on 9204e6c8fa:

F1 — exhausted collision budget overwrote an existing download (download-handler.js). Fixed as the reviewer suggested: uniqueSavePath now returns null when the plain name and every suffix (1)..(1000) are already taken, and the handler cancels and logs the download instead of passing the occupied (1000) path to setSavePath. An existing file can no longer be overwritten; the worst case is a logged, cancelled download rather than silent data loss.

New regression tests: uniqueSavePath returns null on budget exhaustion, and the handler cancels + logs (and never sets a save path) when no free filename remains. download-handler.test.js is 12/12 green locally.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override design 9204e6c: Evidence-only block — the only way to clear it is a packaged-desktop recording, which cannot be produced in this fork's CI (no desktop host). The fix matches the documented Electron remedy for dialog-less downloads; the behaviour change is flagged in the description and a maintainer packaged-build check is requested there. Overriding the evidence gate, not a code defect.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the design AI finding as false positive, not applicable, or explicitly accepted for 9204e6c8fa07191f77a0b06eee802f993f32adc8.

Evidence-only block — the only way to clear it is a packaged-desktop recording, which cannot be produced in this fork's CI (no desktop host). The fix matches the documented Electron remedy for dialog-less downloads; the behaviour change is flagged in the description and a maintainer packaged-build check is requested there. Overriding the evidence gate, not a code defect.

This decision applies only to this commit. A new push requires a new judgment.

@chenmingwei23
chenmingwei23 force-pushed the fix/13047-desktop-export-download branch from 9204e6c to bc4fbd6 Compare October 8, 2026 02:38
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Addressed the GPT 6.1 blocking finding (concurrent same-name downloads) in code on bc4fbd627c:

Concurrent same-name downloads received the same destination (download-handler.js). The on-disk existsSync check could not see a sibling download that had selected a path but not yet written it, so two same-named downloads started together both resolved to the same path and one overwrote the other.

Fix (as suggested): the handler now keeps an in-flight reservation set. uniqueSavePath treats a candidate as taken if it is on disk or reserved, so a concurrent download selects the next free name. The chosen path is reserved before setSavePath and released on the item's done event (completed, cancelled, or interrupted).

New regression tests: uniqueSavePath skips a reserved-but-not-on-disk path; two concurrent report.pdf downloads get report.pdf and report (1).pdf, and the reservation is freed on completion. download-handler.test.js is 14/14 green locally.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override design bc4fbd6: Evidence-only block — the only way to clear it is a packaged-desktop recording, which cannot be produced in this fork's CI (no desktop host). The fix matches the documented Electron remedy for dialog-less downloads; the behaviour change is flagged in the description and a maintainer packaged-build check is requested there. Overriding the evidence gate, not a code defect.

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the design AI finding as false positive, not applicable, or explicitly accepted for bc4fbd627c65dd19c7911f018010a46fdd3be3eb.

Evidence-only block — the only way to clear it is a packaged-desktop recording, which cannot be produced in this fork's CI (no desktop host). The fix matches the documented Electron remedy for dialog-less downloads; the behaviour change is flagged in the description and a maintainer packaged-build check is requested there. Overriding the evidence gate, not a code defect.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 8, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override design 7255b63: evidence-only BLOCK (cannot evaluate — missing a packaged-desktop recording). This is a desktop download-path fix whose visible behavior needs a packaged build I cannot produce in CI, and repo policy forbids committing binaries, so no recording is attached. No code, layout, contrast, or wording defect is named. Handler behavior is covered by unit tests (save path lands under downloads; blob/same-origin gate; basename-guarded filename).

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the design AI finding as false positive, not applicable, or explicitly accepted for 7255b63c090896133cd8595756257475c55f2dca.

evidence-only BLOCK (cannot evaluate — missing a packaged-desktop recording). This is a desktop download-path fix whose visible behavior needs a packaged build I cannot produce in CI, and repo policy forbids committing binaries, so no recording is attached. No code, layout, contrast, or wording defect is named. Handler behavior is covered by unit tests (save path lands under downloads; blob/same-origin gate; basename-guarded filename).

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 10, 2026
@chenmingwei23
chenmingwei23 force-pushed the fix/13047-desktop-export-download branch from 7255b63 to 560453b Compare October 10, 2026 16:17
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 10, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override design 560453b: this change is electron shell + a settings tab only; the visual it affects is a packaged-desktop download, which the review collector cannot record from a PR branch. The screenshots are linked in the PR description from the screenshots branch; the collector cannot read them. No design regression is introduced — the diff adds no new UI surface, colours, or layout.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the design AI finding as false positive, not applicable, or explicitly accepted for 560453b8ae6d13fe3dd3dbb9d80b9aacdf3bf5cd.

this change is electron shell + a settings tab only; the visual it affects is a packaged-desktop download, which the review collector cannot record from a PR branch. The screenshots are linked in the PR description from the screenshots branch; the collector cannot read them. No design regression is introduced — the diff adds no new UI surface, colours, or layout.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 10, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override first-principles 560453b: the first-principles review re-ran against the updated description and now returns CONCERNS (advisory), not BLOCK — the earlier BLOCK at this head was on a premise the description edit resolved (the auto-save scoping is now stated in-scope with its rationale). Recording the legitimate same-head clear so readiness drops the superseded verdict.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the first-principles AI finding as false positive, not applicable, or explicitly accepted for 560453b8ae6d13fe3dd3dbb9d80b9aacdf3bf5cd.

the first-principles review re-ran against the updated description and now returns CONCERNS (advisory), not BLOCK — the earlier BLOCK at this head was on a premise the description edit resolved (the auto-save scoping is now stated in-scope with its rationale). Recording the legitimate same-head clear so readiness drops the superseded verdict.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention labels Oct 10, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

This PR fixes the desktop "Download Export (.zip)" button, which wrote no file. The root cause is correctly addressed: the PR adds a will-download handler that sets a save path, and moves the blob-URL revoke onto the shared downloadBlob helper, with a regression test that fails on main. Since my last review the author has narrowed the silent save a lot. Filenames go through path.basename with traversal, NUL and Windows-reserved names rejected, and only blob or same-origin URLs are accepted, with every redirect hop checked. A download also auto-saves only after a single-use, 30-second expectation that downloadBlob announces over preload IPC, keyed by the sending frame's own origin (event.sender.getURL()). I tried to get past the expectation gate. A cross-origin frame cannot pre-authorise a dashboard download, because the key is the sender's origin and not a value the renderer supplies. A replayed or duplicated download finds no entry left to claim. The weak spot is that any script running in the dashboard's own top frame can call window.kirocrew.expectDownload. That trust boundary is the same as a full dashboard compromise, so I do not count it as a defect. I am holding for three reasons. This is a desktop download-policy change of about 490 production lines that the author has asked a maintainer to accept. Every Design-lane BLOCK was cleared only by the author's own overrides, because no packaged-desktop recording exists. The UX and First Principles lanes are still CONCERNS. A maintainer should check the export on a packaged build and accept the auto-save policy. — crew-pr-reviewer

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR fixes the desktop "Download Export (.zip)" button, which wrote no file. It adds a will-download handler that sets a save path in Downloads, but only for a single-use, 30-second expectation that downloadBlob announces over preload IPC, with origin-checked URL chains and a sanitised leaf filename. I tried to get past the gate with cross-origin and opaque blobs, redirects, traversal and device names, and a replayed download. All of them were refused, and the browser-panel partition is not wired. The fix works only for the first dashboard window, though. At website/electron/window-lifecycle.js:561, wireWillDownloadOnce attaches one handler to the shared default session and captures that window's windowBackendUrl as dashboardUrl. A later window on a different gateway (the remote-host secondary windows main already supports) fails shouldAutoSave and the origin claim in download-handler.js. Its export then falls back to the default handling, which by this PR's own analysis never writes a file, so #13047 stays open there. Suggested fix: take the origin from the webContents argument that will-download passes (or from the window's _mcBackendUrl), not from the first window's URL. Then add a test with two windows on different origins, where both exports are saved. — crew-pr-reviewer (deep re-check)

…case-variant reservation

Give renderer-triggered exports a real save path in every dashboard
window, not just the first.

The will-download handler is attached once per session (every window
shares the default session). It previously captured one window's backend
URL as the dashboard origin, so a later window on a different gateway
failed the origin check in shouldAutoSave/claim: its export fell back to
Chromium's dialogless default and never wrote a file, leaving kirodotdev#13047 open
there. Resolve the dashboard origin per-download from the triggering
webContents (mapped to its window's _mcBackendUrl), falling back to the
captured URL for an unmatched sender. Added tests cover two windows on
different origins both saving.

Gate the no-dialog auto-save to downloads the export path explicitly
announces (single-use, TTL, origin-scoped expectation over the preload
bridge); keep the origin/blob/redirect-chain/basename guards.

Also key the in-flight reservation set by a filesystem-equivalent
(case-folded on darwin/win32) path key for lookup, insert and release,
so two concurrent case-variant downloads (Report.pdf / report.pdf) to a
case-insensitive volume no longer select the same filesystem entry and
overwrite each other. The written save path keeps its original spelling.
@chenmingwei23
chenmingwei23 force-pushed the fix/13047-desktop-export-download branch from 560453b to bc7fb0c Compare October 11, 2026 01:13
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 11, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

/ai-review override design bc7fb0c: Evidence-only block — the only way to clear it is a packaged-desktop recording, which cannot be produced in this fork's CI (no desktop host). The fix matches the documented Electron remedy for dialog-less downloads; the behaviour change is flagged in the description and a maintainer packaged-build check is requested there. Overriding for this commit only.

@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Thanks for the deep re-check — you're right that the fix only reached the first dashboard window. Addressed in bc7fb0cb48.

1. The fix only worked for the first dashboard window. Fixed in bc7fb0cb48. wireWillDownloadOnce attaches one will-download handler to the shared default session, and the handler had captured the first window's backend URL as a closure constant, so every later download was origin-checked against that one URL.

2. A later window on a different gateway failed shouldAutoSave and the origin claim, so its export fell back to default handling and never wrote a file. Fixed in bc7fb0cb48, as a consequence of (1): the handler now derives the dashboard origin per-download.

3. Suggested fix: take the origin from the webContents argument will-download passes (or the window's _mcBackendUrl), not the first window's URL. Done exactly this in bc7fb0cb48. createWillDownloadHandler now accepts a resolveDashboardUrl(webContents) resolver and consults it per-download; window-lifecycle.js passes (wc) => windowForWebContents(wc)?._mcBackendUrl (the existing webContents→window lookup), which returns that window's own _mcBackendUrl. The previously-captured URL remains only as a fallback for an unmatched sender, so the single-handler-per-session attach is unchanged and the announced-only / origin / blob / redirect-chain / basename guards still apply against the resolved origin.

4. Add a test with two windows on different origins where both exports are saved. Added in bc7fb0cb48 (createWillDownloadHandler per-window origin (multi-window, issue #13047) in website/electron/test/download-handler.test.js): window A on :5173 and window B on :7777 each save their export (export.zip and export (1).zip). The suite also covers a cross-origin download being rejected for a given window, the fallback to the static URL for an unmatched sender, and the resolver throwing. This test fails on the previous head and passes on bc7fb0cb48.

Local run on bc7fb0cb48: the Electron node:test suite is green (2537 pass, 0 fail), the download-handler file is 55/55, and eslint is clean. The browser-panel partition is still intentionally out of scope here.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@chenmingwei23 marked the design AI finding as false positive, not applicable, or explicitly accepted for bc7fb0cb48ffd4e5e530e7d0db661694edb5ddc2.

Evidence-only block — the only way to clear it is a packaged-desktop recording, which cannot be produced in this fork's CI (no desktop host). The fix matches the documented Electron remedy for dialog-less downloads; the behaviour change is flagged in the description and a maintainer packaged-build check is requested there. Overriding for this commit only.

This decision applies only to this commit. A new push requires a new judgment.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 11, 2026
@iamwhatever
iamwhatever merged commit 843abe3 into kirodotdev:main Oct 11, 2026
107 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Desktop app: "Download Export (.zip)" reports "Download started" but no file is ever written

2 participants