Skip to content

fix(runtime): expire discovery and room caches on elapsed time - #193147

Merged
obviyus merged 6 commits into
mainfrom
fix/discovery-cache-elapsed-sweep
Nov 5, 2026
Merged

obviyus merged 6 commits into
mainfrom
fix/discovery-cache-elapsed-sweep

Conversation

@obviyus

@obviyus obviyus commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Two process-local cache windows use wall time. A backward clock correction keeps an expired Mantle discovery catalog or Nextcloud Talk room kind fresh longer than its defined lifetime.

User Impact

Use native elapsed time for Mantle's one-hour discovery cache and Nextcloud Talk's room-kind cache. Existing TTLs, credential/account scopes, payloads and policies stay unchanged. IAM-token expiry and pricing dates remain wall-clock/epoch operations.

Why This Change Was Made

Both owners are extensions, so their existing private caches now use performance.now() for recording and checking elapsed windows. No new timers, managers, SDK exports, configuration or migrations are needed.

Credits @wangmiao0668000666. Original commits from #193066 (7c4c1b8e, c45cc5cd) and #193082 (f3ea8175, 61e29e17) are retained via cherry-picks. This sweep supersedes those two fixes; the lead decides their closure after landing. Conditional UI proposal #193070 by the same author is not included: this sweep makes no built-UI, screenshot or gzip-size claim.

The allocation was removed. Mantle expiry coverage now extends existing strict-refresh/recovery cases; room expiry extends credential-scope cases with paired wall/elapsed clock mocks. Existing response fixtures were consolidated without weakening failure/release assertions, and the durable inbound retry consumer also fakes performance alongside Date. Whole patch: production +4/-4 (8 gross lines); tests +24/-24 (net 0).

Evidence

Built Linux Node 24.22.1 Gateways, task-owned profiles/state, synthetic credentials and faithful local services. Only process-local Date.now() was stepped. No system-clock change, performance acceleration or TTL modification.

Detailed receipts: Mantle real-TTL Gateway proof · Nextcloud Talk authenticated room-cache proof.

Mantle discovery

  • Two immediate authenticated models.list refresh RPCs reuse one real HTTPS discovery request, proving the shipped Gateway path reaches the cache.
  • After 3,605,120.823 ms of real elapsed time, the fixture adds a model and the stepped Gateways' Date.now moves backward two hours.
  • Main keeps the stale catalog (1 total discovery GET); candidate refreshes and lists the new model (2 GETs).
  • No-step main and candidate controls both refresh normally (2 GETs each).
  • The real registered provider uses its guarded HTTPS transport through the documented operator proxy with task-owned CA trust. No fetch/SDK mock or TLS/auth/SSRF bypass.

Mantle was exercised at 34c5fe53e37400893d03e19c7fc279bdf28a5691. Its entire extension tree and the complete Gateway/SDK src/ and packages/ trees are identical in the final combined candidate 10c1f02a981d2d0b196d391dec4d62349292e2f6; only disabled-in-those-lanes Nextcloud source/tests were subsequently added. That unchanged-input proof is retained honestly, not relabeled as a different executed artifact.

Nextcloud Talk

  • Own built-Gateway proof at the final combined candidate, normally installed development plugin, real HMAC-authenticated webhooks, Basic-authenticated OCS room lookups and verified signed bot replies.
  • Two initial direct-room messages reuse one room GET per Gateway and produce two replies.
  • After 305,155.867 ms of real elapsed time, the fixture supplies a type-3 room snapshot and only stepped Gateway Date.now moves backward ten minutes.
  • Main-step retains stale direct classification (1 room GET, 3 replies); candidate-step refreshes and applies the existing disabled-group policy (2 GETs, 2 replies).
  • Both no-step controls also refresh and terminate with group_policy_disabled (2 GETs, 2 replies each). All 12 actual message webhooks have durable acceptance markers; every Basic/HMAC check matches.

