Skip to content

fix(discord): remove late previews after transient delete failures - #130392

Merged
steipete merged 3 commits into
mainfrom
codex/qa-discord-stale-draft-cleanup-20260826
Aug 26, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/qa-discord-stale-draft-cleanup-20260826

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130391
Related: #102341, #130006

What Problem This Solves

Fixes an issue where Discord progress previews remain visible after a transient deletion failure during final cleanup. This is particularly visible when a preview POST acknowledgement arrives late while another native message is already being processed: the later final reply arrives, but the old working message remains.

Why This Change Was Made

Discord had two failed-deletion owners. Normal clear() retained failures inside the generic draft lifecycle, while retracted, retargeted, and stale previews used a Discord-owned queue. The controller's final cleanup drained only the latter queue, so a failure during its last normal clear had no subsequent owner to retry it.

Use the existing shared stream-controls API and route normal clear through Discord's existing current-message deletion owner. One private queue now retains the exact channel/message pair for every failed preview deletion, and the existing final cleanup drains it. Rename the private retarget-only cleanup name to describe its actual responsibility. This removes the duplicate retention path without adding timers, a retry layer, transport fallbacks, configuration, authorization, persistence, or SDK changes.

Production LOC: +23/-29 (net -6). Tests: +125/-18 (net +107); test-support changes are a neutral private-method rename.

User Impact

A late working preview disappears when its first deletion fails transiently and the existing final cleanup succeeds. Later final replies remain intact. Error finals still retain their diagnostic progress preview; block preservation, generation fencing, and thread-retarget channel ownership are unchanged.

Evidence

  • Reviewed candidate: 0c19911ac223162bedb72073ec6185979886988f. An ordinary merge incorporates the separately landed upstream CI repair fix(tests): restore sticky model fixture typecheck #130441. All six Discord file blobs and the complete PR diff remain identical to the reviewed repair; 112 focused tests, strict scoped types, typed lint, and a fresh full Codex review passed again after integration. Exact-head CI passed: 30 successful jobs, 21 scope-skipped jobs, no failures.
  • Corrected premise: the first revision covered a controller-local queued-generation scenario. Native ingress did not establish that assumed same-controller route. Real Gateway testing instead exposed the normal-clear ownership defect above across distinct inbound controllers; this revision repairs that observed path and does not claim native core queued-generation proof.
  • Before this refactor, the native Gateway run at bf2639362d83a5d7ad37641eaa8fadf9b44755ea retained the old preview after DELETE 503 even though the later final was delivered. That normal-clear path was unchanged from frozen main a868258156a6708dd798deb3d43d3a4277a4d511. The matching REST-boundary regression failed in two teardown cases before the production edit.
  • After the refactor, 112 focused tests across six files passed. Independent verification passed 88 overlapping tests across four files. Coverage includes successful and failed late-create teardown, bounded persistent failure and later recovery, overlapping clears, replacement identity, error-final retention, thread retargeting, and block preservation.
  • The refreshed candidate's private-QA runtime build passed in 49.5 seconds after the merge commit; both runtime stamps identify 0c19911ac223162bedb72073ec6185979886988f. Native Discord Gateway WebSocket ingress, a mock provider, and a stateful REST fault fixture reproduced the original ordering: held preview POST, second native inbound message, late POST acknowledgement, DELETE 503, DELETE 204, and later final delivery. Fresh visible state contained only the final reply. The separate native provider-error case retained both progress preview and error final without deletion. These reruns used fresh temporary state, not an operator database or a migration.
  • Fresh source-blind validation on the refreshed candidate passed all six clauses across two fault runs with different nonces, a no-fault run, and a provider-error run. Independent readback after 10.497 seconds preserved all three successful finals and both error-receipt messages. An unknown-endpoint check left state unchanged. The temporary runtime was stopped after the final state capture.
  • Fresh authenticated Codex review of the complete final diff and full owner/caller/lifecycle datasets through P2 found no actionable findings. Review and strict typechecking caught test-only mock-return and deferred-helper typing issues; both were corrected using existing contracts. The final 24 focused tests and strict scoped TypeScript project passed without relaxing compiler options.
  • Final six-file typed lint, strict scoped TypeScript, formatting, and diff checks passed. Before the main refresh, the broad local changed-file gate passed all 17 pre-typecheck phases, then stopped only on missing unrelated IMAP dependencies (mailparser, mailauth, imapflow) and their consequent type errors. No dependency manifests or assertions were weakened. The refreshed candidate's hosted typecheck, lint, extension, and required gates all passed in the exact-head CI run above.
  • CI recovery: the first pushed rewrite encountered two upstream sticky-model test type errors introduced on main by feat(models): add configurable model selection scopes #127813. The independent test-only repair fix(tests): restore sticky model fixture typecheck #130441 was landed first, then merged normally into this branch without changing the Discord patch. ClawSweeper's separate partial live-verification flag was an expected-terminal-text mismatch: its captured logs show all six REST tests passing twice. The refreshed focused tests and native scenarios above provide direct behavior evidence; its remaining rank-up request is satisfied by the successful exact-head CI linked above.

Mock-Gateway verdict (real native ingress; not a live Discord SaaS session):

{
  "passed": true,
  "transport": "Discord Gateway WebSocket + stateful REST fixture",
  "provider": "mock-openai",
  "latePreview": {
    "nativeInboundMessages": 2,
    "deleteStatuses": [503, 204],
    "oldPreviewVisibleAfterCleanup": false,
    "laterFinalRetained": true
  },
  "providerError": {
    "progressPreviewRetained": true,
    "errorFinalRetained": true,
    "deletes": 0
  }
}

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added channel: discord Channel integration: discord size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 20:38
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 5:40 PM ET / 21:40 UTC.

ClawSweeper review

What this changes

The PR routes failed Discord progress-preview deletes through one Discord-owned cleanup queue so final cleanup can retry transient failures.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this maintainer-owned PR open. Current main still separates normal-clear failure custody from the controller’s retarget-only drain; this branch unifies that custody and has no blocking correctness findings, pending exact-head CI.

Priority: P2
Reviewed head: 7e346d56c77c6a57c58a3e881946cf2689a0a164

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused owner-boundary coverage and after-fix fault evidence support the repair; exact-head CI remains the final merge gate.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body provides an after-fix mock-Gateway verdict using native Discord ingress and a stateful REST fault fixture, which covers the changed channel-visible path.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides an after-fix mock-Gateway verdict using native Discord ingress and a stateful REST fault fixture, which covers the changed channel-visible path.
Evidence reviewed 6 items Current-main failure path: Current main clears the active draft and then drains only retargeted cleanup, so a failed generic lifecycle clear is not retried by this controller cleanup.
Separate owner on current main: Current main uses the generic finalizable lifecycle for clear(), whose failed deletes remain in its private pending-delete list rather than Discord's retarget queue.
Canonical repair boundary: The branch replaces the generic lifecycle with stream controls and makes both current and detached preview deletion failures enter cleanupPendingMessages before the controller drains it.
Findings None None.
Security None None.

Live Verification

Command: pnpm test extensions/discord/src/monitor/message-handler.draft-preview.rest.test.ts

Result: FAIL (partial) — step 2 expect_output removes a late preview after teardown: expected terminal output was not visible within 30 seconds: "removes a late preview after teardown"

$ node --import tsx scripts/test-projects.mts extensions/discord/src/monitor/message-handler.draft-preview.rest.test.ts
[test] starting test/vitest/vitest.extension-discord.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130392-6Bs3qh/target

 ✓  extension-discord  extensions/discord/src/monitor/message-handler.draft-preview.rest.test.ts (6 tests) 64ms

 Test Files  1 passed (1)
      Tests  6 passed (6)
   Start at  21:41:34
   Duration  25.44s (transform 20.97s, setup 941ms, import 24.08s, tests 64ms, environment 0ms)

[test] passed 1 Vitest shard in 31.97s
$ node --import tsx scripts/test-projects.mts extensions/discord/src/monitor/message-handler.draft-preview.rest.test.ts
[test] starting test/vitest/vitest.extension-discord.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130392-6Bs3qh/target

 ✓  extension-discord  extensions/discord/src/monitor/message-handler.draft-preview.rest.test.ts (6 tests) 61ms

 Test Files  1 passed (1)
      Tests  6 passed (6)
   Start at  21:42:07
   Duration  10.94s (transform 6.64s, setup 434ms, import 10.20s, tests 61ms, environment 0ms)

[test] passed 1 Vitest shard in 17.32s

Assertions:

  • FAIL expect_output: removes a late preview after teardown

How this fits together

Discord progress streaming creates temporary preview messages through Discord REST while inbound message processing later delivers a final reply. The preview controller performs turn cleanup, and the draft stream owns deletion and retry custody for those previews.

flowchart LR
  A[Discord inbound message] --> B[Progress preview stream]
  B --> C[Discord REST create or delete]
  C --> D[Failed deletion queue]
  D --> E[Final reply cleanup]
  E --> F[Preview removed or diagnostic retained]
Loading

Before merge

  • Resolve merge risk (P1) - Required checks for the exact head are still in progress; merge only after they complete successfully.
Agent review details

Security

None.

PR surface

Source -6, Tests +107. Total +101 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 24 30 -6
Tests 3 125 18 +107
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 149 48 +101

Review metrics

Metric Value Why it matters
Production vs test LOC production +23/-29 (net -6); tests +125/-18 (net +107) The bug fix removes duplicate production lifecycle ownership while adding focused late-create and transient-delete regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #130391
Summary: This PR is the candidate repair for the linked late-preview cleanup bug.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the single Discord-owned deletion-custody flow after exact-head CI confirms the focused lifecycle and extension gates.
  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 single Discord-owned deletion-custody flow after exact-head CI confirms the focused lifecycle and extension gates.

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

Yes, at source level: the focused RequestClient lifecycle test holds the preview POST, injects transient DELETE failures, and checks eventual removal; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: placing current-preview and detached-preview delete failures under the same Discord stream owner removes the duplicate retention boundary rather than adding a retry layer or controller-side workaround.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides an after-fix mock-Gateway verdict using native Discord ingress and a stateful REST fault fixture, which covers the changed channel-visible path.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: This fixes a bounded Discord progress-preview cleanup failure without evidence of broader message-delivery loss.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides an after-fix mock-Gateway verdict using native Discord ingress and a stateful REST fault fixture, which covers the changed channel-visible path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides an after-fix mock-Gateway verdict using native Discord ingress and a stateful REST fault fixture, which covers the changed channel-visible path.

Evidence

What I checked:

Likely related people:

  • steipete: Authored this branch and the earlier merged Discord failed-preview-cleanup repair that owns the adjacent stream lifecycle. (role: recent lifecycle owner; confidence: high; commits: 771d5e5393dd, 7e346d56c77c; files: extensions/discord/src/draft-stream.ts, extensions/discord/src/monitor/message-handler.draft-preview.ts)

Rank-up moves

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

  • Wait for the required checks on 7e346d5 to pass.

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 (1 earlier review cycle)
  • reviewed 2026-08-26T20:45:48.579Z sha bf26393 :: needs maintainer review before merge. :: none

@steipete steipete changed the title fix(discord): clean up late progress previews after queued turns fix(discord): remove late previews after transient delete failures Aug 26, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The rewritten head 7e346d56c77c6a57c58a3e881946cf2689a0a164 consolidates preview deletion under one existing cleanup owner. Native Discord Gateway testing corrected the original same-controller premise: the observed failure crossed distinct inbound controllers and left normal-clear failures in a separate queue. The native fault scenario now shows DELETE 503 followed by 204, while a separate provider-error scenario preserves both diagnostic messages. Fresh source-blind validation passed all six clauses; details and scope are in the updated PR body. Exact-head CI is still pending and remains required before landing.

@clawsweeper

clawsweeper Bot commented Aug 26, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 26, 2026
@steipete
steipete merged commit d27b0e9 into main Aug 26, 2026
100 checks passed
@steipete
steipete deleted the codex/qa-discord-stale-draft-cleanup-20260826 branch August 26, 2026 22:32
@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 maintainer Maintainer-authored PR 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: S 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.

Bug: Discord keeps progress previews after transient cleanup failure

1 participant