Skip to content

fix(worker): mark bot sends dropped by the quota gate as failed - #1719

Merged
sung17 merged 1 commit into
mainfrom
fix/bot-quota-skip-mark-failed
Nov 14, 2026
Merged

sung17 merged 1 commit into
mainfrom
fix/bot-quota-skip-mark-failed

Conversation

@sung17

@sung17 sung17 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

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 recorded sent optimistically, 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 gets sendError = "Bot message limit reached" and a realtime messageFailed (silent for bulk broadcast, like the normal failure path), and its comment-automation event is settled failed.
  • sendFlowMessage with a comment-automation anchor: no message exists yet, so only the automation event is settled failed. A spent anchor (the first DM already went out) is left alone.
  • Other bot sends create their message inside the handler, so there is nothing to mark.

The job is still dropped with no retry, and the helper never throws. message:failed is 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 quota

pnpm lint, pnpm --filter worker check-types and both test files pass.

🤖 Generated with Claude Code

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>
@github-actions github-actions Bot added the bug Something isn't working as expected label Nov 14, 2026
@sung17
sung17 merged commit 0e31879 into main Nov 14, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant