#22154: dev(watch): make gateway watch portable on native Windows
docs
gateway
scripts
size: M
Cluster:
Windows Gateway Enhancements
## 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
#22926: feat(gateway): add Windows-native watch DX and tool/channel observa...
by Kansodata · 2026-02-21
92.0%
#22091: docs(readme): add Windows-native dev gateway command
by Kansodata · 2026-02-20
91.6%
#11470: fix: prevent gateway:watch race by passing --no-clean to tsdown
by apetresc · 2026-02-07
80.0%
#23364: Gateway: add risk-ack interlock for dangerous Control UI flags
by bmendonca3 · 2026-02-22
74.9%
#11974: [FEATURE] feat: integrate systemd WatchdogSec for gateway hang dete...
by mcaxtr · 2026-02-08
74.3%
#21120: Security/Gateway: guard dangerous HTTP /tools/invoke re-enables
by bmendonca3 · 2026-02-19
74.3%
#11455: fix(gateway): default gateway.mode to local when unset
by AnonO6 · 2026-02-07
74.2%
#20330: Fix SSH tunnel startup on Windows by resolving ssh from PATH
by graysurf · 2026-02-18
74.2%
#18493: making pnpm build:ui and pnpm build to work on windows
by darkpowerxo · 2026-02-16
74.1%
#8260: fix(macOS): gateway readiness detection + reversible Configure later
by xksteven · 2026-02-03
73.9%