fix(gateway): include port in lock file payload [AI-assisted]#43752
fix(gateway): include port in lock file payload [AI-assisted]#43752liangmoyuTTC wants to merge 2 commits into
Conversation
Greptile SummaryThis PR fixes a gap where gateways started with
Confidence Score: 4/5
Prompt To Fix All With AIThis is a comment left during a code review.
Path: src/infra/gateway-lock.ts
Line: 211-213
Comment:
**Consider adding port range validation**
`Number.isFinite(port)` accepts `0`, negative values, and values above `65535`, all of which are not valid TCP ports. While the port value presumably comes from CLI validation upstream, adding a range check here would make this defensive guard more precise and prevent misleading values from ever being written to the lock file.
```suggestion
if (typeof port === "number" && Number.isFinite(port) && port > 0 && port <= 65535) {
payload.port = port;
}
```
How can I resolve this? If you propose a fix, please make it concise.Last reviewed commit: fb06fac |
|
Addressed Greptile's suggestion — added port range validation ( |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: current main still lacks gateway lock port persistence, and this PR is dirty against main and misses the current schema-backed parser path. The newer open PR #73338 now tracks the same lock-port contract with the schema/readback pieces plus the active TUI consumer for #42461. So I’m closing this here and keeping the remaining discussion on the canonical linked item. Review detailsBest possible solution: Close this PR as superseded and concentrate maintainer review on #73338. If #73338 does not land, extract its gateway-lock schema, writer, verified active-port reader, focused tests, and contributor credit into a narrow replacement. Do we have a high-confidence way to reproduce the issue? Yes. The source-level reproduction is high confidence: current main forwards Is this the best way to solve the issue? No for this PR as-is. The requested direction is correct, but the branch needs a current-main schema update and has been superseded by #73338, which carries the fuller contract and consumer coverage. Security review: Security review cleared: The PR diff is limited to gateway lock payload code and focused tests, with no CI, dependency, package script, secret handling, downloaded artifact, or command-execution changes. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 58a0b077c1c5. |
Summary
--port <port>, the port override is a CLI argument only and is not persisted to the config file. External tools that scan lock files to discover running gateways cannot determine the actual listening port — they fall back to the config file default (18789), producing incorrect results when multiple gateways run on different ports via--profile.--port, making auto-connection fail.portfield toLockPayload. WhenacquireGatewayLockis called with aportoption (already passed byrunGatewayLoop), the actual listening port is now written into the lock file.readLockPayloadalso reads the field back.portremain valid.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
None — no existing issue tracks this.
User-visible / Behavior Changes
Lock files at
$TMPDIR/openclaw-$UID/gateway.<hash>.locknow include aportfield when the gateway is started with an explicit port. No user-facing config or CLI changes.Security Impact (required)
Repro + Verification
Environment
Steps
openclaw gateway --allow-unconfiguredopenclaw --profile work gateway --allow-unconfigured --port 18790cat $TMPDIR/openclaw-$(id -u)/gateway.*.lockExpected
{"pid":...,"port":18789,...}{"pid":...,"port":18790,...}Actual (before fix)
portfield. External tools default to 18789 for both.Evidence
writes port to lock file when providedandomits port from lock file when not providedHuman Verification (required)
--portvalues, lock file content inspectionCompatibility / Migration
portis optional; old lock files without it are read correctlyFailure Recovery (if this breaks)
src/infra/gateway-lock.tsRisks and Mitigations
None — additive optional field with full backward compatibility.