Skip to content

Commit 22fd6e8

Browse files
bkudiessCopilot
andcommitted
docs: define default-on local gateway recovery
Document the macOS-parity supervision contract, persist the default for fresh setup, verify existing settings inherit it, and preserve an explicitly disabled kill switch across setup reruns. Co-authored-by: Copilot App <[email protected]>
1 parent 0e8756b commit 22fd6e8

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

‎docs/CONNECTION_ARCHITECTURE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ On a device-token mismatch, the manager clears **only the rejected role's** devi
210210

211211
For an app-owned setup-managed local WSL gateway (`WslKeepAlivePolicy.IsSetupManagedLocalRecord` — never SSH/remote/ambiguous-localhost), the tray owns process supervision, keeping it out of the connection layer. `ManagedLocalGatewayAutoRepairMonitor` watches the operator connection and, when it is positively transport-unreachable (`GatewayErrorKind.Network`/`Server`, plus a cold-start `Connecting` state with no failure yet; never unknown/auth/pairing/rate-limit/scope/TLS/tunnel/token-drift) for a sustained window, invokes `ManagedLocalGatewayRepairCoordinator`. A typed `LocalPortConflict` is also repairable because its remediation is provenance-gated rather than a blind process restart. The monitor honors a **startup grace** (so a slow WSL cold start is not interrupted), a per-gateway unhealthy threshold and cooldown, a manager-owned explicit disconnect/stop intent, and a settings **kill switch** (`SettingsData.EnableManagedLocalGatewayAutoRepair`, default on).
212212

213+
**Default-on product contract and macOS parity.** App-installed local gateways are supervised by default for both fresh setups and upgrades, matching the macOS local-mode contract where launchd supervision is active unless OpenClaw is paused. Fresh Windows setup writes `EnableManagedLocalGatewayAutoRepair=true` explicitly; an existing settings file that predates the field deserializes to the same default. This enrollment is restricted to records whose setup-managed ownership is positively linked to the installed endpoint. Manual localhost, repointed, SSH, and remote records are never adopted. The user-facing controls are **Disconnect** and **Stop** on the Connection page: either records explicit operator intent and suppresses automatic restart, process remediation, and reconnect until the operator explicitly connects/starts again. An explicitly persisted `false` remains available as a policy/debug kill switch and is never overwritten by setup merge.
214+
213215
`ManagedLocalGatewayRepairCoordinator` **probes before it restarts**: if the gateway is already reachable it just reconnects (the macOS "attach" path); only a genuinely-down gateway triggers a WSL distro restart (via `WslGatewayController`), a keepalive re-arm (`WslGatewayKeepAliveService.TryEnsureAsync`), and a reconnect. For the native-vs-WSL collision case, `ManagedLocalGatewayPortProvenanceService` classifies listeners by address and proves process command line plus scheduled-task/profile lineage. It automatically disables/stops only a fully proven obsolete native OpenClaw gateway; an unknown listener is never killed and produces precise `LocalPortConflict` diagnostics. The shared lifecycle lease serializes that destructive work with manual WSL actions. Reconnect is **gateway-pinned, intent-aware, and cancellable** (`GatewayConnectionManager.ReconnectIfCurrentAsync(gatewayId, ct)`), so gateway switches, explicit Disconnect/Stop, and shutdown always win. Repair is single-flight, verifies success by a real operator connection to the same gateway, is per-gateway restart-budget-bounded, and never reads or logs credentials.
214216

215217
## Client instance lifecycle