This is catalog/room-cache behavior against local protocol fixtures, not live AWS/Nextcloud operation or paid inference. No UI behavior is claimed.

Both builds, targeted format/lint and 47 focused tests passed. Pre-fix witnesses fail as intended: Mantle serves stale data instead of attempting the expired refresh (2 cases); all three room credential-scope cases skip the required refetch. The original #193082 prefer-const red was its own code and its contributor correction is retained; fresh sweep lint passes.

Merge Danger

Two-way door: reverting restores the previous timing without persisted-state or configuration changes. Blast radius is the elapsed validity of these two extension caches. Credential scopes, epoch expiries, channel policies, UI recovery windows and other providers are unchanged.

wangmiao0668000666 and others added 6 commits November 5, 2026 06:01
The per-region catalog cache used the wall clock, so a backward host clock
correction kept fetchedAt fresh and stopped the model catalog from ever
refreshing. Use performance.now() for the process-local window; epoch
timestamps (IAM token expiry) are unchanged.

(cherry picked from commit 7c4c1b8)
The per-account room-kind cache used the wall clock, so a backward host clock
correction kept expiresAt fresh and stopped room kind lookups from ever
refreshing. Use performance.now() for the process-local window.

(cherry picked from commit f3ea817)
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Mantle discovery: built Gateway, real unchanged one-hour TTL

Baseline main: c3cdd6bc2d79efdfc177d3049f0072c6a1eae0b2.
Proven Mantle artifact: 34c5fe53e37400893d03e19c7fc279bdf28a5691.

Four isolated built Gateways ran through dist/entry.js --profile <case> gateway run on loopback ports 25066–25069. A persistent client from the built public openclaw/plugin-sdk/gateway-runtime surface authenticated normally as the CLI operator and called the real Gateway models.list method with:

{"view":"all","provider":"amazon-bedrock-mantle","includeDetails":true,"refresh":true}

The real registered Mantle plugin fetched its normal HTTPS /v1/models URL using its actual guarded transport and a synthetic bearer credential. A purpose-built local HTTPS fixture supplied catalog data through the documented operator-managed forward proxy. Destination TLS remained enabled with a task-owned CA supplied through NODE_EXTRA_CA_CERTS; no TLS/auth/SSRF check was disabled and no SDK/fetch function was mocked. Only the fixture destination was admitted by the proxy. No live Mantle/AWS service, real credential or paid inference was used.

Two immediate catalog refresh RPCs per Gateway produced just one HTTP discovery request, establishing that this shipped path actually reused the plugin cache. All initial/cached outputs included example.cache-old and omitted example.cache-new.

Then the controller waited 3,605,120.823 ms of real elapsed time, exceeding the unchanged 3,600,000 ms cache TTL. performance.now() was not mocked, scaled or advanced. After that wait, the fixture made the new model available and only the stepped Gateways' process-local Date.now() moved backward by 7,200,000 ms. The system clock, fixture clock and client clock were not changed. The existing authenticated WebSocket connections stayed open; authentication was not bypassed or reimplemented.

Lane New model after the real TTL Total discovery GETs
main + backward Date.now step absent (stale catalog) 1
candidate + backward Date.now step present 2
main, no clock step present 2
candidate, no clock step present 2

The HTTP trace contains four initial phase-0 GETs and exactly three phase-1 GETs: main-control, candidate-step and candidate-control. Main-step serves its old catalog without another HTTP request. Gateway/worker clock observations confirm the negative Date offset while native performance time has passed one hour. All four RPC outcomes match the table. This is refresh-on-request after expiry, not a claim of a new periodic background refresh.

The fixture, clients and Gateways were joined after the run. The one-hour TTL and IAM token/pricing epoch logic are unchanged. Candidate's 29 focused Mantle discovery/registered-provider tests passed.

Binding the retained proof to the combined sweep

