Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(commit-feed-push): catch generic lane errors instead of crashing to a raw 500

nirholasea3093d7f230
diff --git a/api/cron/commit-feed-push.js b/api/cron/commit-feed-push.js
index 034a71af2..a6d667911 100644
--- a/api/cron/commit-feed-push.js
+++ b/api/cron/commit-feed-push.js
@@ -35,6 +35,15 @@ export default wrapCron(async (req, res) => {
const failed = Boolean(telegram.error);
if (failed) console.warn('[cron] commit-feed-push lane error', { telegram });
json(res, failed ? 502 : 200, { ok: !failed, telegram });
+ } catch (err) {
+ // pushTelegramLane only swallows its own GitHub-rate-limit case; a
+ // transient GitHub 5xx or network blip fetching a commit page throws
+ // here instead. The lane is idempotent (state lives in app_settings),
+ // so reporting the failure and letting the next tick retry is correct;
+ // re-throwing to wrap()'s generic handler only turned that into a raw
+ // 500 and an unnecessary ops alert.
+ console.warn('[cron] commit-feed-push threw', err?.message || err);
+ json(res, 502, { ok: false, error: String(err?.message || err) });
} finally {
await releaseLock().catch(() => {});
}
diff --git a/tests/commit-feed-push-handler.test.js b/tests/commit-feed-push-handler.test.js
new file mode 100644
index 000000000..5fe21ca2d
--- /dev/null
+++ b/tests/commit-feed-push-handler.test.js
@@ -0,0 +1,68 @@
+// Handler-level test for api/cron/commit-feed-push.js.
+//
+// Production 2026-10-24: a single HTTP 500 on this route with no matching app
+// log. pushTelegramLane() only catches its own GitHub-rate-limit error; any
+// other failure (a transient GitHub 5xx, a network blip fetching a commit
+// page) throws straight out of it. The handler's try/finally has no catch, so
+// that throw reached wrap()'s generic handler and answered a raw 500 instead
+// of the graceful { ok: false } this cron already gives a Telegram failure.
+// Since the cron runs every 5 minutes and is state-driven (app_settings), a
+// transient failure should be reported and retried next tick, not crash.
+
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+const lock = { held: false };
+const pushResult = { value: null, throws: null };
+vi.mock('../api/_lib/commit-feed-push.js', () => ({
+ acquireLock: vi.fn(async () => !lock.held),
+ releaseLock: vi.fn(async () => {}),
+ pushTelegramLane: vi.fn(async () => {
+ if (pushResult.throws) throw pushResult.throws;
+ return pushResult.value;
+ }),
+}));
+vi.mock('../api/_lib/cron-auth.js', () => ({ requireCron: vi.fn(() => true) }));
+
+const { default: handler } = await import('../api/cron/commit-feed-push.js');
+
+function makeReqRes() {
+ const req = { method: 'GET', url: '/api/cron/commit-feed-push', headers: {} };
+ const res = {
+ statusCode: 200,
+ headers: {},
+ body: '',
+ headersSent: false,
+ writableEnded: false,
+ setHeader(k, v) { this.headers[k.toLowerCase()] = v; },
+ getHeader(k) { return this.headers[k.toLowerCase()]; },
+ end(b) { this.body = b ?? ''; this.writableEnded = true; this.headersSent = true; },
+ };
+ return { req, res };
+}
+
+describe('commit-feed-push handler', () => {
+ beforeEach(() => {
+ lock.held = false;
+ pushResult.value = { posted: 0 };
+ pushResult.throws = null;
+ });
+
+ it('answers a graceful degraded response, not a 500, when pushTelegramLane throws a non-rate-limit error', async () => {
+ pushResult.throws = new Error('GitHub commits fetch failed (502)');
+ const { req, res } = makeReqRes();
+ await handler(req, res);
+ expect(res.statusCode).not.toBe(500);
+ expect(res.statusCode).toBe(502);
+ const body = JSON.parse(res.body);
+ expect(body.ok).toBe(false);
+ expect(body.error).toContain('GitHub commits fetch failed');
+ });
+
+ it('still releases the lock after a thrown error', async () => {
+ pushResult.throws = new Error('boom');
+ const { releaseLock } = await import('../api/_lib/commit-feed-push.js');
+ const { req, res } = makeReqRes();
+ await handler(req, res);
+ expect(releaseLock).toHaveBeenCalled();
+ });
+});