Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(relay): preserve signal setup refusals during recovery [H3,H16]

Corey Olsonc7a6c2ace003
diff --git a/src/relay.js b/src/relay.js
index 7c578581..16b42684 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -357,9 +357,10 @@ export async function request(state, path, { method = 'GET', body, allowMissing
// Validate first: a refusal below repeats this address, so it must already be credential-free.
const origin = relayOrigin(state.url);
const startedAt = Date.now();
- const requestSignal = signal ? AbortSignal.any([signal, AbortSignal.timeout(10000)]) : AbortSignal.timeout(10000); // budget: original per-request transport ceiling, shared by a replacement GET.
+ let requestSignal;
for (let attempt = 0; ; attempt += 1) {
try {
+ requestSignal ??= signal ? AbortSignal.any([signal, AbortSignal.timeout(10000)]) : AbortSignal.timeout(10000); // budget: original per-request transport ceiling, shared by a replacement GET.
response = await fetch(origin + path, {
method, redirect: 'error', signal: requestSignal,
headers: { 'x-pullboard-engine': String(ENGINE_VERSION), ...(token ? { authorization: 'Bearer ' + token } : {}), ...(body === undefined ? {} : { 'content-type': 'application/json' }), ...(initialBaseline ? { 'if-none-match': '*' } : {}) },
@@ -369,7 +370,7 @@ export async function request(state, path, { method = 'GET', body, allowMissing
} catch (error) {
if (signal?.aborted) throw new Refused('OAUTH_CANCELLED', 'GitHub device sign-in was cancelled; no board was linked');
// A cached connection can reset before its closure reaches the client loop. Only a read may try once more.
- if (method === 'GET' && attempt === 0 && !requestSignal.aborted && transportFailure(error) === 'ECONNRESET') continue;
+ if (method === 'GET' && attempt === 0 && transportFailure(error) === 'ECONNRESET' && requestSignal && !requestSignal.aborted) continue;
const refusal = new Refused('RELAY_UNAVAILABLE', `the relay ${state.url} did not answer (${transportFailure(error)} after ${Date.now() - startedAt} ms on ${method} ${path.split('?')[0]}); read the local board offline, then retry this move when the relay is reachable`);
refusal.transportFailure = transportFailure(error);
throw refusal;
diff --git a/test/relay-client.test.js b/test/relay-client.test.js
index 2cb05222..cc535774 100644
--- a/test/relay-client.test.js
+++ b/test/relay-client.test.js
@@ -26,6 +26,7 @@ import { ENGINE_VERSION } from '../src/machine.js';
import { presentationShout } from '../src/relay-presentation.js';
import { fetchFresh } from './http-fixture.js';
import { relayResetSample } from './relay-reset-fixture.js';
+import { request as relayRequest } from '../src/relay.js';
import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
const SIGN_INS = new Map();
@@ -1364,4 +1365,6 @@ test('relay read recovery stays bounded and preserves refusals, invalid bodies a
const cancelled = await relayResetSample('abort-reset');
assert.equal(cancelled.code, 'OAUTH_CANCELLED');
assert.equal(cancelled.readAttempts, 1, 'cancellation wins at the reset boundary');
+ await assert.rejects(relayRequest({ url: 'http://127.0.0.1:1' }, '/fixture', { signal: {} }, { ignoreRelayEnvironmentToken: true }),
+ error => error.code === 'RELAY_UNAVAILABLE', 'invalid signal setup keeps its existing transport refusal');
});