Skip to content

Commit 318d12c

Browse files
committed
fix: keep device approval guidance request-bound
1 parent 8146598 commit 318d12c

7 files changed

Lines changed: 46 additions & 28 deletions

File tree

src/OpenClaw.Connection/GatewayConnectionManager.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,6 @@ tunnel.SshPort is < 1 or > 65535 ||
298298
if (Interlocked.Read(ref _generation) != gen) return;
299299
_ = HandleNodePairListUpdatedAsync(list, gen);
300300
};
301-
lifecycle.DataClient.DevicePairListUpdated += (s, list) =>
302-
{
303-
if (Interlocked.Read(ref _generation) != gen) return;
304-
_ = HandleDevicePairListUpdatedAsync(list, gen);
305-
};
306301
lifecycle.DataClient.V2SignatureFallback += (s, _) =>
307302
{
308303
if (Interlocked.Read(ref _generation) != gen) return;
@@ -1468,11 +1463,6 @@ private Task HandleNodePairListUpdatedAsync(PairingListInfo list, long gen)
14681463
return Task.CompletedTask;
14691464
}
14701465

1471-
private async Task HandleDevicePairListUpdatedAsync(DevicePairingListInfo list, long gen)
1472-
{
1473-
await Task.CompletedTask;
1474-
}
1475-
14761466
// Auto-approve only explicitly typed device-pair role upgrades. Gateway-owned
14771467
// node command trust always remains pending for explicit operator approval.
14781468
// _devicePairAutoApproveInFlight is a CAS guard scoped to JUST the approve RPC —

src/OpenClaw.Shared/Models.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,11 +1243,30 @@ public static string BuildNodeApprovalRepairCommand(string? pendingRequestId)
12431243
: "openclaw nodes pending";
12441244
}
12451245

1246+
public static string BuildDeviceApprovalRepairCommand(string? pendingRequestId)
1247+
{
1248+
return TryBuildPairingApprovalCommand(
1249+
pendingRequestId,
1250+
"openclaw devices approve",
1251+
out var approvalCommand)
1252+
? approvalCommand
1253+
: "openclaw devices list";
1254+
}
1255+
12461256
public static string BuildUnknownPairingDiscoveryCommands() =>
12471257
string.Join(Environment.NewLine, "openclaw nodes pending", "openclaw devices list");
12481258

12491259
public static bool TryBuildNodeApprovalCommand(
12501260
string? pendingRequestId,
1261+
out string approvalCommand) =>
1262+
TryBuildPairingApprovalCommand(
1263+
pendingRequestId,
1264+
"openclaw nodes approve",
1265+
out approvalCommand);
1266+
1267+
private static bool TryBuildPairingApprovalCommand(
1268+
string? pendingRequestId,
1269+
string commandPrefix,
12511270
out string approvalCommand)
12521271
{
12531272
var requestId = pendingRequestId?.Trim();
@@ -1262,7 +1281,7 @@ public static bool TryBuildNodeApprovalCommand(
12621281
return false;
12631282
}
12641283

1265-
approvalCommand = $"openclaw nodes approve {requestId}";
1284+
approvalCommand = $"{commandPrefix} {requestId}";
12661285
return true;
12671286
}
12681287

src/OpenClaw.Tray.WinUI/Pages/ConnectionPagePlan.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,7 @@ _ when CountEnabledCapabilities(settings) == 0 => NodeCardState.OnPermissionsInc
633633
// Windows-cmd users.
634634
if (snap.NodePairingApprovalKind == PairingApprovalKind.DevicePair)
635635
{
636-
var deviceId = !string.IsNullOrEmpty(snap.NodeDeviceId)
637-
? ConnectionCardPlanSanitizer.Sanitize(snap.NodeDeviceId!, maxLen: 128)
638-
: null;
639-
return reqId != null
640-
? $"openclaw devices approve {reqId}"
641-
: deviceId != null
642-
? $"openclaw devices approve {deviceId}"
643-
: "openclaw devices list";
636+
return CommandCenterDiagnostics.BuildDeviceApprovalRepairCommand(reqId);
644637
}
645638

646639
if (snap.NodePairingApprovalKind == PairingApprovalKind.NodePair)

