Skip to content

improve: avoid unnecessary Windows startup subprocesses - #149257

Merged
steipete merged 4 commits into
mainfrom
codex/gateway-windows-startup-native
Sep 16, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/gateway-windows-startup-native

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Related: #124407

What Problem This Solves

Windows Gateway startup launches subprocesses for Program Files discovery, console-code-page lookup, and process creation-time lookup even when the common path can avoid them.

User Impact

Startup avoids unnecessary Program Files queries, avoids legacy-code-page discovery for UTF-8/BOM output from runExec, and uses a native Windows process-time lookup when available. Existing fallback behavior remains available. There are no new settings, dependencies, state migrations, or operator actions.

In six established-state pairs on Windows using base 38c4aa42, median readiness improved from 6.84 s to 6.50 s (338 ms, 4.9%). The candidate was faster in four of six pairs; the remaining variation matters. This is a measured incremental improvement, and startup remains above five seconds. The rebase preserves the complete patch byte-for-byte; absolute timing on the newer main composition has not yet been measured.

Why This Change Was Made

Keep discovery lazy in its existing owners and reuse the installed Koffi binding for a limited-query Windows process handle. Native failures retain the existing shell fallback and total deadline. Sealed updater helpers retain shell lookup without loading native modules from the installation being replaced.

The ordinary command runner and raw-output runner retain their pre-spawn encoding snapshot. Review caught a regression where a child changing the console code page caused legacy output to decode incorrectly; this repair restores that contract while retaining runExec's lazy decoding.

Evidence

  • The original optimization passed 150 focused Windows tests, including a real kernel timestamp comparison with shell fallback blocked. The kernel regression fails on the original implementation.
  • The encoding regression reproduced before the repair and passes afterward. Final focused formatting and type-aware lint pass; the three execution/decoder test files pass 118 tests with 11 platform skips. Nine inherited UTF-8 fixture failures reproduced on the base: three fixture groups now use the existing UTF-8 runner, preserving every test row and assertion.
  • Fresh P0–P2 automatic review of the complete repaired candidate completed with no actionable findings.
  • The original baseline and repaired candidate completed full builds and normal Windows package installation/rebuild with identical dependency locks. The repaired emitted/package sealed helper is byte-identical to the artifact that passed the existing dependency-blocked process-identity proof.
  • In the isolated published-driver upgrade cell, candidate migration rehearsal, Doctor lint, config validation, plugin resolution, migration continuation and Gateway canary all passed. The published 2026.9.4 driver then hit its existing 30-second package-fingerprint limit before activation. That limit is already fixed on main (fix(update): preserve full package fingerprints on slow disks #144925, fix(update): derive update budgets from measured state instead of fixed literals #145219), but this cell does not prove managed handoff or the complete upgrade. The original Gateway kept serving; test service removal, process exit, free port and unchanged default service were verified afterward.
  • The complete fixed 14-launch cohort passed HTTP health/readiness, first WebSocket status, acknowledged SIGINT and exit zero. First-status median improved from 6.91 s to 6.57 s. All installation/harness hashes matched afterward. Six paired readiness savings were +720, +77, +539, -103, +617 and -243 ms; paired median saving was 308 ms. Fixed-order fresh launches were 29.81 s and 8.25 s, reported separately without attributing that difference to this patch. Earlier incomplete attempts remain preserved.
  • Exact-head CI run 35007733455 includes the canonical fixture fixes from fix: PR workflow tests fail during repository identity checks #149294 and fix: keep Codex model attribution fixture focused #149301. Windows job 104512311734 has two 120-second timeouts in test/scripts/vitest-worker-artifacts.test.ts: the compiled TUI provider-hook case and the stale-dist/build-error case. The shared repair is published in fix(test): repair Windows compiled worker fixture setup #149403; its complete Windows file passed 29 tests with the same five skips and unchanged deadlines. That repair merged as 027f2082747b and is included in current head acf083ac9935. Exact-head CI35052516068 passed, with all 140 jobs successful or skipped and both Windows jobs successful. The previously failing stale-dist case passed in 41.9 seconds under its unchanged 120-second deadline. The entire nine-file PR patch is byte-identical across this refresh. Earlier performance measurements remain bound to their original baseline; current-main combined startup performance is not yet measured. No retries, deadline increases, or weaker assertions were used to hide these failures.

Update behavior: stored state and migration flow are unchanged. The standalone managed-service handoff retains its existing shell lookup, with dependency-blocked operation proof. The published-driver activation limitation above is outside this patch; no timeout, integrity check, or installed driver was changed to obtain a passing result.

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 15, 2026 16:09
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@steipete steipete self-assigned this Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 4:54 PM ET / 20:54 UTC (Revision 6).

ClawSweeper review

What this changes

Reduces Windows startup subprocesses by deferring directory and encoding probes and reading process creation times through the existing native binding, while preserving shell fallbacks.

Merge readiness

⛔ Blocked before merge - 2 items remain

This remains a useful, bounded optimization absent from current main. No actionable patch findings remain, and the prior encoding regression is repaired. The maintainer-owned PR should remain open through the normal CI and landing workflow.

Priority: P2
Reviewed head: 6c6abf079508efa99f2f364b99142673a3036bf4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with meaningful Windows observations and no remaining actionable code findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded real Windows kernel comparison, sealed-helper isolation, and Gateway readiness/status/shutdown runs exercise the changed identity and startup paths with observed after-fix results; the incomplete upgrade cell is expressly not counted as successful handoff proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded real Windows kernel comparison, sealed-helper isolation, and Gateway readiness/status/shutdown runs exercise the changed identity and startup paths with observed after-fix results; the incomplete upgrade cell is expressly not counted as successful handoff proof.
Evidence reviewed 9 items Pinned scope and repository policy: Verified the repository remote and clean checkout. Read root AGENTS.md fully; no additional ancestor AGENTS.md applies to the changed paths, and .agents/maintainer-notes is absent. The host pins the introduced delta from d363685 to the reviewed head.
Optimization remains absent from main: Fetched main still invokes PowerShell before WMIC for process creation time and eagerly resolves all install roots. The PR retains distinct useful work.
Latest-release comparison: The v2026.9.4 source also uses shell-based process identity lookup. The release file was inspected through the GitHub contents API after its local blob was unavailable.
Findings None None.
Security None None.

How this fits together

Windows startup helpers locate system tools, decode subprocess output, and identify processes for lock ownership. Gateway startup and command execution consume these results.

flowchart TD
  A[Gateway startup and commands] --> B[Windows runtime helpers]
  B --> C[Lazy directory discovery]
  B --> D[Output encoding detection]
  B --> E[Native process identity query]
  E --> F[Shell fallback when needed]
  C --> G[Tool paths and decoded results]
  D --> G
  E --> H[Fresh process identity]
  F --> H
Loading

Before merge

  • Resolve merge risk (P1) - Absolute startup timings were measured on the earlier composition; the newer main composition has not been benchmarked.
  • Resolve merge risk (P1) - The published-driver upgrade cell stopped before activation at the installed driver's fingerprint limit, so it does not establish complete managed handoff.
Agent review details

Security

None.

PR surface

Source +92, Tests +298. Total +390 across 9 files.

View PR surface stats
Area Files Added Removed Net
Source 3 125 33 +92
Tests 6 319 21 +298
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 444 54 +390

Review metrics

Metric Value Why it matters
Production versus test growth production net +92 lines; tests net +298 lines Production growth implements native lookup and deferred discovery; tests cover fallback, identity, decoding, and cache contracts.
Recorded paired startup measurements 6 established-state pairs; 308 ms median paired saving Four pairs improved and two regressed, supporting an incremental benefit rather than a universal latency guarantee.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep discovery lazy within the existing owners while preserving fresh process identities, legacy decoding, and installation-independent sealed helpers.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep discovery lazy within the existing owners while preserving fresh process identities, legacy decoding, and installation-independent sealed helpers.

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

Not applicable as a discrete bug report: this is a performance optimization, supported by current-source probe paths and recorded Windows comparisons; no code was executed during this read-only review.

Is this the best way to solve the issue?

Yes. The patch optimizes existing owners, reuses an installed dependency, and preserves the ordinary runner's encoding snapshot and native-failure fallbacks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2a8c98a737a7.

Labels

Label justifications:

  • P2: A measured Windows startup improvement with limited scope warrants normal priority.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): Recorded real Windows kernel comparison, sealed-helper isolation, and Gateway readiness/status/shutdown runs exercise the changed identity and startup paths with observed after-fix results; the incomplete upgrade cell is expressly not counted as successful handoff proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded real Windows kernel comparison, sealed-helper isolation, and Gateway readiness/status/shutdown runs exercise the changed identity and startup paths with observed after-fix results; the incomplete upgrade cell is expressly not counted as successful handoff proof.