The later combined candidate 10c1f02a981d2d0b196d391dec4d62349292e2f6 adds only Nextcloud Talk room-cache source/tests after the proven Mantle artifact. Nextcloud Talk was not enabled or installed in these Mantle lanes. Git tree identities are equal at both revisions:

  • Gateway/SDK/core src/: 08b7d0390cd46f6a6b8db17701e97257088d9b3e
  • packages/: 924bc96aa220fac97bd950006912a7a8744806e7
  • Entire extensions/amazon-bedrock-mantle/: 79578fe85554fb862e27536d05e4e9d8777e03da

The retained Mantle evidence is reused for those unchanged runtime inputs; it is not relabeled as a newly executed artifact.

@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Nextcloud Talk: built Gateway, authenticated webhooks, unchanged positive-cache TTL

Baseline main: c3cdd6bc2d79efdfc177d3049f0072c6a1eae0b2.
Combined candidate: 10c1f02a981d2d0b196d391dec4d62349292e2f6.

The conditional #193082 fix has its own completed runtime proof. Four isolated built Gateways received ordinary signed Talk Create/Note webhooks on their real Gateway listener. The real Nextcloud Talk plugin was installed through plugins install <development-path> --link --force --accept-capabilities, with its declared saxes/zod runtime dependencies prepared in the container and the host providing its public SDK peer. No code-safety, permission or signature check was disabled. Initial source-layout/dependency/route-readiness setup failures were preserved separately and are not counted as product reproduction.

A purpose-built local Talk service implements the actual OCS room-info and bot-message endpoints. Room GETs require the configured Basic API credentials. Outbound bot POSTs must have the correct HMAC over the extracted message value. Inbound webhook HMACs are generated over random + body and verified by the production receiver. A deterministic local OpenAI-compatible fixture supplies agent responses through the normal registered provider. There are no real Talk/OpenAI credentials, paid calls, SDK mocks or private helper invocations.

Each Gateway first accepted two signed direct-room messages durably and produced two real bot API replies. Both messages shared one authenticated room GET returning OCS type 1, establishing a warm positive room-kind cache. Signed, ignored non-message events were used only to wait for the real channel route to be registered; no agent message was blindly resent after acceptance.

The controller then waited 305,155.867 ms of real elapsed time before the first post-expiry message, exceeding the unchanged 300,000 ms positive TTL. Native performance time and the system clock were not changed. Only the stepped Gateway processes' Date.now() moved backward by 600,000 ms. The fixture next supplied a valid type-3 OCS room snapshot. Configuration stayed constant: direct messages allowed, group messages disabled.

Lane Room GETs Observed room types Final signed bot replies Model HTTP requests
main + backward Date.now step 1 1 only (stale direct kind) 3 6
candidate + backward Date.now step 2 1, then 3 2 4
main, no clock step 2 1, then 3 2 4
candidate, no clock step 2 1, then 3 2 4

Main-step wrongly retains the direct kind, dispatches the third turn and sends another bot reply. Candidate-step refreshes, recognizes the group kind and terminates the inbound action with the actual log drop group sender alice (reason=group_policy_disabled). Both no-step controls refresh and produce the same terminal group-policy drop. No new model request or bot reply follows those three drops.

All 12 actual message webhooks returned HTTP 200 with x-openclaw-delivery-accepted: durable; all room Basic-auth checks and all bot reply HMAC checks matched. The model requests actually used /v1/chat/completions. The fixture supplies valid OCS snapshots to expose refresh and classification; this is not a claim of live Nextcloud operation, a real server room-conversion action or client rendering.

The fixture, Gateways and workers were joined after the run. Existing temp-path protection selected its private state-temp fallback on both refs; it was not disabled or hidden.

