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.

Merge commit '2f627bdaaa2c9c00148501d8eeef99e9c6814da8' into HEAD

Corey Olson7ee71942a5eb
diff --cc src/relay.js
index 1456ae66,e60cf365..cc70eacb
--- a/src/relay.js
+++ b/src/relay.js
@@@ -339,51 -347,53 +347,54 @@@ async function rawRequest(state, path,
// Validate first: a refusal below repeats this address, so it must already be credential-free.
const origin = relayOrigin(state.url);
const startedAt = Date.now();
- let requestSignal;
- for (let attempt = 0; ; attempt += 1) {
- try {
- requestSignal ??= signal ? AbortSignal.any([signal, AbortSignal.timeout(io?.relayTimeoutMs ?? 10000)]) : AbortSignal.timeout(io?.relayTimeoutMs ?? 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': '*' } : {}) },
- ...(body === undefined ? {} : { body: JSON.stringify(body) }),
- });
- break;
- } catch (error) {
+ const finishPhase = beginCommandPhase('waiting-relay');
+ try {
+ let requestSignal;
+ for (let attempt = 0; ; attempt += 1) {
+ try {
+ requestSignal ??= signal ? AbortSignal.any([signal, AbortSignal.timeout(io?.relayTimeoutMs ?? 10000)]) : AbortSignal.timeout(io?.relayTimeoutMs ?? 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': '*' } : {}) },
+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),
+ });
+ break;
+ } catch (error) {
+ if (signal?.aborted) throw new Refused('OAUTH_CANCELLED', 'GitHub device sign-in was cancelled; no board was linked');
+ // A stale cached connection reports ECONNRESET or EPIPE across supported Node runtimes. Only a read may try once more.
+ if (method === 'GET' && attempt === 0 && ['ECONNRESET', 'EPIPE'].includes(transportFailure(error)) && 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;
+ }
+ }
+ let document;
+ try { document = await response.json(); }
+ catch {
if (signal?.aborted) throw new Refused('OAUTH_CANCELLED', 'GitHub device sign-in was cancelled; no board was linked');
- // A stale cached connection reports ECONNRESET or EPIPE across supported Node runtimes. Only a read may try once more.
- if (method === 'GET' && attempt === 0 && ['ECONNRESET', 'EPIPE'].includes(transportFailure(error)) && 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;
+ const error = new Refused('RELAY_RESPONSE', 'the relay returned an invalid response; retry with the configured relay address');
+ error.httpStatus = response.status;
+ throw error;
}
- }
- let document;
- try { document = await response.json(); }
- catch {
- if (signal?.aborted) throw new Refused('OAUTH_CANCELLED', 'GitHub device sign-in was cancelled; no board was linked');
- const error = new Refused('RELAY_RESPONSE', 'the relay returned an invalid response; retry with the configured relay address');
- error.httpStatus = response.status;
- throw error;
- }
- relayNotices(document, io);
- // Only off can forget a link after a supported API reports that the board is gone.
- if (allowMissing && method === 'DELETE' && response.status === 404 && document.version === 1) return { alreadyDeleted: true };
- if (!response.ok) {
- const error = new Refused(document.error?.code || 'RELAY_UNAVAILABLE', (document.error?.code === 'AUTH_REQUIRED' ? ((state.agent || token?.startsWith('pa_')) ? 'this agent token is expired or revoked; use a new token issued by the person for this agent, then retry with PULLBOARD_RELAY_TOKEN' : 'the relay sign-in expired or was revoked; run pullboard relay on to sign in again without changing the board key') : (document.error?.message ? `the relay ${state.url}: ${document.error.message}` : null)) || 'the relay refused this send; retry this command explicitly when reachable',
- document.error?.code === 'AUTH_REQUIRED' ? undefined : document.error?.next);
- error.httpStatus = response.status;
- error.relayVersion = document.version;
- error.relayCode = document.error?.code;
- error.relayMessage = document.error?.message;
- if (document.version === 1 && document.error?.code === 'BAD_UPLOAD') error.snapshotLimit = document.error.snapshotLimit;
- if (/^[0-9a-f]{64}$/u.test(document.error?.page ?? '')) error.page = document.error.page;
- const storage = relayStorage(document.error?.storage);
- if (storage) error.storage = storage;
- throw error;
- }
- if (document.version !== 1) throw new Refused('RELAY_VERSION', 'the relay API version is unsupported; upgrade Pullboard before syncing');
- return document;
+ relayNotices(document, io);
+ // Only off can forget a link after a supported API reports that the board is gone.
+ if (allowMissing && method === 'DELETE' && response.status === 404 && document.version === 1) return { alreadyDeleted: true };
+ if (!response.ok) {
+ const error = new Refused(document.error?.code || 'RELAY_UNAVAILABLE', (document.error?.code === 'AUTH_REQUIRED' ? ((state.agent || token?.startsWith('pa_')) ? 'this agent token is expired or revoked; use a new token issued by the person for this agent, then retry with PULLBOARD_RELAY_TOKEN' : 'the relay sign-in expired or was revoked; run pullboard relay on to sign in again without changing the board key') : (document.error?.message ? `the relay ${state.url}: ${document.error.message}` : null)) || 'the relay refused this send; retry this command explicitly when reachable',
+ document.error?.code === 'AUTH_REQUIRED' ? undefined : document.error?.next);
+ error.httpStatus = response.status;
+ error.relayVersion = document.version;
+ error.relayCode = document.error?.code;
+ error.relayMessage = document.error?.message;
++ if (document.version === 1 && document.error?.code === 'BAD_UPLOAD') error.snapshotLimit = document.error.snapshotLimit;
+ if (/^[0-9a-f]{64}$/u.test(document.error?.page ?? '')) error.page = document.error.page;
+ const storage = relayStorage(document.error?.storage);
+ if (storage) error.storage = storage;
+ throw error;
+ }
+ if (document.version !== 1) throw new Refused('RELAY_VERSION', 'the relay API version is unsupported; upgrade Pullboard before syncing');
+ return document;
+ } finally { finishPhase(); }
}
/** Read durable local event rows; their ids are the crash-safe outbox after the saved cursor. */