Retry when the model provider fails a turn instead of calling it invalid JSON. A Codex turn that ends failed (9router "high demand" on lti-api !1388 and lti-web-client !859) left an empty answer that Labuh parsed as invalid JSON, answered with "Labuh rejected your verdict", and gave up within a minute. Now the turn error surfaces as ReviewerUnavailable, no rejection prompt is sent, the queue waits 2/4/8/16/32 minutes, and only then posts a manual-check comment that says the model could not be reached. An empty answer from a completed turn is reported as empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 18:02:52 +07:00
parent 710782b786
commit 2723f9b998
8 changed files with 111 additions and 11 deletions

View File

@@ -99,3 +99,8 @@ test('evidence must exist; ok without evidence is dropped; failing pipeline hold
const escape: Verdict = { verdict: 'no_go', reason: 'Tahan', post_deploy: [], findings: [{ kind: 'bad', text: 'keluar repo', evidence: [ev({ path: '../../etc/hosts', line: 1 })] }] };
assert.match((await check(escape, ctx)).errors.join(), /does not exist/);
});
test('an empty answer is reported as empty, not as invalid JSON', async () => {
const { shapeErrors } = await import('../src/contract.ts');
assert.deepEqual(shapeErrors(' ').errors, ['The answer is empty.']);
});

View File

@@ -696,3 +696,63 @@ test('a rejected MR can be closed after the grace period; undo drops only the cl
assert.deepEqual(dry.w.gl.closed, []);
assert.equal(dry.w.store.ajuanById(dry.a.id).status, 'go');
});
// lti-api !1388 (2026-11-09): 9router answered "high demand" and Codex ended both turns
// `failed` with no message. Labuh read the empty text as invalid JSON, told the model its
// verdict was rejected, and gave up at once with a misleading comment.
const unavailable = () => {
const e = new Error('Model tidak bisa dihubungi: We’re currently experiencing high demand');
e.name = 'ReviewerUnavailable';
throw e;
};
test('a turn the provider failed is not a rejected verdict: review stops after one turn', async () => {
const turns: string[] = [];
const s = {
mr: { webUrl: 'https://gitlab.com/x', sha: 's', pipeline: null, pipelineIds: [], projectId: 1, diffs: [], commits: [], labels: [] },
reviewer,
threadId: 't',
workDir: mkdtempSync(path.join(os.tmpdir(), 'labuh-rev-')),
usage: null,
client: {
runTurn: async (_t: string, prompt: string) => {
turns.push(prompt);
return { finalText: '', usage: null, commands: [], refused: [], error: { message: 'We’re currently experiencing high demand', info: 'internal_server_error' } };
},
},
} as unknown as Session;
await assert.rejects(review(s), (e: any) => e.name === 'ReviewerUnavailable' && /high demand/.test(e.message));
assert.equal(turns.length, 1, 'no "Labuh rejected your verdict" turn follows');
});
test('provider failures make the queue wait and retry, then the review lands', async () => {
const w = world();
w.gl.mrs.set(21, { sha: 'abab1111', state: 'opened', labels: ['labuh'] });
w.script(unavailable, unavailable, ok(checked('go', 'Aman')));
await w.hub.poll();
const t0 = Date.now();
assert.equal(await w.hub.drain(t0), 0);
assert.equal(await w.hub.drain(t0 + 60_000), 0, 'still waiting out the first 2 minutes');
assert.equal(w.calls.review.length, 1, 'no review call while waiting');
assert.equal(await w.hub.drain(t0 + 2 * 60_000), 0, 'second failure: now waits 4 minutes');
assert.equal(await w.hub.drain(t0 + 5 * 60_000), 0);
assert.equal(await w.hub.drain(t0 + 6 * 60_000), 1);
assert.equal(w.store.ajuan(PROJECT, 21)!.status, 'go');
assert.equal(w.store.outbox(w.store.ajuan(PROJECT, 21)!.id).filter((o) => /Perlu dicek manual/.test(o.body)).length, 0, 'no error comment on the way');
});
test('a provider down for about an hour ends in a manual check that says so', async () => {
const w = world();
w.gl.mrs.set(22, { sha: 'cdcd2222', state: 'opened', labels: ['labuh'] });
w.script(unavailable, unavailable, unavailable, unavailable, unavailable, unavailable);
await w.hub.poll();
let t = Date.now();
for (let i = 0; i < 6; i++, t += 33 * 60_000) await w.hub.drain(t);
const a = w.store.ajuan(PROJECT, 22)!;
assert.equal(w.calls.review.length, 6);
assert.equal(a.status, 'reviewer_error');
const body = w.store.outbox(a.id)[0].body;
assert.match(body, /tidak bisa dihubungi/);
assert.doesNotMatch(body, /not valid JSON/);
assert.equal(w.store.nextEvent(), undefined);
});