Skip to content

fix(cli): preserve foreground Gateway argument handling - #138765

Merged
steipete merged 1 commit into
mainfrom
codex/stable-review-respawn-cleanup-20260904
Sep 5, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stable-review-respawn-cleanup-20260904

Conversation

@steipete

@steipete steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Closes #138762

Additional instructions

Allow edits from maintainers is to remain enabled when this PR is created.

What Problem This Solves

Fixes an issue where users running a foreground Gateway with --ambient-channels or its deprecated alias would get an unnecessary respawn parent. It also fixes existing argument failures where --verbose --no-color or trailing --log-level were rejected before Gateway startup validation.

The first local candidate exposed the reduced parser's existing no-color defect for ambient flags. Managed review caught that P2 before publication; this version fixes the shared owner rather than excluding the new cases from the fast path.

Why This Change Was Made

Foreground detection now uses the canonical Gateway flag table instead of duplicate lists. The reduced parser reuses existing metadata-aware no-color normalization, and fast-path root-option admission is consistent before and after gateway. Log-level validation and logging preactions remain with the full parser that owns them.

Production 27 additions/48 deletions: net -21. Tests 70 additions/4 deletions: net +66. No new CLI options, config/environment surfaces, persistence changes, timeout changes or compatibility paths. Windows containment and the separate managed-service handoff lifecycle repair are not included.

User Impact

The two documented ambient-channel flags preserve foreground process ownership. Global no-color and log-level options work with the applicable Gateway arguments, without weakening invalid-option or invalid-log-level validation. Required flag-looking token values remain intact.

Evidence

Fresh Node 24.20.0/pnpm 12.1.0 installs and supported dist-backed runtime builds were compared against d329e6144965561c88cad197380def7b12eb6beb on macOS 27.0.

Actual check Baseline / first candidate Final candidate
Ambient primary and alias Two process starts: launcher+respawn child One process start each
Ambient flag followed by no-color Baseline reaches port validation; first candidate rejects no-color Reaches port validation
Existing verbose followed by no-color Unknown no-color option Reaches port validation
Trailing valid log-level Unknown log-level option Reaches port validation, as the prefix form does
Invalid log-level Existing validator retained Specific invalid-log-level error
Required token value --no-color Existing value contract retained Reaches port validation

Supported build/CLI commands included:

node scripts/run-node.mjs gateway run --ambient-channels --no-color --port 0
node openclaw.mjs gateway run --ambient-channels --port 0
node openclaw.mjs gateway run --dev-ambient-channels --port 0
node openclaw.mjs gateway run --dev-ambient-channels --no-color --port 0
node openclaw.mjs gateway run --verbose --no-color --port 0
node openclaw.mjs gateway run --log-level debug --port 0
node openclaw.mjs --log-level debug gateway run --port 0
node openclaw.mjs gateway run --log-level=loud --port 0
node openclaw.mjs gateway run --token --no-color --port 0

A passive main-thread process-start observer supplied with Node --require captured the process comparisons; it did not mock spawning. Every command used private HOME/state/config/TMP. Valid argument cases intentionally ended with:

Invalid --port. Use a port number from 1 to 65535, for example 18789.

Invalid log-level retained its dedicated validation error:

OpenClaw could not parse this command: option '--log-level <level>' argument 'loud' is invalid. Invalid --log-level (use silent|fatal|error|warn|info|debug|trace)
Try: openclaw --help

These are normal expected exit 1 outcomes, not Gateway-start success; no operator Gateway/listener or Windows VM was launched.

The entry regression failed 3 intended cases before repair. The real runCli+Commander+Gateway-registration regression failed 3 intended parse-exit cases before normalization repair and passed afterward. 696 tests passed across 10 focused files, with no skips. Existing value/terminator, option-collision, exit/profile and log-level coverage remained intact. The canonical 29-check changed gate passed in 397.25s (25 printed subprocess commands plus 4 internally run check stages), including formatting, core/test types, lint and required guards. Final managed P0–P2 review passed both partitions with no actionable findings; complete integration context was retained in both.

The first review's P2 and all red receipts remain retained. A baseline setup attempt initially failed because a root-only dependency symlink missed plugin-local workspace dependencies; a fresh authorized frozen install resolved that setup issue. Earlier source-entry observations are not used as the supported dist-backed proof. No successful Gateway boot, Windows execution or native containment proof is claimed.

@clawsweeper

clawsweeper Bot commented Sep 5, 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 cli CLI command changes size: S maintainer Maintainer-authored PR labels Sep 5, 2026
@steipete
steipete marked this pull request as ready for review September 5, 2026 01:39
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 5, 2026
@clawsweeper

clawsweeper Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 10:00 PM ET / September 5, 2026, 02:00 UTC.

ClawSweeper review

What this changes

Shares Gateway flag recognition between startup paths and fixes foreground launches using ambient-channel flags, trailing no-color, or log-level options.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: fetched main still contains the reported failures, and this re-review found no blocking patch defect. The supplied dist-backed CLI evidence directly demonstrates the repaired argument handling and process count.

Priority: P2
Reviewed head: 2b24f0a02fcb94e2d4d90b17f09e4ae5e95e96b3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative repair with relevant before/after CLI evidence and regression coverage; no blocking correctness finding remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied macOS dist-backed CLI comparison exercises the changed respawn and parser owners: both ambient spellings produce one process, valid color/log-level combinations reach intentional port validation, and invalid log levels retain their specific rejection. These observations prove the changed pre-startup behavior without claiming Gateway boot or Windows containment.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The supplied macOS dist-backed CLI comparison exercises the changed respawn and parser owners: both ambient spellings produce one process, valid color/log-level combinations reach intentional port validation, and invalid log levels retain their specific rejection. These observations prove the changed pre-startup behavior without claiming Gateway boot or Windows containment.
Evidence reviewed 12 items Verified patch boundary: The checkout matches the pinned original head. The test merge records the pinned base followed by that exact head, and its base-relative delta contains only the five introduced files; unrelated endpoint drift is not attributed to this PR.
Current main still needs the repair: Main's separate respawn flag list omits both ambient-channel spellings. Its reduced-parser selector still admits trailing log-level, while the reduced parser lacks that option and parses without the metadata-aware no-color normalization.
Foreground process owner: The shared Gateway flag table now feeds foreground detection used by both respawn policies. The entrypoint calls buildCliRespawnPlan, whose early return preserves foreground process ownership; Gmail, interactive commands, status, and native-hook-specific branches remain unchanged.
Findings None None.
Security None None.

How this fits together

The CLI startup layer decides whether to create a replacement process and which argument parser handles a command. For foreground Gateway launches, it passes validated options to the existing server startup owner.

flowchart TD
  A[CLI arguments] --> B[Shared Gateway flag recognition]
  B --> C[Foreground process decision]
  C --> D[Keep Gateway in process]
  B --> E{Root options need full parsing?}
  E -->|No| F[Reduced parser with color normalization]
  E -->|Yes| G[Full parser and logging validation]
  F --> H[Gateway startup validation]
  G --> H
Loading

Before merge

  • Resolve merge risk (P1) - Reviewer-side limitation: pinned Commander 15.0.0 source was unavailable locally and network retrieval failed; direct dependency inspection covered 14.0.3, while version-specific behavior is supported by the supplied dist-backed execution evidence.
Agent review details

Security

None.

PR surface

Source -21, Tests +66. Total +45 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 27 48 -21
Tests 2 70 4 +66
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 97 52 +45

Review metrics

Metric Value Why it matters
Production versus tests Production net -21 lines; tests net +66 lines The repair removes duplicated policy and reuses existing parsing machinery rather than growing production behavior.
Public option surface 0 new options; 2 existing ambient flag spellings recognized This restores handling of documented arguments without adding configuration or changing their runtime defaults.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138762
Summary: This PR is the candidate implementation for the linked open issue; the pair should remain open until the implementation lands.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain one shared Gateway argument policy, reuse metadata-aware color normalization, and keep log-level validation and logging preactions with their existing full-parser owner.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain one shared Gateway argument policy, reuse metadata-aware color normalization, and keep log-level validation and logging preactions with their existing full-parser owner.

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

Yes: the supplied baseline commands and process observations map to unchanged failing paths on fetched main. This review established the mechanism from source rather than executing the CLI.

Is this the best way to solve the issue?

Yes: the patch repairs the shared argument owner and reuses existing normalization instead of duplicating flag lists or adding log-level handling to the reduced parser.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d8262bf1500b.

Labels

Label justifications:

  • P2: The fix addresses bounded foreground Gateway argument failures and unnecessary process wrapping without evidence of data loss or a core-runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The supplied macOS dist-backed CLI comparison exercises the changed respawn and parser owners: both ambient spellings produce one process, valid color/log-level combinations reach intentional port validation, and invalid log levels retain their specific rejection. These observations prove the changed pre-startup behavior without claiming Gateway boot or Windows containment.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied macOS dist-backed CLI comparison exercises the changed respawn and parser owners: both ambient spellings produce one process, valid color/log-level combinations reach intentional port validation, and invalid log levels retain their specific rejection. These observations prove the changed pre-startup behavior without claiming Gateway boot or Windows containment.

Evidence

