Skip to content

fix(discord): retry stale preview cleanup after final delivery - #104893

Merged
steipete merged 7 commits into
openclaw:mainfrom
arcabotai:cad/fix-discord-preview-cleanup-retry
Jul 13, 2026
Merged

steipete merged 7 commits into
openclaw:mainfrom
arcabotai:cad/fix-discord-preview-cleanup-retry

Conversation

@arcabotai

@arcabotai arcabotai commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Closes #104865

What Problem This Solves

Discord partial streaming can leave a stale preview beside the fresh final reply when preview deletion fails transiently. The old lifecycle released the only retry target before awaiting Discord's DELETE.

Why This Change Was Made

The shared finalizable-draft lifecycle now owns failed deletion targets until a later clear succeeds. Cleanup is serialized, replacement IDs survive an in-flight clear, and post-DELETE bookkeeping failures are not mistaken for remote deletion failures.

Discord keeps one bounded teardown retry after successful fresh-final delivery. Mattermost now uses the same lifecycle-owned clear path. Finalized-in-place previews remain untouched.

User Impact

A transient Discord preview cleanup failure receives one recovery attempt during normal teardown. The final reply is still sent exactly once. No timer, configuration, background queue, or extra final-message send was added.

Evidence

  • Prepared head: 574cc1ea367cc3c24fd81334833988cfc4dd86c3.
  • Rebase patch identity: pre/post-rebase stable patch ID 1a9061321745a1d8468932d252b515c5a968d4ac.
  • Blacksmith Testbox tbx_01kxcr0r94tc3rrmzk1g3j7rxg (run): 169/169 focused tests passed across shared draft controls, Discord draft/process handling, and Mattermost draft handling.
  • Targeted oxfmt --check and git diff --check passed.
  • Fresh autoreview completed with no accepted/actionable finding after the shared lifecycle refactor.
  • Exact-head CI: run 29241946883 on 574cc1ea367cc3c24fd81334833988cfc4dd86c3.
  • Live Discord fault injection: Crabbox run run_4627a4bad139 forced the first preview DELETE to HTTP 500, observed exactly one real final reply, forwarded one teardown retry to Discord, then observed preview GET 404 and final GET 200.
  • The live run exercised the unchanged Discord HTTP sequence on ancestor 5582df93dfe17ac4ec3d8c39dc3d9a857a9f5bf5. Later maintainer commits strengthened shared ownership and concurrency semantics; focused tests cover failed-target retention, overlapping clears, replacement IDs, successful-DELETE callback failures, bounded Discord retry, and finalized-in-place preservation.
  • Source-blind behavior validation passed all three exercised clauses. The finalized-in-place branch was not repeated live; focused tests cover it.

The live artifact omits credentials, broker data, guild/channel/application/message IDs, endpoints, and message content. The first 500 is controlled fault injection because a transient Discord 5xx cannot be requested deterministically; the retry and both postconditions are live Discord API results.

AI Assistance

AI-assisted by Cad from Arca. Maintainer review, refactor, focused proof, source-blind validation, and exact-head landing checks were completed independently.

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 13, 2026, 12:03 AM ET / 04:03 UTC.

Summary
The PR adds failure-target retention and compare-and-clear behavior to the shared finalizable draft lifecycle, retries Discord preview cleanup once after fresh final delivery, updates Mattermost to use the shared lifecycle clear path, and expands concurrency and regression coverage.

PR surface: Source +34, Tests +171. Total +205 across 5 files.

Reproducibility: yes. The issue and PR provide a deterministic current-main failing path where the first preview DELETE rejects and the stored ID is unavailable to a second clear, plus live Discord confirmation of the user-visible stale-preview outcome.

Review metrics: 1 noteworthy metric.

  • Plugin SDK lifecycle additions: 1 failure callback and 1 lifecycle clear variant added. These additions refine a public channel-outbound cleanup contract used by bundled and potentially external channel plugins.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104865
Summary: This PR is the active candidate fix for the canonical Discord stale-preview issue; the competing implementation was closed as a duplicate, while the earlier fresh-final PR is adjacent provenance rather than remaining canonical work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦐 gold shrimp
Patch quality: 🦞 diamond lobster
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Rerun the redacted live Discord failed-first-DELETE scenario on current head db2d6db0 and update the PR body with the resulting transcript or diagnostic manifest.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The linked redacted live Discord run convincingly proves the behavior on 5582df93, but current head db2d6db0 materially refactors ownership and concurrency after that run; rerun the same scenario and redact IDs, tokens, endpoints, and message content before posting. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The exact-head live proof is stale: it validates 5582df93, while current head db2d6db0 changes the cleanup ownership mechanism and concurrency behavior.
  • [P1] External channel plugins using the exported finalizable-draft lifecycle may observe a failed DELETE being retried by a later clear call; that compatibility-sensitive behavior is intentional but needs current-head proof.

