Skip to content

Commit 7be0688

Browse files
shanselmanCopilot
andcommitted
Fix PR 816 port guards
Preserve non-actionable handling for ambiguous legacy pairing fallback IDs and make the MXC SDK restore target version-stamped so stale node_modules cannot satisfy the 0.7.0 port. Co-authored-by: Copilot <[email protected]>
1 parent 8eebd9c commit 7be0688

3 files changed

Lines changed: 76 additions & 4 deletions

File tree

‎src/OpenClaw.Connection/PairingApprovalQueue.cs‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public sealed class PairingApprovalDelta
4444
/// <item>Filter out the local node's own pairing request (handled by the auto-approve path)
4545
/// so the operator is never prompted to approve their own machine. Matches against any of
4646
/// the node's advertised identifiers (device id and/or gateway node id).</item>
47-
/// <item>Drop entries with no usable id and de-duplicate by <see cref="PendingApproval.Key"/>.</item>
47+
/// <item>Drop entries with no usable id and legacy fallback-id collisions that cannot be
48+
/// approved/rejected unambiguously, then de-duplicate by <see cref="PendingApproval.Key"/>.</item>
4849
/// <item>Treat a submitted approve/reject as <em>optimistic-pending</em> — suppress it from the
4950
/// actionable set, but only report it <see cref="PairingApprovalDelta.ConfirmedDecisions">
5051
/// confirmed</see> once the gateway actually drops it from a provided list for that kind. If
@@ -94,6 +95,10 @@ bool KindProvided(PairingApprovalKind kind) =>
9495
kind == PairingApprovalKind.DevicePair ? devicesProvided : nodesProvided;
9596

9697
var incoming = BuildIncoming(devices, nodes, ownNodeDeviceIds);
98+
var ambiguousFallbackKeys = FindAmbiguousFallbackKeys(incoming);
99+
if (ambiguousFallbackKeys.Count > 0)
100+
incoming = incoming.Where(a => !ambiguousFallbackKeys.Contains(a.Key)).ToList();
101+
97102
var incomingByKey = new Dictionary<string, PendingApproval>(StringComparer.Ordinal);
98103
foreach (var item in incoming)
99104
incomingByKey[item.Key] = item; // last wins on duplicate ids
@@ -104,6 +109,11 @@ bool KindProvided(PairingApprovalKind kind) =>
104109
if (!KindProvided(kv.Value.Kind) && !incomingByKey.ContainsKey(kv.Key))
105110
incomingByKey[kv.Key] = kv.Value;
106111

112+
// If a legacy fallback id becomes ambiguous, cancel any optimistic wait instead of treating
113+
// its absence from the actionable queue as a confirmed gateway decision.
114+
foreach (var key in _submitted.Keys.Where(ambiguousFallbackKeys.Contains).ToArray())
115+
_submitted.Remove(key);
116+
107117
// Confirmed resolutions: decisions we submitted whose request has now left a PROVIDED list.
108118
// This — not the send-ack — is the authoritative "the gateway accepted it" signal.
109119
var confirmed = new List<PairingApprovalResolution>();
@@ -209,6 +219,16 @@ private static List<PendingApproval> BuildIncoming(
209219
return list;
210220
}
211221