‎src/OpenClaw.SetupEngine/SetupContext.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ public IReadOnlyList<string> GetEnabledCommandIds()
209209
public sealed class TraySettingsConfig
210210
{
211211
public bool EnableNodeMode { get; set; } = true;
212+
public bool? EnableManagedLocalGatewayAutoRepair { get; set; }
212213
public bool AutoStart { get; set; } = false;
213214
public bool NodeSystemRunEnabled { get; set; } = true;
214215
public bool NodeCanvasEnabled { get; set; } = true;
@@ -264,6 +265,12 @@ public void MergeIntoSettingsFile(string settingsPath)
264265
foreach (var kvp in setupOwnedSettings)
265266
settings[kvp.Key] = kvp.Value;
266267

268+
const string autoRepairKey = "EnableManagedLocalGatewayAutoRepair";
269+
if (EnableManagedLocalGatewayAutoRepair is { } configuredAutoRepair)
270+
settings[autoRepairKey] = configuredAutoRepair;
271+
else if (!settings.ContainsKey(autoRepairKey))
272+
settings[autoRepairKey] = true;
273+
267274
Directory.CreateDirectory(Path.GetDirectoryName(settingsPath)!);
268275
var json = JsonSerializer.Serialize(settings, SetupConfig.JsonWriteOptions);
269276
AtomicFile.WriteAllText(settingsPath, json);

‎tests/OpenClaw.SetupEngine.Tests/SetupConfigTests.cs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,47 @@ public void TraySettingsConfig_MergesIntoFile_OverwritesSetupKeysAndPreservesUnk
289289

290290
var result = JsonDocument.Parse(File.ReadAllText(settingsPath));
291291
Assert.True(result.RootElement.GetProperty("EnableNodeMode").GetBoolean());
292+
Assert.True(result.RootElement.GetProperty("EnableManagedLocalGatewayAutoRepair").GetBoolean());
292293
Assert.False(result.RootElement.GetProperty("AutoStart").GetBoolean());
293294
Assert.False(result.RootElement.GetProperty("NodeCameraEnabled").GetBoolean());
294295
Assert.Equal("custom_value", result.RootElement.GetProperty("CustomKey").GetString());
295296
}
296297

298+
[Fact]
299+
public void TraySettingsConfig_ExplicitAutoRepairChoice_IsPersistedForFreshSetup()
300+
{
301+
var settingsPath = Path.Combine(_tempDir, "settings.json");
302+
var traySettings = new TraySettingsConfig
303+
{
304+
EnableManagedLocalGatewayAutoRepair = false,
305+
};
306+
307+
traySettings.MergeIntoSettingsFile(settingsPath);
308+
309+
using var result = JsonDocument.Parse(File.ReadAllText(settingsPath));
310+
Assert.False(
311+
result.RootElement
312+
.GetProperty("EnableManagedLocalGatewayAutoRepair")
313+
.GetBoolean());
314+
}
315+
316+
[Fact]
317+
public void TraySettingsConfig_SetupRerun_PreservesExistingAutoRepairKillSwitch()
318+
{
319+
var settingsPath = Path.Combine(_tempDir, "settings.json");
320+
File.WriteAllText(
321+
settingsPath,
322+
"""{"EnableManagedLocalGatewayAutoRepair":false}""");
323+
324+
new TraySettingsConfig().MergeIntoSettingsFile(settingsPath);
325+
326+
using var result = JsonDocument.Parse(File.ReadAllText(settingsPath));
327+
Assert.False(
328+
result.RootElement
329+
.GetProperty("EnableManagedLocalGatewayAutoRepair")
330+
.GetBoolean());
331+
}
332+
297333
[Fact]
298334
public void TraySettingsConfig_ApplyCapabilities_MapsSetupCapabilitiesToRuntimeNodeSettings()
299335
{

‎tests/OpenClaw.Tray.Tests/SettingsRoundTripTests.cs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,30 @@ public void HubNavPaneOpen_DefaultsTrue_ForEmptyJson()
270270
Assert.True(settings!.HubNavPaneOpen);
271271
}
272272

273+
[Fact]
274+
public void ManagedLocalAutoRepair_DefaultsOn_ForExistingSettingsWithoutField()
275+
{
276+
var settings = SettingsData.FromJson(
277+
"""{"SettingsSchemaVersion":1,"EnableNodeMode":true}""");
278+
279+
Assert.NotNull(settings);
280+
Assert.True(settings!.EnableManagedLocalGatewayAutoRepair);
281+
}
282+
283+
[Fact]
284+
public void ManagedLocalAutoRepair_ExplicitFalse_RoundTrips()
285+
{
286+
var original = new SettingsData
287+
{
288+
EnableManagedLocalGatewayAutoRepair = false,
289+
};
290+
291+
var restored = SettingsData.FromJson(original.ToJson());
292+
293+
Assert.NotNull(restored);
294+
Assert.False(restored!.EnableManagedLocalGatewayAutoRepair);
295+
}
296+
273297
[Fact]
274298
public void SettingsManager_PreservesLegacySandboxFallbackDefault()
275299
{

0 commit comments

Comments
 (0)