Focused checks and prior red attribution

  • Combined candidate: 29 Mantle tests, 15 room-info/timeout tests and 3 durable inbound retry tests passed (47 total), plus targeted formatting/lint and builds.
  • Main's three credential-scope regressions fail specifically with room GET count expected 3, received 2 after backward wall-clock movement and elapsed expiry.
  • The contributor's original lint red was its own room-info.test.ts:160:9, prefer-const, at f3ea8175, run https://github.com/openclaw/openclaw/actions/runs/41942735186 . Their corrective 61e29e17 is retained. The consolidated tests use const spy handles and pass fresh lint; the old red is not labeled inherited.
  • Whole sweep: 8 gross production lines; tests +24/-24, net 0; allocation removed. Both original fixes remain credited to @wangmiao0668000666 via cherry-picks.

@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus marked this pull request as ready for review November 5, 2026 02:50
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper

clawsweeper Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Use monotonic elapsed time to expire the Mantle discovery and Nextcloud Talk room-kind caches despite wall-clock corrections.

Example: A cached Nextcloud room changes from type 1 to type 3 after 305 seconds while the Gateway wall clock moves backward ten minutes.

  • Before: The stale direct classification permits a third bot reply despite disabled group messaging.
  • After: The expired cache refreshes, and the existing group policy prevents the third reply.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A minimal complete repair with shipped-entry-point comparisons, retained regression coverage, and no identified correctness or security defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Supplied built Linux Gateway receipts exercise real catalog RPCs and authenticated Talk webhooks over actual transports against local protocol fixtures, with unchanged TTLs, backward wall-clock steps, baseline failures, candidate recovery, and no-step controls; Mantle proof reuse is verified by matching runtime trees.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Clock rollback can keep model catalogs and room classifications stale beyond their intended cache lifetimes.
Reason: The maintainer-authored direction restores existing expiry contracts with four production substitutions and no new configuration or ownership layer.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR fixes two current-main cache-expiry defects with a minimal patch and credible Gateway runtime proof; no actionable findings remain, and exact-head CI is still running.

Priority: P2
Reviewed head: 10c1f02a981d2d0b196d391dec4d62349292e2f6

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Mantle provider caches authenticated model discovery results, while Nextcloud Talk caches authenticated room classifications consumed by inbound access policy; both caches live only in process memory.

flowchart TD
  A[Gateway model listing] --> B[Mantle discovery cache]
  B --> C[Guarded HTTPS model discovery]
  D[Authenticated Talk webhook] --> E[Room classification cache]
  E --> F[Authenticated OCS lookup]
  E --> G[Inbound policy and reply dispatch]
Loading

Technical review

Best possible solution:

Merge the existing owner-local clock substitutions once the normal exact-head gates pass.

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

Current-main source directly permits stale cache reuse after a backward clock correction, and supplied built-Gateway comparisons demonstrate both failures against unchanged affected code; this review executed no target code.

Is this the best way to solve the issue?

Changing both timestamp production and comparison to performance.now is the smallest complete repair, preserving the existing owners, scopes, TTLs, retry behavior, and epoch-based auth and pricing logic.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Mantle discovery cache changes intended behavior with a stated reason (7879c7f: The available refactor removed injected clock and fetch seams while retaining the existing cache window and adding guarded transport; wall-time arithmetic predates that refactor.)
  • Nextcloud room expiry changes intended behavior with a stated reason (39dfbc8: The retry repair made cached expiry explicit while assigning temporary failures to durable ingress and preserving permanent fallbacks; this PR explains why the interval needs monotonic time.)
  • Credential and failure contracts keeps the original intent (e8df190: Room classifications are scoped to the actual server, credentials, and network policy; existing strict/advisory catalog outcomes and room retry assertions remain protected.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e8df190 adds extensions/nextcloud-talk/src/room-info.ts:62 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e8df190f4617; files: extensions/nextcloud-talk/src/room-info.ts)
  • Ayaan Zaidi: Raw commit d1dce58 adds extensions/amazon-bedrock-mantle/discovery.ts:384 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d1dce5857a3a; files: extensions/amazon-bedrock-mantle/discovery.ts)
  • sunlit-deng: Raw commit 39dfbc8 adds extensions/nextcloud-talk/src/room-info.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 39dfbc860249; files: extensions/nextcloud-talk/src/room-info.ts)