222+
private static HashSet<string> FindAmbiguousFallbackKeys(IEnumerable<PendingApproval> incoming)
223+
{
224+
var ambiguous = incoming
225+
.GroupBy(a => a.Key, StringComparer.Ordinal)
226+
.Where(g => g.Count() > 1 && g.Any(a => string.IsNullOrEmpty(a.RequestId)))
227+
.Select(g => g.Key);
228+
229+
return new HashSet<string>(ambiguous, StringComparer.Ordinal);
230+
}
231+
212232
private static bool IsOwnNode(PendingApproval approval, IReadOnlyCollection<string>? ownNodeDeviceIds)
213233
{
214234
if (ownNodeDeviceIds is null || ownNodeDeviceIds.Count == 0) return false;

‎src/OpenClaw.Tray.WinUI/OpenClaw.Tray.WinUI.csproj‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@
8989
<MxcArch Condition="'$(MxcArch)' == '' And '$(PlatformTarget)' == 'ARM64'">arm64</MxcArch>
9090
<MxcArch Condition="'$(MxcArch)' == '' And '$(RuntimeIdentifier)' == ''">x64</MxcArch>
9191
<MxcSdkBinDir>$(OpenClawRepoRoot)node_modules\@microsoft\mxc-sdk\bin\$(MxcArch)\</MxcSdkBinDir>
92+
<MxcSdkExpectedVersion>0.7.0</MxcSdkExpectedVersion>
93+
<MxcSdkPackageJson>$(OpenClawRepoRoot)node_modules\@microsoft\mxc-sdk\package.json</MxcSdkPackageJson>
94+
<MxcSdkRestoreStamp>$(OpenClawRepoRoot)node_modules\.openclaw-mxc-sdk-$(MxcSdkExpectedVersion).stamp</MxcSdkRestoreStamp>
9295
</PropertyGroup>
9396

9497
<!--
@@ -200,9 +203,18 @@
200203
BeforeTargets="Build;Publish;CopyWxcExecToOutput;CopyWxcExecToPublish"
201204
Condition="'$(SkipMxcNodeBridgeRestore)' != 'true' And Exists('$(OpenClawRepoRoot)package-lock.json')"
202205
Inputs="$(OpenClawRepoRoot)package-lock.json"
203-
Outputs="$(OpenClawRepoRoot)node_modules\.package-lock.json">
206+
Outputs="$(MxcSdkRestoreStamp)">
204207
<Message Importance="high" Text="Restoring @microsoft/mxc-sdk to extract wxc-exec.exe ($(MxcArch))" />
205208
<Exec Command="npm ci --no-audit --no-fund" WorkingDirectory="$(OpenClawRepoRoot)" />
209+
<Touch Files="$(MxcSdkRestoreStamp)" AlwaysCreate="true" />
210+
</Target>
211+
212+
<Target Name="ValidateMxcSdkVersion"
213+
BeforeTargets="CopyWxcExecToOutput;CopyWxcExecToPublish"
214+
DependsOnTargets="RestoreMxcNodeBridge"
215+
Condition="'$(SkipMxcNodeBridgeRestore)' != 'true' And Exists('$(OpenClawRepoRoot)package-lock.json')">
216+
<Error Condition="!Exists('$(MxcSdkPackageJson)')" Text="@microsoft/mxc-sdk package.json missing at $(MxcSdkPackageJson). Run `npm ci` at $(OpenClawRepoRoot)." />
217+
<Error Condition="Exists('$(MxcSdkPackageJson)') And !$([System.IO.File]::ReadAllText('$(MxcSdkPackageJson)').Contains('&quot;version&quot;: &quot;$(MxcSdkExpectedVersion)&quot;'))" Text="@microsoft/mxc-sdk version mismatch. Expected $(MxcSdkExpectedVersion) in $(MxcSdkPackageJson). Run `npm ci` at $(OpenClawRepoRoot)." />
206218
</Target>
207219

208220
<!-- Copy ONLY wxc-exec.exe (and any sibling DLLs) for the active arch into

‎tests/OpenClaw.Connection.Tests/PairingApprovalQueueTests.cs‎

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void Reconcile_ReportsResolvedWhenRequestLeaves()
136136
var delta = q.Reconcile(Devices(), null);
137137

138138
Assert.Single(delta.ResolvedKeys);
139-
Assert.Equal("Device:a", delta.ResolvedKeys[0]);
139+
Assert.Equal("DevicePair:a", delta.ResolvedKeys[0]);
140140
Assert.Empty(delta.Current);
141141
}
142142

@@ -282,7 +282,47 @@ public void Reconcile_NullNodeList_DoesNotDropExistingNodeRequests()
282282
// Device-only refresh (node list null): the node request must not vanish.
283283
var delta = q.Reconcile(Devices(Device("dev")), null);
284284
Assert.Contains(delta.Current, a => a.Kind == PairingApprovalKind.NodePair && a.RequestId == "n1");
285-
Assert.DoesNotContain("Node:n1", delta.ResolvedKeys);
285+
Assert.DoesNotContain("NodePair:n1", delta.ResolvedKeys);
286+
}
287+
288+
[Fact]
289+
public void Reconcile_DropsAmbiguousLegacyFallbackIds()
290+
{
291+
var q = new PairingApprovalQueue();
292+
var delta = q.Reconcile(Devices(
293+
new DevicePairingRequest { RequestId = "", DeviceId = "legacy", DisplayName = "first" },
294+
new DevicePairingRequest { RequestId = "", DeviceId = "legacy", DisplayName = "second" }), null);
295+
296+
Assert.Empty(delta.Added);
297+
Assert.Empty(delta.Current);
298+
}
299+
300+
[Fact]
301+
public void Reconcile_DropsAmbiguousLegacyNodeFallbackIds()
302+
{
303+
var q = new PairingApprovalQueue();
304+
var delta = q.Reconcile(null, Nodes(
305+
new PairingRequest { RequestId = "", NodeId = "legacy-node", DisplayName = "first" },
306+
new PairingRequest { RequestId = "", NodeId = "legacy-node", DisplayName = "second" }));
307+
308+
Assert.Empty(delta.Added);
309+
Assert.Empty(delta.Current);
310+
}
311+
312+
[Fact]
313+
public void Reconcile_DoesNotConfirmSubmittedDecisionWhenFallbackIdBecomesAmbiguous()
314+
{
315+
var q = new PairingApprovalQueue();
316+
var first = q.Reconcile(Devices(
317+
new DevicePairingRequest { RequestId = "", DeviceId = "legacy", DisplayName = "first" }), null);
318+
q.MarkSubmitted(first.Added[0], approved: true, nowMs: 0);
319+
320+
var delta = q.Reconcile(Devices(
321+
new DevicePairingRequest { RequestId = "", DeviceId = "legacy", DisplayName = "first" },
322+
new DevicePairingRequest { RequestId = "", DeviceId = "legacy", DisplayName = "second" }), null, nowMs: 100);
323+
324+
Assert.Empty(delta.ConfirmedDecisions);
325+
Assert.Empty(delta.Current);
286326
}
287327

288328
[Fact]

0 commit comments

Comments
 (0)