Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion bin/contributor-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions bin/contributor-relay.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
});
1 change: 1 addition & 0 deletions changelog.d/fixed-standby-relay-active-slot.md
Original file line number Diff line number Diff line change
@@ -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)
Loading