Skip to content

fix: apply Gateway port changes during in-process restarts - #206501

Merged
daniel-lxs merged 4 commits into
mainfrom
openclaw/gateway-port-rebind-on-restart-b4b6dc
Nov 27, 2026
Merged

daniel-lxs merged 4 commits into
mainfrom
openclaw/gateway-port-rebind-on-restart-b4b6dc

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #206498

What Problem This Solves

Changing gateway.port on an unmanaged Gateway saves the new setting and triggers an in-process restart, but the listener stays on the old port. The configured address is then unreachable.

User Impact

Port changes take effect during the existing automatic restart. Explicit --port and launch-time OPENCLAW_GATEWAY_PORT still win. No new setting or migration is required.

Why This Change Was Made

I refresh the startup config before reacquiring listener ownership and keep the listener and owner record on the same port. The Gateway's own exported port is not treated as a launch override.

I keep config-read failures with the existing startup recovery owner, after restart admission resets, so automatic recovery and manual SIGUSR2 recovery remain available. Actual lock-acquisition failures still terminate as before.

I moved the unchanged startup snapshot reader into a sibling module to satisfy the file-size ratchet. The CLI remains the single port owner; no duplicate run-loop port state is added. Simplification pass against main's merge base: production +77/-40, tests +152/-70, docs +6/-2. Most test churn parameterizes the existing real-custody case.

Evidence

Main-vs-fix AWS proof: main 009566554a35 kept serving 19771; the fix served 19772 in the same PID and updated the owner record.

I replayed the real CLI on AWS through crabbox-wrapper with the final source at 08c8adeba8854abde7a6865f5139a34bfecad729. Final runtime proof:

Launch mode Saved port Healthy port after restart PID before / after Owner port
Config only 19772 19772, not 19771 31048 / 31048 19772
Explicit CLI port 19772 19771, not 19772 31744 / 31744 19771
Launch environment port 19772 19771, not 19772 32471 / 32471 19771

Three original regressions failed against main and passed with the fix. I also reproduced and fixed the review's config-read recovery regression, including a red-before/green-after manual-admission case. The final production code passed 257 focused tests with one existing skip. After test-only lint corrections, I reran all three real-custody cases; core/config-CLI typechecks, targeted lint and formatting passed. The real CLI build passed.

I verified that all nine changed files on AWS matched the committed source; aggregate SHA-256: aff0b94a1c6b1020c6f0827c30240bd1396630336190b5b5bde03780a0a81315. I released all task AWS leases and joined the test Gateway processes before removing their temporary state.

Independent source review found the recovery issues addressed above. Local Codex autoreview remained blocked at its read-only sandbox preflight. ClawSweeper passed source review on this head with no actionable code findings. I also ran the published v2026.11.10 updater on CrabBox AWS and verified the resulting PR-head Gateway preserved the seeded settings, full session history and workspace file through port rebinding and both launch overrides. Redacted stable-to-head upgrade proof. Full CI and native-supervisor upgrade flows remain unverified. Nothing has been merged or deployed.

Co-authored with @daniel-lxs.

Work sessions

Linked for team reference; these sessions aren’t public.

Worked on by

roboclaw-bot and others added 2 commits November 27, 2026 08:17
Refresh the startup config before reacquiring listener ownership, preserving explicit CLI and launch-time environment overrides. Move the unchanged snapshot reader into its own module and keep restart regressions with config guard tests to satisfy file-size limits.

Co-authored-by: daniel-lxs <[email protected]>
Worked on by:
- @daniel-lxs

Co-authored-by: daniel-lxs <[email protected]>
OpenClaw-Publication: cd1692df-a183-48cf-9ab8-2e1253037b84
@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: S labels Nov 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. labels Nov 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 27, 2026
@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

Refresh the configured Gateway port before an in-process restart reacquires ownership and starts its listener.

Example: An unmanaged Gateway changes gateway.port from 19771 to 19772 without a launch override.

  • Before: The restart keeps serving port 19771 despite the saved setting.
  • After: The same PID serves port 19772, releases 19771, and records ownership on 19772.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused, worthwhile repair with shipped CLI proof, latest-stable upgrade evidence, passing exact-head CI, and no remaining findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Public terminal evidence exercises the real Linux Gateway at this head, demonstrates same-PID rebinding and both launch overrides, and verifies a published-stable upgrade with settings, session history, and workspace content preserved.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Saving a new Gateway port triggers a restart but leaves the configured endpoint unreachable because the listener retains its old port.
