From bd3a86c1200399509958aacd523e70c9158c0bae Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 20 Nov 2026 14:20:16 +0000 Subject: [PATCH] Write the review trace while the review runs The trace was buffered in memory and written only once the review finished, so a running review's page in the Console showed no steps even though it polls for them. Each step now queues a write; steps recorded while one is out go in the next, so a busy review sends batches rather than a request per step. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01F3M7tuyQdK2G5ViFDvatmP Co-authored-by: Torsten Dittmann <1759475+TorstenDittmann@users.noreply.github.com> --- packages/engine/src/review-job.test.ts | 30 ++++++++++++++++++++++++++ packages/engine/src/review-job.ts | 13 +++++++++++ 2 files changed, 43 insertions(+) diff --git a/packages/engine/src/review-job.test.ts b/packages/engine/src/review-job.test.ts index 1980dbc..f4d1a75 100644 --- a/packages/engine/src/review-job.test.ts +++ b/packages/engine/src/review-job.test.ts @@ -185,6 +185,36 @@ describe('runReviewJob', () => { expect(results.events.some((e) => e.type === 'review.posted')).toBe(true); }); + test('writes the trace while the review runs, so the Console can follow it live', async () => { + let seenWhileRunning: string[] = []; + const { github, results, context } = setup(); + const model = new MockLanguageModelV4({ + doGenerate: async () => { + seenWhileRunning = results.events.map((e) => e.type); + return toolCall('submit_review', { + summary: 'Divides for real.', + findings: [], + tier: 'A', + walkthrough: [] + }); + } + }); + context.models = { review: { model, provider: 'mock', modelId: 'mock-1' } }; + github.patches = [ + { + path: 'src/math.ts', + patch: + '@@ -1,3 +1,3 @@\n export function divide(a, b) {\n- return 0;\n+ return a / b;\n }' + } + ]; + results.queue({ id: 'review1' }); + + await runReviewJob(job(), context, first); + + expect(seenWhileRunning).toContain('review.mode'); + expect(results.review('review1')?.status).toBe('completed'); + }); + test('a push that changes nothing after the blocking finding settled stops blocking the PR', async () => { const model = new MockLanguageModelV4({ doGenerate: [ diff --git a/packages/engine/src/review-job.ts b/packages/engine/src/review-job.ts index d82a0e1..cb08fa6 100644 --- a/packages/engine/src/review-job.ts +++ b/packages/engine/src/review-job.ts @@ -281,8 +281,21 @@ async function executeReview( .catch((error: unknown) => log.warn('could not record review usage', { err: error })); return pendingWrites; }; + // Steps are written as they happen, so the Console can follow a running review. Steps + // recorded while a write is out wait for the next one, so a busy review sends batches, + // not a request per step. + let writeQueued = false; + const flushSoon = () => { + if (writeQueued) return; + writeQueued = true; + pendingWrites = pendingWrites.then(() => { + writeQueued = false; + }); + void flush(); + }; const record = (event: TraceStep) => { events.push({ type: event.type, at: new Date(), data: event.data ?? {} }); + flushSoon(); progress.onEvent(event); if (event.type !== 'anchoring.suspicious') return; log.warn('most findings could not be attached to a changed line', {