Skip to content

fix(islands): ignore inactive session messages#10330

Open
peter-gy wants to merge 2 commits into
marimo-team:mainfrom
peter-gy:ptr/filter-inactive-island-session-messages
Open

fix(islands): ignore inactive session messages#10330
peter-gy wants to merge 2 commits into
marimo-team:mainfrom
peter-gy:ptr/filter-inactive-island-session-messages

Conversation

@peter-gy

@peter-gy peter-gy commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Follow up to #10207.

Drops kernel messages after their session yields ownership of the shared islands frontend.

Retained navigation reuses one frontend store across app sessions. Messages already in transit from the outgoing session could otherwise apply cell or UI updates to the incoming document when cell IDs overlap.

The bridge now tracks accepted session generations. Replacement and teardown revoke the outgoing generation before their asynchronous worker calls begin. A failed replacement restores ownership to the previous session. Multi-app documents retain every generation started for the current document.

@vercel

vercel Bot commented Jul 25, 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, Comment Jul 25, 2026 6:41pm

Request Review

@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.

All reported issues were addressed across 2 files

Architecture diagram
sequenceDiagram
    participant Worker as Pyodide Worker
    participant Bridge as IslandsPyodideBridge
    participant Store as Jotai Store
    participant UI as React UI Components
    
    Note over Worker,UI: Active session flow
    
    Bridge->>Bridge: startSession(request)
    Bridge->>Bridge: activeSessionGenerations.add(generation)
    Bridge->>Store: Set islandsPendingInitialRunsAtom
    Bridge->>Worker: proxy.request.startSession(request)
    Worker-->>Bridge: session ready
    
    loop Kernel messages
        Worker->>Bridge: "kernelMessage" event
        alt activeSessionGenerations.has(sessionGeneration)
            Bridge->>Bridge: Forward to messageConsumer
            Bridge->>UI: Apply cell/UI updates
        else Session inactive
            Bridge->>Bridge: Ignore message
        end
    end
    
    Note over Worker,UI: Session replacement flow
    
    Bridge->>Bridge: initializeApps()
    Bridge->>Bridge: activeSessionGenerations.clear()
    Bridge->>Bridge: nextSessionGeneration++
    Bridge->>Bridge: startSession(request)
    Bridge->>Bridge: activeSessionGenerations.add(generation)
    
    alt Replaces previous single app
        Bridge->>Store: Reset notebookAtom
    end
    
    Bridge->>Worker: proxy.request.startSession(request)
    
    Note over Worker,Bridge: Asynchronous worker call in flight
    Worker->>Bridge: "kernelMessage" (old generation)
    alt Generation not in activeSessionGenerations
        Bridge->>Bridge: Drop message
    end
    
    Worker-->>Bridge: session ready
    Bridge->>Bridge: sessionReady.resolve()
    
    Note over Worker,UI: Session stop flow
    
    UI->>Bridge: stopSession()
    Bridge->>Bridge: activeSessionGenerations.delete(generation)
    Bridge->>Worker: proxy.request.stopSession(request)
    
    Note over Worker,Bridge: Asynchronous worker call in flight
    Worker->>Bridge: "kernelMessage" (stopped generation)
    alt Generation not in activeSessionGenerations
        Bridge->>Bridge: Ignore message
    end
    
    alt Error during session start
        Bridge->>Bridge: activeSessionGenerations.delete(generation)
        Bridge->>Bridge: Revert session to previous
        Bridge->>Store: Restore previous state
    end
Loading

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

Re-trigger cubic

Comment thread frontend/src/core/islands/bridge.ts
@peter-gy
peter-gy marked this pull request as ready for review July 25, 2026 18:51
Copilot AI review requested due to automatic review settings July 25, 2026 18:51

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@peter-gy
peter-gy requested a review from mscolnick July 25, 2026 18:51
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