Skip to content

fix(auto-reply): reject redeliveries without recreating drained queues - #124723

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-followup-queue-leak
Aug 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-followup-queue-leak

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

enqueueFollowupRun called getFollowupQueue() — which inserts a new FollowupQueueState into the process-global FOLLOWUP_QUEUES registry — before the recent-message-id dedupe peek. A provider redelivery (Discord/Signal redelivering the same message id within the 5-minute dedupe TTL) arriving after the original queue had drained and self-deleted would recreate the registry entry, get rejected by the peek, and leave an empty FollowupQueueState (AbortController, item arrays, WeakSets) in the global map forever: registry entries are only deleted when a drain finishes with no pending work, and a queue that never receives an item never drains. Long-lived gateways leaked one state object per redelivered session key.

Why This Change Was Made

Root cause: mutation-before-validation ordering. The dedupe key derivation (buildRecentMessageIdKey) only needs the run and the queue key, not the queue object, so the peek now runs first and the registry entry is created only for work that passes redelivery dedupe. One reorder, no new state or branches.

User Impact

No more unbounded registry growth from provider redeliveries on long-lived gateways. No behavior change for admitted messages.

Evidence

  • New regression in src/auto-reply/reply/queue.dedupe.test.ts: drains a queue to registry self-deletion, replays the same message id, asserts rejection and that no registry entry reappears — fails pre-fix (entry recreated), passes post-fix.
  • node scripts/run-vitest.mjs run src/auto-reply/reply/queue — 8 files, 32 tests pass; dedupe suite 15/15.
  • tsgo core + core-test shards, oxfmt, oxlint clean.
  • Codex autoreview: clean, 0.99 ("patch is correct").
  • LOC: prod +4 −1 (reorder + invariant comment), test +42.

enqueueFollowupRun called getFollowupQueue (which inserts into the
process-global FOLLOWUP_QUEUES registry) before the recent-message-id
dedupe peek. A provider redelivery arriving after the original queue
drained and self-deleted recreated the registry entry, was rejected by
the peek, and left an empty FollowupQueueState (AbortController, arrays,
WeakSets) in the map forever — registry entries are only deleted when a
drain finishes, and a queue with no items never drains. Long-lived
gateways leaked one state object per redelivered session key.

Root cause: mutation-before-validation ordering. The dedupe key
derivation does not need the queue, so the peek now runs first and the
registry entry is only created for admitted work.

Regression: new dedupe test drains a queue to self-deletion, replays the
message, and asserts no registry entry reappears — fails pre-fix.
@clawsweeper

clawsweeper Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 16, 2026
@steipete
steipete marked this pull request as ready for review August 16, 2026 18:00
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 16, 2026
@steipete
steipete merged commit 98805b8 into main Aug 16, 2026
280 checks passed
@steipete
steipete deleted the codex/autoqa-followup-queue-leak branch August 16, 2026 18:15
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 17, 2026
openclaw#124723)

enqueueFollowupRun called getFollowupQueue (which inserts into the
process-global FOLLOWUP_QUEUES registry) before the recent-message-id
dedupe peek. A provider redelivery arriving after the original queue
drained and self-deleted recreated the registry entry, was rejected by
the peek, and left an empty FollowupQueueState (AbortController, arrays,
WeakSets) in the map forever — registry entries are only deleted when a
drain finishes, and a queue with no items never drains. Long-lived
gateways leaked one state object per redelivered session key.

Root cause: mutation-before-validation ordering. The dedupe key
derivation does not need the queue, so the peek now runs first and the
registry entry is only created for admitted work.

Regression: new dedupe test drains a queue to self-deletion, replays the
message, and asserts no registry entry reappears — fails pre-fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant