Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2ff7866
fix(snapshot): approve restored clone pairing from local state
cv Jul 27, 2026
919cc45
test(snapshot): keep clone pairing fixture linear
cv Jul 27, 2026
6220e46
test(snapshot): remove inert primary-state sentinel
cv Jul 27, 2026
cd0a91c
test(cli): isolate compiled dispatch cache
cv Jul 27, 2026
d0ba4ec
merge(main): update repair branch
cv Jul 27, 2026
7a7b56c
ci(e2e): route clone pairing snapshot coverage
cv Jul 27, 2026
039f410
Merge branch 'main' into codex/fix-restored-clone-pairing-gate
cv Jul 27, 2026
a7bf7e3
merge(main): trust snapshot coverage selector
cv Jul 27, 2026
977b87f
merge(pr): preserve concurrent main sync
cv Jul 27, 2026
f04cdb6
fix(snapshot): retain restored clone identity for pairing
cv Jul 27, 2026
0f5ea39
merge(pr): sync release evidence from main
cv Jul 27, 2026
5c01638
Merge branch 'main' into codex/fix-restored-clone-pairing-gate
cv Jul 27, 2026
d3bea7c
merge(pr): preserve concurrent remote sync
cv Jul 27, 2026
8905412
fix(snapshot): accept duplicated pairing request ID
cv Jul 27, 2026
8b78339
merge(pr): sync current main
cv Jul 27, 2026
ab26497
fix(snapshot): read restored clone pending state
cv Jul 28, 2026
72b2f11
merge(pr): sync current main
cv Jul 28, 2026
d2ba160
test(snapshot): keep pending fixtures linear
cv Jul 28, 2026
08b9ef6
merge(pr): sync current main
cv Jul 28, 2026
acd04de
fix(snapshot): retain clone token for cold pairing
cv Jul 28, 2026
e9652d9
fix(snapshot): converge restored clone device auth
cv Jul 28, 2026
d592843
test(snapshot): linearize clone auth fixture setup
cv Jul 28, 2026
e9c189f
fix(snapshot): reject invalid stored-auth scopes
cv Jul 28, 2026
8bfc001
fix(snapshot): use clone token for scope repair
cv Jul 28, 2026
606fc06
fix(snapshot): reconcile watcher-completed clone approval
cv Jul 28, 2026
98bb2ec
test(snapshot): pin clone approval request identity
cv Jul 28, 2026
4d15b3e
fix(snapshot): reconcile timed-out clone approval
cv Jul 28, 2026
df88095
test(snapshot): bound approval timeout fixture
cv Jul 28, 2026
2468d21
fix(snapshot): pin clone state descriptors
cv Jul 28, 2026
16a6381
fix(snapshot): pin restored clone pairing context
cv Jul 28, 2026
eaa7138
test(snapshot): keep race cleanup linear
cv Jul 28, 2026
c27b46e
Merge branch 'main' into codex/fix-restored-clone-pairing-gate
cv Jul 28, 2026
5b350b1
Merge branch 'main' into codex/fix-restored-clone-pairing-gate
cjagwani Jul 29, 2026
13b4f0c
Merge branch 'main' into codex/fix-restored-clone-pairing-gate
cjagwani Jul 29, 2026
a547645
merge: resolve conflicts with main
github-actions[bot] Jul 31, 2026
477bf2c
Merge branch 'main' into codex/fix-restored-clone-pairing-gate
cv Aug 3, 2026
05b5bf5
test(e2e): format snapshot pairing control
cv Aug 3, 2026
9146a55
test(e2e): name source pairing control precisely
cv Aug 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 99 additions & 18 deletions scripts/patch-openclaw-device-self-approval.mts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
* OpenClaw create a canonical pending scope-upgrade request. Keep the entire
* approval in OpenClaw instead: for the exact bounded CLI mismatch, continue
* only into OpenClaw's pairing gate. For the resulting same-device scope
* transition, including an operator.write request created before paired-state
* convergence, explicitly use OpenClaw's stored device credential with
* operator.pairing. Then let the gateway's canonical approveDevicePairing path
* reload, lock, rotate the token, persist, broadcast, and respond.
* transition, use OpenClaw's stored device credential with operator.pairing.
* A restored clone whose paired server state exists before its client-auth
* store converges instead opts into one narrower path: its exact pairing-only
* device token must match the explicit environment token, its signed identity
* remains attached, and a direct live pairing list must exactly match the
* clone-local preflight before one canonical approval can run. Then let the
* gateway's canonical approveDevicePairing path reload, lock, rotate the token,
* persist, broadcast, and respond.
* The ordinary patch tests and pinned real-dist proof cover this paired
* pre-convergence transition separately from a cold clone, which has no paired
* record and must not select stored device authentication.
Expand All @@ -44,8 +48,9 @@ const CLI_MARKER = "nemoclaw: forward stored device auth for bounded same-device
const CLI_APPROVE_MARKER =
"nemoclaw: select stored device auth for bounded same-device scope approval";
const CLI_SCOPE_MARKER = "nemoclaw: reach gateway for bounded same-device scope approval";
const CLI_RETRY_MARKER = "nemoclaw: keep bounded stored device auth fail closed";
const CLI_RETRY_MARKER = "nemoclaw: keep bounded device auth fail closed";
const CLI_LIST_MARKER = "nemoclaw: preflight bounded stored device auth before live pairing list";
const CLI_PAIRED_TOKEN_MARKER = "nemoclaw: preflight bounded paired token before live pairing list";
const CALL_FORCE_IDENTITY_MARKER = "nemoclaw: force device identity for loopback pairing bootstrap";
const CALL_STORED_IDENTITY_MARKER =
"nemoclaw: retain stored CLI device identity for loopback shared-token scope enforcement";
Expand All @@ -55,6 +60,7 @@ const CLI_APPLIED_MARKERS = [
CLI_SCOPE_MARKER,
CLI_RETRY_MARKER,
CLI_LIST_MARKER,
CLI_PAIRED_TOKEN_MARKER,
] as const;
const AUTH_SCOPE_UPGRADE_MARKER =
"nemoclaw: route bounded CLI device-token scope upgrade into pairing";
Expand Down Expand Up @@ -176,14 +182,24 @@ const CLI_TARGET = [

const CLI_HELPER_ANCHOR = "function resolveApprovePairingScopesForRequest(request, paired) {";
const CLI_HELPER = [
"function resolveNemoClawSelfRepairPairingContext(request, paired) {",
"function resolveNemoClawExactScopes(rawScopes) {",
"\tif (!Array.isArray(rawScopes) || rawScopes.length === 0) return null;",
'\tconst normalized = rawScopes.map((scope) => typeof scope === "string" ? scope.trim() : "");',
"\tif (normalized.some((scope) => !scope) || normalized.length !== new Set(normalized).size) return null;",
"\treturn normalized.toSorted();",
"}",
"",
"function resolveNemoClawSelfRepairPairingContext(request, paired, nemoclawAllowRedactedPaired = false) {",
"\tconst nemoclawRawScopes = request.scopes;",
"\tconst nemoclawRoles = normalizeDeviceRoles(request);",
"\tconst nemoclawPairedTokens = paired?.tokens;",
'\tconst nemoclawPairedView = nemoclawPairedTokens && typeof nemoclawPairedTokens === "object" && !Array.isArray(nemoclawPairedTokens) ? { ...paired, tokens: Object.values(nemoclawPairedTokens) } : paired;',
"\tconst nemoclawPairedTokenList = Array.isArray(nemoclawPairedView?.tokens) ? nemoclawPairedView.tokens : [];",
'\tconst nemoclawPairedOperatorTokens = nemoclawPairedTokenList.filter((token) => token && typeof token === "object" && normalizeOptionalString(token.role) === OPERATOR_ROLE && !token.revokedAtMs);',
"\tconst nemoclawPairedOperatorToken = nemoclawPairedOperatorTokens.length === 1 && nemoclawPairedTokenList.length === 1 ? nemoclawPairedOperatorTokens[0] : null;",
"\tconst nemoclawPairedScopes = resolvePairedOperatorScopes(nemoclawPairedView);",
"\tconst nemoclawPairingBaselineVisible = nemoclawPairedScopes.length > 0;",
'\tconst nemoclawNormalizedRawScopes = Array.isArray(nemoclawRawScopes) ? nemoclawRawScopes.map((scope) => typeof scope === "string" ? scope.trim() : "") : [];',
"\tconst nemoclawNormalizedRawScopes = resolveNemoClawExactScopes(nemoclawRawScopes) ?? [];",
"\tconst nemoclawNonRepairWriteTransition =",
"\t\trequest.isRepair === false &&",
'\t\tnemoclawNormalizedRawScopes.includes("operator.write") &&',
Expand All @@ -203,17 +219,60 @@ const CLI_HELPER = [
"\tconst nemoclawPairedDeviceId = normalizeOptionalString(nemoclawPairedView?.deviceId);",
"\tconst nemoclawRequestPublicKey = normalizeOptionalString(request.publicKey);",
"\tconst nemoclawPairedPublicKey = normalizeOptionalString(nemoclawPairedView?.publicKey);",
"\tconst nemoclawPairedRoles = normalizeDeviceRoles(nemoclawPairedView ?? {});",
"\tconst nemoclawPairedRawScopes = resolveNemoClawExactScopes(nemoclawPairedView?.scopes);",
"\tconst nemoclawPairedApprovedScopes = resolveNemoClawExactScopes(nemoclawPairedView?.approvedScopes);",
"\tconst nemoclawPairedTokenScopes = resolveNemoClawExactScopes(nemoclawPairedOperatorToken?.scopes);",
"\tconst nemoclawRequestId = normalizeOptionalString(request.requestId);",
"\tconst nemoclawPairedApprovedScopesMatch =",
"\t\t(nemoclawPairedApprovedScopes?.length === 1 && nemoclawPairedApprovedScopes[0] === PAIRING_SCOPE) ||",
"\t\t(nemoclawAllowRedactedPaired && nemoclawPairedView?.approvedScopes === void 0);",
"\tconst nemoclawPairedTokenScopeUpgrade =",
"\t\t(request.isRepair === true || request.isRepair === false) &&",
'\t\tnemoclawNormalizedRawScopes.includes("operator.write") &&',
"\t\tnemoclawNormalizedRawScopes.every((scope) => nemoclawStoredAuthAllowedScopes.has(scope)) &&",
"\t\tnemoclawRoles.length === 1 &&",
"\t\tnemoclawRoles[0] === OPERATOR_ROLE &&",
"\t\tnemoclawPairedRoles.length === 1 &&",
"\t\tnemoclawPairedRoles[0] === OPERATOR_ROLE &&",
"\t\tnemoclawPairedRawScopes?.length === 1 &&",
"\t\tnemoclawPairedRawScopes[0] === PAIRING_SCOPE &&",
"\t\tnemoclawPairedApprovedScopesMatch &&",
"\t\tnemoclawPairedTokenScopes?.length === 1 &&",
"\t\tnemoclawPairedTokenScopes[0] === PAIRING_SCOPE &&",
"\t\tBoolean(nemoclawRequestId) &&",
"\t\tBoolean(nemoclawRequestDeviceId) &&",
"\t\tnemoclawRequestDeviceId === nemoclawPairedDeviceId &&",
"\t\tBoolean(nemoclawRequestPublicKey) &&",
"\t\tnemoclawRequestPublicKey === nemoclawPairedPublicKey &&",
"\t\trequest.clientId === GATEWAY_CLIENT_NAMES.CLI &&",
"\t\trequest.clientMode === GATEWAY_CLIENT_MODES.CLI;",
"\tconst nemoclawPairedTokenContext = nemoclawPairedTokenScopeUpgrade ? JSON.stringify([",
"\t\tnemoclawRequestId,",
"\t\tnemoclawRequestDeviceId,",
"\t\tnemoclawRequestPublicKey,",
"\t\trequest.clientId,",
"\t\trequest.clientMode,",
"\t\tnemoclawRoles,",
"\t\tnemoclawNormalizedRawScopes,",
"\t\tnemoclawPairedRoles,",
"\t\tnemoclawPairedRawScopes,",
"\t\tnemoclawPairedTokenScopes",
"\t]) : null;",
"\treturn {",
"\t\tusePairingTransport: nemoclawUsePairingTransport,",
"\t\tuseStoredDeviceAuth:",
"\t\t\tnemoclawUsePairingTransport &&",
"\t\t\tnemoclawNormalizedRawScopes.length > 0 &&",
"\t\t\tnemoclawNormalizedRawScopes.length === new Set(nemoclawNormalizedRawScopes).size &&",
"\t\t\tnemoclawNormalizedRawScopes.every((scope) => nemoclawStoredAuthAllowedScopes.has(scope)) &&",
"\t\t\tnemoclawPairedScopes.includes(PAIRING_SCOPE) &&",
"\t\t\tBoolean(nemoclawRequestDeviceId) &&",
"\t\t\tnemoclawRequestDeviceId === nemoclawPairedDeviceId &&",
"\t\t\tBoolean(nemoclawRequestPublicKey) &&",
"\t\t\tnemoclawRequestPublicKey === nemoclawPairedPublicKey",
"\t\t\tnemoclawRequestPublicKey === nemoclawPairedPublicKey,",
"\t\tpairedTokenContext: nemoclawPairedTokenContext,",
"\t\tpairedDeviceToken: nemoclawPairedTokenContext ? normalizeOptionalString(nemoclawPairedOperatorToken?.token) : void 0",
"\t};",
"}",
"",
Expand Down Expand Up @@ -276,44 +335,66 @@ const CLI_CONTEXT_TARGET = [
].join("\n");
const CLI_CONTEXT_REPLACEMENT = [
"async function resolveApprovePairingGatewayContext(opts, requestId) {",
'\tconst nemoclawPairedTokenRequested = process.env.NEMOCLAW_OPENCLAW_FORCE_DEVICE_PAIRING === "1";',
"\tlet nemoclawLocalStoredAuthCandidate = false;",
"\tlet nemoclawLocalPairedTokenContext = null;",
"\ttry {",
"\t\tconst nemoclawLocalList = await listDevicePairing();",
"\t\tconst nemoclawLocalRequest = findPendingRequestById(nemoclawLocalList.pending, requestId);",
"\t\tif (nemoclawLocalRequest) {",
"\t\t\tconst nemoclawLocalPaired = lookupPairedDevice(indexPairedDevices(nemoclawLocalList.paired), nemoclawLocalRequest);",
"\t\t\tnemoclawLocalStoredAuthCandidate = resolveNemoClawSelfRepairPairingContext(nemoclawLocalRequest, nemoclawLocalPaired).useStoredDeviceAuth;",
"\t\t\tconst nemoclawLocalContext = resolveNemoClawSelfRepairPairingContext(nemoclawLocalRequest, nemoclawLocalPaired);",
"\t\t\tnemoclawLocalStoredAuthCandidate = !nemoclawPairedTokenRequested && nemoclawLocalContext.useStoredDeviceAuth;",
"\t\t\tconst nemoclawExplicitEnvToken = normalizeOptionalString(process.env.OPENCLAW_GATEWAY_TOKEN);",
"\t\t\tconst nemoclawHasTransportOrCredentialOverride = Boolean(normalizeOptionalString(opts.url) || normalizeOptionalString(opts.token) || normalizeOptionalString(opts.password) || normalizeOptionalString(process.env.OPENCLAW_GATEWAY_URL) || normalizeOptionalString(process.env.OPENCLAW_GATEWAY_PORT) || normalizeOptionalString(process.env.OPENCLAW_GATEWAY_PASSWORD));",
"\t\t\tif (",
"\t\t\t\tnemoclawPairedTokenRequested &&",
"\t\t\t\t!nemoclawHasTransportOrCredentialOverride &&",
"\t\t\t\tnemoclawExplicitEnvToken &&",
"\t\t\t\tnemoclawExplicitEnvToken === nemoclawLocalContext.pairedDeviceToken",
"\t\t\t) nemoclawLocalPairedTokenContext = nemoclawLocalContext.pairedTokenContext;",
"\t\t}",
"\t} catch {}",
"\tif (nemoclawPairedTokenRequested && !nemoclawLocalPairedTokenContext) return {",
"\t\toriginalRequest: null,",
"\t\tscopes: void 0,",
"\t\tnemoclawUseStoredDeviceAuth: false,",
"\t\tnemoclawUsePairedToken: false,",
"\t\tnemoclawRefuseUnsafeApproval: true",
"\t};",
"\ttry {",
"\t\tconst nemoclawListCallOpts = nemoclawLocalStoredAuthCandidate ? {",
"\t\t\tscopes: [PAIRING_SCOPE],",
"\t\t\tuseStoredDeviceAuth: true,",
"\t\t\trequiredStoredDeviceAuthScopes: [PAIRING_SCOPE]",
"\t\t} : void 0;",
"\t\tconst list = await listPairingWithFallback(opts, nemoclawListCallOpts);",
'\t\tconst list = nemoclawPairedTokenRequested ? parseDevicePairingList(await callGatewayCli("device.pair.list", opts, {}, { scopes: [PAIRING_SCOPE] })) : await listPairingWithFallback(opts, nemoclawListCallOpts); // nemoclaw: preflight bounded paired token before live pairing list (#4462)',
"\t\tconst request = findPendingRequestById(list.pending, requestId);",
"\t\tif (!request) return {",
"\t\t\toriginalRequest: null,",
"\t\t\tscopes: void 0,",
"\t\t\tnemoclawUseStoredDeviceAuth: false,",
"\t\t\tnemoclawRefuseUnsafeApproval: nemoclawLocalStoredAuthCandidate",
"\t\t\tnemoclawUsePairedToken: false,",
"\t\t\tnemoclawRefuseUnsafeApproval: nemoclawPairedTokenRequested || nemoclawLocalStoredAuthCandidate",
"\t\t};",
"\t\tconst paired = lookupPairedDevice(indexPairedDevices(list.paired), request);",
"\t\tconst nemoclawSelfRepairContext = resolveNemoClawSelfRepairPairingContext(request, paired);",
"\t\tconst nemoclawSelfRepairContext = resolveNemoClawSelfRepairPairingContext(request, paired, nemoclawPairedTokenRequested);",
"\t\tconst nemoclawUseStoredDeviceAuth = nemoclawLocalStoredAuthCandidate && nemoclawSelfRepairContext.useStoredDeviceAuth;",
"\t\tconst nemoclawUsePairedToken = nemoclawPairedTokenRequested && nemoclawLocalPairedTokenContext === nemoclawSelfRepairContext.pairedTokenContext;",
"\t\treturn {",
"\t\t\toriginalRequest: request,",
"\t\t\tscopes: resolveApprovePairingScopesForRequest(request, paired),",
"\t\t\tnemoclawUseStoredDeviceAuth,",
"\t\t\tnemoclawRefuseUnsafeApproval: nemoclawLocalStoredAuthCandidate && !nemoclawUseStoredDeviceAuth",
"\t\t\tnemoclawUsePairedToken,",
"\t\t\tnemoclawRefuseUnsafeApproval: nemoclawPairedTokenRequested ? !nemoclawUsePairedToken : nemoclawLocalStoredAuthCandidate && !nemoclawUseStoredDeviceAuth",
"\t\t};",
"\t} catch {",
"\t\treturn {",
"\t\t\toriginalRequest: null,",
"\t\t\tscopes: void 0,",
"\t\t\tnemoclawUseStoredDeviceAuth: false,",
"\t\t\tnemoclawRefuseUnsafeApproval: nemoclawLocalStoredAuthCandidate",
"\t\t\tnemoclawUsePairedToken: false,",
"\t\t\tnemoclawRefuseUnsafeApproval: nemoclawPairedTokenRequested || nemoclawLocalStoredAuthCandidate",
"\t\t};",
"\t}",
"}",
Expand All @@ -322,11 +403,11 @@ const CLI_CONTEXT_REPLACEMENT = [
const CLI_APPROVE_HEADER_TARGET =
"\tconst { scopes, originalRequest } = await resolveApprovePairingGatewayContext(opts, requestId);";
const CLI_APPROVE_HEADER_REPLACEMENT =
'\tconst { scopes, originalRequest, nemoclawUseStoredDeviceAuth, nemoclawRefuseUnsafeApproval } = await resolveApprovePairingGatewayContext(opts, requestId);\n\tif (nemoclawRefuseUnsafeApproval) throw new Error("bounded same-device approval context changed before gateway approval");';
'\tconst { scopes, originalRequest, nemoclawUseStoredDeviceAuth, nemoclawUsePairedToken, nemoclawRefuseUnsafeApproval } = await resolveApprovePairingGatewayContext(opts, requestId);\n\tif (nemoclawRefuseUnsafeApproval) throw new Error("bounded same-device approval context changed before gateway approval");';
const CLI_APPROVE_CALL_TARGET =
'\t\treturn await callGatewayCli("device.pair.approve", opts, { requestId }, scopes ? { scopes } : void 0);';
const CLI_APPROVE_CALL_REPLACEMENT = [
'\t\treturn await callGatewayCli("device.pair.approve", opts, { requestId }, nemoclawUseStoredDeviceAuth ? {',
'\t\treturn await callGatewayCli("device.pair.approve", opts, { requestId }, nemoclawUsePairedToken ? { scopes: [PAIRING_SCOPE] } : nemoclawUseStoredDeviceAuth ? {',
"\t\t\tscopes,",
"\t\t\tuseStoredDeviceAuth: true, // nemoclaw: select stored device auth for bounded same-device scope approval (#4462)",
"\t\t\trequiredStoredDeviceAuthScopes: [PAIRING_SCOPE]",
Expand All @@ -337,11 +418,11 @@ const CLI_ADMIN_RETRY_TARGET =
const CLI_ADMIN_RETRY_TARGET_2026_7_1 =
'\t\tif (isDevicePairingApprovalDenied(error) && !scopes?.includes("operator.admin")) try {';
const CLI_ADMIN_RETRY_REPLACEMENT = [
"\t\tif (nemoclawUseStoredDeviceAuth) throw error; // nemoclaw: keep bounded stored device auth fail closed (#4462)",
"\t\tif (nemoclawUseStoredDeviceAuth || nemoclawUsePairedToken) throw error; // nemoclaw: keep bounded device auth fail closed (#4462)",
CLI_ADMIN_RETRY_TARGET,
].join("\n");
const CLI_ADMIN_RETRY_REPLACEMENT_2026_7_1 = [
"\t\tif (nemoclawUseStoredDeviceAuth) throw error; // nemoclaw: keep bounded stored device auth fail closed (#4462)",
"\t\tif (nemoclawUseStoredDeviceAuth || nemoclawUsePairedToken) throw error; // nemoclaw: keep bounded device auth fail closed (#4462)",
CLI_ADMIN_RETRY_TARGET_2026_7_1,
].join("\n");

Expand Down
Loading
Loading