Skip to content

Commit a1c77bb

Browse files
committed
feat: make node.pair.approve idempotent for already-paired nodes (fixes #94040)
When approveNodePairing returns null (e.g., request expired, superseded by reconnect), check if the node is already paired. If so, treat it as a successful approval to avoid misleading 'unknown requestId' errors during duplicate clicks or delayed approvals. Changes: - Add getPairedNode import - Before approval, capture nodeId from pending request (if still present) - If approve returns null but nodeId exists and node already paired, synthesize approved result - Maintain existing error handling for truly unknown requests This improves UX by making approval actions idempotent once pairing is complete.
1 parent 7048906 commit a1c77bb

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

‎src/gateway/server-methods/nodes.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { listDevicePairing } from "../../infra/device-pairing.js";
3030
import { formatErrorMessage } from "../../infra/errors.js";
3131
import {
3232
approveNodePairing,
33+
getPairedNode,
3334
listNodePairing,
3435
rejectNodePairing,
3536
removePairedNode,
@@ -816,7 +817,18 @@ export const nodeHandlers: GatewayRequestHandlers = {
816817
// Intentionally fail closed for RPC callers without an explicit scoped session.
817818
const callerScopes = Array.isArray(client?.connect?.scopes) ? client.connect.scopes : [];
818819
await respondUnavailableOnThrow(respond, async () => {
820+
// Check if request is still pending to obtain nodeId for idempotent handling
821+
const pairing = await listNodePairing();
822+
const pendingEntry = pairing.pending.find(p => p.requestId === requestId);
823+
const nodeIdFromPending = pendingEntry?.nodeId;
819824
const approved = await approveNodePairing(requestId, { callerScopes });
825+
// If approve returned null but we have nodeId and node is already paired, treat as idempotent success
826+
if (!approved && nodeIdFromPending) {
827+
const alreadyPaired = await getPairedNode(nodeIdFromPending);
828+
if (alreadyPaired) {
829+
approved = { requestId, node: alreadyPaired };
830+
}
831+
}
820832
if (!approved) {
821833
respond(false, undefined, errorShape(ErrorCodes.INVALID_REQUEST, "unknown requestId"));
822834
return;

0 commit comments

Comments
 (0)