From d49f1c959f8424b4db978af3dbdb875fcb3b92a9 Mon Sep 17 00:00:00 2001 From: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Date: Tue, 3 Nov 2026 14:59:41 -0500 Subject: [PATCH] fix(relay): accept standby assignments from any acknowledged hub Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com> Co-authored-by: onkar717 <144542684+onkar717@users.noreply.github.com> --- bin/contributor-relay.js | 6 +++++- bin/contributor-relay.test.js | 17 +++++++++++++++++ changelog.d/fixed-standby-relay-active-slot.md | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fixed-standby-relay-active-slot.md diff --git a/bin/contributor-relay.js b/bin/contributor-relay.js index 6b304134ca..2c1c9afb9f 100755 --- a/bin/contributor-relay.js +++ b/bin/contributor-relay.js @@ -9707,6 +9707,7 @@ function handleMessage(data, hub) { const accepted = (msg.standby && Array.isArray(msg.standby.accepted)) ? msg.standby.accepted.length : 0; const rejected = (msg.standby && Array.isArray(msg.standby.rejected)) ? msg.standby.rejected.length : 0; console.log(`Standby acknowledged by ${hub.url}: ${accepted} accepted, ${rejected} rejected`); + hub.standbyAcked = accepted > 0; break; } @@ -9728,7 +9729,10 @@ function handleMessage(data, hub) { sendTo(hub, { type: 'task_failed', seq: nextSeq(), task_id: msg.task_id, reason: 'Hive disabled by contributor', failure_kind: 'environment' }); break; } - if (!currentTask && hub !== hubs[activeHubIndex]) { + // A standby assignment is pushed by the hub that acknowledged this relay's + // standby; the relay is not polling, so that hub is never the active slot. + const standbyPush = !!msg.standby_lane && hub.standbyAcked === true; + if (!currentTask && !standbyPush && hub !== hubs[activeHubIndex]) { console.log(`Rejecting task ${taskDisplay(msg)} from ${hub.url} — hub is not the active polling slot`); sendTo(hub, { type: 'task_failed', seq: nextSeq(), task_id: msg.task_id, reason: 'Hub is not the active polling slot' }); break; diff --git a/bin/contributor-relay.test.js b/bin/contributor-relay.test.js index 14cbb29760..93f6b26d4f 100644 --- a/bin/contributor-relay.test.js +++ b/bin/contributor-relay.test.js @@ -16776,3 +16776,20 @@ test('tls-mismatch: an ordinary error still reconnects with backoff — only the teardown(relay); } }); + +test('#16422 standby assignment from an acknowledging non-active hub is accepted', () => { + const relay = loadRelay({ env: { ...MULTI_HUB_ENV, HIVE_STANDBY: '1' } }); + try { + const { hubs, sentA, sentB } = attachHubSinks(relay); + scopeAuth(relay, hubs[0], []); + scopeAuth(relay, hubs[1], ['standby_v1']); + relay.handleMessage(JSON.stringify({ type: 'standby_ack', standby: { accepted: [{ lane: 'guide' }], rejected: [] } }), hubs[1]); + const offer = { type: 'task_assign', kind: 'issue', repo: 'foo/bar', number: 1, title: 'x' }; + relay.handleMessage(JSON.stringify({ ...offer, task_id: 'plain' }), hubs[1]); + assert.ok(sentB.some(m => m.type === 'task_failed' && m.reason === 'Hub is not the active polling slot'), + 'non-standby work from a non-active hub is still rejected'); + relay.handleMessage(JSON.stringify({ ...offer, task_id: 'sb', standby_lane: 'guide' }), hubs[1]); + assert.ok(sentB.some(m => m.type === 'task_accepted' && m.task_id === 'sb')); + assert.strictEqual(sentA.filter(m => m.type === 'task_failed').length, 0); + } finally { relay.setCurrentTask(null); teardown(relay); } +}); diff --git a/changelog.d/fixed-standby-relay-active-slot.md b/changelog.d/fixed-standby-relay-active-slot.md new file mode 100644 index 0000000000..2d49bded98 --- /dev/null +++ b/changelog.d/fixed-standby-relay-active-slot.md @@ -0,0 +1 @@ +- relay: a multi-hub relay now accepts standby assignments from the hub that acknowledged its standby instead of rejecting them as not the active polling slot (#16422)