@@ -239,22 +239,6 @@ private async Task ConnectCoreAsync(string? gatewayId = null)
239239 _gatewayNeedsV2Signature = true ;
240240 } ;
241241
242- // Operator-side auto-approve: the node-side WindowsNodeClient
243- // only sees its own pairing state. But when the gateway broadcasts
244- // a node.pair.requested event, the OPERATOR client gets a fresh
245- // NodePairListUpdated push. If our own node deviceId shows up in
246- // that pending list and we have approval scopes, approve it
247- // immediately — otherwise the user is stuck looking at a connected
248- // node with empty capabilities until they manually approve.
249- // This complements (not replaces) the node-side flow on line ~810
250- // which still handles the case where the node knows it's pending
251- // before any operator event lands.
252- lifecycle . DataClient . NodePairListUpdated += ( s , info ) =>
253- {
254- if ( Interlocked . Read ( ref _generation ) != gen ) return ;
255- _ = TryOperatorAutoApproveOwnNodePairAsync ( info , gen ) ;
256- } ;
257-
258242 // If we already know this gateway needs v2, tell the client upfront
259243 if ( _gatewayNeedsV2Signature )
260244 lifecycle . DataClient . UseV2Signature = true ;
@@ -903,9 +887,9 @@ private async void OnNodePairingStatusChanged(object? sender, PairingStatusEvent
903887 finally
904888 {
905889 // Only dedupe after an actual approve attempt. If the operator
906- // client was disconnected or lacked scope, the operator-side
907- // NodePairListUpdated path must still be able to approve this
908- // same requestId once the operator is ready .
890+ // client was disconnected or lacked scope, do not burn the
891+ // requestId; a later Pending event can still retry once the
892+ // operator client is ready or has approval scope .
909893 if ( attemptedApprove && Interlocked . Read ( ref _generation ) == approvalGeneration )
910894 _lastAutoApprovedRequestId = e . RequestId ;
911895 Interlocked . Exchange ( ref _autoApproveInFlight , null ) ;
@@ -923,99 +907,6 @@ private async void OnNodePairingStatusChanged(object? sender, PairingStatusEvent
923907 }
924908 }
925909
926- /// <summary>
927- /// Operator-side auto-approve. When the gateway pushes
928- /// <see cref="OpenClawGatewayClient.NodePairListUpdated"/> and there is a
929- /// pending entry for our OWN node's deviceId, approve it. The node-side
930- /// auto-approve at <see cref="OnNodePairingStatusChanged"/> handles the
931- /// case where the node already knows it is pending; this method handles
932- /// the case where the node is device-paired (its WindowsNodeClient sees
933- /// itself as Paired) but its node-sub-pairing hasn't been approved yet —
934- /// the only signal for that case is the operator-side broadcast.
935- /// </summary>
936- private async Task TryOperatorAutoApproveOwnNodePairAsync ( PairingListInfo ? info , long gen )
937- {
938- if ( info ? . Pending == null || info . Pending . Count == 0 ) return ;
939-
940- var ownNodeId = _nodeConnector ? . NodeDeviceId ;
941- if ( string . IsNullOrWhiteSpace ( ownNodeId ) ) return ;
942-
943- var operatorClient = _activeLifecycle ? . DataClient ;
944- if ( operatorClient ? . IsConnectedToGateway != true ) return ;
945- if ( ! OperatorScopeHelper . CanApproveDevices ( operatorClient . GrantedOperatorScopes ) ) return ;
946-
947- // Track whether ANY approve succeeded so we know to schedule one
948- // reconnect at the end (rather than reconnecting per-entry, which
949- // would race with itself).
950- string ? lastApprovedRequestId = null ;
951-
952- foreach ( var req in info . Pending )
953- {
954- if ( Interlocked . Read ( ref _generation ) != gen ) return ;
955- if ( string . IsNullOrWhiteSpace ( req . RequestId ) ) continue ;
956- if ( req . RequestId == _lastAutoApprovedRequestId ) continue ;
957- if ( ! string . Equals ( req . NodeId , ownNodeId , StringComparison . OrdinalIgnoreCase ) ) continue ;
958-
959- // CAS guard scoped to JUST the approve RPC. Release before the
960- // post-approve reconnect so unrelated approvals are not starved
961- // (e.g. another own-node pending with a different requestId in
962- // the same or next snapshot).
963- if ( Interlocked . CompareExchange ( ref _autoApproveInFlight , req . RequestId , null ) != null )
964- continue ;
965-
966- bool approved = false ;
967- try
968- {
969- _diagnostics . Record ( "node" , $ "Operator-side auto-approving own node pairing (requestId={ req . RequestId } )") ;
970- try
971- {
972- approved = await operatorClient . NodePairApproveAsync ( req . RequestId ) ;
973- if ( ! approved )
974- _diagnostics . Record ( "node" , "Operator-side node pair approval rejected by gateway" ) ;
975- }
976- catch ( Exception ex )
977- {
978- _logger . Warn ( $ "[ConnMgr] Operator-side node auto-approve failed: { ex . Message } ") ;
979- _diagnostics . Record ( "node" , $ "Operator-side auto-approve error: { ex . Message } ") ;
980- }
981- }
982- finally
983- {
984- // Always record the requestId — both on success (prevent
985- // re-approving the same id after the gateway re-broadcasts)
986- // and on failure (prevent a spin loop on a rejected id).
987- // Re-check generation: if a reconnect happened during the
988- // await above, DisposeActiveClient already cleared
989- // _lastAutoApprovedRequestId for the new generation; we must
990- // not overwrite that null with a stale id from the old gen.
991- if ( Interlocked . Read ( ref _generation ) == gen )
992- _lastAutoApprovedRequestId = req . RequestId ;
993- Interlocked . Exchange ( ref _autoApproveInFlight , null ) ;
994- }
995-
996- if ( approved )
997- {
998- lastApprovedRequestId = req . RequestId ;
999- // Continue scanning so a second own-pending in the same
1000- // snapshot (e.g. stale requestId from prior session) also
1001- // gets attempted — broken only by an explicit failure to
1002- // approve, which we still try the next entry for.
1003- }
1004- // On failure/rejection, fall through to next own-pending entry
1005- // rather than break — the gateway may not re-broadcast if the
1006- // approve frame round-tripped and was rejected mid-flight.
1007- }
1008-
1009- // Single reconnect after the snapshot is fully processed.
1010- if ( lastApprovedRequestId is not null )
1011- {
1012- _diagnostics . Record ( "node" , $ "Operator-side approved { lastApprovedRequestId } — reconnecting node so caps propagate") ;
1013- await Task . Delay ( 1000 ) ;
1014- if ( Interlocked . Read ( ref _generation ) == gen )
1015- await StartNodeConnectionAsync ( ) ;
1016- }
1017- }
1018-
1019910 // ─── Helpers ───
1020911
1021912 private void EmitStateChanged ( OverallConnectionState previousOverall )
0 commit comments