Skip to content

fix(slack): avoid shutdown stalls during Socket Mode retries - #188745

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-shutdown-metadata-retirement-20260919
Oct 30, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-shutdown-metadata-retirement-20260919

Conversation

@steipete

@steipete steipete commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway shutdown spending the full metadata-retirement grace period and reporting retained plugin resources when a Slack Socket Mode startup is stopped while retrying its connection URL.

User Impact

Slack account stop and reload can finish releasing plugin custody instead of leaving an old monitor pending. No configuration or migration is required.

Why This Change Was Made

The SDK clears its reconnect timer on disconnect, but OpenClaw's patched scheduler left the promise behind that timer unresolved. Startup awaited that promise, so the channel monitor never reached its custody-release finally block. Settle the pending retry on the SDK's existing disconnect event, and settle retries admitted after stop immediately. Preserve the SDK distinction between fire-and-forget native restarts and awaited URL retrieval; remove the listener when the timer runs normally.

The fix stays in the Slack owner and preserves core retirement checks. Runtime production delta is +11 lines, needed for promise settlement and listener cleanup. The regression delta is +38 lines: the installed SDK is exercised with stop before and after retry admission, and the existing native-restart test now checks settlement. A separate test-line allocation records that growth. The rerunnable synthetic benchmark adds 148 tooling lines.

Evidence

  • Both new real-SDK cases fail on the base because startup remains pending. All 26 focused tests pass across provider.interop.test.ts, provider.reconnect-loop.test.ts, and provider.ingress-start-cleanup.test.ts. The original local invocation took 198.90 s; the integrated candidate also passed all 26 tests in 214.41 s (mostly worker compilation). Exact-head CI ran for a 7m54s job span: 31 jobs succeeded, 27 skipped, and the test-line ratchet plus its aggregate gate failed (run 41140725084, attempt 1).
  • pnpm check:changed: passed before the conflict-only integration (including extension/test/script typechecks, lint, exports, and repository-policy guards). The integration drops a redundant per-script Knip entry now covered by main’s existing performance-script glob; runtime and test changes are identical.
  • Independent Codex autoreview of the complete final candidate against 528b92792ed041366e037d084041369f93d244a7: scoped-clean through P2, no accepted/actionable findings. Simplification pass retains one scheduler owner and no new caches or retirement fallback.

The committed probe runs 44 real plugin instances and one real Slack SDK monitor with synthetic API responses through channel custody and cache retirement. Five serial A/B pairs on source base 77869fe2570c with Node 26.12.1, after A/A controls:

Owner measurement Base Fix
Stop + retirement median 5007.588 ms 9.282 ms
Stop + retirement p95 (maximum, n=5) 5029.424 ms 46.861 ms
Retirement-only median 5005.548 ms 8.816 ms
Process CPU median 33.664 ms 24.161 ms
Retained consumers after grace 1 in all runs 0 in all runs

A/A total timings were 5005.832/5004.519 ms before and 7.567/7.644 ms after. Separate sampled allocations were 2,641,112/2,568,288 bytes. CPU ranges overlap and the host was busy; no CPU or allocation reduction claim. The reliable result is elimination of the five-second wait and retained consumer. Separately, the updated generation owner on main 528b92792ed0 with Node 24.22.1 reproduces the failure at 5033.036 ms; the integrated fix retires cleanly at 7.688 ms with zero consumers. This single pair verifies integration and is not mixed into the earlier distribution.

Reproduce with node --expose-gc --import ./scripts/tsx.mjs scripts/perf/slack-shutdown-retirement-measure.ts; add --allocations separately. Timing excludes imports/setup. This owner does no database or workspace I/O, so this is lifecycle proof, not whole-Gateway state-scale performance. The synthetic failure matches the retained-resource signature, but does not establish the exact await point in an earlier production incident.

CI's tested merge f12e8da20f926dcf74a40ee7e4c291904ff8e21d used main base b39e2d09329cc81b09cf55980a2506623236ea59. Its only test-line delta is +38 LF lines with an equal +38 allocation. The ratchet reports 6,314,087 lines against 6,313,062 credit, an inherited 1,025-line overage. An exact Git-blob census of the CI base finds 6,314,049 test LF lines against 6,313,024 credit: the same 1,025-line debt before this PR. The checker and shared scalar are unchanged, and the PR’s +38 test/+38 allocation pair preserves that debt exactly. The scheduled-main comparison labeled this job new because its older main job passed; this exact-base attribution is stronger than that job-name comparison. The shared baseline remains unchanged. CI is recorded as failed, not green.

@clawsweeper

clawsweeper Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: slack Channel integration: slack scripts Repository scripts size: M labels Oct 30, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 30, 2026
@clawsweeper

clawsweeper Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR settles cancelled Slack Socket Mode retries so stopped account monitors can release their plugin resources.

Example: apps.connections.open returns internal_error and the account stops during its 15-second retry delay.

  • Before: The timer is cancelled, but startup stays pending and retains one plugin consumer.
  • After: The retry settles, startup exits, and the monitor releases its consumer.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair appears correct and worthwhile; recorded proof reaches the production owners through an in-process harness.
Proof confidence 🦐 gold shrimp (3/6) The maintainer-authored PR is outside the ordinary contributor proof gate; its recorded synthetic benchmark exercises the real Slack SDK startup, channel custody, and plugin retirement, reporting zero retained consumers after cancellation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Stopping or reloading Slack during a connection URL retry can leave its monitor pending and delay resource cleanup.
Reason: This restores expected stop completion with a narrow owner-local repair; the maintainer-authored direction is already approved.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this PR fixes a concrete pending-startup leak that remains on main, with no introduced correctness defect found; the draft has confirmed merge conflicts.

Priority: P2
Reviewed head: 6722358afa06bf2090e8e396651bbbc59cfc29b4

Before merge

  • Complete next step - Resolve GitHub-reported merge conflicts on this PR branch.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied measurement exercises SDK startup and real custody retirement in process, rather than stop or reload through a running shipped Gateway.
Agent review details

How this fits together

The Slack monitor awaits Bolt startup while Gateway custody retains its plugin instance; SDK retry cancellation must settle that startup before retirement can finish.

flowchart TD
  A[Account stop] --> B[Slack monitor]
  B --> C[Bolt Socket Mode client]
  C --> D[Retry timer and promise]
  D --> E[Startup settles]
  E --> F[Gateway releases plugin custody]
  F --> G[Plugin retirement completes]
Loading

Technical review

Best possible solution:

Keep cancellation settlement in the existing Slack retry scheduler while preserving SDK timer ownership and Gateway custody checks.

Do we have a high-confidence way to reproduce the issue?

Yes: the pinned SDK clears the pending retry timer on disconnect while current main awaits a promise settled only by that timer; the PR also records red-on-base SDK regressions.

Is this the best way to solve the issue?

The patch repairs the unresolved promise at its existing owner, preserves native reconnect behavior, and needs no additional state, fallback, or retirement exception.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d107cb81b327.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +11, Tests +38, Docs +17, Other +151. Total +217 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 15 4 +11
Tests 1 39 1 +38
Docs 2 17 0 +17
Config 0 0 0 0
Generated 0 0 0 0
Other 3 151 0 +151
Total 7 222 5 +217

Review metrics

Metric Value Why it matters
Runtime versus regression growth Runtime +11 net lines; tests +38 net lines The growth supplies cancellation settlement and distinct stop-before/after-admission regressions without adding another lifecycle owner.

Labels

Label changes:

  • add P2: Stopping a retrying Slack account can retain plugin custody and delay shutdown or reload; the trigger is limited to connection retry cancellation.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Stopping a retrying Slack account can retain plugin custody and delay shutdown or reload; the trigger is limited to connection retry cancellation.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 30, 2026, 6:12 PM ET / 22:12 UTC.

@steipete
steipete force-pushed the steipete/perf-micro-shutdown-metadata-retirement-20260919 branch from 6722358 to 50a652d Compare October 30, 2026 22:49
@steipete
steipete marked this pull request as ready for review October 30, 2026 22:50
@chatgpt-codex-connector

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

Copy link
Copy Markdown
Contributor

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-30T22:52:06.821352Z 50a652d Draft marked ready
ℹ️ 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.

@steipete
steipete merged commit a1d1da7 into main Oct 30, 2026
199 of 205 checks passed
@steipete
steipete deleted the steipete/perf-micro-shutdown-metadata-retirement-20260919 branch October 30, 2026 23:17
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
RomneyDa added a commit that referenced this pull request Nov 17, 2026
Release adaptation: backport only the Socket Mode reconnect waiter owner
and focused regression tests; omit the performance harness and main-only
transport documentation addition. Add listener-count assertions for timer
settlement and disconnect cancellation; adjust the test allocation to 41.

Companion dispositions: #198007 is specific to SDK 3.2 callback/abort
semantics and is not applicable to this line pinned to socket-mode 3.1.0.
#197657 retires main allocations; other audit hits (#200523, #197009,
#194964, #184507, #192197, #192051, #190003, #189850) only overlap the
excluded shared perf README. No later #188745 mention through bd692e9.

(cherry picked from commit a1d1da7)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: slack Channel integration: slack docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant