Files
openclaw/scripts/watch-node.mjs
chenyangjun-xy c557246437 fix(watch): defer restart when dist/entry.js is missing mid-rebuild (#99972)
* fix(watch): defer restart when dist/ is mid-rebuild (#99603)

Defer gateway:watch child restart when run-node's build/runtime-postbuild
readiness contract reports a hard dist/ failure. Only defers on conditions
where the child physically cannot start, preserving normal restart behavior
for soft staleness that run-node can rebuild on start.

Hard failures (defer restart):
  - missing_dist_entry (mid-rebuild)
  - missing_bundled_plugin_dist_entry
  - missing_private_qa_dist
  - missing_runtime_postbuild_output

Soft staleness (allow restart, run-node rebuilds):
  - missing_build_stamp (w/ direct entry.js check for masked case)
  - git_head_changed, dirty_watched_tree
  - config_newer, build_stamp_missing_head, source_mtime_newer

isBuildReadyForRestart delegates to resolveBuildRequirement and
resolveRuntimePostBuildRequirement from run-node.mjs, using the
watcher process environment for consistency with the child runner.
200ms polling with 5-min timeout. Child-exit bounded recovery.
Clears stale restartRequested on timeout/poll errors.

Ref: #99603
Co-Authored-By: Claude <noreply@anthropic.com>

* fix(watch): deduplicate deferral loops, add single-flight guard, remove lint suppression

- Extract deferUntilBuildReady(onReady, onTimeout) shared helper,
  replacing the near-identical pollBuildReady and pollAfterChildExit.
- Add single-flight guard (deferredRestartActive) so concurrent file
  change events during deferral coalesce into one poll loop instead of
  spawning a git-subprocess storm.
- Replace inline .catch arrow callback with method-style call, removing
  the oxlint-disable-next-line suppression and its allowlist entry.
- Add tests: coalescing multiple changes, requestRestart recovery.

Ref: #99603
Co-Authored-By: Claude <noreply@anthropic.com>

* fix: keep gateway watch alive during concurrent builds

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Peter Steinberger <steipete@gmail.com>
2026-07-11 01:58:16 -07:00

21 KiB