Skip to content

fix(discord): keep REST entity cache entries on elapsed time - #190997

Merged
obviyus merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/discord-entity-cache-elapsed
Nov 2, 2026
Merged

obviyus merged 3 commits into
openclaw:mainfrom
wangmiao0668000666:fix/discord-entity-cache-elapsed

Conversation

@wangmiao0668000666

@wangmiao0668000666 wangmiao0668000666 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Discord entity data expiring too early or remaining stale too long when the wall clock is corrected while the Gateway stays connected.

User Impact

Discord's existing 30-second REST entity-cache window follows elapsed time rather than clock corrections. This prevents unnecessary REST requests after a forward correction and stale user, member, guild, channel, or emoji reads after a backward correction. Normal no-step behavior is unchanged.

Why This Change Was Made

Retains @wangmiao0668000666's original fix: sample performance.now() in the existing private cache owner. Lookup, expiry creation, and sweeping already use that single sample. No new owner, SDK export, setting, persistence, or public timestamp contract is introduced. The TTL, sweep interval, 5,000-entry cap, and event invalidation stay intact. The sweep origin remains zero; its first process-start sweep can therefore wait until the existing 30-second interval, while reads still check expiry on every access.

The clock regression now extends the existing emoji-cache contract, with explicit Date/performance fake clocks. The independent capacity, late-response sweep, and event-invalidation cases remain. Removed the redundant standalone regression and its test-line allocation. Against frozen main 68a413a67ab14a569c4a82ff96bf8627e5163f51: source +1/−1, tests +4/−5 (net −1), docs +5.

Evidence

Built both artifacts in secretless Docker on Node 24.22.1, then exercised the bundled built Gateway with the actual Discord plugin, not a manually constructed Client or transport. An authenticated operator called HTTP /tools/invoke with the real message tool's emoji-list action; the native Discord clients used a task-trusted TLS CONNECT protocol fixture at their normal authorities. The Discord Gateway connection remained alive throughout each run.

Main twice, candidate twice, with fresh isolated profiles each time:

Scenario Main, both runs Candidate, both runs
No clock step Reuses clock_v1 while fresh; reads clock_v2 after 31 real seconds Same
Forward +60s wall step while fresh Incorrect immediate refetch: 2 REST reads, clock_v2 Keeps fresh entry: 1 REST read, clock_v1
Backward −60s wall step, then 31 real seconds Incorrect stale entry: 1 REST read, clock_v1 Correct expiry: 2 REST reads, clock_v2
Restore wall time Refreshes the stale main result to clock_v2 Retains the already refreshed clock_v2

The step changes only the Gateway process's Date.now(), as in #190894. The system clock, native timers, performance.now(), public tool path, cache implementation, and its 30-second TTL are not replaced or accelerated. The fixture supplies protocol responses, not production credentials or live Discord delivery; all tool responses and actual REST requests are captured.

The consolidated regression fails on main for the two intended clock-direction assertions (2 failed / 5 passed) and passes on the candidate (7/7). Focused formatting and changed-file lint passed. Detailed native-wire and returned-value receipts.

Merge danger: two-way door; reverting fully restores the previous process-local timing behavior, with no stored-data migration. Blast radius is the Discord Client's existing REST entity cache and its consumers; incorrect behavior could increase REST calls or prolong stale cached entities.

@clawsweeper

clawsweeper Bot commented Nov 2, 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 channel: discord Channel integration: discord size: XS labels Nov 2, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 2, 2026
@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR makes Discord REST entity-cache expiry follow elapsed time instead of wall-clock corrections.

Example: The wall clock moves backward 60 seconds after emoji-list caches clock_v1, then 31 real seconds pass.

  • Before: emoji-list returns stale clock_v1 without another REST request.
  • After: The expired entry refreshes through REST and returns clock_v2.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal owner-level repair with shipped-entry-point before/after evidence, focused red/green coverage, and no persistent-state migration; required CI is still pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Node 24 Docker proof exercises the bundled Gateway's HTTP message-tool emoji-list path through the actual Discord plugin and native REST client against a TLS protocol fixture, twice on base and candidate, showing ordinary expiry plus correct recovery from both wall-clock directions; final-head executable production code matches the tested candidate.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Discord entity reads can refresh too early or remain stale beyond their intended window after a host clock correction.
Reason: This restores the existing freshness contract with a minimal repair, and collaborator involvement supports the direction without introducing a new product choice.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused, proven fix for a cache-expiry bug still present on current main; no actionable defects were found.

Priority: P2
Reviewed head: bf39ccfdf2a6f654e5940a8163bb8233911b39d6

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Discord plugin's private Client caches REST-fetched entities for connected Gateway consumers, returning cached values until expiry or Gateway-event invalidation.

flowchart LR
  A[Message tool emoji-list] --> B[Discord action handler]
  B --> C[Account Gateway plugin]
  C --> D[Client entity cache]
  D --> E[Discord REST client]
  E --> F[Normalized emoji result]
  D --> F
Loading

Technical review

Best possible solution:

Merge the existing one-line clock repair with its consolidated regression and documentation after required checks pass.

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

Current-main source directly exposes both clock-step failures, and the supplied built-Gateway traces independently demonstrate them; this read-only review ran no target code.

Is this the best way to solve the issue?

Yes: changing the existing private owner's single clock sample fixes every entity-cache consumer without adding state, APIs, configuration, or a parallel timing path.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Private REST entity-cache ownership and expiry keeps the original intent (0cf5e00: The merged refactor folded the previous DiscordEntityCache into Client while preserving behavior and removing private forwarding surfaces; this identifies the ownership move rather than the original clock choice.)
  • Entity-cache regression coverage keeps the original intent (8e9341e: The merged test cleanup reduced repeated setup and overlapping assertions while retaining distinct contracts; this PR extends an existing contract instead of adding duplicate scaffolding.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 0cf5e00 adds extensions/discord/src/internal/client.ts:335 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 0cf5e00fbe57; files: extensions/discord/src/internal/client.ts)
  • Ayaan Zaidi: Raw commit fca1c6e adds extensions/discord/src/internal/client.ts:487 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fca1c6ec13f4; files: extensions/discord/src/internal/client.ts)

PR surface

Source 0, Tests -1, Docs +5. Total +4 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 1 0
Tests 1 4 5 -1
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 10 6 +4

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: Wall-clock corrections can cause premature REST refetches or prolonged stale Discord entity reads, with a limited plugin-cache blast radius.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-02T09:24:37.520Z sha a5e19b3 :: needs real behavior proof before merge. :: none
  • reviewed 2026-11-02T10:11:41.076Z sha a5e19b3 :: needs maintainer review before merge. :: none

Reviewed November 2, 2026, 6:11 AM ET / 11:11 UTC (Revision 3).

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed 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. labels Nov 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Nov 2, 2026
@obviyus

obviyus commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Bundled-Gateway cache proof

Final head: bf39ccfdf2a6f654e5940a8163bb8233911b39d6 (original contributor commit preserved). Frozen main: 68a413a67ab14a569c4a82ff96bf8627e5163f51. Runtime candidate build: 90bb7952b0a1a9e5a07b7247df8f32e7504b21c7; the final commit only consolidates tests/docs and removes the explanatory comment, without changing the production clock statement used in the runtime proof.

Final exact-head gates: CI and openclaw/ci-gate passed, 0 failing / 0 cancelled jobs. Codex review: 5/6 overall, proof, and patch; complete scope; no findings. after-push.sh passed with the exact head and three changed files. The proof container is stopped and retained.

Both full builds succeeded in secretless node:24.22.1 Docker. Each run starts the real dist/index.js --profile … gateway with the bundled Discord plugin. No direct Client construction, private-cache access, endpoint override, replaced transport/cache method, or TTL acceleration is used.

The operator invokes the actual Gateway HTTP endpoint with its real task-owned bearer credential:

{
  "tool": "message",
  "args": {
    "action": "emoji-list",
    "channel": "discord",
    "guildId": "223456789012345678"
  },
  "sessionKey": "agent:main:entity-cache"
}

The native client makes real GET /api/v10/guilds/<guild>/emojis requests through a task-trusted TLS CONNECT peer at discord.com. TLS verification remains enabled. Real Discord Gateway HELLO/IDENTIFY/READY and heartbeat/ACK frames keep the bundled plugin connected. The fixture changes its emoji response from clock_v1 to clock_v2 after the initial read; it sends no invalidation event, so subsequent reads exercise the existing cache TTL. This is a protocol-fixture proof, not a live Discord-account or message-delivery claim.

Observed twice on each artifact

Read Main REST count / returned emoji, both runs Candidate REST count / returned emoji, both runs
Ordinary warm 1 / clock_v1 1 / clock_v1
Ordinary immediate repeat 1 / clock_v1 1 / clock_v1
Ordinary after 31 real seconds 2 / clock_v2 2 / clock_v2
Forward-step warm 1 / clock_v1 1 / clock_v1
Forward +60,000ms, still fresh 2 / clock_v2 — premature expiry 1 / clock_v1 — retained
Backward-step warm / fresh repeat 1 / clock_v1 1 / clock_v1
Backward −60,000ms, then 31 real seconds 1 / clock_v1 — stale 2 / clock_v2 — refreshed
Restore wall clock 2 / clock_v2 2 / clock_v2

All operator calls returned HTTP 200 with the actual message-tool result payload. The REST counts come from received native wire requests, not a mocked method. Every run observed exactly one Discord IDENTIFY for its entire sequence, and its config bytes remained unchanged; no restart or reconnect cleared the cache between reads.

The harness steps only the Gateway child's Date.now(), with the same process-local wall-step method as #190894. It does not change the system clock or replace/advance native timers or performance.now(). The driver and protocol peer remain on their original clocks. Observed second-run backward reads were separated by about 31.12s on main and 31.09s on the candidate. Restoring wall time makes main discover the same valid clock_v2 payload, confirming the earlier stale result was the cache decision rather than invalid fixture data.

Focused regression and simplification

The existing emoji-cache test now covers zero, forward, and backward wall steps. All independent 5,000-entry cap, late-response sweep, guild-emoji invalidation, and member/user invalidation cases remain.

Frozen main + consolidated regression:
  +60000ms: expected fetch count 1, received 2
  -60000ms: expected fetch count 2, received 1
  Tests: 2 failed / 5 passed; exit 1

Candidate:
  Tests: 7 passed / 7; exit 0
  Changed-file lint: No problems in 2 files
  Formatting: passed for all 3 changed files

Source delta against frozen main: +1/−1. Tests: +4/−5 (net −1). Docs: +5. No test allocation remains, no SDK export is added, and no public/persisted epoch or configuration contract changes.

Retained receipts

Proof directory: ~/Developer/.agents/handoffs/openclaw-bugloop/proofs/190997/workboard/.

Successful observed/task-evidence/*/result.json captures:

  • Main 1: entity-base-1-8Axzh7
  • Main 2: entity-base-2-QDuEuI
  • Candidate 1: entity-candidate-1-PRulzT
  • Candidate 2: entity-candidate-2-oe0RYF

Each includes actual tool payloads, native request paths/counts/timing, Gateway wire opcodes, isolation paths, and config checks; accompanying gateway.log and steps.jsonl retain startup and clock observations. The harness stops each owned Gateway and peer and restores the process-local offset. Pueue receipts: full builds 13328, first main 13330, remaining matrix 13332, red/green regression and lint 13333. The worktree, branch, container, and exact harness are retained for the maintainer.

@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 2, 2026
@obviyus
obviyus merged commit 1306cc5 into openclaw:main Nov 2, 2026
122 of 123 checks passed
@obviyus

obviyus commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Landed in 1306cc5. Thanks @wangmiao0668000666. The Discord entity cache now ages correctly across clock changes.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Thanks @obviyus for landing this in 1306cc5 — and for the careful re-review that got it to a clean state. Appreciate the ride-along on the Discord entity cache fix. Happy to pick up any follow-ups if the elapsed-time aging surfaces anything else.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…w#190997)

fix(discord): measure entity cache age with the monotonic clock

The Discord entity cache measured entry age with the wall clock. When the clock moved forward, entries expired too early; when it moved back, stale entries were served past their lifetime. The cache now measures age with `performance.now()`. Behavior without a clock change is unchanged.

Evidence: bundled built Gateway with the Discord plugin in secretless Node 24.22.1 Docker, through the real `message` tool's `emoji-list` action, stepping only the process wall clock (`Date.now`). On main, entries expired early after a forward step and stale results were served after a backward step plus 31 real seconds, twice each; with this change both cases were correct twice. No-step controls matched. Details: openclaw#190997 (comment).

Thanks @wangmiao0668000666.

Co-authored-by: Ayaan Zaidi <[email protected]>
@wangmiao0668000666
wangmiao0668000666 deleted the fix/discord-entity-cache-elapsed branch November 4, 2026 02:52
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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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