Skip to content

fix(sse): rotate workspace streams without gaps - #7061

Merged
waleedlatif1 merged 2 commits into
stagingfrom
codex/fix-sse-rotation
Aug 25, 2026
Merged

fix(sse): rotate workspace streams without gaps#7061
waleedlatif1 merged 2 commits into
stagingfrom
codex/fix-sse-rotation

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Bound workspace SSE connections with make-before-break rotation
  • Preserve cache reconciliation for genuine reconnect gaps without refetching on seamless rotations
  • Make subscription setup and teardown failure-safe

Type of Change

  • Bug fix

Testing

  • bun run --cwd apps/sim test -- lib/events/sse-endpoint.test.ts lib/events/rotating-event-source.test.ts hooks/use-mothership-chat-events.test.ts hooks/queries/mcp.test.tsx
  • bun run type-check
  • bun run lint
  • bun run apps/sim/scripts/check-block-registry.ts origin/staging
  • bun run check:audits
  • Standalone Next.js production-server validation under Bun 1.3.14

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have added tests that prove the fix is effective
  • New and existing unit tests pass locally
  • My changes generate no new warnings

@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 25, 2026 4:24am

Request Review

@greptile-apps

greptile-apps Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR bounds workspace SSE lifetimes while using make-before-break client rotation to preserve event delivery and reconcile caches after genuine reconnect gaps.

  • Adds a reusable rotating EventSource connection that retains the current stream until its replacement opens.
  • Updates MCP and mothership chat subscriptions to use rotation-aware reconnect handling.
  • Makes SSE subscription setup and teardown failure-safe and adds lifecycle coverage.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/events/rotating-event-source.ts Introduces rotation-aware EventSource ownership, make-before-break replacement, reconnect classification, and complete disposal.
apps/sim/lib/events/sse-endpoint.ts Replaces hard expiration with announced rotation and a grace period while making setup and teardown failure-safe.
apps/sim/hooks/queries/mcp.ts Migrates MCP event subscriptions to the rotating connection and reconciles queries after genuine reconnects.
apps/sim/hooks/use-mothership-chat-events.ts Migrates mothership chat events to rotation-aware subscriptions while preserving cache reconciliation behavior.
apps/sim/lib/events/rotating-event-source.test.ts Covers seamless replacement, reconnect classification, disposal during rotation, and replacement-construction failure.
apps/sim/lib/events/sse-endpoint.test.ts Covers rotation grace behavior and failure-safe subscription setup and teardown.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Old as Current SSE stream
    participant Server
    participant New as Replacement SSE stream
    Server->>Old: rotate event
    Old->>Client: rotation requested
    Client->>New: open replacement connection
    Note over Old,New: Current stream remains active
    New-->>Client: connection opened
    Client->>Old: close current connection
    Client->>New: promote replacement
    alt Current stream dropped before replacement opened
        Client->>Client: classify as reconnect
        Client->>Client: reconcile affected caches
    else Seamless replacement
        Client->>Client: classify as rotation
    end
Loading

Reviews (2): Last reviewed commit: "test(sse): cover delivery across rotatio..." | Re-trigger Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 7 files

Confidence score: 4/5

  • apps/sim/hooks/queries/mcp.ts can leave the legacy global connection map undiscovered during refresh, causing the hook to open a second workspace SSE stream; preserve or migrate the legacy key and close any stale connection.
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="apps/sim/hooks/queries/mcp.ts">

<violation number="1" location="apps/sim/hooks/queries/mcp.ts:546">
P2: During a refresh from the previous implementation, this new key leaves the old global connection map undiscovered, so the hook can open a second workspace SSE stream. Preserve or migrate the legacy key, and close any legacy entries that cannot be reused.</violation>
</file>

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

Re-trigger cubic

Comment thread apps/sim/hooks/queries/mcp.ts Outdated
Comment thread apps/sim/lib/events/rotating-event-source.test.ts
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 merged commit ea9207d into staging Aug 25, 2026
29 checks passed
@waleedlatif1
waleedlatif1 deleted the codex/fix-sse-rotation branch August 25, 2026 04:58
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.

1 participant