Skip to content

fix(worker): fold a backlog of group texts into a few turns - #66

Merged
NatanTechofNY merged 3 commits into
mainfrom
fix/group-backlog-folding
Oct 13, 2026
Merged

NatanTechofNY merged 3 commits into
mainfrom
fix/group-backlog-folding

Conversation

@NatanTechofNY

Copy link
Copy Markdown
Owner

Why

Goopers messages sent at 10:35 PM were processed at ~10:57 PM. Sendblue was not slow: webhooks are received and queued in milliseconds (date_sent to receipt ≈ 0 s). The worker was the bottleneck: arrivals were 10–18/min, each processed text cost a ~9 s completion (even ones ending in stay_quiet), ~6–7/min drained.

Root cause

Group texts that arrive in a burst are folded into the next queued text's turn, bounded by MAX_BURST_MS (15 s). For the first text of a burst the age fell back to the event's arrival time, so as soon as the queue was a few seconds deep every text looked too old to fold. Folding switched off exactly when it was needed, every text got its own turn, and the backlog fed itself.

Fix

  • burstState() replaces burstStartedAt(): age is measured from when the worker began filing the burst, plus a 40-message cap so a deep backlog is answered in a few turns.
  • Test: 45 backdated group texts produce 2 turns (was 45). Fails on the old code.
  • docs/SMS_AND_EVENTS.md updated.

Made with Cursor

A burst's age was measured from when its first text arrived, so once the
queue was a few seconds deep every text was past the 15 s bound, folding
switched off, and each text cost a full completion. A busy group out-ran
the worker and answers came 20 minutes late. Measure from when the worker
began filing the burst and cap it at 40 messages.

Co-authored-by: Cursor <cursoragent@cursor.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T03:07:11.188410Z 266af9f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 266af9fa5d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/worker.ts
NatanTechofNY and others added 2 commits October 12, 2026 23:12
…arrival

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@NatanTechofNY
NatanTechofNY merged commit 0900837 into main Oct 13, 2026
2 checks passed
@NatanTechofNY
NatanTechofNY deleted the fix/group-backlog-folding branch October 13, 2026 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant