Skip to content

fix: export filenames are unreadable in molab - #10478

Open
Light2Dark wants to merge 2 commits into
mainfrom
fix/molab-export-download-filename
Open

fix: export filenames are unreadable in molab#10478
Light2Dark wants to merge 2 commits into
mainfrom
fix/molab-export-download-filename

Conversation

@Light2Dark

@Light2Dark Light2Dark commented Aug 6, 2026

Copy link
Copy Markdown
Member

📝 Summary

Fixes molab export downloads failing with Export response is missing a filename.

After #10349, exports required reading Content-Disposition from the fetch response. In molab instant-launch, the editor runs on {sandbox}-session.sb.molab.run but calls the kernel on {sandbox}.sb.molab.run, so that header is not visible to JS cross-origin. The export body still succeeds; only the filename lookup failed.

This adds client-side default filenames (notebook name, or download.*) when the header cannot be read, and broadens Content-Disposition parsing.

The root cause fix is on molab-side, but regardless, downloads shouldn't fail when the header cannot be read.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.

✅ Merge Checklist

molab instant-launch serves the editor from the session host but calls
the kernel on the sandbox host, so Content-Disposition is not visible to
JS. Use notebook-derived defaults instead of failing the download.

Co-authored-by: Cursor <cursoragent@cursor.com>
@Light2Dark Light2Dark added the bug Something isn't working label Aug 6, 2026
@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview Aug 6, 2026 6:16pm

Request Review

@Light2Dark
Light2Dark requested a review from Copilot August 6, 2026 17:46
@Light2Dark Light2Dark changed the title fix: fall back when export filenames are unreadable cross-origin fix: filenames are unreadable in molab due to cross-origin Aug 6, 2026
@Light2Dark Light2Dark changed the title fix: filenames are unreadable in molab due to cross-origin fix: export filenames are unreadable in molab Aug 6, 2026
@Light2Dark
Light2Dark requested a review from peter-gy August 6, 2026 17:52
@Light2Dark
Light2Dark marked this pull request as ready for review August 6, 2026 17:52
@Light2Dark
Light2Dark requested a review from mscolnick August 6, 2026 17:53

@cubic-dev-ai cubic-dev-ai Bot 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.

2 issues found across 6 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="frontend/src/core/network/api.ts">

<violation number="1" location="frontend/src/core/network/api.ts:28">
P2: Malformed percent-encoding in a readable `filename*` causes export handling to throw instead of using `opts.defaultFilename`; catch decode failures and return `undefined` so the existing fallback runs.</violation>
</file>

<file name="frontend/src/core/network/export-filename.ts">

<violation number="1" location="frontend/src/core/network/export-filename.ts:23">
P2: Exports for notebooks whose filename uses Windows separators receive a path-containing download name instead of the notebook basename. Splitting both separators or reusing `Paths.basename` keeps the fallback filename portable.</violation>
</file>
Architecture diagram
sequenceDiagram
    participant Editor as Editor UI (Browser)
    participant Network as Network Requests
    participant Kernel as Kernel Backend (Molab)
    participant Filename as Default Filename Resolver
    participant Store as Jotai Store (filenameAtom)
    participant Api as API Client (api.ts)

    Note over Editor,Kernel: Export flow (HTML, Markdown, Script, IPYNB, PDF)

    Editor->>Network: Trigger export (e.g., Download as HTML)
    Network->>Kernel: POST export endpoint with format params
    Kernel-->>Network: Export body + Content-Disposition header

    Note over Network,Api: Molab cross-origin: editor domain differs from kernel domain, so Content-Disposition may not be exposed to JS

    alt Markdown export
        Network->>Filename: NEW: getDefaultMarkdownExportFilename(flavor)
        Filename->>Filename: Map flavor to extension (.qmd, .md, .myst.md)
    else Other export types
        Network->>Filename: NEW: getDefaultExportFilename(extension)
    end

    Filename->>Store: Read current notebook filename
    alt Notebook has a name
        Store-->>Filename: "folder/my_notebook.py"
        Filename-->>Network: "my_notebook.html"
    else Notebook is unnamed or filename missing
        Store-->>Filename: null
        Filename-->>Network: "download.html"
    end

    Network->>Api: NEW: handleExportResponse(response, { defaultFilename })
    Api->>Api: Parse export body (blob/text)

    alt Content-Disposition header readable
        Api->>Api: CHANGED: Parse RFC5987, quoted, or unquoted filename
        Api-->>Network: Use filename from header
    else Header missing or unparsable
        Api-->>Network: NEW: Use defaultFilename
    end

    Api->>Api: Read Content-Type media type
    alt Content-Type missing
        Api-->>Network: Reject export (missing media type)
    else Valid response
        Api-->>Network: ExportedFile { contents, filename, mediaType }
        Network-->>Editor: Trigger browser download with resolved filename
    end
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread frontend/src/core/network/api.ts Outdated
Comment thread frontend/src/core/network/export-filename.ts Outdated
Wrap malformed RFC 5987 decoding in try/catch so default filenames apply,
and use Paths.basename for notebook stems on Windows paths.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI 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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Coverage Report for ./frontend

Status Category Percentage Covered / Total
🔵 Lines 78.83% 81643 / 103564
🔵 Statements 78.83% 81643 / 103564
🔵 Functions 71.22% 693 / 973
🔵 Branches 79.38% 4863 / 6126
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
frontend/src/core/network/api.ts 96.1% 100% 100% 96.1% 105-107, 140-142
frontend/src/core/network/export-filename.ts 100% 0% 100% 100%
frontend/src/core/network/requests-network.ts 99.8% 83.33% 100% 99.8% 423
frontend/src/core/network/types.ts 0% 0% 0% 0%
Generated in workflow #20269 for commit ffe0b16 by the Vitest Coverage Report Action

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants