Skip to content

[deep-review][duplication] D4: _useV2Signature fallback state machine duplicated across operator and node clients #367

Closed

Description

@codemonkeychris

Summary

The v3→v2 signature fallback (see also C10) is implemented twice — once in OpenClawGatewayClient, once in WindowsNodeClient — with the same three-piece state (flag declaration, set-on-error, read-on-connect).

Where

  • src/OpenClaw.Shared/OpenClawGatewayClient.cs:51, 881-899, 1494-1499 (operator)
  • src/OpenClaw.Shared/WindowsNodeClient.cs:37, 568-575, 828-830 (node)

The base class WebSocketClientBase exists and is the natural home for shared connection state, but currently only owns the WS transport and reconnect backoff.

Why it matters

Three concrete problems:

  1. Future drift risk. If C10 (reset-after-N-successes) is implemented in one client but not the other, the operator and node would have different downgrade behaviours for the same gateway. The two clients share an identity directory and a v2 flag in GatewayConnectionManager._gatewayNeedsV2Signature, so a divergent client implementation introduces subtle staleness.
  2. Test surface is doubled. Every signature-fallback test currently covers one client; the other might silently drift.
  3. Audit cost. A security reviewer looking at the v3-to-v2 fallback has to read both implementations and verify they agree.

Proposed fix

Lift the state to WebSocketClientBase (or a small SignatureNegotiationState helper):

protected bool UseV2Signature { get; private set; }
protected void OnSignatureRejected();   // bumps state machine
protected void OnHandshakeSucceeded();  // resets counters, may probe v3 again

Both OpenClawGatewayClient and WindowsNodeClient call the protected method on error / success. The state machine (including C10's reset-after-N-successes) lives in one place.

Make the migration in two PRs:

  1. Land the helper; have both clients call it without changing behaviour.
  2. Implement C10's reset-after-N-successes inside the helper. Both clients get the fix.

Severity

Low — duplication that becomes Medium when C10 is addressed (because the fix would have to be done twice otherwise).

Related

  • C10 (sticky downgrade).

Activity

  1. github-actions commented on May 17, 2026

    @github-actions
    Contributor

    Note

    The pull request was not created — a fallback review issue was created instead due to protected file changes: #431

    🤖 This is an automated response from Repo Assist.

    Good analysis. A two-step migration is the right call here — it avoids introducing risk before the behaviour is proven stable.

    A concrete sketch for step 1 using an inner type in WebSocketClientBase:

    // WebSocketClientBase.cs
    protected sealed class SignatureNegotiationState
    {
        private volatile bool _useV2;
    
        public bool UseV2 => _useV2;
    
        /// Call when the gateway rejects the v3 signature.
        public void OnRejected() => _useV2 = true;
    
        /// Call on each successful authenticated handshake.
        /// Returns true when the state was reset (useful for logging).
        public bool OnHandshakeSucceeded()
        {
            if (!_useV2) return false;
            _useV2 = false;
            return true;
        }
    }
    
    protected readonly SignatureNegotiationState SignatureNegotiation = new();

    Both OpenClawGatewayClient and WindowsNodeClient can replace their _useV2Signature field with SignatureNegotiation.UseV2 / .OnRejected() / .OnHandshakeSucceeded(). The state machine is now in one place.

    One thing to be aware of: _useV2Signature currently lives as a per-instance bool, but GatewayConnectionManager._gatewayNeedsV2Signature is a separate field that acts as a persistent memo across reconnects. Make sure step 1 doesn't silently drop that cross-reconnect persistence — the per-instance state in SignatureNegotiationState should be re-seeded from GatewayConnectionManager on each reconnect, the same way the existing booleans are today.

    For step 2 (C10: reset-after-N-successes), the OnHandshakeSucceeded method is the natural place to add a counter.

    Generated by 🌈 Repo Assist, see workflow run. Learn more.

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/repo-assist.md@97143ac59cb3a13ef2a77581f929f06719c7402a
    
  2. shanselman commented on May 18, 2026

    @shanselman
    Collaborator

    Closing during the post-refactor deep-review cleanup. This duplicates the v3/v2 fallback concern tracked by #350 and #372. This keeps the signal while reducing stale one-off issue noise.

  3. locked as resolved and limited conversation to collaborators on May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions