Skip to content

fix(discord): preserve component waiter message ownership - #117492

Merged
steipete merged 1 commit into
openclaw:mainfrom
IWhatsskill:fix/discord-component-waiter-owner
Aug 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
IWhatsskill:fix/discord-component-waiter-owner

Conversation

@IWhatsskill

Copy link
Copy Markdown
Contributor

[AI-assisted]

What Problem This Solves

When Discord starts a second component wait for the same message and channel, the component registry intentionally replaces the first waiter. The displaced promise currently receives the second call's Message object instead of the Message instance that originally created that wait.

Failure mode

The replacement branch resolves the stored waiter with its timeout-shaped result, but closes over the new method argument for the message field. That crosses ownership between two distinct callers even though the registry already stores the original Message beside the resolver and timer.

Why This Change Was Made

Resolve a replaced waiter with the Message instance stored in its own registry entry. The newly registered waiter remains active and continues to resolve through the normal component interaction path.

Root Cause

The replacement path used the incoming message parameter rather than existing.message from the waiter being displaced.

Layer ownership

replyAndWaitForComponent supplies the caller-owned Message, ComponentRegistry owns waiter identity and replacement, and interaction dispatch owns later resolution. The fix stays in the registry owner layer without changing Discord transport, interaction payloads, component parsing, or presentation.

User Impact

Each caller now receives the same Message instance that created its wait, including when a later wait replaces it. The replaced waiter still ends with success: false and reason: timed out, while the replacement waiter still resolves normally from a component interaction.

Evidence

At exact head ba23fcf7dd412a4e67603a19c4304cdfd35b8d78, 36 focused and adjacent Discord tests passed, Extension source and test typechecks passed, scoped formatting/lint checks were clean, and a real registry run preserved both distinct Message owners across replacement and normal resolution.

Inspect exact-head proof ledger

Provenance

  • Base: b83a966c056288adaef187e3e5826188d9f67724
  • Proof head: ba23fcf7dd412a4e67603a19c4304cdfd35b8d78
  • Revalidated: on the bound base

Direct behavior

Discord component waiter ownership command

node --import tsx --input-type=module -
  • Discord component waiter ownership (PRODUCTION_RUNTIME; boundary: node --import tsx --input-type=module - running the production Discord ComponentRegistry, one-off waiter map, Message class, and resolution path) — Observed: Two real production Message instances shared the same registry key; replacing the first wait returned its original Message by identity, kept the second Message distinct, and the production resolver then completed the second wait with its own Message and selected value. Result: the displaced waiter retained its first Message owner and the active waiter retained and resolved with its second Message owner. Proves registry replacement no longer crosses Message ownership between callers. Preserves timeout-shaped replacement settlement and normal component interaction resolution.

Sanitized exact-head production output

head=ba23fcf7dd412a4e67603a19c4304cdfd35b8d78
test_runner=none
owners=all-real
mocks=none
distinct_messages=true
first_owner_preserved=true
second_owner_preserved=true
first_status=timed-out
second_status=resolved
resolve_returned=true
values=one
result=PASS

Automated verification

Discord registry and owner chain

pnpm exec vitest run extensions/discord/src/internal/client.test.ts extensions/discord/src/internal/interaction-dispatch.test.ts extensions/discord/src/internal/interactions.test.ts --reporter=dot
  • pnpm exec vitest run extensions/discord/src/internal/client.test.ts extensions/discord/src/internal/interaction-dispatch.test.ts extensions/discord/src/internal/interactions.test.ts --reporter=dot — [TEST] 36/36 tests passed across 3 test files with 0 failures. Proves replacement preserves both caller Message identities and adjacent interaction routing remains compatible. Preserves wildcard and custom-id resolution, interaction dispatch, timer caps, and reply-and-wait behavior.

Extension source type boundary

pnpm tsgo:extensions
  • pnpm tsgo:extensions — [TYPECHECK] completed with exit code 0. Proves the registry source change satisfies the Extension TypeScript contract. Preserves the existing component result and Message API surface.

Extension test type boundary

pnpm tsgo:extensions:test
  • pnpm tsgo:extensions:test — [TYPECHECK] completed with exit code 0. Proves the identity regression test satisfies the Extension test TypeScript contract. Preserves the existing Vitest typing boundary.

Static verification

pnpm exec oxlint extensions/discord/src/internal/component-registry.ts extensions/discord/src/internal/client.test.ts
  • pnpm exec oxlint extensions/discord/src/internal/component-registry.ts extensions/discord/src/internal/client.test.ts — [LINT] reported 0 warnings and 0 errors. Proves the changed source and regression test satisfy scoped lint rules. Preserves the repository lint boundary.
pnpm exec oxfmt --check extensions/discord/src/internal/component-registry.ts extensions/discord/src/internal/client.test.ts
  • pnpm exec oxfmt --check extensions/discord/src/internal/component-registry.ts extensions/discord/src/internal/client.test.ts — [STATIC] reported both files correctly formatted. Proves the changed files match repository formatting. Preserves the bounded two-file diff.
git diff --check origin/main...HEAD
  • git diff --check origin/main...HEAD — [STATIC] completed with exit code 0 and no output. Proves the exact-head patch is whitespace-clean. Preserves the bounded two-file diff.

Preserved boundaries

  • A replaced waiter still settles with success: false and reason: timed out; only its Message owner is corrected.
  • The replacement waiter remains registered and resolves through the existing interaction path with custom ID and values unchanged.
  • One-off key construction, timeout scheduling, wildcard component parsing, and ordinary component registration are unchanged.
  • No Discord API, authentication, permission, configuration, persistence, protocol, visual, or localization contract changes.

Proof gap

Focused registry and adjacent owner-chain tests, both Extension typechecks, scoped static checks, and a real exact-head ComponentRegistry plus Message proof were run. A credentialed live Discord interaction, the full repository test suite, and GitHub CI were not run locally; no live Discord API, repository-wide, or CI result is claimed.

Artifacts

  • None attached.

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: XS labels Aug 1, 2026
@IWhatsskill
IWhatsskill marked this pull request as ready for review August 1, 2026 16:06
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 4:53 PM ET / 20:53 UTC.

ClawSweeper review

What this changes

The PR makes Discord component-wait replacement return the displaced caller’s original Message object and adds a regression test for two waits sharing one message-and-channel key.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this PR open for normal maintainer merge review. Current main still returns the incoming replacement call’s message when it settles the displaced waiter, while this narrow patch restores ownership to the stored waiter and covers both replacement and normal interaction resolution; no actionable patch defect was found.

Priority: P2
Reviewed head: ba23fcf7dd412a4e67603a19c4304cdfd35b8d78

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, correct on the traced owner boundary, and supported by direct runtime proof plus targeted regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides exact-head terminal evidence from the production ComponentRegistry path using distinct real Message instances, showing both displaced-owner preservation and normal active-wait resolution.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides exact-head terminal evidence from the production ComponentRegistry path using distinct real Message instances, showing both displaced-owner preservation and normal active-wait resolution.
Evidence reviewed 6 items Current-main defect: Current main stores each waiter’s message in the registry entry but settles a displaced waiter with the incoming replacement method argument, so two distinct Message instances with the same key cross ownership.
Owner-boundary repair: The PR changes only the replacement settlement to use the stored waiter message, matching the existing normal interaction-resolution path that already returns entry.message.
Caller and resolver trace: replyAndWaitForComponent creates the caller-owned Message before registering the wait, and interaction dispatch resolves the active wait through the registry; the registry is the correct owner for preserving that identity.
Findings None None.
Security None None.

How this fits together

Discord interaction replies create a local Message and register a one-off component wait keyed by message and channel. The component registry either replaces that wait or resolves it from an incoming interaction, then returns the message-bearing result to the original caller.

flowchart LR
  A[Discord interaction reply] --> B[Create caller message]
  B --> C[Component wait registry]
  C --> D{Wait key already exists?}
  D -->|Yes| E[Settle displaced caller]
  D -->|No| F[Store active waiter]
  G[Discord component interaction] --> C
  C --> H[Return result with owner message]
Loading

Before merge

  • Resolve merge risk (P1) - GitHub reports the branch as mergeable but behind current main, and the supplied check state includes failed aggregate/build checks; merge should use a refreshed exact-head required-check result rather than relying on the earlier PR proof alone.
  • Complete next step (P2) - No discrete repair remains for automation; the next action is normal maintainer merge review with current exact-head check gating.
Agent review details

Security

None.

PR surface

Source 0, Tests +38. Total +38 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 38 0 +38
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 39 1 +38

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the registry-owner fix with its identity regression test after refreshing the branch/check state against current main; keep replacement timeout semantics and ordinary interaction resolution unchanged.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the registry-owner fix with its identity regression test after refreshing the branch/check state against current main; keep replacement timeout semantics and ordinary interaction resolution unchanged.

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

Yes. A high-confidence source reproduction creates two distinct Message objects with the same message/channel key, starts the second wait, and observes that current main resolves the first waiter with the second object; the PR regression test encodes that path.

Is this the best way to solve the issue?

Yes. The registry owns both the displaced resolver and its original message, and using the stored message aligns replacement settlement with the existing normal-resolution path without changing Discord transport or public configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 77796591370d.

Labels

Label justifications:

  • P2: This is a confirmed narrow Discord interaction-result ownership bug with limited blast radius and a focused repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides exact-head terminal evidence from the production ComponentRegistry path using distinct real Message instances, showing both displaced-owner preservation and normal active-wait resolution.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head terminal evidence from the production ComponentRegistry path using distinct real Message instances, showing both displaced-owner preservation and normal active-wait resolution.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Introduced component-registry.ts and the replacement behavior during the Discord internal-surface refactor. (role: feature introducer; confidence: high; commits: 3932a6038ca8; files: extensions/discord/src/internal/component-registry.ts)
  • Vincent Koc: Current-main blame attributes the registry wait path to the recent merge that carried this Discord code into the present tree. (role: recent area contributor; confidence: medium; commits: b830a658217a; files: extensions/discord/src/internal/component-registry.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch/check state against current main and merge only when the required checks are green for the exact reviewed head.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-01T16:11:50.691Z sha ba23fcf :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T20:18:36.342Z sha ba23fcf :: needs maintainer review before merge. :: none

@steipete steipete self-assigned this Aug 1, 2026
@steipete
steipete merged commit b2278f3 into openclaw:main Aug 1, 2026
241 of 249 checks passed
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

2 participants