Evidence

What I checked:

  • Pinned scope and repository policy: Verified the repository remote and clean checkout. Read root AGENTS.md fully; no additional ancestor AGENTS.md applies to the changed paths, and .agents/maintainer-notes is absent. The host pins the introduced delta from d363685 to the reviewed head. (AGENTS.md:1, 6c6abf079508)
  • Optimization remains absent from main: Fetched main still invokes PowerShell before WMIC for process creation time and eagerly resolves all install roots. The PR retains distinct useful work. (src/infra/windows-process-start.ts:81, 2a8c98a737a7)
  • Latest-release comparison: The v2026.9.4 source also uses shell-based process identity lookup. The release file was inspected through the GitHub contents API after its local blob was unavailable. (src/infra/windows-process-start.ts:81, 3a9d69db306c)
  • Native identity and fallback preservation: The native reader opens a limited-query handle for each PID, closes it in finally, preserves millisecond timestamp representation, and falls back within the remaining deadline. Sealed builds skip native loading; the existing managed-handoff build configuration defines that marker. (src/infra/windows-process-start.ts:13, 6c6abf079508)
  • Prior encoding finding resolved: The introduced delta leaves exec-runner.ts unchanged. Its encoding snapshot remains before spawning, and new raw/ordinary-runner regression cases exercise a child changing the console page. runExec retains its existing post-completion decoding contract while letting the shared decoder skip probes for UTF-8 and BOM output. (src/process/exec.windows.test.ts:714, 6c6abf079508)
  • Native binding contract: The direct Koffi import in windows-process-start.ts establishes the dependency signal. npm metadata verifies Koromix/koffi ownership for version 3.2.1; its packaged documentation supports BigInt pointers, synchronous output buffers, and __stdcall prototypes. No Codex dependency signal applies.

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: 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 (5 earlier review cycles)
  • reviewed 2026-09-15T16:16:42.575Z sha 60a9947 :: blocked before merge. :: none
  • reviewed 2026-09-15T16:41:21.686Z sha b647fca :: blocked before merge. :: [P2] Preserve the encoding snapshot for ordinary command results
  • reviewed 2026-09-15T18:20:44.117Z sha 140896f30baeb8eaac7fa93eaf9106aff6eedde1 :: blocked before merge. :: none
  • reviewed 2026-09-15T18:45:33.569Z sha 6c6abf0 :: blocked before merge. :: none
  • reviewed 2026-09-15T19:22:37.764Z sha 6c6abf0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 15, 2026
@steipete
steipete force-pushed the codex/gateway-windows-startup-native branch from 140896f to 6c6abf0 Compare September 15, 2026 18:28
@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 15, 2026
@steipete
steipete merged commit baa836b into main Sep 16, 2026
204 checks passed
@steipete
steipete deleted the codex/gateway-windows-startup-native branch September 16, 2026 04:10
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 16, 2026
)

* improve: avoid unnecessary Windows startup subprocesses

* test: fix Windows process identity lint findings

* fix: preserve Windows command encoding snapshots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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: 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.

1 participant