Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/review/enrichment-wire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,20 @@ export async function buildReviewEnrichment(
}),
signal: AbortSignal.timeout(timeoutMs),
});
if (!response.ok) return undefined;
if (!response.ok) {
// A non-2xx from REES (auth/5xx/bad-gateway) silently degraded the review to no-enrichment with no signal.
// Surface it at ERROR level (same event as the catch below) so the Sentry forwarder catches a broken REES.
console.error(
JSON.stringify({
level: "error",
event: "review_context_fetch_failed",
repository: input.repoFullName,
contextType: "enrichment",
message: `REES /v1/enrich returned ${response.status}`,
}),
);
return undefined;
}
const brief = (await response.json()) as {
promptSection?: string;
systemSuffix?: string;
Expand Down
15 changes: 13 additions & 2 deletions test/unit/enrichment-wire.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,24 @@ describe("buildReviewEnrichment", () => {
expect(await buildReviewEnrichment(env({}), input)).toBeUndefined();
});

it("undefined on a non-200 response", async () => {
it("undefined on a non-200 response, and surfaces it at ERROR for Sentry (was a silent skip)", async () => {
const errSpy = vi.spyOn(console, "error").mockImplementation(() => {});
globalThis.fetch = vi.fn(
async () => ({ ok: false, json: async () => ({}) }) as Response,
async () =>
({ ok: false, status: 502, json: async () => ({}) }) as Response,
) as unknown as typeof fetch;
expect(
await buildReviewEnrichment(env({ REES_URL: "https://r" }), input),
).toBeUndefined();
// A non-2xx REES response now logs at error level (was a silent skip) so a broken backend is visible in Sentry.
expect(
errSpy.mock.calls.some(
(c) =>
String(c[0]).includes("review_context_fetch_failed") &&
String(c[0]).includes("502"),
),
).toBe(true);
errSpy.mockRestore();
});

it("undefined on a fetch error (network/timeout) and surfaces it at ERROR for Sentry (#5)", async () => {
Expand Down
Loading