Skip to content

fix(mothership): re-attach at once when the user returns to a recovered stream - #8675

Merged
waleedlatif1 merged 4 commits into
stagingfrom
fix/mothership-reattach-on-return
Oct 6, 2026
Merged

waleedlatif1 merged 4 commits into
stagingfrom
fix/mothership-reattach-on-return

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • After the user leaves a running chat and comes back, the return recovery owns the stream for the rest of the turn, and every later online / visible / pageshow event just joined that in-flight recovery.
  • So a later network drop waited out whatever the recovery was doing: a tail that went silent held the stream until the 45s idle timeout, and a tail that failed slept out a reconnect backoff of up to 30s. The same drop on a stream the send still owned re-attached immediately.
  • A return signal now supersedes an in-flight recovery the same way it supersedes the send's reader, and the new recovery re-attaches from the cursor.

Type of Change

  • Bug fix

Testing

  • New DOM regression in use-chat.dom.test.tsx covering both a stalled tail and a failed tail in backoff; both fail on staging.
  • Browser E2E on a local Sim + worker stack (tab hidden and returned, then 90s offline): streaming resumed under 1s after the network came back, versus ~48s before.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

…ed stream

Once the user left a running chat and came back, the return recovery owned the
stream for the rest of the turn, and every later online/visible/pageshow event
just joined it. So a network drop after that waited out whatever the recovery
was doing: a tail that went silent held the stream until the 45s idle timeout,
and a tail that failed slept out a reconnect backoff of up to 30s. The same
drop on a stream the send still owned re-attached immediately, because the
return signal supersedes the send's reader. On the local QA stack the stream
resumed 48s after the network came back.

A return signal now supersedes an in-flight recovery the same way, and the new
recovery re-attaches from the cursor.
@vercel

vercel Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 6, 2026 6:05pm UTC

Request Review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@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

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

Fix all with cubic | Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
@greptile-apps

greptile-apps Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Changes stream recovery logic when user returns to chat.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR lets a browser-return signal supersede an in-flight stream recovery and reattach from the current cursor. It also resolves a locally running turn after the server has finished it, including when the POST response was lost, while leaving a not-yet-admitted send alone.

  • Adds DOM regressions for stalled and failed recovery tails, completed turns, and pending POST admission.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Browser return signal] --> B[Abort prior recovery]
  B --> C[Load chat history]
  C --> D{Active server stream?}
  D -->|Yes| E[Reattach from cursor]
  D -->|No| F{Local turn admitted?}
  F -->|Yes| G[Resolve terminal stream and finalize]
  F -->|No| H[Leave pending POST alone]
Loading

Reviews (4) · Last reviewed commit: "fix(mothership): finish an admitted turn..."

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts
A return recovery used the chat history's `activeStreamId` to decide what to
re-attach to. When the turn had ended while this surface was not listening (its
reader stalled, or a later return superseded the recovery that held it), the
history listed no running turn, so recovery returned without touching the
stream this surface still showed as running, and the chat stayed on Stop until
an idle timeout or backoff happened to run into the terminal state.

When the history lists no running turn but this surface is still sending,
recovery now resolves that stream: its terminal status replays the remaining
events and finalizes.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@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

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

Fix all with cubic | Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
A send shows as running before its POST is admitted, but the chat cannot list
it yet. Resolving that stream on a return event read it as ended and aborted
the POST. Recovery now resolves only a locally running stream whose POST was
admitted.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Outdated
… return

Recovery left a send alone while its POST had not answered, so a turn the server
admitted and finished, whose answer never reached the client, kept the chat on
Stop with nothing to clear it. The send now counts as admitted once the loaded
chat holds its message, and recovery resolves its stream as any other.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

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

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 662bd70 into staging Oct 6, 2026
33 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/mothership-reattach-on-return branch October 6, 2026 21:19

This branch was previously deployed

1 inactive deployment
Preview — 8fc5dae3 Deployed Oct 6, 2026 by vercel[bot]
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