PR surface

Source 0, Tests 0. Total 0 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 4 4 0
Tests 3 24 24 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 28 28 0

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test LOC Production +4/-4; tests +24/-24 The fix replaces clock calls without production growth and extends existing regression cases without net test growth.

Root-cause cluster

Relationship: canonical
Canonical: #193147
Summary: This combined PR owns the two plugin cache repairs; the UI recovery proposal changes separate owners.

Members:

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

Labels

Label changes:

  • add P2: Backward wall-clock corrections extend cache freshness incorrectly, affecting model discovery and room classification within two plugins.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Backward wall-clock corrections extend cache freshness incorrectly, affecting model discovery and room classification within two plugins.
  • 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.

Reviewed November 4, 2026, 9:56 PM ET / November 5, 2026, 02:56 UTC.

@obviyus
obviyus merged commit 2f183b3 into main Nov 5, 2026
193 checks passed
@obviyus
obviyus deleted the fix/discovery-cache-elapsed-sweep branch November 5, 2026 03:02
@obviyus

obviyus commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 2f183b3. Thanks @wangmiao0668000666 and @wangmiao0668000666. Mantle discovery and Nextcloud Talk room caches now expire on elapsed time.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

Thanks @obviyus for the quick review, cherry-picking the commits over, and landing this as a single sweep. Appreciate the detailed Mantle and Nextcloud Talk proof receipts, and that the contributor attribution was kept intact. Also noted #193070 (the conditional UI proposal) was intentionally left out of this sweep — happy to follow up there if it's still wanted.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 5, 2026
…law#193147)

fix: use elapsed time for Mantle discovery and Nextcloud Talk room caches

The Mantle model discovery cache and the Nextcloud Talk room-kind cache measured expiry with the wall clock. A backward clock step kept stale entries past their TTL: Mantle kept serving an old catalog, and Nextcloud Talk kept classifying a room with its old kind, so the room's current group policy was not applied. Both caches now use elapsed time. TTLs, cached data and existing guards are unchanged.

Sweep of openclaw#193066 and openclaw#193082; contributor commits are kept. openclaw#193070 is related but not included.

Evidence: built Gateway, stepping only the process-local `Date`, after real TTLs (one hour for Mantle, five minutes for Nextcloud Talk). Main kept serving stale data; with this change both caches refresh, and Nextcloud Talk applies the existing group policy. No-step controls are unchanged. Details: openclaw#193147 (comment) and openclaw#193147 (comment).

Thanks @wangmiao0668000666 and @wangmiao0668000666.

Co-authored-by: wangmiao0668000666 <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 5, 2026
The active-memory recall cache measured its TTL with the wall clock, so a
backwards clock step kept stale recall results past their TTL: a repeated
prompt within a session returned the previous turn's memory summary instead
of searching again until the step elapsed.

Cache expiry now runs on `performance.now()`, matching the elapsed-time
caches in other extensions. The test fixture that forces expiry advances the
same clock so its intent is unchanged.

Sweep of the elapsed-cache family (openclaw#191606, openclaw#192700, openclaw#193147).
wangmiao0668000666 added a commit to wangmiao0668000666/openclaw that referenced this pull request Nov 5, 2026
The shared provider live catalog cache measured its TTL with the wall clock,
so a backwards clock step kept stale catalogs past their TTL: provider model
rows and the shared upstream metadata feed kept serving an expired answer and
new or retired models did not refresh until the step elapsed.

Cache expiry now runs on elapsed time. The deadline recorded for catalog
expiries stays on the wall clock because its consumers compare it to
Date.now(), so expiry and the published deadline keep separate fields.

Sweep of the elapsed-cache family (openclaw#191606, openclaw#192700, openclaw#193147).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: nextcloud-talk Channel integration: nextcloud-talk extensions: amazon-bedrock-mantle 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: 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.

2 participants