improve: restore terminal state and standardize the OpenClaw runtime environment - #43
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 4:01 PM ET / 20:01 UTC (Revision 20). ClawSweeper reviewWhat this changesAdds reusable Windows console restoration and runtime-environment helpers, twelve unit tests, and test-scoped analyzer exceptions, with production integration deferred to later stack layers. Merge readiness✅ Ready for maintainer review This remains useful stack groundwork that is absent from main. No blocking introduced defect was found; the current head also has an approving collaborator review. Likely related people: paulcam206 and anna-dingler, as launcher-area routing candidates. Priority: P2 Review scores
Verification
How this fits togetherThe Windows package launcher starts the bundled OpenClaw runtime. These helpers prepare child-process environment values and capture and restore the caller’s console state; this layer does not yet connect them to launcher execution. flowchart TD
A[Caller environment] --> B[Runtime environment helper]
C[Interactive or detached context] --> B
B --> D[Child environment values]
E[Windows console state] --> F[Console capture helper]
F --> G[UTF-8 initialization]
G --> H[Dispose and restore console]
Before mergeNone. Agent review detailsSecurityNone. Review metrics
Technical reviewBest possible solution: Keep one shared console and environment contract, with its production callers introduced and validated in the dependent stack layers. Do we have a high-confidence way to reproduce the issue? Not applicable to a blocking patch defect: none was identified. The proposed helpers are not called by production in this layer, and Windows runtime behavior was not executed during this review. Is this the best way to solve the issue? Yes, as a preparatory stack layer: the helpers provide a focused reusable boundary, preserve explicit environment values, and leave activation to the linked integration work. AGENTS.md: not found in the target repository. Codex review notes: model internal, reasoning medium; reviewed against 685ee93b7ebb. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (19 earlier review cycles; latest 8 shown)
|
a14611b to
8370f04
Compare
8370f04 to
bb24b18
Compare
bb24b18 to
b59630f
Compare
b59630f to
e00315a
Compare
| _native.GetConsoleMode(_vtOutput, out uint current); | ||
| _native.SetConsoleMode( | ||
| _vtOutput, | ||
| current | EnableVirtualTerminalProcessing); |
There was a problem hiding this comment.
[Linus's bot] Could we also enable ENABLE_PROCESSED_OUTPUT alongside ENABLE_VIRTUAL_TERMINAL_PROCESSING before writing the cleanup escape sequence? Microsoft's SetConsoleMode docs explicitly say: "Ensure ENABLE_PROCESSED_OUTPUT is set when using this flag."
Normal consoles already have it enabled; setting both here would cover a child clearing it before exit. Small defensive hardening suggestion, not a blocker.
e00315a to
72fb92c
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 97c31f3f-0c7b-43e8-b979-6418dcb7fedc
72fb92c to
5a879fc
Compare
| private static void AddDefault( | ||
| Dictionary<string, string> environment, | ||
| string name, | ||
| string? currentValue, |
There was a problem hiding this comment.
nit: Is it intentional that we aren't applying the currentValue if its present? I see if the logic above that we only apply our default values after currentValue has been applied and perf == 1. Maybe a comment about the conditional would add clarity, or combining the AddIfPresent and AddDefault methods
| } | ||
| catch (Exception exception) when (exception is IOException or | ||
| InvalidOperationException or System.ComponentModel.Win32Exception) | ||
| { |
There was a problem hiding this comment.
Should we be handling/logging the errors here?
| } | ||
| } | ||
|
|
||
| private static class Native |
There was a problem hiding this comment.
nit: In case we have more imports later, it could make sense to put this class in its own file.
What Problem This Solves
Windows console state can be left altered after a child process runs, and launcher environment decisions were scattered. That makes terminal behavior inconsistent before the isolated-session work has a stable host foundation.
User Impact
Terminal users get console mode and encoding restored around child execution, plus consistent color and interactivity decisions. This is independently useful host behavior; it does not create or route an isolated session yet.
Why This Change Was Made
WindowsHostConsolecaptures and restores the Windows console mode and encoding around a child process so the launcher does not leak its terminal changes back to the caller.OpenClawRuntimeEnvironmentcentralizes theFORCE_COLOR,WT_SESSION, andNO_COLORrules and interactive detection. Later layers can build on one environment contract instead of duplicating terminal heuristics.The stack’s end goal is an owned isolated Windows agent session that can run
openclaw, an interactive PowerShell entry point, a supervised gateway, sign-in recovery, redacted diagnostics, safe teardown, and runnable local deployment. This layer deliberately remains the smallest independently useful slice: it establishes stable host behavior without introducing MXC, session state, or a new account/profile.Review fixes addressed
Review found no blocking defect. This revision also tolerates UTF-8 encoding initialization when console handles are redirected; the attached MXC integration in #44 initializes UTF-8 inside the existing capture/restore lifetime.
Current validation
Current layer head:
5a879fca143aed40e0e847dff21cae515a50aefa. This layer is included in the final integrated stack tipcce2b02f3acd5791654b7a6b1a5a9c27db5ff63brebased onto685ee93b7ebbec1e784205a3544c460bea740e11.Integrated local gates: exact .NET SDK 10.0.100;
Test-DotNetQuality.ps1with 0 warnings/errors; full solution tests 642/642; NativeAOT x64 and ARM64 publishes for both launcher and session host; NativeAOT CLI, deployment, MXC, signing, runtime-input, release-identity, bundle, isolation-plugin, and packaging-relevance policy suites.Live x64 MXC evidence: final-tip Developer Mode deployment registered
OpenClaw.Gateway_0.1.2451.40134_x64__kaa03rpbbqef6from workflow payload run 35191206689;openclaw --versionreturnedOpenClaw 2026.9.4 (3a9d69d);clawctl statusconfirmed the isolated session was running. Earlier final-tip validation also exercised setup, Node.js 24.20.0 reuse, package-qualified activation, detached gateway launch, and redacted diagnostics collection.Signed package evidence: local NativeAOT x64 and ARM64 packages and a multi-architecture bundle were composed and test-signed. Elevated upgrade validation passed all four proof-release transitions (
v0.0.0.0andv0.0.0.1, standalone and bundle), retained package-family LocalState in every transition, and accepted fresh standalone and bundle installs. The temporary certificate and test package were removed, then the Developer Mode registration was restored.Layer 1 of 12. Parent: main