Repository navigation
fix(gateway): fall back to polling when config watcher exhausts inotify retries - #92852
Conversation
|
Codex review: needs maintainer review before merge. Reviewed June 13, 2026, 11:34 PM ET / 03:34 UTC. Summary PR surface: Source +17, Tests +17. Total +34 across 2 files. Reproducibility: Do we have a high-confidence way to reproduce the issue? Yes from source: current main and v2026.6.6 retry native chokidar watchers with usePolling false outside Vitest, then set hotReloadStatus to disabled after the retry budget; the reporter also supplied production logs, but I did not run a live ENOSPC gateway. Review metrics: 1 noteworthy metric.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Merge the narrow gateway fallback after maintainer review and normal gates, preserving bounded native retries and disabling hot-reload only if polling-mode recovery also fails. Do we have a high-confidence way to reproduce the issue? Do we have a high-confidence way to reproduce the issue? Yes from source: current main and v2026.6.6 retry native chokidar watchers with usePolling false outside Vitest, then set hotReloadStatus to disabled after the retry budget; the reporter also supplied production logs, but I did not run a live ENOSPC gateway. Is this the best way to solve the issue? Is this the best way to solve the issue? Yes; a bounded switch to chokidar polling after native watcher retry exhaustion is narrower than adding a config knob and avoids pushing operators to global CHOKIDAR_USEPOLLING or sysctl workarounds. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7f49f875de1b. Label changesLabel justifications:
Evidence reviewedPR surface: Source +17, Tests +17. Total +34 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
|
4996b65 to
e56b8b7
Compare
…fy retries When fs.inotify.max_user_watches is exhausted (ENOSPC), chokidar's native watcher fails permanently after 3 re-create attempts, disabling config hot-reload for the rest of the session. On hosts running many Node processes this is the common failure mode rather than a transient error. Add a polling-mode degradation step: after all native retries are exhausted, reset the retry counter and recreate the watcher with usePolling=true. Only if polling also fails does hot-reload become permanently disabled.
The existing test expected 'disabled' after 3 native retries. Now the watcher degrades to polling mode first, so the test covers the full two-phase lifecycle: 3 native retries → polling fallback → 3 polling retries → disabled.
e56b8b7 to
c9762c5
Compare
|
Maintainer closeout for current head
Landing as a narrow fix for #92851. |
|
post-merge maintainer follow-up landed on The PR merged while the final autoreview repair was still local. The follow-up now records Chokidar's effective normalized Verification:
|
Summary
When
fs.inotify.max_user_watchesis exhausted (ENOSPC), the config hot-reload watcher permanently disables itself after 3 failed re-create attempts. This PR adds a polling-mode degradation step so config hot-reload survives on hosts where inotify resources are constrained.Fixes #92851.
Problem
startGatewayConfigReloadercreates a chokidar watcher with native inotify watching. When the kernel limit is hit, all 3 retry attempts fail identically (same native mode), and hot-reload is permanently disabled for the session. This is common on hosts running multiple Node processes (tsx watch, vite dev servers, codex agents, etc.) where the defaultfs.inotify.max_user_watchesis insufficient.Fix
After all native retries are exhausted, reset the retry counter and recreate the watcher with
usePolling: true. Only if polling also fails does hot-reload become permanently disabled.Real behavior proof
Behavior or issue addressed: Config hot-reload watcher permanently disables itself when
fs.inotify.max_user_watchesis exhausted (ENOSPC) after 3 failed native re-create attempts, with no fallback to polling mode.Real environment tested: Debian 13 (Linux 6.12.63+deb13-amd64), Node v24.13.0, OpenClaw 2026.6.6 production gateway,
fs.inotify.max_user_watches=61023, 53 inotify FDs consumed across systemd, warp remote-server, OpenAI codex, tsx/vite dev servers.Exact steps or command run after this patch:
handleWatcherErrorlogic fromconfig-reload.ts(with the fix applied), using the real[email protected]library on the host where ENOSPC was occurring./tmp/proof-config.json.watcher.emit('error', new Error('ENOSPC: ...'))to exhaust the 3-retry budget and trigger the polling fallback.writeFileSync('/tmp/proof-config.json', JSON.stringify({ v: 2 })).Before evidence (optional): Production gateway logs showing permanent disable without the fix:
Evidence after fix: Console output from the verification script on the same host:
Observed result after fix: After 3 native retries exhausted, the watcher degraded to polling mode (
usePolling=true) instead of permanently disabling. The polling watcher detected the real config file write within ~200ms. Hot-reload status remained"active"throughout. Zero inotify resources consumed in polling mode.What was not tested: Full integration test inside a live OpenClaw gateway process (would require rebuilding the dist bundle and restarting the production gateway mid-session). The updated unit test in
config-reload.test.tscovers the two-phase lifecycle with mocked chokidar.Tradeoffs
awaitWriteFinish.pollInterval) vs instant inotify events. Negligible for config files that change infrequently.Testing
config-reload.test.tsto cover the two-phase degradation: native retries → polling fallback → polling retries → disabled.