Repository navigation
Conversation
…ady queued completeConversationWork returns "pending" when conversation status is "awaiting_resume", which causes processConversationWork to enqueue an extra wake nudge. scheduleAgentContinue already enqueues its own wake (requestConversationWork + queue.send + markConversationWorkEnqueued), so the extra nudge is a duplicate. When continuations repeatedly fail and reschedule, these duplicates amplify into a runaway queue loop. Fix: skip the extra nudge when markConversationWorkEnqueued recorded an accepted wake during the current lease (lastEnqueuedAtMs !== undefined). Preserve the recovery nudge when queue.send may have failed before markConversationWorkEnqueued ran (lastEnqueuedAtMs === undefined). Fixes the loop observed Jun 29-30 2026 where conversation slack:C0B595QDZLL:1782764912.916989 generated ~2M requests over 29h. Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
force-pushed
the
fix/conversation-work-double-enqueue
branch
from
July 1, 2026 00:16
54b70e1 to
11bef7e
Compare
…orded Use runnable && !hasQueuedWake instead of hasPending || (needsRun && !hasQueuedWake). Any accepted conversation wake is conversation-level and can process both pending mailbox messages and continuation resumes, so the hasPending exception is unnecessary and creates a remaining amplification path when hasPending is true alongside needsRun and a recorded wake. Add adversarial test: pending mailbox + continuation + recorded wake all coexist at completion time — asserts no extra nudge is sent. Co-Authored-By: Claude Sonnet 4.5 <[email protected]> Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
Member
Author
|
Closing in favor of merging the fix directly. The structural refactor is tracked in #705. |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
completeConversationWorkreturns"pending"wheneverexecution.status === "awaiting_resume", which causesprocessConversationWorkto enqueue an extra wake nudge. The problem:scheduleAgentContinuealready enqueues its own wake (viarequestConversationWork→queue.send→markConversationWorkEnqueued), making the extra nudge a duplicate. Because the queue idempotency key includesnowMs, it is never deduplicated.When continuations repeatedly fail and reschedule (e.g. the continuation lock is consistently busy), each cycle adds one more message. This caused a 29-hour runaway loop on Jun 29–30 2026 where conversation
slack:C0B595QDZLL:1782764912.916989generated ~2M/api/internal/agent/continuerequests at ~22 req/sec.How
In
completeConversationWork, checklastEnqueuedAtMsbefore returning"pending":lastEnqueuedAtMs !== undefined→ an accepted wake was recorded during this lease viamarkConversationWorkEnqueued. Skip the extra nudge (return "completed"), but still setstatus: "pending"in durable state so the already-queued message finds work when it arrives. Accepted wakes are conversation-level and can handle both pending mailbox messages and continuation resumes.lastEnqueuedAtMs === undefined→queue.sendmay have failed beforemarkConversationWorkEnqueuedran. Send a recovery nudge as before.The fix uses
runnable && !hasQueuedWake(stronger thanhasPending || (needsRun && !hasQueuedWake)) so that any accepted wake suppresses the extra nudge regardless of whether pending mailbox messages also exist at completion time. TreatinghasPendingas an unconditional nudge reason would leave a remaining amplification path when all three conditions coexist.The key invariant:
startConversationWorkclearslastEnqueuedAtMswhen acquiring a lease, so any non-undefinedvalue seen incompleteConversationWorkwas set during the current worker's run.All
scheduleAgentContinuecall sites areawait-ed; no fire-and-forget race.Tests
Three new cases in
conversation-work.test.ts:scheduleAgentContinuesequence (requestConversationWork+markConversationWorkEnqueued): asserts result is"completed", no extra queue message sent, durable status is"pending",lastEnqueuedAtMspreserved.queue.sendfailure (onlyrequestConversationWork, nomarkConversationWorkEnqueued): asserts result is"pending_requeued", recovery nudge sent.hasPending=true,needsRun=true,hasQueuedWake=true.The existing
"requeues work requested while a lease is running"test continues to pass unchanged (callsrequestConversationWorkwithoutmarkConversationWorkEnqueued, recovery path fires).What this does NOT fix
The underlying cause of why a specific continuation keeps failing indefinitely (e.g. permanent lock contention, tool errors on every retry). A separate circuit-breaker (max
sliceIdfor timeout continuations) is worth considering as a follow-up operational guardrail, but is intentionally left out of this PR to keep the scope narrow.