src/OpenClaw.Tray.WinUI/Services/CommandCenterStateBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ node.ApprovalState is GatewayNodeApprovalState.PendingApproval or
6767
{
6868
var approvalCommand = _snapshot.NodePairingApprovalKind switch
6969
{
70-
PairingApprovalKind.DevicePair => $"openclaw devices approve {_snapshot.NodeService.FullDeviceId}",
70+
PairingApprovalKind.DevicePair => CommandCenterDiagnostics.BuildDeviceApprovalRepairCommand(
71+
_snapshot.NodePairingRequestId),
7172
PairingApprovalKind.NodePair => CommandCenterDiagnostics.BuildNodeApprovalRepairCommand(_snapshot.NodePairingRequestId),
7273
_ => CommandCenterDiagnostics.BuildUnknownPairingDiscoveryCommands()
7374
};

tests/OpenClaw.Shared.Tests/ModelsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,20 @@ public void BuildNodeApprovalRepairCommand_ValidatesRequestId(
14051405
Assert.Equal(expected, CommandCenterDiagnostics.BuildNodeApprovalRepairCommand(requestId));
14061406
}
14071407

1408+
[Theory]
1409+
[InlineData("request-123", "openclaw devices approve request-123")]
1410+
[InlineData(" request:123 ", "openclaw devices approve request:123")]
1411+
[InlineData(null, "openclaw devices list")]
1412+
[InlineData("", "openclaw devices list")]
1413+
[InlineData("request-1;whoami", "openclaw devices list")]
1414+
[InlineData("<requestId>", "openclaw devices list")]
1415+
public void BuildDeviceApprovalRepairCommand_ValidatesRequestId(
1416+
string? requestId,
1417+
string expected)
1418+
{
1419+
Assert.Equal(expected, CommandCenterDiagnostics.BuildDeviceApprovalRepairCommand(requestId));
1420+
}
1421+
14081422
[Fact]
14091423
public void BuildUnknownPairingDiscoveryCommands_IncludesBothApprovalQueues()
14101424
{

tests/OpenClaw.Tray.Tests/ConnectionPageApproveCommandTests.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,14 @@ public void UnknownNodePairingKind_UsesBothDiscoveryQueuesEvenWithRequestId()
5454
}
5555

5656
[Theory]
57-
[InlineData(PairingApprovalKind.DevicePair, null, "openclaw devices list")]
58-
[InlineData(PairingApprovalKind.DevicePair, "node-device-789", "openclaw devices approve node-device-789")]
59-
public void MissingDevicePairRequestId_EmitsShellSafeDiscoveryCommand_NotBareApprove(
60-
PairingApprovalKind approvalKind,
61-
string? nodeDeviceId,
62-
string expected)
57+
[InlineData(null)]
58+
[InlineData("node-device-789")]
59+
public void MissingDevicePairRequestId_EmitsDiscoveryCommand_NotDeviceId(
60+
string? nodeDeviceId)
6361
{
64-
var plan = BuildNodePairingPlan(null, approvalKind, nodeDeviceId);
62+
var plan = BuildNodePairingPlan(null, PairingApprovalKind.DevicePair, nodeDeviceId);
6563

66-
AssertShellSafeCommand(expected, plan.NodeApproveCommand);
64+
AssertShellSafeCommand("openclaw devices list", plan.NodeApproveCommand);
6765
}
6866

6967
[Fact]

tests/OpenClaw.Tray.Tests/ConnectionPageNodeApprovalSourceTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public void CommandCenterFallback_ProjectsLocalDeclarationsAsUnverified()
2121
Assert.Contains("!hasAuthoritativePendingLocalNodeTrust;", builderSource);
2222
Assert.Contains("if (shouldShowPendingLocalNodeApproval &&", builderSource);
2323
Assert.Contains("_snapshot.NodePairingApprovalKind switch", builderSource);
24+
Assert.Contains(
25+
"PairingApprovalKind.DevicePair => CommandCenterDiagnostics.BuildDeviceApprovalRepairCommand(",
26+
builderSource);
2427
Assert.Contains(
2528
"PairingApprovalKind.NodePair => CommandCenterDiagnostics.BuildNodeApprovalRepairCommand(_snapshot.NodePairingRequestId)",
2629
builderSource);

0 commit comments

Comments
 (0)