Maintainer options:

  1. Prove the refined lifecycle on current head (recommended)
    Rerun the live Discord first-DELETE-500 scenario on db2d6db0 and merge only if it shows one final send, one bounded retry, preview 404, and final 200.
  2. Accept proof inheritance manually
    A channel SDK owner may explicitly accept that the later commits are semantics-preserving refinements and merge with the earlier live proof plus current focused tests.

Next step before merge

  • [P1] No code defect remains to automate; the merge blocker is renewed exact-head live proof and normal owner acceptance of the Plugin SDK compatibility change.

Security
Cleared: The patch changes bounded channel cleanup state and tests without dependencies, secrets, workflow permissions, downloads, publishing metadata, or new code-execution sources.

Review details

Best possible solution:

Keep the refined stateful lifecycle design, preserve standalone claim-before-delete semantics, and rerun the redacted failed-first-DELETE Discord scenario on current head before merge.

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

Yes. The issue and PR provide a deterministic current-main failing path where the first preview DELETE rejects and the stored ID is unavailable to a second clear, plus live Discord confirmation of the user-visible stale-preview outcome.

Is this the best way to solve the issue?

Yes. The current head is the narrowest maintainable fix because it keeps retry policy at existing lifecycle boundaries, claims targets before asynchronous deletion to prevent duplicate clears, and preserves replacement IDs rather than adding timers, queues, configuration, or extra final sends.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1aff6da8274c.

Label changes

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The linked redacted live Discord run convincingly proves the behavior on 5582df93, but current head db2d6db0 materially refactors ownership and concurrency after that run; rerun the same scenario and redact IDs, tokens, endpoints, and message content before posting. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: The PR fixes a moderate, bounded Discord partial-streaming regression that can leave duplicated stale preview content after a transient DELETE failure.
  • merge-risk: 🚨 compatibility: The PR changes retry behavior on an exported Plugin SDK draft-lifecycle surface, so external channel callers may observe different repeated-clear behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The linked redacted live Discord run convincingly proves the behavior on 5582df93, but current head db2d6db0 materially refactors ownership and concurrency after that run; rerun the same scenario and redact IDs, tokens, endpoints, and message content before posting. Updating the PR body should trigger review, or a maintainer can request @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +34, Tests +171. Total +205 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 70 36 +34
Tests 2 176 5 +171
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 246 41 +205

What I checked:

