From 117b10de278b86649fabbb57e0ee54e57c3521f7 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:39:20 -0500 Subject: [PATCH 1/2] fix(relay): clear hub.standbyAcked when the hub socket closes Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> --- bin/contributor-relay.js | 1 + changelog.d/fixed-relay-standby-acked-reset.md | 1 + 2 files changed, 2 insertions(+) create mode 100644 changelog.d/fixed-relay-standby-acked-reset.md diff --git a/bin/contributor-relay.js b/bin/contributor-relay.js index 2c1c9afb9f..73f09ead7d 100755 --- a/bin/contributor-relay.js +++ b/bin/contributor-relay.js @@ -10178,6 +10178,7 @@ function connectHub(hub) { hub.readyOutstanding = false; hub.authenticated = false; hub.scopeAckVersion = null; + hub.standbyAcked = false; hub.scopePending = hub.repoScope !== null || !!hub.scopeSent; writeRelayStatus(); invalidateReadyRetry(hub, 'socket closed'); diff --git a/changelog.d/fixed-relay-standby-acked-reset.md b/changelog.d/fixed-relay-standby-acked-reset.md new file mode 100644 index 0000000000..e93bfe8740 --- /dev/null +++ b/changelog.d/fixed-relay-standby-acked-reset.md @@ -0,0 +1 @@ +- relay: a hub that acknowledged standby no longer stays trusted for standby_lane pushes after its socket closes (#16463) From 1b4a458c36cf4017fb5d58c39efbace432c9fc66 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 15:58:52 -0500 Subject: [PATCH 2/2] fix(relay): forget standby ack on every hub teardown path; add regression 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> --- bin/contributor-relay.js | 5 ++++ bin/contributor-relay.test.js | 49 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/bin/contributor-relay.js b/bin/contributor-relay.js index 73f09ead7d..3c985ebabb 100755 --- a/bin/contributor-relay.js +++ b/bin/contributor-relay.js @@ -1561,6 +1561,7 @@ let fetchHubRegistry = (registryURL, cb) => { function handleTLSHostMismatch(hub, err) { hub.tlsHostMismatch = true; hub.authenticated = false; + hub.standbyAcked = false; const registryURL = hub.relocationAttempted ? null : hubRegistryURLFor(hub.sourceURL || hub.url); if (!registryURL) { console.error(tlsHostMismatchRemediation(hub, null)); @@ -1710,6 +1711,9 @@ function makeHub(url, token, disabled = false, contributorId = '', repoScope = n readyRequestSeq: 0, authenticated: false, authFailed: false, + // #16462/#16463: set by standby_ack, cleared whenever the connection it + // was granted on goes away. + standbyAcked: false, // Set by handleTLSHostMismatch when the dialed host is not in the served // certificate; parks the hub (no reconnect loop) until contributor.env // changes. relocationAttempted bounds the hub-registry re-resolution to @@ -2699,6 +2703,7 @@ function stopHub(hub, reason) { hub.ws = null; } hub.authenticated = false; + hub.standbyAcked = false; hub.readyOutstanding = false; hub.connectGeneration++; writeRelayStatus(); diff --git a/bin/contributor-relay.test.js b/bin/contributor-relay.test.js index 93f6b26d4f..a0dcf4da10 100644 --- a/bin/contributor-relay.test.js +++ b/bin/contributor-relay.test.js @@ -16793,3 +16793,52 @@ test('#16422 standby assignment from an acknowledging non-active hub is accepted assert.strictEqual(sentA.filter(m => m.type === 'task_failed').length, 0); } finally { relay.setCurrentTask(null); teardown(relay); } }); + +test('#16463 standby acknowledgement does not outlive the connection it was granted on', () => { + const relay = loadRelay({ env: { ...MULTI_HUB_ENV, HIVE_STANDBY: '1' } }); + const log = console.log; const error = console.error; + console.log = () => {}; console.error = () => {}; + try { + const { hubs, sentB } = attachHubSinks(relay); + const hub = hubs[1]; + scopeAuth(relay, hubs[0], []); + relay.__wsInstances.length = 0; + relay.connectHub(hub); + const ws = relay.__wsInstances[0]; + assert.ok(ws, 'setup: connectHub must open a socket'); + ws.send = p => sentB.push(JSON.parse(p)); + const ack = JSON.stringify({ type: 'standby_ack', standby: { accepted: [{ lane: 'guide' }], rejected: [] } }); + const offer = { type: 'task_assign', kind: 'issue', repo: 'foo/bar', number: 1, title: 'x', standby_lane: 'guide' }; + + // ws close handler: the socket the ack arrived on dies. + scopeAuth(relay, hub, ['standby_v1']); + relay.handleMessage(ack, hub); + assert.strictEqual(hub.standbyAcked, true, 'setup: standby acknowledged on the first connection'); + ws.emit('close', 1006, ''); + if (hub.reconnectTimer) { clearTimeout(hub.reconnectTimer); hub.reconnectTimer = null; } + assert.strictEqual(hub.standbyAcked, false, 'the close handler forgets the acknowledgement'); + // The reconnected hub no longer advertises standby_v1, so declareStandby + // never asks and no standby_ack arrives; its standby_lane push must be + // refused like any other non-active-hub assignment. + scopeAuth(relay, hub, []); + relay.handleMessage(JSON.stringify({ ...offer, task_id: 'after-close' }), hub); + assert.ok(sentB.some(m => m.type === 'task_failed' && m.task_id === 'after-close' && m.reason === 'Hub is not the active polling slot'), + `standby push after reconnect is rejected: ${JSON.stringify(sentB.filter(m => m.task_id === 'after-close'))}`); + assert.ok(!sentB.some(m => m.type === 'task_accepted' && m.task_id === 'after-close')); + + // TLS host-mismatch redial: tears the socket down without its close handler. + scopeAuth(relay, hub, ['standby_v1']); + relay.handleMessage(ack, hub); + assert.strictEqual(hub.standbyAcked, true, 'setup: standby acknowledged again'); + relay.handleTLSHostMismatch(hub, ALTNAME_ERR); + assert.strictEqual(hub.standbyAcked, false, 'the mismatch path forgets the acknowledgement too'); + hub.tlsHostMismatch = false; + scopeAuth(relay, hub, []); + relay.handleMessage(JSON.stringify({ ...offer, task_id: 'after-mismatch' }), hub); + assert.ok(sentB.some(m => m.type === 'task_failed' && m.task_id === 'after-mismatch' && m.reason === 'Hub is not the active polling slot')); + assert.ok(!sentB.some(m => m.type === 'task_accepted' && m.task_id === 'after-mismatch')); + } finally { + console.log = log; console.error = error; + relay.setCurrentTask(null); teardown(relay); + } +});