Reason: Restores documented config application behavior with existing owners and no new setting; maintainer authorship establishes direction.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current-main Gateway restart bug and has sufficient runtime and upgrade evidence; no actionable findings remain.

Reviewed head: 08c8adeba8854abde7a6865f5139a34bfecad729

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Gateway CLI resolves config and launch overrides, while its run loop closes the previous server, reacquires state custody, and starts the next listener.

flowchart TD
  A[Saved Gateway config] --> C[CLI port resolution]
  B[Launch overrides] --> C
  C --> D[Restart recovery]
  D --> E[State custody]
  E --> F[Gateway listener]
  D --> G[Startup failure recovery]
Loading

Technical review

Best possible solution:

Land the focused port-refresh repair while preserving launch overrides, shared custody, and existing startup recovery.

Do we have a high-confidence way to reproduce the issue?

Current-main source retains the captured startup port, matching the linked issue's real CLI reproduction; no target code was executed during this read-only review.

Is this the best way to solve the issue?

The repair keeps port selection in the CLI, passes one refreshed snapshot into startup, and reuses the existing recovery owner without a parallel lifecycle path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 360e306f454f.

Provenance checked

  • Unmanaged in-process restart keeps the original intent (fix(gateway): keep unmanaged restarts in-process #83138: Preserve PID tracking by avoiding detached replacement children during ordinary unmanaged restarts.)
  • Startup failure recovery keeps the original intent (b85fac0: Keep unmanaged Gateways alive for manual recovery when automatic triage declines or fails.)
  • Startup snapshot reader relocation keeps the original intent (edf6c4d: Reuse admitted startup plugin metadata and migration facts rather than performing redundant state reads.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit b85fac0 adds src/cli/gateway-cli/run-loop-startup.ts:40 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b85fac0aa84a; files: src/cli/gateway-cli/run-loop-startup.ts)
  • Free Wortley: Raw commit 0ffeebc adds src/cli/gateway-cli/run-loop-startup.ts:41 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0ffeebc9df42; files: src/cli/gateway-cli/run-loop-startup.ts)

PR surface

Source +37, Tests +82, Docs +4. Total +123 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 77 40 +37
Tests 4 152 70 +82
Docs 1 6 2 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 235 112 +123

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +77/-40; tests +152/-70 Production growth includes relocating the unchanged snapshot reader and integrating restart recovery; test growth covers distinct config-default and recovery paths.

Root-cause cluster

Relationship: same_root_cause
Canonical: #206498
Summary: This PR implements the unmanaged in-process port-rebinding repair described by the linked issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-27T08:33:42.799Z sha cadc495 :: needs changes before merge. :: [P2] [P2] Route restart config-read failures through startup recovery
  • reviewed 2026-11-27T09:20:40.138Z sha 08c8ade :: passed. :: none

Reviewed November 27, 2026, 4:53 AM ET / 09:53 UTC (Revision 3).

roboclaw-bot and others added 2 commits November 27, 2026 08:43
Remove the unused extracted type import and preserve the optional test-call boundary before reading its startup snapshot.

Co-authored-by: daniel-lxs <[email protected]>
Route restart config-read failures through the existing startup recovery owner after resetting admission. Keep lock-acquisition failures terminal and cover both automatic and external-signal manual recovery.

Co-authored-by: daniel-lxs <[email protected]>
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review November 27, 2026 09:15
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Nov 27, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 27, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

I verified a real published v2026.11.10 → 08c8adeba8854abde7a6865f5139a34bfecad729 upgrade on CrabBox AWS, then all three restart cases passed with the existing settings, session history and workspace file intact. The earlier recovery finding and its provenance item are already fixed in this head; no additional source change was needed.

Redacted upgrade and restart proof

AWS c7a.2xlarge, 8 vCPU / 15,613 MiB, Linux x64, Node 24.19.0. Wrapper: scripts/crabbox-wrapper.mjs. Run: run_4684c2288c951f5fb0d82138453b2998; lease: cbx_5def5252fb4a. I am posting only sanitized extracts, not the raw infrastructure logs.

I installed [email protected] into an isolated npm prefix, started its real Gateway, created a session through sessions.create, injected a message through chat.inject, and read it back through chat.history. After cleanly stopping that Gateway, I invoked the published old CLI:

