Repository navigation
fix(worker): mark bot sends dropped by the quota gate as failed - #1719
Merged
Merged
Conversation
When the owner's bot message quota is reached, the chat worker dropped the
send silently. A public comment reply was already written to the inbox and
its comment-automation event recorded as `sent`, so both kept looking
delivered while nothing reached the channel.
The gate now records the skipped send: an existing message gets a
`sendError` ("Bot message limit reached") plus a realtime `messageFailed`,
and the comment-automation event (public reply or anchored flow DM) is
settled `failed`. The job is still dropped without a retry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A customer on the Free plan (bot messages 1,702 / 1,000) reported Instagram comment automations that "sent" but never arrived: the reply sat in the Inbox with no error and the automation log showed
sent.When the owner's bot message quota is reached, the chat worker's gate (
apps/worker/src/chat/worker.ts) logged and returned. But a public comment reply is written to the Inbox before it is enqueued, and its comment-automation event is recordedsentoptimistically, to be flipped only by a send failure. The gate never produced one, so both kept looking delivered.Fix
New
recordQuotaSkippedSend(apps/worker/src/chat/handlers/record-quota-skipped-send.ts), called by the gate before it drops the job:sendChannelMessage: the message already exists, so it getssendError = "Bot message limit reached"and a realtimemessageFailed(silent for bulk broadcast, like the normal failure path), and its comment-automation event is settledfailed.sendFlowMessagewith a comment-automation anchor: no message exists yet, so only the automation event is settledfailed. Aspentanchor (the first DM already went out) is left alone.The job is still dropped with no retry, and the helper never throws.
message:failedis deliberately not emitted: an over-quota workspace can drop thousands of sends and would flood the workspace Error Log.Out of scope: plain-text private-reply DMs go straight to the Send API and bypass this gate entirely; that is a follow-up PR.
Tests
apps/worker/__tests__/record-quota-skipped-send.test.ts(new)apps/worker/__tests__/chat-worker-quota-gate.test.ts: the gate records skipped sends and records nothing below the quotapnpm lint,pnpm --filter worker check-typesand both test files pass.🤖 Generated with Claude Code