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): answer a GitHub rate limit with HTTP 429 [H5,H16]

Corey Olsona00c56143893
diff --git a/relay/auth-http.js b/relay/auth-http.js
index d64bbe7b..be18ef5d 100644
--- a/relay/auth-http.js
+++ b/relay/auth-http.js
@@ -164,7 +164,7 @@ export function createAuthHandler({ auth, publicOrigin }) {
} catch (error) {
const code = error instanceof Refused ? error.code : 'INTERNAL_ERROR';
const message = error instanceof Refused ? error.message.replace(/^\[[^\]]+\] /, '') : 'the relay could not complete this request; retry or contact its coordinator';
- const status = code === 'RELAY_BOARD_DELETED' ? 410 : code === 'BOARD_NOT_LINKED' ? 404 : code === 'AUTH_REQUIRED' ? 401 : ['DEVICE_REVOKED', 'NO_REPO_ACCESS', 'TOKEN_BOARD', 'TOKEN_NOT_OWNED', 'HUMAN_REQUIRED', 'BAD_ORIGIN', 'WRITE_REQUIRED'].includes(code) ? 403 : code === 'GITHUB_UNAVAILABLE' ? 503 : code === 'INTERNAL_ERROR' ? 500 : 400;
+ const status = code === 'RELAY_BOARD_DELETED' ? 410 : code === 'BOARD_NOT_LINKED' ? 404 : code === 'AUTH_REQUIRED' ? 401 : ['DEVICE_REVOKED', 'NO_REPO_ACCESS', 'TOKEN_BOARD', 'TOKEN_NOT_OWNED', 'HUMAN_REQUIRED', 'BAD_ORIGIN', 'WRITE_REQUIRED'].includes(code) ? 403 : code === 'GITHUB_RATE_LIMITED' ? 429 : code === 'GITHUB_UNAVAILABLE' ? 503 : code === 'INTERNAL_ERROR' ? 500 : 400;
json(res, status, { error: { code, message, next: message } });
}
return true;
diff --git a/test/relay-auth.test.js b/test/relay-auth.test.js
index 265b8aae..55ed9cf3 100644
--- a/test/relay-auth.test.js
+++ b/test/relay-auth.test.js
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
import { createServer } from 'node:http';
import { once } from 'node:events';
import { test } from 'node:test';
+import { createAuthHandler } from '../relay/auth-http.js';
import { createGitHubClient } from '../relay/github.js';
import { githubFixture } from './relay-fixture.js';
@@ -25,6 +26,13 @@ test('a GitHub rate limit is named as one [H5,H16]', async (t) => {
assert.match(error.message, new RegExp(resetAt.replace(/[.]/g, '\\.')));
return true;
});
+ const relay = createServer(createAuthHandler({ auth: { boardsFor: () => rateLimited.access(user, 'fixture/repository') }, publicOrigin: 'http://127.0.0.1' }));
+ relay.listen(0, '127.0.0.1');
+ await once(relay, 'listening');
+ t.after(() => { relay.closeAllConnections(); relay.close(); });
+ const answer = await fetch('http://127.0.0.1:' + relay.address().port + '/auth/boards');
+ assert.equal(answer.status, 429);
+ assert.equal((await answer.json()).error.code, 'GITHUB_RATE_LIMITED');
assert.ok(lines.some(line => line.includes('403') && line.includes('x-ratelimit-remaining=0') && line.includes('x-ratelimit-reset=' + reset)), lines.join('\n'));
fixture.state.installed = false;