What I checked:

  • Verified patch boundary: The checkout matches the pinned original head. The test merge records the pinned base followed by that exact head, and its base-relative delta contains only the five introduced files; unrelated endpoint drift is not attributed to this PR. (3fab34946969)
  • Current main still needs the repair: Main's separate respawn flag list omits both ambient-channel spellings. Its reduced-parser selector still admits trailing log-level, while the reduced parser lacks that option and parses without the metadata-aware no-color normalization. (src/cli/respawn-policy.ts:5, d8262bf1500b)
  • Foreground process owner: The shared Gateway flag table now feeds foreground detection used by both respawn policies. The entrypoint calls buildCliRespawnPlan, whose early return preserves foreground process ownership; Gmail, interactive commands, status, and native-hook-specific branches remain unchanged. (src/cli/gateway-run-argv.ts:36, 2b24f0a02fcb)
  • Canonical parser repair: The reduced parser reuses normalizeRootNoColorArgvForProgram before parsing. Its metadata walk distinguishes boolean options from required values. Log-level instead reaches the existing full parser, its registered validator, and the preaction that applies OPENCLAW_LOG_LEVEL. (src/cli/run-main.ts:255, 2b24f0a02fcb)
  • Existing option and runtime contracts: Both ambient spellings are already registered on the Gateway command and inherited by its run child. The runtime still allows ambient channel triggers only when either explicit option is true; otherwise it suppresses them. The documentation already describes these flags and global no-color/log-level options. (src/cli/gateway-cli/run-command.ts:44, 2b24f0a02fcb)
  • Focused regression coverage: The new parser test exercises real runCli, Commander, and Gateway registration across six parent/child combinations while mocking server execution. Respawn coverage checks three argument forms across three platform selections. Existing sibling tests cover ambient defaults, inheritance, invalid ports, terminators, required values, and log-level validation. Tests were inspected, not executed during this read-only review. (src/cli/run-main.test.ts:32, 2b24f0a02fcb)

Likely related people:

  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-05T01:48:46.558Z sha 2b24f0a :: needs maintainer review before merge. :: none

@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

The remaining reviewer-side dependency gap is resolved by direct inspection of the installed Commander 15.0.0 used for the recorded tests and dist-backed CLI proof. I inspected lib/command.js lines 834–859 (positional option contract), 1562–1698 (subcommand dispatch, unknown options and preactions), and 1760–1920 (parseOptions, required values, terminators and positional dispatch). Its SHA-256 is 751c19479dac3e3f415fbbd709df90d25c595034f699dba7bef6eeab4dc1304b.

The source confirms why the fix keeps log-level validation/preactions in the full parser and applies the existing metadata-aware no-color normalization at the reduced parser boundary. Required values that resemble flags remain values. This supplements—not substitutes for—the supplied actual Commander tests and dist-backed process/argument observations; the review did not reveal a patch defect requiring a different implementation.

Exact-head CI on 2b24f0a02fcb94e2d4d90b17f09e4ae5e95e96b3 is green (run 33936802123, including openclaw/ci-gate). The clean independent managed review, 696 passing tests, and final changed-file gate bind the same candidate. No Gateway startup, Windows containment, or operator-service claim is made. Production delta: −21; tests: +66. The latest ClawSweeper review has no separate Rank-up moves or actionable code findings; its dependency-inspection item is addressed above.

@steipete
steipete merged commit 4311b45 into main Sep 5, 2026
247 checks passed
@steipete
steipete deleted the codex/stable-review-respawn-cleanup-20260904 branch September 5, 2026 02:48
@steipete

steipete commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
vincentkoc added a commit to LiuwqGit/openclaw that referenced this pull request Sep 5, 2026
* refs/remotes/origin/main: (602 commits)
  fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746)
  perf(sqlite): reuse compiled plugin state point reads (openclaw#138758)
  refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793)
  ci: reduce Doctor test startup and core lint jobs (openclaw#138796)
  feat(update): retain run history and share outcome reports (openclaw#138690)
  chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500)
  fix: preserve global board ownership from pinning to notifications (openclaw#138675)
  fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674)
  perf(sessions): index pending conversation replies (openclaw#127182)
  perf(auth): reuse ordered provider alias entries (openclaw#138805)
  docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804)
  perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766)
  fix: allow older source on newer Testbox checkouts (openclaw#138782)
  fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785)
  perf(codex): reduce rollout tail scan CPU (openclaw#138784)
  perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655)
  fix(build): bound native declaration inputs to checkout (openclaw#138742)
  fix(cli): preserve foreground Gateway argument handling (openclaw#138765)
  fix(ui): align task toolbar with side-panel tabs (openclaw#138769)
  fix(logbook): drain accepted work before closing SQLite (openclaw#138754)
  ...

# Conflicts:
#	src/agents/embedded-agent-runner/compact.queued.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

[Bug]: Gateway startup rejects trailing root options and respawns with ambient channels

1 participant