Skip to content

Stop queued operator reconnects from reviving a disconnected gateway #2075

Closed

Description

@shanselman

Lane 4 of 5 for #2071. Filed by a Copilot agent.

Problem:

  • GatewayConnectionManager.ScheduleOperatorReconnectAsync (~3351) checks IsCurrentLifecycle(request.Attempt) without holding _transitionSemaphore. It then calls ReconnectIfCurrentAsync, which checks only the user-disconnect intent and the active gateway id.
  • A plain DisconnectAsync does not change either of those. Plain disconnects are used for:
    • the setup connector timeout cleanup (ConnectionManagerOperatorConnector ~111/162)
    • direct-connect rollback (GatewayDirectConnectService ~203)
    • removing the active gateway (ConnectionPage ~2667)
  • So a reconnect queued behind one of those disconnects can reconnect the gateway the caller just tore down.

Fix:

  • Make the scheduled reconnect take the semaphore via AcquireCurrentAttemptAsync(request.Attempt), and reconnect under that lease.
  • Use DisconnectByUserAsync when removing the active gateway.

Done when:

  • a deterministic GatewayConnectionManagerTests case (hold the semaphore, queue the disconnect, release) shows no reconnect
  • the required validation passes

Activity

  1. self-assigned this
    on Nov 8, 2026
  2. added
    lever
    on Nov 8, 2026
  3. added
    clawsweeper:intake:bug
    clawsweeper:intake:needs-environment
    clawsweeper:intake:needs-repro
    P2
    clawsweeper:source-repro
    impact:other
    issue-rating: 🦞 diamond lobster
    and removed
    clawsweeper:intake:bug
    clawsweeper:intake:needs-environment
    clawsweeper:intake:needs-repro
    on Nov 8, 2026
  4. clawsweeper commented on Nov 8, 2026

    @clawsweeper

    Codex review: this still needs some work.

    Summary
    Current main still permits a queued operator reconnect to outlive a plain disconnect; this collaborator-authored issue also remains part of an open coordinated audit.

    Reproducibility: Source establishes the interleaving: hold the transition semaphore, queue plain DisconnectAsync, let a scheduled reconnect pass its generation check and wait behind the disconnect, then release the semaphore; the disconnect advances the generation but the subsequent reconnect accepts unchanged gateway ID and intent.

    Next step
    Within the coordinated audit, establish the queued-disconnect regression, validate the attempt under the reconnect lease, and use user-disconnect intent for active-gateway removal.

    Review details

    Best possible solution:

    Reject stale reconnect requests under one semaphore hold and make active-gateway removal record disconnected intent.

    Do we have a high-confidence way to reproduce the issue?

    Source establishes the interleaving: hold the transition semaphore, queue plain DisconnectAsync, let a scheduled reconnect pass its generation check and wait behind the disconnect, then release the semaphore; the disconnect advances the generation but the subsequent reconnect accepts unchanged gateway ID and intent.

    Is this the best way to solve the issue?

    The proposed lease is the appropriate existing seam, provided the reconnect executes under that lease through core logic rather than calling ReconnectIfCurrentAsync and deadlocking on semaphore reacquisition; preserve pinned-gateway, cancellation, and user-intent checks.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The precise interleaving is established from source but still needs a deterministic failing regression; no runtime reproduction or tests were run during this read-only review.

    Codex review notes: model internal, reasoning medium; reviewed against e70292487958.

    Label changes

    Label changes:

    • add P2: A narrow asynchronous ordering race can undo connection teardown, with no evidence of a widespread outage or unrecoverable onboarding failure.
    • add impact:other: Connection lifecycle correctness: a retired operator attempt can unexpectedly reopen a gateway connection.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.

    Label justifications:

    • P2: A narrow asynchronous ordering race can undo connection teardown, with no evidence of a widespread outage or unrecoverable onboarding failure.
    • impact:other: Connection lifecycle correctness: a retired operator attempt can unexpectedly reopen a gateway connection.
    Evidence reviewed

    What I checked:

    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge; those execution lanes are retired.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

    Reviewed November 8, 2026, 1:29 AM ET / 06:29 UTC.

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

Metadata

Metadata

Assignees

Labels

P2clawsweeper:source-reproimpact:otherissue-rating: 🦞 diamond lobsterlever

Type

No type

Fields

Priority

None yet

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions