Skip to content

fix(discord): avoid blocking presence event handling - #149576

Merged
steipete merged 1 commit into
mainfrom
codex/discord-async-storage-callers
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/discord-async-storage-callers

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Presence updates can stall Discord event handling while cooldown state is read or written synchronously.

User Impact

Presence cooldown persistence runs off the Gateway event loop, while greetings still wait for a durable claim and stale work cannot publish after a policy change, session replacement, or shutdown. Existing cooldown data, eight-hour expiry, and capacity rules stay compatible without migration.

Thread-binding persistence retains its shipped synchronous completion contract. On older hosts without conditional deletion, a failed greeting leaves its cooldown to expire instead of risking deletion of a newer reservation.

Why This Change Was Made

Use the existing asynchronous keyed-store owner for cooldown reads, claims, and atomic conditional rollback. Recheck policy and Gateway generation after storage waits, and join active work during provider cleanup, including work detached by reconnect resets and cleanup following a message-handler failure.

Evidence

  • All 58 focused cases passed across presence handling, provider startup/cleanup, and the canonical SQLite fork lane. Real SQLite proof covers reopen, duplicate claim refusal, expiry metadata, and conditional rollback.
  • The new delayed-claim regression fails against the original listener because it queues a greeting before the claim settles.
  • The complete changed-file gate passed for the runtime, tests, and docs; the added canonical fork-inventory entry passed syntax, formatting, and diff checks.
  • Fresh independent review found no actionable P0–P2 findings.
  • pnpm build passed, including SDK export verification and the UI build.

Validation uses synthetic Discord events and isolated SQLite state; no live channel sends were performed.

@clawsweeper

clawsweeper Bot commented Sep 16, 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: discord Channel integration: discord plugin: file-transfer size: M maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 01:44
@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 Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 15, 2026, 9:49 PM ET / September 16, 2026, 01:49 UTC.

ClawSweeper review

What this changes

Moves Discord greeting cooldown storage off the Gateway event loop and drains pending presence work during shutdown while preserving existing cooldown data and rules.

Merge readiness

✅ Ready for maintainer review

The change remains useful: current main and the latest release still perform synchronous cooldown storage. No blocking introduced defect was found, and this maintainer-authored PR is protected from automatic closure.

Priority: P2
Reviewed head: 78f1d6d60bd2b6b7ffe52c2e5c2749cb2f640c66

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair using the established storage owner, with meaningful race coverage and no blocking defect found.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-author exemption applies to this internal storage scheduling repair. Captured evidence covers synthetic listener races and real isolated SQLite operations, not live Discord delivery or measured event-loop latency.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-author exemption applies to this internal storage scheduling repair. Captured evidence covers synthetic listener races and real isolated SQLite operations, not live Discord delivery or measured event-loop latency.
Evidence reviewed 7 items Current main still needs the change: The fetched main revision opens the presence cooldown namespace through openSyncKeyedStore, so the proposed asynchronous conversion is not already implemented there.
Latest release comparison: The same synchronous opener is present in v2026.9.4; this release does not contain the requested conversion.
Durable claim and publication fencing: The introduced listener awaits lookup and atomic claim, rechecks current policy and Gateway generation after each storage wait, and conditionally rolls back an unused claim. Shutdown stops admission and joins active runs, including runs detached from reconnect queues.
Findings None None.
Security None None.

How this fits together

Discord presence updates feed a listener that checks greeting policy, channel visibility, and cooldowns before waking an agent. The shared SQLite worker now handles cooldown operations while the listener retains ordering and publication control.

flowchart TD
  A[Discord presence updates] --> B[Presence listener]
  B --> C[Policy and channel visibility]
  C --> D[SQLite worker cooldown claim]
  D --> E[Recheck policy and session]
  E --> F[Queue greeting and wake agent]
  G[Provider shutdown] --> B
  G --> H[Drain pending work and rollback]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +43, Tests +203, Docs +7. Total +253 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 5 57 14 +43
Tests 5 221 18 +203
Docs 2 9 2 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 287 34 +253

Review metrics

Metric Value Why it matters
Production and regression coverage production net +43 lines; tests net +202 lines Production growth supports asynchronous lifecycle tracking and publication checks, with regression coverage for the resulting races.

Technical review

Best possible solution:

Use the existing asynchronous storage owner while retaining durable-before-greeting ordering, current-policy checks, conditional rollback, and joined shutdown.

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

Yes, at source level: configured presence greetings on current main perform synchronous SQLite operations inside event handling. Runtime stall duration was not measured in this read-only review.

Is this the best way to solve the issue?

Yes. The patch adopts the existing worker-backed API and preserves its storage contract, while addressing the ordering and cleanup obligations introduced by awaiting persistence.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This addresses event-loop blocking in optional Discord presence greetings without evidence of an urgent widespread outage.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-author exemption applies to this internal storage scheduling repair. Captured evidence covers synthetic listener races and real isolated SQLite operations, not live Discord delivery or measured event-loop latency.

Label justifications:

  • P2: This addresses event-loop blocking in optional Discord presence greetings without evidence of an urgent widespread outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-author exemption applies to this internal storage scheduling repair. Captured evidence covers synthetic listener races and real isolated SQLite operations, not live Discord delivery or measured event-loop latency.

Evidence

What I checked:

  • Current main still needs the change: The fetched main revision opens the presence cooldown namespace through openSyncKeyedStore, so the proposed asynchronous conversion is not already implemented there. (extensions/discord/src/monitor/presence-cooldown-store.ts:9, fc1cadae3286)
  • Latest release comparison: The same synchronous opener is present in v2026.9.4; this release does not contain the requested conversion. (extensions/discord/src/monitor/presence-cooldown-store.ts:9, 3a9d69db306c)
  • Durable claim and publication fencing: The introduced listener awaits lookup and atomic claim, rechecks current policy and Gateway generation after each storage wait, and conditionally rolls back an unused claim. Shutdown stops admission and joins active runs, including runs detached from reconnect queues. (extensions/discord/src/monitor/listeners.ts:447, 78f1d6d60bd2)
  • Existing storage owner and compatibility: The existing asynchronous keyed-store facade dispatches lookup, registerIfAbsent, and deleteIfEqual to the shared worker. The PR preserves the namespace, numeric payload, eight-hour expiry, capacity, and reject-new policy; it adds no schema or public SDK method. (src/plugin-state/plugin-state-store.ts:281, 78f1d6d60bd2)
  • Focused regression evidence: Inspected tests cover policy replacement during lookup and claim, shutdown waiting for detached rollback, preservation of replacement cooldowns, SQLite reopen, duplicate claims, expiry metadata, and conditional deletion. The captured PR body reports 58 focused cases and a successful build, explicitly using synthetic Discord events without live sends; these runs were not repeated during this read-only review. (extensions/discord/src/monitor/listeners.presence.test.ts:269, 78f1d6d60bd2)
  • Prior area history: Current-main history identifies Peter Steinberger's prior work on live Discord access policy and presence audience restrictions. This supports routing relevance, not attribution of the original defect. (extensions/discord/src/monitor/listeners.ts, 1ebb4c09323d)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete
steipete merged commit 1c6aca2 into main Sep 16, 2026
214 checks passed
@steipete
steipete deleted the codex/discord-async-storage-callers branch September 16, 2026 02:23
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord docs Improvements or additions to documentation maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. plugin: file-transfer rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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