Skip to content

fix(mothership): keep a failed direct send ahead of follow-ups queued during its POST - #8738

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/mothership-requeue-failed-send-first
Oct 7, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/mothership-requeue-failed-send-first

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • A failed direct send goes back to the head of the queue. When a direct send's POST failed (offline, a network blip, or a busy refusal), the message was re-queued at the tail, behind any follow-up typed while that POST was out. The queue became [B, A], and the drain could send the follow-up before the message written first.
  • Why the head is right: a direct send only goes out when nothing is queued ahead of it (shouldQueueOutgoingMessage), so anything queued while its POST was out was written after it. It now goes back with insertAt(…, 0).
  • Why tests missed it: every existing direct-send test sent its follow-up only after the first send had resolved, so a follow-up never queued during the POST.

Type of Change

  • Bug fix

Testing

  • keeps a failed direct send ahead of a follow-up queued during its POST, for offline, an online network blip, and a busy 409. Each fails on staging: the follow-up is sent ahead of the first message.
  • The full gate and integration tests ran on the CI runner.

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)

… during its POST

A direct send that failed (offline, a network blip, or a busy refusal) was
re-queued at the tail, behind any follow-up typed while its POST was out,
and the drain could send that follow-up first. A direct send only goes out
with nothing queued ahead of it, so it now goes back to the head.
@vercel

vercel Bot commented Oct 7, 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 7, 2026 9:04am 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 7, 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

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes message queue ordering when a direct send fails.

The PR appears safe to merge.

What we checked:

  • Older messages keep their place: A direct send starts only with an empty queue. It marks the chat as sending before waiting, so follow-ups join the queue behind it.
  • Browser mocks reset between tests: The app uses the shared Vitest configuration, which restores spies and globals before each test.

Summary

Failed direct sends now return to the front of the chat queue, ahead of follow-ups written while their POST was pending.

  • Adds regression coverage for offline failures, online network failures, and busy refusals.
  • Keeps the existing request identity, retry flags, and retry timing.
  • No actionable issues found.
Diagram
sequenceDiagram
    participant User
    participant Chat
    participant Server
    participant Queue
    User->>Chat: Send A with an empty queue
    Chat->>Server: POST A
    User->>Chat: Send B while POST A is pending
    Chat->>Queue: Append B
    Server-->>Chat: A fails or is refused
    Chat->>Queue: Insert A at the front
    Note over Queue: Queue order is A, then B
Loading

Reviews (1) · Last reviewed commit: "fix(mothership): keep a failed direct se..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 96014bd into staging Oct 7, 2026
33 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/mothership-requeue-failed-send-first branch October 7, 2026 16:32

This branch was previously deployed

1 inactive deployment
Preview — 1f2e2d92 Deployed Oct 7, 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