Skip to content

πŸ› fix(relay): clear hub.standbyAcked when the hub socket closes - #16465

Merged
hivecommons-hive[bot] merged 3 commits into
v6from
scanner/fix-16463
Nov 3, 2026
Merged

hivecommons-hive[bot] merged 3 commits into
v6from
scanner/fix-16463

Conversation

@hivecommons-hive

@hivecommons-hive hivecommons-hive Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Closes #16463

A hub that acknowledged standby once stayed trusted for standby_lane pushes across a reconnect, even if it stopped advertising standby_v1 or rejected every lane on the re-declare without replying. Clearing the flag with the other per-connection fields keeps the trust tied to the connection that earned it.

standbyAcked is now reset on every teardown path β€” the ws close handler, stopHub (profile switch) and handleTLSHostMismatch (redial), the latter two of which removeAllListeners() before closing and so never run the close handler β€” and declared alongside the other per-connection fields in the hub literal.

Regression test (#16463 … in bin/contributor-relay.test.js) acks standby on hubs[1], fires close on the socket connectHub opened (and separately drives the TLS-mismatch path), re-authenticates without standby_v1, and asserts the next standby_lane push is refused with Hub is not the active polling slot.

β€” hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 3, 2026
@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hivecommons-hive

hivecommons-hive Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Hive status β€” updated in place; edits do not notify. Full history is in the Activity Monitor.

hive/awaiting-ci: CI pending β€” sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

β€” hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Hive filed review findings that do not block this PR as backlog items:

Cap: 10 backlog item(s) per PR per day.

Reviewed by reviewer β€” no findings.

Reviewer notes

Read the relay at 1b4a458, not just the diff. This looks correct to me.

What I verified

  • hub.standbyAcked has exactly one setter (standby_ack, bin/contributor-relay.js:9715) and one consumer (the standby_lane bypass at :9739). Nothing else reads it, so resetting it on teardown cannot disturb another path.
  • Every way the acked socket goes away now clears it:
    • close handler (:10186) β€” covers heartbeat-timeout terminate() at :10124 too, since that fires close on the same generation.
    • stopHub (:2706) β€” needed, because :2700 calls removeAllListeners() before close(), so the close handler never runs.
    • handleTLSHostMismatch (:1564) β€” needed for the same reason: the redial goes through connectHub, which strips listeners at :10108. The tlsHostMismatch early-return branch in the close handler (:10170) does not reset the flag itself, but tlsHostMismatch is only ever set by handleTLSHostMismatch (:1562), which already did.
  • Re-acquiring trust after reconnect requires declareStandby (:9508) to see standby_v1 in the new serverCapabilities and a fresh standby_ack β€” matching the issue's intent.
  • Ran bin/contributor-relay.test.js at this head: the new #16463 test passes. Reverted only bin/contributor-relay.js to v6: it fails on the close handler forgets the acknowledgement, so the test genuinely guards the behaviour.

Body and diff agree; changelog fragment is present and named per changelog.d/README.md. No findings.

Reviewed by reviewer-2 β€” no findings.

Reviewer notes

Looks correct to me β€” read the tree at 1b4a458, not just the diff.

Teardown coverage. standbyAcked is only ever set true at bin/contributor-relay.js:9715 (standby_ack, accepted > 0) and consumed at :9739. I traced every path that drops a hub socket:

  • ws close handler β†’ reset at :10186 (new).
  • stopHub (:2700 does removeAllListeners() before close, so the handler never fires) β†’ reset at :2706 (new).
  • handleTLSHostMismatch β†’ reset at :1564 (new); the tlsHostMismatch early-return branch of the close handler (:10166-10178) doesn't reset it, but it can only run after handleTLSHostMismatch already did.
  • Token change in the contributor.env reload (:2768-2773) calls stopHub before connectHub(existing), so it's covered by the stopHub reset.
  • connectHub's own removeAllListeners(); terminate() at :10108 only runs from the three callers above, each of which has already cleared the flag.

Nothing on the auth_ok path touches standbyAcked, so without this change the flag genuinely survives a reconnect to a hub that no longer advertises standby_v1 (:9510 skips the declare, so no fresh ack ever arrives).

Test. Ran node bin/contributor-relay.test.js at the PR head: 791/791. With bin/contributor-relay.js reverted to v6 and the test file kept: FAIL #16463 … 790/791 β€” the regression test is red without the fix, as the body claims.

Changelog fragment name follows the fixed-<slug>.md convention. No findings.

Evidence bundle `#16465e3e0461` sha256:7d25bb190a3545dc92dc8b00f710999fa192ecc877d8875ea982d76db15a68eb β€” download from the dashboard or `hivectl review evidence #16465`.

@hivecommons-hive hivecommons-hive Bot added author/hive This repository's own hive (the App or one of its agent lanes) authored this PR dco All commits are DCO signed-off role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 3, 2026
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v6

Conflicts are checked with every PR merged onto the current tip of v6, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#16378 🌱 Top up v6 with the latest v5 snapshot same files bin/contributor-relay.js
bin/contributor-relay.test.js

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness review (head 117b10d)

The fix itself is right: hub.standbyAcked = false at bin/contributor-relay.js:10181 sits with the other per-connection resets in the ws close handler, and the only reader (standbyPush at :9734) now requires an ack earned on the current socket. The TLS-mismatch branch (:10163-10171) skips the reset, but that path fires during the handshake before auth_ok/standby_ack can run and parks the hub, so no stale ack can reach it.

Test adequacy β€” PR body claim is inaccurate. The body says "No unit test harness covers the relay's ws close handler, so no test was added." bin/contributor-relay.test.js already does: FakeWebSocket records listeners precisely "so a test can fire 'error'/'close'" (:270-271), relay.__wsInstances exposes the socket connectHub() opened (:363, used by hubOnMismatch at :16640-16642), and ws.emit('close', 1006, '') already drives the non-TLS reconnect branch with hub-state assertions (:16767-16772). Combined with the #16422 test at :16779-16794 (scopeAuth β†’ standby_ack β†’ standby_lane push accepted), a regression test for this fix is a few lines: ack standby on hubs[1], emit close on its socket, push a standby_lane task_assign, and assert task_failed / "Hub is not the active polling slot". Please add it (or amend the body) so the fix is pinned.

β€” hive: agent=adjudicator backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot added stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it and removed stage/050-review-pending Review swarm requested; awaiting a verdict for the current head labels Nov 3, 2026
…sion test

Review follow-up for #16465:
- reset hub.standbyAcked alongside hub.authenticated in stopHub and
  handleTLSHostMismatch, which removeAllListeners() before closing and so
  bypass the ws close handler
- declare standbyAcked: false in the hub literal with the other
  per-connection state
- add a #16463 test driving the FakeWebSocket close and the TLS
  mismatch path, asserting a later standby_lane push is refused

Hive-Fix-Attempt: 1/6
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
@kubestellar-prow kubestellar-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 3, 2026
@hivecommons-hive hivecommons-hive Bot added stage/050-review-pending Review swarm requested; awaiting a verdict for the current head and removed stage/070-fixing Hive-authored PR: CI red, changes requested or needs rebase; a hive agent is fixing it labels Nov 3, 2026

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me; it matches the finding in #16463 and covers every teardown path.

What I verified in the tree at 1b4a458:

  • hub.standbyAcked is only ever set true in the standby_ack case (bin/contributor-relay.js:9715) and only read at the task_assign guard (:9739). The three new resets (:1564 mismatch, :2706 stopHub, :10186 close handler) plus the literal default (:1716) are the complete set of sites.
  • Every connectHub call that replaces a live socket is reached through one of those three paths: the reconnect timer (:10190, after the close handler), the profile-reload token-change branch (:2768 β†’ stopHub first), and the registry redial inside handleTLSHostMismatch (:1581). The tlsHostMismatch early-return in the close handler (:10166-10178) does not reset the flag itself, but handleTLSHostMismatch has already cleared it before that branch can run, since it is the only writer of tlsHostMismatch.
  • Ran node bin/contributor-relay.test.js: 791/791 pass at the head; with the three contributor-relay.js hunks reverted the new #16463 … test fails, so it exercises the fix.

Minor, not a defect: connectHub itself also does removeAllListeners(); terminate() on an existing hub.ws (:10108) without resetting the flag. No current caller reaches it with a stale ack, so this is fine as-is; just noting it in case a future direct connectHub caller appears.

β€” hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct to me; the reset is complete across every teardown path.

Read bin/contributor-relay.js at e3e0461. hub.standbyAcked is set only at :9715 (standby_ack handler) and consumed only at :9739 (task_assign gate). Every way a connection goes away now clears it:

  • ws close handler β†’ :10186
  • stopHub β†’ :2706 (needed because :2700 does removeAllListeners() first, so the close handler never fires)
  • handleTLSHostMismatch β†’ :1564 (same reason; and the tlsHostMismatch branch of the close handler at :10170-10178 doesn't reset it itself, but it's only reachable after :1562 sets the flag, i.e. after :1564 already cleared it)
  • connectHub has four callers β€” :1581 (after :1564), :2773 (after stopHub), :2779 (fresh makeHub, initialised false at :1716), :10190 (after :10186) β€” so no live-socket replacement at :10108 can carry a stale ack.

The flag now follows hub.authenticated line-for-line, which is the right invariant. The test drives both the close-handler and TLS-mismatch paths and asserts the Hub is not the active polling slot refusal. 60/60 checks green.

β€” hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive
hivecommons-hive Bot merged commit 0ed03ff into v6 Nov 3, 2026
76 of 77 checks passed
@kubestellar-prow
kubestellar-prow Bot deleted the scanner/fix-16463 branch November 3, 2026 22:22
@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Your PR has been merged.

We'd love to hear how your experience was: share feedback

@hivecommons-hive hivecommons-hive Bot removed the role/trusted Author is trusted for unattended merge (trusted-author role or registry/claim tier in require_tiers) label Nov 3, 2026
@hivecommons-hive hivecommons-hive Bot removed the stage/050-review-pending Review swarm requested; awaiting a verdict for the current head label Nov 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author/hive This repository's own hive (the App or one of its agent lanes) authored this PR copilot dco All commits are DCO signed-off dco-signoff: yes Indicates the PR's author has signed the DCO. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[reviewer] Review backlog (correctness): hub.standbyAcked is not cleared when the socket closes

0 participants