Skip to content

fix(discord): cache unavailable thread starters - #128653

Merged
steipete merged 9 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-128532
Aug 26, 2026
Merged

steipete merged 9 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-128532

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated Discord REST lookups for deleted, inaccessible, or empty thread starters. Previously every inbound message in the same thread retried the unavailable starter, increasing rate-limit pressure and delaying normal message processing.

Fixes #128532.

Why This Change Was Made

The Discord thread-starter owner now caches authoritative successful and unavailable outcomes separately. Successful entries retain the existing five-minute bounded LRU; confirmed missing starters and typed Discord 403/404 responses use a 30-second negative cache. Transient transport errors, server errors, and rate limits remain retryable.

Both cached outcomes and concurrent in-flight lookups are owned by the complete (account ID, thread ID, effective Discord message-channel ID) identity. This prevents one account's permissions from suppressing another account, while ensuring that an unavailable provisional parent-channel route cannot poison a subsequently discovered forum-thread route. Missing parent metadata does not suppress an existing valid parent-channel lookup, and a truly unavailable route is neither cached nor entered into single-flight.

The previous standalone proof script was removed because it imported another plugin across its package boundary and was an unreferenced production-tree file. Its coverage now lives in the existing Discord owner and full message-processing suites instead of weakening architecture or dead-code checks.

User Impact

Busy Discord threads stop repeatedly fetching deleted or inaccessible starter messages. Valid starter text remains visible when optional parent-channel type metadata is absent, and forum threads recover correctly when their effective Discord API route becomes known. Account permissions remain isolated; no operator configuration, authentication, persistence, or public API changes are required.

Evidence

  • Exact reviewed head: 321ff5a34e3df5817f69b941224a6ba6f7ccf317.
  • Original contributor: @sunlit-deng; the existing contributor-owned pull request and all original contributor commits are preserved.
  • Existing and added Discord owner regressions cover account-isolated 403 outcomes, 30-second negative-cache expiry, transient failure recovery, same-route concurrent request coalescing, valid starters without parent-type metadata, and ordered parent-route-to-forum-route recovery.
  • The existing full processDiscordMessage regression again exercises a valid thread starter without requiring optional parent-type metadata.
  • Fresh full-branch source review, a separate immutable read-only reviewer, and two independent owner/security reviews reported no actionable findings.
  • First sandboxed exact-head execution: GitHub Actions CI run 32965828319 completed successfully: all 59 jobs passed or were intentionally skipped, including the Discord owner suites, dependency and plugin-boundary checks, and required openclaw/ci-gate.
  • Contributor-controlled code was intentionally not executed on the maintainer's local machine. The passing GitHub-hosted run is the first and only runtime proof; final landing additionally requires a fresh passing Workflow Sanity check and the repository's standard protected merge gates.

@clawsweeper

clawsweeper Bot commented Aug 24, 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: M labels Aug 24, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 8:02 AM ET / 12:02 UTC.

ClawSweeper review

What this changes

The PR adds account-scoped positive and short-lived negative caching plus concurrent lookup coalescing for Discord thread-starter resolution.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 4 items remain

Keep open. Current main still retries null and failed Discord thread-starter lookups without caching them, and this branch’s owner-boundary repair is coherent; however, the claimed real-behavior proof is for an older head and its referenced harness is absent from the current head.

Priority: P2
Reviewed head: 321ff5a34e3df5817f69b941224a6ba6f7ccf317

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch and regression coverage are solid, but current-head real-behavior evidence is not inspectable.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The supplied Gateway/REST output names an earlier head and a script absent from the current head; add redacted current-head after-fix proof before merge. 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.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The supplied Gateway/REST output names an earlier head and a script absent from the current head; add redacted current-head after-fix proof before merge. 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 7 items Current-main defect: Current main returns null for a missing starter and catches REST failures without writing a cache entry, so repeated inbound messages retry the same lookup.
Branch repair: The branch distinguishes hit and miss cache values, uses a 30-second miss TTL, keys by account and route, and clears the single-flight entry after resolution.
Discord REST error contract: The plugin’s RequestClient turns non-429 non-success responses into DiscordError with the response status, supporting the branch’s narrow 403/404 negative-cache classification.
Findings None None.
Security None None.

Live Verification

Command: pnpm test extensions/discord/src/monitor/threading.starter.test.ts -- --no-file-parallelism

