← Back to PRs

#22154: dev(watch): make gateway watch portable on native Windows

by Kansodata open 2026-02-20 20:03 View on GitHub →
docs gateway scripts size: M
## Summary - Problem: `pnpm gateway:watch` depended on `gateway --force` (requires `lsof`), which fails on native Windows; docs also drifted from real behavior. - Why it matters: Windows contributors hit avoidable startup/port-conflict failures in the core dev loop. - What changed: - Added cross-platform watch wrapper: `scripts/gateway-watch.mjs`. - Updated `package.json` so `gateway:watch` now uses the wrapper. - On native Windows, wrapper does best-effort `openclaw gateway stop` then runs a compatible watch command (`gateway run --bind loopback --port 18789 --allow-unconfigured`). - Updated docs (`README.md`, `docs/help/debugging.md`, `docs/start/setup.md`) to reflect portable watch behavior. - Added gateway method consistency guard test to catch drift between listed public methods and implemented handlers. - Refactored gateway startup config bootstrap out of `server.impl.ts` into `src/gateway/startup-config.ts` (no intended behavior change). - What did NOT change (scope boundary): no protocol/schema changes, no channel behavior changes, no auth/pairing model changes, and no plugin API contract changes. ## Change Type (select all) - [x] Bug fix - [ ] Feature - [x] Refactor - [x] Docs - [ ] Security hardening - [x] Chore/infra ## Scope (select all touched areas) - [x] Gateway / orchestration - [ ] Skills / tool execution - [ ] Auth / tokens - [ ] Memory / storage - [ ] Integrations - [x] API / contracts - [x] UI / DX - [x] CI/CD / infra ## Linked Issue/PR - Closes # - Related #22091 ## User-visible / Behavior Changes - `pnpm gateway:watch` now works in native Windows setups without requiring `lsof`. - Docs now describe the portable watch flow and Windows-specific handling. - Developer experience is improved for local iteration; no runtime behavior changes expected for existing Linux/macOS flows. ## Security Impact (required) - New permissions/capabilities? `(No)` - Secrets/tokens handling changed? `(No)` - New/changed network calls? `(No)` - Command/tool execution surface changed? `(Yes)` - Data access scope changed? `(No)` - If any `Yes`, explain risk + mitigation: - `gateway:watch` now runs a best-effort local `openclaw gateway stop` on native Windows to avoid port conflicts from installed daemon sessions. - Scope is local dev workflow only; no remote command execution paths were added. - Existing gateway auth/authorization flows are unchanged. ## Repro + Verification Steps: 1. Native Windows (PowerShell), with daemon previously installed or active. 2. Run `pnpm gateway:watch`. 3. Confirm watcher starts gateway without `lsof` dependency errors. 4. Modify a TS file under `src/` and verify restart-on-change behavior. 5. Run method consistency test: - `pnpm exec vitest run --config vitest.gateway.config.ts src/gateway/server-methods-consistency.test.ts` Expected: - Watch mode starts successfully on Windows without `lsof`. - No persistent port conflict from previously running daemon in common dev path. - Consistency test passes. Actual: - Verified in local Windows native environment. - Consistency test passed. <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds cross-platform watch wrapper to enable `pnpm gateway:watch` on native Windows without `lsof` dependency. On Windows, wrapper runs best-effort `openclaw gateway stop` then starts gateway with compatible fallback arguments (`gateway run --bind loopback --port 18789 --allow-unconfigured`). Linux/macOS flows remain unchanged. Key changes: - New `scripts/gateway-watch.mjs` wrapper detects platform and adjusts gateway start command - Refactored startup config bootstrap from `server.impl.ts` into `src/gateway/startup-config.ts` (clean extraction, no behavior change) - Added method consistency guard test to prevent drift between public method catalog and implemented handlers - Updated docs (README, debugging, setup) to reflect portable watch behavior and Windows handling No runtime behavior changes for existing Linux/macOS dev workflows. <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - Clean refactoring with well-scoped changes: the startup config extraction is a straightforward move with no logic changes, the Windows watch wrapper has clear platform detection and fallback behavior, the consistency test adds guardrails, and documentation accurately reflects the changes. No protocol/schema/API contract changes. - No files require special attention <sub>Last reviewed commit: c1bc62c</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs