Skip to content

fix(cored): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease#23147

Merged
ibetitsmike merged 1 commit into
mainfrom
fix/flake-interrupt-autopromote-later-usage-limit
Mar 17, 2026
Merged

fix(cored): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease#23147
ibetitsmike merged 1 commit into
mainfrom
fix/flake-interrupt-autopromote-later-usage-limit

Conversation

@ibetitsmike

Copy link
Copy Markdown
Collaborator

Fixes coder/internal#1406

Root cause

The second SendMessage("later queued") was called after waiting for the interrupted channel. By that point, the auto-promoted "queued" message's processChat could complete (request #2 returns instantly via OpenAIStreamingResponse), leaving the chat in Waiting status with an empty queue. shouldQueueUserMessage(Waiting) returns false and len(existingQueued) == 0, so the message was inserted directly instead of queued — Queued: false.

Fix

Move SendMessage("later queued") to immediately after SendMessage("queued"), before waiting for the interrupt. At that point, "queued" is guaranteed to still be in chat_queued_messages (the auto-promotion requires multiple goroutine switches and DB transactions that cannot complete between two consecutive synchronous calls). The len(existingQueued) > 0 condition reliably triggers queueing regardless of chat status.

Passes 25/25 with -count=25.

…tIncrease

Send "later queued" immediately after "queued" while the first
message is still in chat_queued_messages. The existing backlog
(len(existingQueued) > 0) guarantees queueing regardless of chat
status, avoiding a race where the auto-promoted "queued" message
finishes processing before the second SendMessage is called.
@ibetitsmike ibetitsmike changed the title fix(chatd): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease fix(chatd): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease by Mar 17, 2026
@ibetitsmike ibetitsmike changed the title fix(chatd): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease by fix(agents): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease Mar 17, 2026
@ibetitsmike ibetitsmike requested a review from johnstcn March 17, 2026 07:57
@ibetitsmike ibetitsmike enabled auto-merge (squash) March 17, 2026 07:57
@ibetitsmike ibetitsmike changed the title fix(agents): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease fix(cored/chatd): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease Mar 17, 2026
@ibetitsmike ibetitsmike changed the title fix(cored/chatd): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease fix(cored): fix flaky TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease Mar 17, 2026
@ibetitsmike ibetitsmike merged commit 5d0eb77 into main Mar 17, 2026
36 of 42 checks passed
@ibetitsmike ibetitsmike deleted the fix/flake-interrupt-autopromote-later-usage-limit branch March 17, 2026 08:08
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flake: TestInterruptAutoPromotionIgnoresLaterUsageLimitIncrease

2 participants