openclaw update --yes --json --no-restart --tag <candidate.tgz>
status: ok
before: 2026.11.10-release-6ea542fd97e2-2026-11-24T23-17-47.129Z
after:  2026.11.10-08c8adeba885-2026-11-27T09-23-54.721Z
candidate SHA-256:
74f008e9c82fc25cd458da96fec3f4e5a31cf6bb5827e48b2926f93f4f582745

The version field is unchanged on this branch; the distinct build IDs identify the published release and PR-head code. I built and integrity-checked the installable package using the repository packer. After each restart, gateway probe confirmed the serving build ID equals the candidate, not merely that its files were installed.

Each candidate run started on 19771, then I saved gateway.port=19772. There was no external supervisor; OPENCLAW_NO_RESPAWN=1 pinned the in-process path.

Launch Saved port Ready/healthy after restart Other port closed Actual PID before / after
Config only 19772 19772 19771 26050 / 26050
--port 19771 19772 19771 19772 26624 / 26624
OPENCLAW_GATEWAY_PORT=19771 19772 19771 19772 27178 / 27178

Captured config-only sequence:

09:45:25.740 [gateway] http server listening
09:45:29.889 [reload] config change detected; evaluating reload (gateway.port)
09:45:31.806 [gateway] restart mode: in-process restart (OPENCLAW_NO_RESPAWN)
09:45:35.743 [gateway] http server listening
native runtime PID: 26050 before and after
/readyz: 200 on port 19772; port 19771 closed
UPGRADE_PROOF_PASS
UPGRADE_READINESS_EXIT=0

I asserted the original session ID and entire returned messages array were unchanged after the update and every restart, the workspace marker retained exact bytes, and the existing auth, bind, mode, reload, plugins, agents and logging settings matched their pre-update values. Only the requested port changed. The automatic/manual recovery custody regression cases also passed on AWS: 3/3.

Two harness issues were corrected before the passing run: an obsolete fixture setting and assertions against outdated console wording. The passing run uses HTTP readiness and the actual native-runtime PID; no product assertion was relaxed. The test Gateways were joined and their isolated state removed.

Not verified here: native-supervisor upgrades, other operating systems, live model/channel traffic, or completed full CI.

@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 27, 2026
@daniel-lxs
daniel-lxs merged commit c47c525 into main Nov 27, 2026
237 of 238 checks passed
@daniel-lxs
daniel-lxs deleted the openclaw/gateway-port-rebind-on-restart-b4b6dc branch November 27, 2026 09:58
tideclaw-bot pushed a commit that referenced this pull request Nov 28, 2026
Apply saved gateway.port changes when an unmanaged Gateway restarts in
process. Preserve explicit launch port overrides and startup recovery.

Closes #206498.

(cherry picked from commit c47c525)

Backport adaptation: Keep the release invalid-config reset tests and add the upstream restart-port cases; do not import the unrelated snapshot-retention test absent on this branch. Production startup-config and lock changes are unchanged.

Co-authored-by: RomneyDa <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 28, 2026
…206501)

Apply saved gateway.port changes when an unmanaged Gateway restarts in
process. Preserve explicit launch port overrides and startup recovery.

Closes openclaw#206498.
tideclaw-bot added a commit that referenced this pull request Nov 28, 2026
Adapt upstream #206649 (461f650): apply only the stale export cleanup for release backport #206501.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot pushed a commit that referenced this pull request Nov 30, 2026
Apply saved gateway.port changes when an unmanaged Gateway restarts in
process. Preserve explicit launch port overrides and startup recovery.

Closes #206498.

(cherry picked from commit c47c525)

Follow-up audit: 974d792 update status, 516166c rejected argument exits, 2fca213 debug capture, 9f63c3c restart blockers, e2fcd4d update readiness receipts, af76d15 fixture pruning, and 461f650 startup export guards are independent of overriding the saved in-process restart port.

Release adaptation: Keep stable invalid-config reset tests; add only the restart-port cases and omit the unrelated selected-snapshot collection test.

Co-authored-by: RomneyDa <[email protected]>
tideclaw-bot added a commit that referenced this pull request Nov 30, 2026
The Z.AI catalog, #208041 subagent stop, #206501 Gateway restart, #203923 backup inventory, #208414 Docker TLS, and reconnect chat-admission backports left six files unformatted after adapting them to stable. Apply the pinned repository formatter without changing behavior.

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime impact:other This issue has meaningful maintainer-visible impact outside the owned taxonomy. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unmanaged Gateway keeps its old port after a config-triggered restart

2 participants