Repository navigation
fix(gateway): cap device-required probe cache to prevent unbounded growth - #147708
Patrick-Erichsen merged 1 commit into
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 11:50 PM ET / September 15, 2026, 03:50 UTC (Revision 4). ClawSweeper reviewWhat this changesCaps the Gateway diagnostic probe’s remembered device-required failures at 500 URLs using the existing pruning helper and adds regression coverage. Merge readiness✅ Ready for maintainer review This PR remains useful: current main and the latest release retain the uncapped cache. No blocking correctness or security defect was found, and the supplied real-transport evidence supports bounded retention. Priority: P2 Review scores
Verification
How this fits togetherGateway diagnostics probe configured endpoints and report connectivity and authentication results. A process-local cache suppresses repeated unauthenticated probes after device-required rejections. flowchart TD
A[Diagnostic target URL] --> B[Check credentials and recent failures]
B -->|Suppressed| C[Cached diagnostic result]
B -->|Probe allowed| D[Gateway WebSocket client]
D --> E[Connectivity and authentication result]
E -->|Device required| F[Remember failure and cap at 500 URLs]
E -->|Success| G[Clear remembered failure]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +7, Tests +9. Total +16 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep failure retention bounded within the existing probe owner while preserving authenticated recovery, TTL expiration, and successful-probe cleanup. Do we have a high-confidence way to reproduce the issue? Yes, from source: repeated device-required failures at distinct URLs accumulate entries on current main without global pruning. This review did not execute a failing main reproduction. Is this the best way to solve the issue? Yes. Applying the shared insertion-order pruning helper at the sole insertion point is a narrow repair without timers, configuration, or persistent-state changes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a4790958b284. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
@clawsweeper re-review. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…owth The deviceRequiredProbeCache Map had no size limit. In environments with many distinct gateway URLs, repeated unauthenticated probes could accumulate entries indefinitely since expired entries are only evicted on re-access. Cap the cache at 500 entries using the existing pruneMapToMaxSize helper, matching the pattern used by bootstrap-cache and other Maps in the codebase. Closes openclaw#146417
196d611 to
996e917
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…owth (openclaw#147708) The deviceRequiredProbeCache Map had no size limit. In environments with many distinct gateway URLs, repeated unauthenticated probes could accumulate entries indefinitely since expired entries are only evicted on re-access. Cap the cache at 500 entries using the existing pruneMapToMaxSize helper, matching the pattern used by bootstrap-cache and other Maps in the codebase. Closes openclaw#146417
* commit 'd8e50a38fd1c4df6dd69bcbc155697c464e1be45': (23 commits) fix(cron): release queued reservations when activation fails (#141008) fix(gateway): reduce CPU work in session lists and searches (#148713) feat(gateway): add admin CPU profile diagnostics (#148004) fix(gateway): cap device-required probe cache to prevent unbounded growth (#147708) fix(ci): align Gateway E2E expectations (#148653) refactor(ai): remove unused overflow wrapper (#148719) feat: stage selected chat text as editable comments (#148649) fix(ci): admit reachable release refs with large histories (#148161) fix(agents): allow authorized email CLI actions (#148521) improve(agents): trim large tool results with less CPU (#148718) refactor(docker): share image version parsing (#148243) fix(ci): retain passing hosted checks after skipped duplicates (#148722) fix(update): report configuration failures during repair (#144819) refactor(imessage): share handle classification (#148229) fix(ui): keep the selected agent across Settings pages (#148667) test(telegram): reuse deferred fixture helper (#148501) fix(media): resize images before understanding (#122431) fix: preserve unfinished work during completed PR cleanup (#148704) refactor(migrate-hermes): reuse canonical config record coercion (#148645) perf(channels): reduce history worker metadata footprint (#148711) ...
Closes #146417
What Problem This Solves
The gateway keeps a small memory cache to avoid repeatedly probing URLs that are known to require device authentication. This cache never had a size limit — every new URL that returned a device-required response added a permanent entry, and expired entries were only cleaned up if that exact URL was visited again. In environments with many rotating gateway URLs (load balancers, multi-gateway fleets), the cache could grow without bound, slowly consuming memory.
deviceRequiredProbeCacheis aMapwith no cap. Entries are only evicted on re-access of the same key, so distinct URLs accumulate indefinitely.pruneMapToMaxSizehelper, which removes the oldest insertion-order entries when the limit is exceeded.src/gateway/probe.ts—noteDeviceRequiredProbeFailurenow callspruneMapToMaxSizeafter inserting a new entry.Why This Change Was Made
The codebase already has
pruneMapToMaxSize(src/infra/map-size.ts) used by 10+ other Maps —bootstrap-cache,prompt-cache-observability,tool-loop-warning-buckets, etc. This fix applies the same established pattern.pruneMapToMaxSizeon insert is sufficient since dead keys are evicted by insertion order.User Impact
Long-running gateway instances in multi-URL environments no longer accumulate unbounded probe-cache entries, preventing gradual memory growth. No visible behavior change for end users.
Evidence
Real behavior proof (head
996e917): a minimal realwsWebSocketServer on 127.0.0.1 speaks the real gateway connect protocol — it sends theconnect.challengeevent frame (mirroringsrc/gateway/server/connection.ts:336-346), then on the client'sconnectrequest replies with aNOT_PAIREDerror response carrying theDEVICE_IDENTITY_REQUIREDdetail code and closes 1008 / "device identity required" (mirroringsrc/gateway/server/ws-connection/connect-auth.ts:337-340). The realprobeGatewaybuilds a realGatewayClientover a real ws transport — no mock — and drives 501 distinct URL paths:The cache reaches the 500 cap on the 500th distinct failure and never exceeds it; the 501st insert evicts the oldest entry. Re-probing
probe-0(evicted long ago) is not short-circuited —gatewayReached=trueand the real 1008 close confirm it went back through the real client, demonstrating oldest-entry eviction rather than a test-only size accessor.Unit test (unchanged):
src/gateway/probe.test.ts > evicts the oldest device-required cache entries once the cap is reachedinserts 501 distinct URLs and assertsgetDeviceRequiredProbeCacheSizeForTest() <= 500. All 37 probe tests pass, including TTL expiry, per-URL isolation, and paired-probe-clears.AI Assistance
This PR is AI-assisted. Used
git grepto confirmpruneMapToMaxSizeis the canonical Map-capping utility across the codebase (10+ existing call sites) and verified the eviction test pattern inbootstrap-cache.test.ts. The implementer understands the code: the cache short-circuits repeated unauthenticated probes per URL; without a cap, distinct URLs accumulate indefinitely. Round 2: added real behavior proof (realwsserver + realGatewayClientover the gateway connect protocol) after review feedback that the mocked-client unit test alone was insufficient. Round 3: no code change (empty amend to retrigger CI); proof re-run against the new head confirms identical bounded-retention results.