fix(mothership): hang condition ux bug#3852
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview The stop endpoint now calls Written by Cursor Bugbot for commit dddbf53. Configure here. |
Greptile SummaryThis PR fixes a deadlock/hang condition in the Mothership copilot chat: when a stream hangs, stopping it and immediately resending a message would leave the new message stuck in the queue because the per-chat distributed lock (Redis + in-memory promise) was never released until the hung stream's own
Key concern: The lock is released before the DB update in the stop route. If a new stream starts and writes Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Client (useChat)
participant S as Stop API Route
participant L as Lock (Redis + pendingChatStreams)
participant D as Database
participant N as New Stream
Note over C,N: Bug scenario (before fix)
C->>S: POST /stop (streamId=A)
S->>D: UPDATE copilotChats SET conversationId=null WHERE conversationId=A
Note over L: Lock still held by stream A's finally block
C->>N: sendMessage (new message)
N-->>L: acquireLock() → timeout/queue (lock never released!)
Note over C,N: Fixed flow (after this PR)
C->>S: POST /stop (streamId=A)
S->>L: releasePendingChatStream(chatId, A) ← NEW
S->>D: UPDATE copilotChats SET conversationId=null WHERE conversationId=A
C->>N: sendMessage (new message)
N->>L: acquireLock() → acquired immediately ✓
N->>D: INSERT new stream
Note over C: Client-side fix (use-chat.ts)
C-->>C: finalize({ error: true })
C-->>C: pendingRecoveryMessageRef = null ← NEW
C-->>C: setPendingRecoveryMessage(null) ← NEW
C-->>C: setMessageQueue([])
Reviews (1): Last reviewed commit: "fix(mothership): hang condition" | Re-trigger Greptile |
Summary
When stream hangs, even after stop and resend of message -- it queues it. This PR fixes that by releasing lock accurately.
Type of Change
Testing
Tested manually
Checklist