Repository navigation
fix(slack): retry app_mention/message flush races on reply-session init conflict (ENG-18283) - #132
Conversation
…it conflict (ENG-18283) Slack delivers app_mention and message events for the same underlying message separately; when they miss each other's debounce window they can flush independently and race on session init, throwing the CAS-conflict error from src/auto-reply/reply/session.ts. Nothing classified that error as retryable in production, so it surfaced as a hard watchdog alert (and potentially a dropped reply) instead of retrying like Telegram already does for the identical race. Extracts isReplySessionInitializationConflictError into openclaw/plugin-sdk/error-runtime as a shared classifier, migrates Telegram's polling-session.ts onto it, and adds native (non-relay) auto-retry with a bounded attempt count to Slack's debounce flush.
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
cubic analysis
All reported issues were addressed across 7 files
Linked issue analysis
| Status | Acceptance criteria | Notes |
|---|---|---|
| ✅ | Slack recognizes reply-session initialization conflicts as retryable inbound failures. | The PR adds a shared classifier for the known conflict message, including wrapped errors, and uses it in Slack. |
| ✅ | Native Slack debounce flushes retry the conflict instead of hard-failing, with bounded delayed retries. | Native entries are re-enqueued after a 1-second delay, with a maximum of three retry attempts; tests cover successful retry and exhaustion. |
| ✅ | Retrying a failed flush releases seen-message keys so the batch can be rebuilt and dispatched. | The failure path releases seen keys for every buffered entry before scheduling the retry. |
| ✅ | The fix prevents the known app_mention/message race from producing dropped replies or watchdog hard failures. | The Slack flush path now retries the identified session-init race, and focused Slack tests verify the retry behavior. |
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
… marker, suppress watchdog alert on scheduled retry cubic review on PR #132 flagged two real issues in the session-init-conflict retry: - The retryable-failure cleanup cleared appMentionDispatchedKeys for every entry in a failed batch, including "message" entries. That can erase a different, already-succeeded app_mention's winner marker and let the scheduled retry dispatch a duplicate reply. Only an app_mention entry may now clear its own marker. - retryEntries() successfully scheduling a retry still rethrew, so the debounce onError log (and the watchdog alert this PR exists to remove) fired on every attempt even when a later retry recovered. The flush now only rethrows when no retry was scheduled; relay-owned completions are rejected either way. Also bumps the plugin SDK surface budgets in scripts/plugin-sdk-surface-report.mjs to match the new isReplySessionInitializationConflictError export (verified against a clean origin/boon baseline via a temp worktree: 2 more public exports, 2 more callable exports, 1 more deprecated export via the pre-existing infra-runtime compat shim's wildcard re-export).
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
…ENG-18283 test Fixes check-test-types failure on PR #132 — the untyped Promise inferred as Promise<unknown>, mismatching dispatchPreparedSlackMessageMock's Promise<void> return type.
- Drop dangling real setTimeout in the app_mention-race regression test by wrapping the retry-triggering assertions in vi.useFakeTimers/useRealTimers, so the internal retry timer can no longer leak into a later test's mock call counts (cubic P2). - Remove Linear ticket references from test titles/comments per repo policy (cubic P3 x2, plus two more instances cubic did not flag).
There was a problem hiding this comment.
Approved.
Scope matches the ticket: broadens the retryable-inbound classifier to include the reply-session-init CAS conflict (via a shared isReplySessionInitializationConflictError in src/infra/errors, re-exported through plugin-sdk), migrates Telegram off its duplicate regex, and adds bounded internal retry (1s delay, 3 attempts) for native Slack debounce flushes.
Correctness checks I looked at:
- Relay-owned dispatches (
awaitDispatch/dispatchCompletion) are explicitly filtered out of the internal retry list, so router redelivery still owns those cases and cannot race with an internal retry. Completions are still rejected on the retryable error either way (verified by the new relay-exclusion test). - The retryable-error cleanup now correctly only clears
appMentionDispatchedKeysforapp_mentionentries — a losingmessageentry's cleanup can no longer wipe a different, already-succeeded app_mention's winner marker for the same ts. The new preservation test covers exactly that race. - Seen-message keys are released for every buffered entry (not just
last) before the retry re-enters ingress, so the rebuilt batch passesmarkMessageSeenagain. Delivery-state isn't recorded on retryable errors, sohasSlackInboundMessageDeliveryalso stays clear for the re-entry. Combined effect matches the intent. retryScheduledsuppresses the rethrow intoonErrorwhen the retry will own recovery, which removes the false watchdog alert — the exact regression this PR exists to fix. The unrelated case where no retry gets scheduled (max attempts exhausted, or all entries relay-owned) still rethrows.- Cause-graph traversal in
isReplySessionInitializationConflictErrormatches wrapped errors and plain strings; tests cover both. - Retry counter: initial undefined → 1 → 2 → 3, then
>= 3short-circuits — 1 initial + 3 retries = 4 total dispatch attempts, which lines up with the max-attempts test.
Cubic's AC table shows all four criteria satisfied and all its P2/P3 findings addressed. Tests are focused (retry success, exhaustion, marker preservation, relay exclusion, classifier) and use fake timers to avoid leaking scheduled retries into later tests. CI green across the relevant shards.
Nothing blocking. Ship it.
What Problem This Solves
Guido's Slack watchdog fired on
slack inbound debounce flush failed: reply session initialization conflicted for agent:main:slack:channel:c0b3...(https://boon-technologies-inc.slack.com/archives/C0B8WQ4B91N/p1787058990332899). Slack deliversapp_mentionandmessageevents for the same underlying Slack message separately; when they miss each other's debounce window they flush independently and race on session init (src/auto-reply/reply/session.ts:863throws a CAS-conflict error once its own single retry is exhausted). Nothing inextensions/slackclassified that error as retryable, so it surfaced as a hard failure/watchdog alert instead of retrying — the losing side of the race could drop its reply.Telegram already handles this identical race (
REPLY_SESSION_INIT_CONFLICT_MESSAGE_REinpolling-session.ts, spooled-update retry with backoff). Upstreamopenclawfixed the Slack side too, infbdfd19622("Fix Slack retry for session init conflicts", shippedv2026.7.1), but this fork's last upstream merge (v2026.6.11) landed two days before that fix, so it was never pulled in. A raw cherry-pick doesn't apply cleanly — boon'smessage-handler.tshas since diverged (thread-ts resolution, top-level debounce pending-key tracking, persisted delivery-state dedup) — so this reimplements the same behavior against the current file shape instead.Why This Change Was Made
isReplySessionInitializationConflictErrortoopenclaw/plugin-sdk/error-runtime(backed bysrc/infra/errors.ts) as a single shared classifier for this specific, known-transient race, and migrates Telegram'spolling-session.tsonto it — removing a second, independently-drifting copy of the same regex/traversal (previously duplicated verbatim between the two plugins).awaitDispatch/dispatchCompletion) are explicitly excluded from the new internal retry — the router already owns redelivery for those, and retrying in both places could race and duplicate a reply.User Impact
app_mentionandmessageevents for one message arrive far enough apart to escape debounce coalescing will no longer hard-fail (and potentially drop a reply) on this race — Slack now retries it the same way Telegram already does.Evidence
pnpm test extensions/slack— 107 files / 1371 tests passedpnpm test extensions/telegram/src/polling-session.test.ts— 65 tests passedpnpm test src/infra/errors.test.ts— 25 tests passed (new)pnpm tsgo:coreandpnpm tsgo:extensions— cleannode scripts/run-oxlint.mjson all touched files — clean/code-reviewpass — one actionable finding (duplicated regex/traversal between Slack and Telegram) applied via the shared helper above; remaining findings (backoff-curve shape mismatch vs. Telegram, closure-per-flush allocation, minor two-step await, pre-existing nested try/catch) judged out of scope for this focused fix and not applied.Summary by cubic
Retries Slack debounce flushes on reply-session init conflicts to prevent false watchdog alerts and dropped replies. Previously these conflicts hard-failed; now native Slack messages auto-retry up to 3 times with a 1s delay, and Telegram uses the same shared classifier.
isReplySessionInitializationConflictErrorinsrc/infra/errors.ts, re-exported viaopenclaw/plugin-sdk/error-runtime; migratesextensions/telegram/src/polling-session.tsoff its duplicate regex.extensions/slack/src/monitor/message-handler.ts: auto-retries retryable flush failures for non-relay messages, releases seen-message keys for all entries so the batch can rebuild, preserves the app_mention winner marker (only app_mention may clear its own marker), excludes relay-owned dispatches (awaitDispatch) from internal retry, and does not rethrow when a retry is scheduled (suppresses the debounce onError alert).scripts/plugin-sdk-surface-report.mjsbudgets for the new public export.Written for commit d941f6b. Summary will update on new commits.