Likely related people:

  • steipete: Authored the current-head commits that reshaped failed-target retention, callback separation, and standalone claim semantics across the shared lifecycle and channel callers. (role: recent area contributor and branch refactor author; confidence: high; commits: 1a2b509daf6d, adede03b704d, 368bae5f6fef; files: src/channels/draft-stream-controls.ts, src/channels/draft-stream-controls.test.ts, extensions/discord/src/monitor/message-handler.draft-preview.ts)
  • davelutztx: Authored the merged change that switched Discord partial streaming to fresh final messages followed by preview cleanup, which is the lifecycle this regression repairs. (role: introduced adjacent Discord final-delivery behavior; confidence: high; commits: 8aaf9fc6bc5c; files: extensions/discord/src/monitor/message-handler.process.ts, extensions/discord/src/monitor/message-handler.draft-preview.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (5 earlier review cycles)
  • reviewed 2026-07-12T02:48:10.225Z sha c526c0c :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-12T03:01:49.396Z sha 5582df9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-12T03:21:40.666Z sha 5582df9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-12T03:30:00.511Z sha 5582df9 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-12T03:37:51.506Z sha 5582df9 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 12, 2026
@Solvely-Colin

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

The PR body now includes redacted live Discord proof on exact head 5582df93dfe17ac4ec3d8c39dc3d9a857a9f5bf5:

  • controlled first preview DELETE returned HTTP 500;
  • preview ownership was retained;
  • exactly one real final reply was created;
  • teardown made one real Discord DELETE retry;
  • live postconditions were preview GET 404 and final GET 200.

Run: https://crabbox.openclaw.ai/portal/runs/run_4627a4bad139

@clawsweeper

clawsweeper Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@Solvely-Colin

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

The PR body now contains the complete accessible redacted diagnostic manifest, including the controlled first DELETE 500, retained ownership, one final reply, one teardown retry, and preview 404/final 200 postconditions.

CI attribution is also complete: the three remaining terminal-session shard failures reproduce on current main, and the unrelated exact-head CLI shard rerun is green: https://github.com/openclaw/openclaw/actions/runs/29177408781/job/86610722846

@Solvely-Colin Solvely-Colin self-assigned this Jul 12, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 12, 2026
@arcabotai

Copy link
Copy Markdown
Contributor Author

Exact-head/current-main CI classification for the remaining session-rotation failures:

  • PR head tested: 5582df93dfe17ac4ec3d8c39dc3d9a857a9f5bf5
  • Current origin/main: b67417909bd1edfeac90fa9cf4a5cc580d3f60a8
  • Focused file: src/gateway/server-methods/agent.test.ts
  • Case: handles a terminal main session from a 'endedAt-only row' when its transcript is newer

Result on the exact PR head:

2 failed (gateway-client + gateway-methods)
AssertionError: expected 'terminal-main-session' not to be 'terminal-main-session'

Result on current main with the same focused case:

2 passed
468 skipped

The relevant intervening commit is 7984973a8cd8341b832ec45360d7d2c893d21e51 / PR #104925 (test(sessions): align terminal freshness fixtures with SQLite). It updates these terminal-freshness fixtures to mock SQLite transcript stats (lastMutationAtMs / lastObservedMutationAtMs) instead of relying on filesystem mtime.

This classifies the observed failure as branch drift in untouched session-test infrastructure, not a Discord preview-cleanup regression. Rebasing the PR onto current main should bring the fixture repair into the branch; no Discord-side change is indicated by this failure.

@steipete steipete assigned steipete and unassigned Solvely-Colin Jul 13, 2026
@openclaw-barnacle openclaw-barnacle Bot added channel: mattermost Channel integration: mattermost size: M and removed size: S labels Jul 13, 2026
@steipete
steipete force-pushed the cad/fix-discord-preview-cleanup-retry branch from 8de9d6d to db2d6db Compare July 13, 2026 03:32
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Jul 13, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 13, 2026
@steipete
steipete force-pushed the cad/fix-discord-preview-cleanup-retry branch from db2d6db to 574cc1e Compare July 13, 2026 10:12
@steipete

Copy link
Copy Markdown
Contributor

Maintainer preparation complete at 574cc1ea367cc3c24fd81334833988cfc4dd86c3.

What changed beyond the original patch:

  • failed preview DELETE targets now remain owned separately from replacement preview IDs;
  • cleanup calls are serialized, so overlapping clears cannot double-delete the same preview;
  • successful DELETE bookkeeping failures no longer cause retries of an already-deleted message;
  • Mattermost uses the same stateful lifecycle; Discord keeps one bounded teardown retry and preserves finalized-in-place previews.

Proof:

  • Blacksmith Testbox tbx_01kxcr0r94tc3rrmzk1g3j7rxg (lease run): 3 Vitest shards, 169/169 focused tests passed across shared controls, Discord draft/process, and Mattermost draft.
  • Targeted oxfmt --check and git diff --check passed.
  • Fresh autoreview completed with no accepted/actionable finding.
  • Rebase identity: the pre/post-rebase stable patch ID is 1a9061321745a1d8468932d252b515c5a968d4ac.
  • Exact-head CI: run 29241946883 completed with 44 successful and 12 skipped jobs, no failures.
  • Live Discord fault injection: Crabbox run run_4627a4bad139 forced the first preview DELETE to 500, delivered exactly one final reply, retried cleanup once, then observed preview GET 404 and final GET 200.
  • The live run exercised the unchanged Discord HTTP sequence on ancestor 5582df93dfe17ac4ec3d8c39dc3d9a857a9f5bf5; the later maintainer commits strengthen shared lifecycle ownership/concurrency and are covered by the 169 focused tests.
  • Source-blind validation passed all three exercised clauses. The finalized-in-place branch was not repeated live; focused tests cover it.

@steipete
steipete merged commit 0e5ed90 into openclaw:main Jul 13, 2026
110 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 14, 2026
…law#104893)

* fix(discord): retry stale preview cleanup

* test(channels): use compatible deferred helper

* test(channels): satisfy deferred lint

* chore: prepare Discord preview cleanup

* fix(channels): retain failed draft cleanup targets

* fix(channels): separate draft cleanup callbacks

* fix(channels): claim standalone draft cleanup ids

---------

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

Labels

channel: discord Channel integration: discord channel: mattermost Channel integration: mattermost merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Discord partial streaming forgets preview after cleanup failure

3 participants