Result: FAIL (failed) — step 1 run pnpm test extensions/discord/src/monitor/threading.starter.test.ts -- --no-file-parallelism: previous terminal command was still running after 30 seconds: "pnpm test extensions/discord/src/monitor/threading.starter.test.ts -- --no-file-parallelism"

$ node --import tsx scripts/test-projects.mts extensions/discord/src/monitor/threading.starter.test.ts -- --no-file-parallelism
[test] starting test/vitest/vitest.extension-discord.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-128653-hLcuCN/target

Assertions:

  • FAIL expect_output: threading.starter.test.ts

How this fits together

Discord inbound thread messages resolve their starter before constructing agent context. The Discord plugin either returns a bounded in-memory cache result or requests the starter through its REST client, then passes starter text or an intentional absence downstream.

flowchart LR
  A[Discord thread message] --> B[Context builder]
  B --> C[Starter resolver]
  C --> D{Cached or in flight?}
  D -->|yes| E[Starter or no starter]
  D -->|no| F[Discord REST client]
  F --> G[Account-scoped cache]
  G --> E
  E --> H[Agent context]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The supplied Gateway/REST output names an earlier head and a script absent from the current head; add redacted current-head after-fix proof before merge. 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.
  • Resolve merge risk (P1) - The current head has no inspectable after-fix production-path proof: its PR-body command names a missing script and an older SHA.
  • Resolve merge risk (P1) - Production code is net +48 lines for a bug repair; the added cache-result state, TTL policy, account key, and in-flight owner appear necessary, but the growth should remain limited to that canonical resolver path.
  • Complete next step (P2) - Await contributor-provided current-head behavior proof; there is no discrete automated repair to dispatch.
Agent review details

Security

None.

PR surface

Source +48, Tests +228. Total +276 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 60 12 +48
Tests 2 241 13 +228
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 301 25 +276

Review metrics

Metric Value Why it matters
Production versus test delta production +60/-12 (net +48); tests +241/-13 (net +228) Production growth implements cache result states, short miss expiry, account scoping, and one canonical in-flight request owner; test growth covers the new behavioral cases.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/discord/src/monitor/threading.starter.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128532
Summary: This PR is the candidate fix for the open Discord thread-starter cache-miss 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
    Keep the resolver-owned cache design and publish redacted current-head Gateway/REST evidence showing stable 403/404 misses are cached while transient failures remain retryable.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the resolver-owned cache design and publish redacted current-head Gateway/REST evidence showing stable 403/404 misses are cached while transient failures remain retryable.

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

Yes, from current source: a null starter or caught REST error returns without a cache write, so the same thread reaches the REST client again on subsequent messages.

Is this the best way to solve the issue?

Yes for the code shape: cache ownership remains in the Discord resolver, account and route scope prevent cross-context reuse, and retryable failures remain uncached; exact-head real behavior proof is still required.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • 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 supplied Gateway/REST output names an earlier head and a script absent from the current head; add redacted current-head after-fix proof before merge. 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: 🐚 platinum hermit: 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 addresses avoidable Discord REST traffic and rate-limit pressure for active affected threads.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The supplied Gateway/REST output names an earlier head and a script absent from the current head; add redacted current-head after-fix proof before merge. 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

What I checked:

Likely related people:

  • steipete: Current-head blame assigns the resolver and cache changes here; recent Discord thread-starter history is also concentrated in this area. (role: recent area contributor; confidence: high; commits: 321ff5a34e3d, 7864980d9e8b; files: extensions/discord/src/monitor/threading.starter.ts, extensions/discord/src/monitor/threading.cache.ts)

Rank-up moves

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

  • Post redacted current-head output from a plugin-owned production RequestClient-to-REST harness; screenshots or logs must omit private endpoints, IDs, and credentials.

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 (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-24T10:44:40.016Z sha 3af871e :: needs real behavior proof before merge. :: [P2] Coalesce in-flight starter lookups
  • reviewed 2026-08-24T11:50:39.396Z sha 191e7d8 :: needs changes before merge. :: [P2] Coalesce concurrent starter lookups
  • reviewed 2026-08-24T13:09:44.462Z sha c9a15ba :: needs maintainer review before merge. :: none
  • reviewed 2026-08-24T13:53:12.061Z sha c9a15ba :: needs changes before merge. :: [P2] Exclude metadata failures from the single-flight map
  • reviewed 2026-08-24T14:35:12.599Z sha 83e25b5 :: found issues before merge. :: [P2] Keep the proof harness behind plugin boundaries
  • reviewed 2026-08-24T15:40:20.844Z sha e562355 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T15:59:00.373Z sha e562355 :: needs changes before merge. :: [P2] Keep unknown parent type out of the miss cache
  • reviewed 2026-08-26T00:58:30.044Z sha 6797ae9 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 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 Aug 24, 2026
@clawsweeper clawsweeper Bot added 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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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 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. 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 Aug 24, 2026
@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: L and removed size: M labels Aug 24, 2026
@clawsweeper clawsweeper Bot added 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. 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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. 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 Aug 24, 2026
@clawsweeper clawsweeper Bot added 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. and removed 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. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 26, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed scripts Repository scripts size: L labels Aug 26, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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. labels Aug 26, 2026
@steipete
steipete merged commit 1e6844b into openclaw:main Aug 26, 2026
119 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

@steipete

Copy link
Copy Markdown
Contributor

Postmerge verification addendum for 1e6844b: the missing connected Gateway/REST proof from the latest completed ClawSweeper review has now been run successfully. This evidence was obtained after merge, not before it.

The actual flow was native Discord MESSAGE_CREATE over WSS → production Gateway and Discord RequestClient → starter REST/cache resolution → mock Responses HTTP/SSE → actual Discord reply POST. Two Crabline accounts and loopback services exercised the existing channels.discord.proxy configuration. No private resolver calls, global-fetch replacement, or production source edits were used. Independent source and final-artifact review confirmed the connected path.

Redacted verdict from the completed run:

{
  "verdict": "PASS",
  "build": "a95d5bc4a164b8539bc57ffd7af44b1f4ee24944",
  "mergedCommit": "1e6844b71aa2299c082d23cf66dce38ff00b2211",
  "modelRequests": 9,
  "deliveredMessages": 9,
  "unknownParentIncludedInProvider": true,
  "accountBStarterIncludedInProvider": true
}
Case Observed production-owner REST result
Unknown parent type Parent-route 200; starter text present in model input
Repeated missing starter Two messages, only one starter GET (404)
Provisional parent becomes forum Parent-route 404, then own-thread route 200
Account isolation, same thread IDs Account A 403; account B 200 and its starter text in model input
Transient failure 503 on the first message, a new GET returning 200 on the next

Every inbound case was correlated to exactly one provider request and one reply to the expected account/thread. Native thread metadata and all eight starter GETs were captured; an empty starter trace fails the proof. Owned processes shut down cleanly and the command exited 0.

Runtime provenance: existing successful CI run 32965828319, dist-runtime-build artifact 9606063917, build job 98168310657. The extracted build identifies synthetic merge a95d5bc4...; its Discord subtree is byte-identical to merged 1e6844b..., and changed owner/test blobs match final reviewed head 321ff5a. Local tar.zst integrity was verified, SHA-256 3bb63f2f39ac6b177203181a007675e8175c2ff1756c4d147de3ac1b5b47c250. No new build was substituted. Verdict SHA-256: e6580bbd6d6ac1b1eed077c46ce569edbcd8791c054fabb60dc41ec6b9ae4575.

Scope: this is a configured-proxy loopback protocol proof, not authenticated external Discord or default direct-network/DNS/SSRF/TLS proof. It does not add a pre-fix runtime baseline, TTL-expiry, LRU, or parallel-singleflight claim. Forum/transient recovery proves REST route/status recovery; established-session context intentionally does not reinject starter text. Earlier harness setup attempts were rejected as proof until the real owner REST path was observed.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
* fix(discord): cache unavailable thread starters

* test(discord): prove thread starter cache over rest api

* test(discord): satisfy proof lint guards

* fix(discord): coalesce thread starter lookups

* fix(discord): avoid coalescing incomplete metadata

* test(discord): keep proof inside plugin boundary

* test(discord): keep proof runner responsive

* fix(discord): retry starters when parent type is unknown

* fix(discord): preserve thread starter route ownership

---------

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 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 thread-starter cache never caches misses - deleted or inaccessible starters cause one REST GET per inbound thread message

2 participants