-
Notifications
You must be signed in to change notification settings - Fork 835
fix: fail closed on unavailable llm review #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
autogame-17
wants to merge
1
commit into
main
Choose a base branch
from
claude/recursing-carson-ca2ddf
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+283
−31
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| 'use strict'; | ||
|
|
||
| const { describe, it, beforeEach, afterEach } = require('node:test'); | ||
| const assert = require('node:assert/strict'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
|
|
||
| const { runLlmReview, parseReviewResponse } = require('../src/gep/llmReview'); | ||
|
|
||
| const input = { | ||
| diff: 'diff --git a/example.js b/example.js\n+const safe = true;', | ||
| gene: { id: 'gene_llm_review_test', category: 'repair' }, | ||
| signals: ['review-boundary'], | ||
| mutation: { rationale: 'exercise the review boundary' }, | ||
| }; | ||
|
|
||
| let previousEnabled; | ||
| beforeEach(function () { | ||
| previousEnabled = process.env.EVOLVER_LLM_REVIEW; | ||
| process.env.EVOLVER_LLM_REVIEW = 'true'; | ||
| }); | ||
| afterEach(function () { | ||
| if (previousEnabled === undefined) delete process.env.EVOLVER_LLM_REVIEW; | ||
| else process.env.EVOLVER_LLM_REVIEW = previousEnabled; | ||
| }); | ||
|
|
||
| function assertUnavailable(result, reason, attempts) { | ||
| assert.equal(result.approved, false); | ||
| assert.equal(result.status, 'unavailable'); | ||
| assert.equal(result.reason, reason); | ||
| assert.equal(result.retryable, true); | ||
| assert.equal(result.attempts, attempts); | ||
| assert.equal(result.trace.length, attempts); | ||
| assert.ok(result.trace.every(entry => entry.status === 'unavailable')); | ||
| } | ||
|
|
||
| describe('llmReview fail-closed boundary', function () { | ||
| it('does not approve malformed output after retry exhaustion', function () { | ||
| const result = runLlmReview(input, { execute: () => 'not-json', maxAttempts: 2 }); | ||
| assertUnavailable(result, 'malformed_output', 2); | ||
| }); | ||
|
|
||
| it('does not approve empty output after retry exhaustion', function () { | ||
| const result = runLlmReview(input, { execute: () => ' \n', maxAttempts: 2 }); | ||
| assertUnavailable(result, 'empty_output', 2); | ||
| }); | ||
|
|
||
| it('does not approve runner errors after retry exhaustion', function () { | ||
| const result = runLlmReview(input, { | ||
| execute: () => { const error = new Error('runner failed'); error.code = 'EIO'; throw error; }, | ||
| maxAttempts: 2, | ||
| }); | ||
| assertUnavailable(result, 'runner_error', 2); | ||
| }); | ||
|
|
||
| it('does not approve timeouts after retry exhaustion', function () { | ||
| const result = runLlmReview(input, { | ||
| execute: () => { const error = new Error('spawnSync node ETIMEDOUT'); error.code = 'ETIMEDOUT'; throw error; }, | ||
| maxAttempts: 2, | ||
| }); | ||
| assertUnavailable(result, 'timeout', 2); | ||
| }); | ||
|
|
||
| it('does not approve truncated or structurally partial responses', function () { | ||
| const truncated = runLlmReview(input, { | ||
| execute: () => '{"approved":true,"confidence":', | ||
| maxAttempts: 1, | ||
| }); | ||
| assertUnavailable(truncated, 'partial_response', 1); | ||
|
|
||
| const incomplete = runLlmReview(input, { | ||
| execute: () => JSON.stringify({ approved: true, confidence: 0.8 }), | ||
| maxAttempts: 1, | ||
| }); | ||
| assertUnavailable(incomplete, 'partial_response', 1); | ||
| }); | ||
|
|
||
| it('retries a recoverable failure and preserves the valid success path', function () { | ||
| let calls = 0; | ||
| const result = runLlmReview(input, { | ||
| execute: () => { | ||
| calls += 1; | ||
| if (calls === 1) return ''; | ||
| return JSON.stringify({ approved: true, confidence: 0.9, concerns: [], summary: 'verified' }); | ||
| }, | ||
| maxAttempts: 2, | ||
| }); | ||
|
|
||
| assert.equal(result.approved, true); | ||
| assert.equal(result.status, 'approved'); | ||
| assert.equal(result.reason, 'review_approved'); | ||
| assert.equal(result.retryable, false); | ||
| assert.equal(result.attempts, 2); | ||
| assert.deepEqual(result.trace, [ | ||
| { attempt: 1, status: 'unavailable', reason: 'empty_output' }, | ||
| { attempt: 2, status: 'approved', reason: 'review_approved' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('preserves explicit rejection and compatibility fields', function () { | ||
| const result = runLlmReview(input, { | ||
| execute: () => JSON.stringify({ | ||
| approved: false, | ||
| confidence: 0.95, | ||
| concerns: ['unsafe mutation'], | ||
| summary: 'reject unsafe mutation', | ||
| }), | ||
| maxAttempts: 1, | ||
| }); | ||
|
|
||
| assert.deepEqual( | ||
| { | ||
| approved: result.approved, | ||
| confidence: result.confidence, | ||
| concerns: result.concerns, | ||
| summary: result.summary, | ||
| status: result.status, | ||
| reason: result.reason, | ||
| }, | ||
| { | ||
| approved: false, | ||
| confidence: 0.95, | ||
| concerns: ['unsafe mutation'], | ||
| summary: 'reject unsafe mutation', | ||
| status: 'rejected', | ||
| reason: 'review_rejected', | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| it('is idempotent for the same input and deterministic runner output', function () { | ||
| const prompts = []; | ||
| const execute = ({ prompt }) => { | ||
| prompts.push(prompt); | ||
| return JSON.stringify({ approved: true, confidence: 0.8, concerns: [], summary: 'stable review' }); | ||
| }; | ||
|
|
||
| const first = runLlmReview(input, { execute, maxAttempts: 1 }); | ||
| const second = runLlmReview(input, { execute, maxAttempts: 1 }); | ||
|
|
||
| assert.deepEqual(second, first); | ||
| assert.equal(prompts.length, 2); | ||
| assert.equal(prompts[1], prompts[0]); | ||
| }); | ||
|
|
||
| it('records a real subprocess trace and removes its temporary directory', function () { | ||
| const before = new Set(fs.readdirSync(os.tmpdir()).filter(name => name.startsWith('evolver-review-'))); | ||
| const result = runLlmReview(input, { maxAttempts: 1, timeoutMs: 5000 }); | ||
| const after = fs.readdirSync(os.tmpdir()).filter(name => name.startsWith('evolver-review-')); | ||
|
|
||
| assert.equal(result.approved, true); | ||
| assert.deepEqual(result.trace, [{ attempt: 1, status: 'approved', reason: 'review_approved' }]); | ||
| assert.deepEqual(after.filter(name => !before.has(name)), []); | ||
| }); | ||
|
|
||
| it('returns null when review is disabled', function () { | ||
| process.env.EVOLVER_LLM_REVIEW = 'false'; | ||
| assert.equal(runLlmReview(input, { execute: () => { throw new Error('must not run'); } }), null); | ||
| }); | ||
| }); | ||
|
|
||
| describe('parseReviewResponse', function () { | ||
| it('rejects out-of-range confidence', function () { | ||
| const invalid = parseReviewResponse(JSON.stringify({ approved: true, confidence: 2, concerns: [], summary: 'bad' })); | ||
| assert.equal(invalid.ok, false); | ||
| assert.equal(invalid.reason, 'partial_response'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temp dir leaks on write failure
Low Severity
mkdtempSynccreatesevolver-review-*before thetry/finally, andwriteFileSyncalso sits outside that block. If the prompt write throws, the new directory is never removed, unlike theexecFileSyncpath which always cleans up infinally.Reviewed by Cursor Bugbot for commit b094d5b. Configure here.