Skip to content

fix(slack): retry app_mention/message flush races on reply-session init conflict (ENG-18283) - #132

Merged
convyusboy merged 4 commits into
boonfrom
ridho/eng-18283-slack-session-init-conflict-retry
Aug 20, 2026
Merged

convyusboy merged 4 commits into
boonfrom
ridho/eng-18283-slack-session-init-conflict-retry

Conversation

@convyusboy

@convyusboy convyusboy commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

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 delivers app_mention and message events 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:863 throws a CAS-conflict error once its own single retry is exhausted). Nothing in extensions/slack classified 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_RE in polling-session.ts, spooled-update retry with backoff). Upstream openclaw fixed the Slack side too, in fbdfd19622 ("Fix Slack retry for session init conflicts", shipped v2026.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's message-handler.ts has 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

  • Adds isReplySessionInitializationConflictError to openclaw/plugin-sdk/error-runtime (backed by src/infra/errors.ts) as a single shared classifier for this specific, known-transient race, and migrates Telegram's polling-session.ts onto it — removing a second, independently-drifting copy of the same regex/traversal (previously duplicated verbatim between the two plugins).
  • Slack's debounce flush now retries native (non-relay) entries up to 3 times with a 1s delay when this error is classified as retryable, and releases all buffered entries' seen-message keys so the retry can rebuild the batch cleanly.
  • Relay-owned dispatches (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

  • Busy Slack channels where app_mention and message events 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.
  • No behavior change for relay-delivered messages, non-retryable failures, or any other Slack ingress path.

Evidence

  • Root cause + fork-gap analysis: ENG-18283
  • pnpm test extensions/slack — 107 files / 1371 tests passed
  • pnpm test extensions/telegram/src/polling-session.test.ts — 65 tests passed
  • pnpm test src/infra/errors.test.ts — 25 tests passed (new)
  • pnpm tsgo:core and pnpm tsgo:extensions — clean
  • node scripts/run-oxlint.mjs on all touched files — clean
  • Fresh /code-review pass — 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.

  • Adds isReplySessionInitializationConflictError in src/infra/errors.ts, re-exported via openclaw/plugin-sdk/error-runtime; migrates extensions/telegram/src/polling-session.ts off 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).
  • Tests updated for Slack retry behavior (no rejection on scheduled retry, max attempts), app_mention marker preservation, relay exclusion, and the new classifier; fixes a test type annotation; wraps retry tests with fake timers to prevent timer leaks and removes Linear ticket refs per repo policy.
  • Bumps scripts/plugin-sdk-surface-report.mjs budgets for the new public export.
  • Linear: ENG-18283.

Written for commit d941f6b. Summary will update on new commits.

Review in cubic

…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

claude Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Claude encountered an error —— View job


I'll analyze this and get back to you.

@cubic-dev-ai cubic-dev-ai 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.

cubic analysis

All reported issues were addressed across 7 files

Linked issue analysis

Linked issue: ENG-18283: Slack gateway missing upstream session-init-conflict retry fix (fbdfd19622, v2026.7.1) — causes false watchdog alerts / dropped app_mention replies

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).

@cubic-dev-ai cubic-dev-ai 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.

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).

@gandalfboon gandalfboon 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.

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 appMentionDispatchedKeys for app_mention entries — a losing message entry'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 passes markMessageSeen again. Delivery-state isn't recorded on retryable errors, so hasSlackInboundMessageDelivery also stays clear for the re-entry. Combined effect matches the intent.
  • retryScheduled suppresses the rethrow into onError when 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 isReplySessionInitializationConflictError matches wrapped errors and plain strings; tests cover both.
  • Retry counter: initial undefined → 1 → 2 → 3, then >= 3 short-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.

@convyusboy
convyusboy merged commit e3155e3 into boon Aug 20, 2026
147 of 152 checks passed
@convyusboy
convyusboy deleted the ridho/eng-18283-slack-session-init-conflict-retry branch August 20, 2026 07:49
convyusboy added a commit that referenced this pull request Aug 21, 2026
Cut a fork release containing the inbound-attachment-failure-visibility
fix from #139, the Slack reply-session-init-conflict retry from #132, and
the browser login handoff tool from #137.

Bump the gateway and published fork plugins in lockstep.
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