Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

πŸ› fix(verify): repair Acceptance-review rejections inside the round (#21790)

Arvin Xu9c892d31c6ef
diff --git a/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts b/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts
index 34aacced7db..0909f05b017 100644
--- a/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts
+++ b/apps/server/src/services/verify/__tests__/driveTaskFromVerify.test.ts
@@ -10,7 +10,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { scheduleGoalAdvance } from '@/server/services/goal/scheduler';
import { reviewGoalDelivery } from '../goalReview';
-import { maybeAutoRepair } from '../repairService';
+import { maybeAutoRepair, repairRejectedReview } from '../repairService';
import { driveTaskFromVerify, finalizeVerifyRun } from '../settle';
import { attachTaskRunToAcceptance, resolveTaskAcceptance } from '../taskAcceptance';
@@ -28,6 +28,7 @@ vi.mock('../taskAcceptance', () => ({
vi.mock('../repairService', () => ({
maybeAutoRepair: vi.fn(),
+ repairRejectedReview: vi.fn().mockResolvedValue(null),
}));
vi.mock('../reporter', () => ({
VerifyReporterService: vi.fn(function () {
@@ -160,6 +161,62 @@ describe('driveTaskFromVerify', () => {
);
});
+ /**
+ * Regression: a Goal Task whose content was done in its first attempt ran
+ * seven more, each a fresh topic re-capturing evidence, because a review
+ * rejection always paused the Task into another attempt. A repairable check is
+ * now fixed inside the round, and the repair round settles the Task.
+ */
+ it('repairs a rejected check in the round instead of pausing the Goal Task', async () => {
+ runFindByOperation.mockResolvedValue({
+ id: 'run-1',
+ acceptanceId: 'acceptance-1',
+ status: 'passed',
+ });
+ goalFindByTask.mockResolvedValue({ id: 'goal-1' });
+ const rejectedChecks = [{ checkItemId: 'c1', feedback: 'Add the second screenshot.' }];
+ vi.mocked(reviewGoalDelivery).mockResolvedValueOnce({
+ status: 'rejected',
+ feedback: 'Landing: Add the second screenshot.',
+ predictionIds: ['p1'],
+ rejectedChecks,
+ });
+ vi.mocked(repairRejectedReview).mockResolvedValueOnce({ repairOperationId: 'repair-op' });
+
+ await driveTaskFromVerify(db, 'u1', 'op-1');
+
+ expect(repairRejectedReview).toHaveBeenCalledWith(db, 'u1', 'op-1', rejectedChecks, undefined);
+ expect(taskUpdateStatus).not.toHaveBeenCalled();
+ expect(serviceUpdateStatus).not.toHaveBeenCalled();
+ expect(deliverMock).not.toHaveBeenCalled();
+ expect(scheduleGoalAdvance).not.toHaveBeenCalled();
+ });
+
+ it('pauses the Goal Task as before when no in-round repair can start', async () => {
+ runFindByOperation.mockResolvedValue({
+ id: 'run-1',
+ acceptanceId: 'acceptance-1',
+ status: 'passed',
+ });
+ goalFindByTask.mockResolvedValue({ id: 'goal-1' });
+ vi.mocked(reviewGoalDelivery).mockResolvedValueOnce({
+ status: 'rejected',
+ feedback: 'Landing: Add the second screenshot.',
+ predictionIds: ['p1'],
+ rejectedChecks: [{ checkItemId: 'c1', feedback: 'Add the second screenshot.' }],
+ });
+ vi.mocked(repairRejectedReview).mockResolvedValueOnce(null);
+
+ await driveTaskFromVerify(db, 'u1', 'op-1');
+
+ expect(taskUpdateStatus).toHaveBeenCalledWith('task-1', 'paused', {
+ error: 'Delivery did not pass verification.',
+ });
+ expect(scheduleGoalAdvance).toHaveBeenCalledWith(
+ expect.objectContaining({ goalId: 'goal-1', trigger: 'settle' }),
+ );
+ });
+
/**
* Regression: an undecidable criterion paused the Task with the "did not pass"
* contract string, which the coordinator routes to another attempt. The
diff --git a/apps/server/src/services/verify/__tests__/goalReview.test.ts b/apps/server/src/services/verify/__tests__/goalReview.test.ts
index 0eede79de31..c8386c738c4 100644
--- a/apps/server/src/services/verify/__tests__/goalReview.test.ts
+++ b/apps/server/src/services/verify/__tests__/goalReview.test.ts
@@ -160,6 +160,37 @@ describe('Goal automatic Acceptance review', () => {
});
});
+ it('names the rejected checks of the reviewed round so they can be repaired in it', async () => {
+ mocks.predict.mockResolvedValue({
+ id: 'p1',
+ status: 'judged',
+ action: 'reject',
+ comment: 'Each chapter needs a second screenshot.',
+ });
+ expect(await reviewGoalDelivery(db, 'u1', 't1', 'op1')).toMatchObject({
+ rejectedChecks: [{ checkItemId: 'c1', feedback: 'Each chapter needs a second screenshot.' }],
+ });
+ });
+
+ it('does not offer an earlier round’s result for an in-round repair', async () => {
+ mocks.run.mockResolvedValue({ id: 'r2', acceptanceId: 'a1', metadata: {} });
+ mocks.rounds.mockResolvedValue({
+ runs: [
+ { id: 'r1', roundIndex: 1, plan: [check] },
+ { id: 'r2', roundIndex: 2, plan: [{ ...check, id: 'c2' }] },
+ ],
+ results: [result, { ...result, id: 'result2', checkItemId: 'c2', verifyRunId: 'r2' }],
+ });
+ mocks.predict.mockImplementation(async ({ checkResultId }: { checkResultId: string }) =>
+ checkResultId === 'result1'
+ ? { id: 'p1', status: 'judged', action: 'reject', comment: 'Old evidence is short.' }
+ : { id: 'p2', status: 'judged', action: 'accept' },
+ );
+ const review = await reviewGoalDelivery(db, 'u1', 't1', 'op1');
+ expect(review?.status).toBe('rejected');
+ expect(review?.rejectedChecks).toBeUndefined();
+ });
+
it('reviews supplementary checks across rounds, not only the bound run', async () => {
mocks.run.mockResolvedValue({ id: 'r2', acceptanceId: 'a1', metadata: {} });
mocks.rounds.mockResolvedValue({
diff --git a/apps/server/src/services/verify/__tests__/repairService.test.ts b/apps/server/src/services/verify/__tests__/repairService.test.ts
index 083f96b4f3a..7ef4469f37a 100644
--- a/apps/server/src/services/verify/__tests__/repairService.test.ts
+++ b/apps/server/src/services/verify/__tests__/repairService.test.ts
@@ -1,7 +1,7 @@
// @vitest-environment node
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { VerifyRepairService } from '../repairService';
+import { carriedRunPolicy, VerifyRepairService } from '../repairService';
const m = vi.hoisted(() => ({
findVerifyMessage: vi.fn(),
@@ -140,6 +140,127 @@ describe('VerifyRepairService.triggerAutoRepair', () => {
).toEqual({ repairOperationId: 'repair-op' });
});
+ /**
+ * Regression: rounds the Goal's Acceptance review sent back still read
+ * `passed`, so they counted as a delivered acceptance and every later round's
+ * auto-repair was declined as superseded. A one-artifact gap then cost a whole
+ * new Task attempt each time.
+ */
+ it('still repairs after a passed round the Acceptance review sent back', async () => {
+ m.listResults.mockResolvedValue([gateFailure('gif-check')]);
+ m.rounds.mockResolvedValue([
+ {
+ id: 'round-2',
+ metadata: { goalReview: { status: 'rejected' } },
+ roundIndex: 2,
+ status: 'passed',
+ userDecision: null,
+ },
+ round,
+ ]);
+ const spawner = vi.fn().mockResolvedValue({ repairOperationId: 'repair-op' });
+
+ expect(
+ await new VerifyRepairService({} as any, 'user').triggerAutoRepair('op-3', spawner),
+ ).toEqual({ repairOperationId: 'repair-op' });
+ });
+
+ it('stops once another round passed the Acceptance review too', async () => {
+ m.listResults.mockResolvedValue([gateFailure('gif-check')]);
+ m.rounds.mockResolvedValue([
+ {
+ id: 'round-2',
+ metadata: { goalReview: { status: 'passed' } },
+ roundIndex: 2,
+ status: 'passed',
+ userDecision: null,
+ },
+ round,
+ ]);
+ const spawner = vi.fn();
+
+ expect(
+ await new VerifyRepairService({} as any, 'user').triggerAutoRepair('op-3', spawner),
+ ).toBeNull();
+ expect(spawner).not.toHaveBeenCalled();
+ });
+
+ describe('a check the Acceptance review sent back', () => {
+ const reviewed = {
+ ...round,
+ plan: [
+ {
+ ...item('landing'),
+ title: 'Chapters land in the site',
+ verifierConfig: {
+ requiredEvidence: [
+ { hint: 'β‰₯2 screenshots per chapter', type: 'screenshot' },
+ { type: 'dom_snapshot' },
+ ],
+ },
+ },
+ item('optional-video', false),
+ ],
+ status: 'passed',
+ };
+ const rejection = [{ checkItemId: 'landing', feedback: 'ch09 lacks its second screenshot.' }];
+
+ beforeEach(() => {
+ m.run.mockResolvedValue(reviewed);
+ m.rounds.mockResolvedValue([reviewed]);
+ m.listResults.mockResolvedValue([
+ { checkItemId: 'landing', status: 'passed', verdict: 'passed' },
+ ]);
+ });
+
+ it('is repaired in the round although its verifier passed it', async () => {
+ const spawner = vi.fn().mockResolvedValue({ repairOperationId: 'repair-op' });
+
+ expect(
+ await new VerifyRepairService({} as any, 'user').triggerAutoRepair(
+ 'op-3',
+ spawner,
+ rejection,
+ ),
+ ).toEqual({ repairOperationId: 'repair-op' });
+ expect(spawner).toHaveBeenCalledWith(expect.objectContaining({ failedItemIds: ['landing'] }));
+ });
+
+ /**
+ * Regression: told only what was missing, the builder re-submitted that one
+ * artifact and dropped the rest β€” the screenshots one attempt, the DOM
+ * snapshot the next β€” since the repaired check is judged from scratch.
+ */
+ it('asks for every required evidence of the check, not only the missing one', async () => {
+ const spawner = vi.fn().mockResolvedValue({ repairOperationId: 'repair-op' });
+
+ await new VerifyRepairService({} as any, 'user').triggerAutoRepair(
+ 'op-3',
+ spawner,
+ rejection,
+ );
+
+ const { instruction } = spawner.mock.calls[0][0];
+ expect(instruction).toContain(
+ 'Chapters land in the site β€” the Acceptance review sent it back: ch09 lacks its second screenshot.',
+ );
+ expect(instruction).toContain(
+ 'Submit all of its required evidence to item landing, not only what is missing: screenshot (β‰₯2 screenshots per chapter); dom_snapshot.',
+ );
+ });
+
+ it('does not spend a repair on an optional check the review named', async () => {
+ const spawner = vi.fn();
+
+ expect(
+ await new VerifyRepairService({} as any, 'user').triggerAutoRepair('op-3', spawner, [
+ { checkItemId: 'optional-video', feedback: 'No video.' },
+ ]),
+ ).toBeNull();
+ expect(spawner).not.toHaveBeenCalled();
+ });
+ });
+
describe('records the auto-repair decision', () => {
const trigger = (spawner?: any) =>
new VerifyRepairService({} as any, 'user').triggerAutoRepair('op-3', spawner);
@@ -174,3 +295,21 @@ describe('VerifyRepairService.triggerAutoRepair', () => {
});
});
});
+
+describe('carriedRunPolicy', () => {
+ /**
+ * A repair spawned after its source round was driven (the Acceptance review
+ * path) inherited `taskDrivenAt`, so its own settle read "already drove" and
+ * the Task never completed.
+ */
+ it('carries the policy but not how the source round settled', () => {
+ expect(
+ carriedRunPolicy({
+ autoRepair: 'spawned',
+ goalReview: { feedback: 'x', predictionIds: [], status: 'rejected' },
+ maxRepairRounds: 2,
+ taskDrivenAt: '2026-10-28T08:43:00.000Z',
+ }),
+ ).toEqual({ maxRepairRounds: 2 });
+ });
+});
diff --git a/apps/server/src/services/verify/goalReview.ts b/apps/server/src/services/verify/goalReview.ts
index 9f2de18442c..c8cc40b9a5d 100644
--- a/apps/server/src/services/verify/goalReview.ts
+++ b/apps/server/src/services/verify/goalReview.ts
@@ -119,6 +119,15 @@ export const reviewGoalDelivery = async (
const predictor = new VerifyReviewPredictorService(db, userId, workspaceId);
const feedback: string[] = [];
+ // Only a check this round itself answered can be repaired inside the round;
+ // one judged from an earlier round's result has no row here to re-open.
+ const rejectCheck = (check: (typeof checks)[number], reason: string) => {
+ if (check.result?.verifyRunId !== run.id) return;
+ (review.rejectedChecks ??= []).push({
+ checkItemId: check.result.checkItemId,
+ feedback: reason,
+ });
+ };
// Checks are judged concurrently, so the aggregate has to be order
// independent: take the most blocking outcome seen rather than letting the
// last writer win. `rejected` outranks `unjudgeable` because one genuinely
@@ -183,7 +192,10 @@ export const reviewGoalDelivery = async (
// The criterion asks for something no reader can confirm. Re-delivering
// cannot change that, so this must not read as a rejected delivery.
escalate('unjudgeable');
- } else escalate('rejected');
+ } else {
+ escalate('rejected');
+ rejectCheck(check, prediction.comment ?? 'Acceptance review rejected this check.');
+ }
feedback.push(
`${check.title}: ${prediction?.comment ?? prediction?.statusReason ?? 'Review could not reach a decision.'}`,
);
diff --git a/apps/server/src/services/verify/repairService.ts b/apps/server/src/services/verify/repairService.ts
index b5181b33e61..e24e1dec2e8 100644
--- a/apps/server/src/services/verify/repairService.ts
+++ b/apps/server/src/services/verify/repairService.ts
@@ -1,6 +1,6 @@
import { AcceptanceEvidenceIdentifier } from '@lobechat/builtin-tool-acceptance-evidence';
import { DEFAULT_MAX_REPAIR_ROUNDS } from '@lobechat/const/verify';
-import type { VerifyCheckItem, VerifyRunMetadata } from '@lobechat/types';
+import type { VerifyAgentPlanConfig, VerifyCheckItem, VerifyRunMetadata } from '@lobechat/types';
import debug from 'debug';
import { AgentOperationModel } from '@/database/models/agentOperation';
@@ -44,6 +44,20 @@ const resolveMaxRepairRounds = async (
return rubric?.config?.maxRepairRounds ?? DEFAULT_MAX_REPAIR_ROUNDS;
};
+/**
+ * How the source round settled is its own record, not policy. A repair spawned
+ * after the round was driven (the Acceptance review path) would otherwise
+ * inherit `taskDrivenAt` and never settle the Task, and inherit the rejected
+ * review as if it were its own.
+ */
+const ROUND_SETTLE_KEYS = ['autoRepair', 'goalReview', 'taskDrivenAt'] as const;
+
+export const carriedRunPolicy = (metadata: Record<string, unknown>): Record<string, unknown> => {
+ const policy = { ...metadata };
+ for (const key of ROUND_SETTLE_KEYS) delete policy[key];
+ return policy;
+};
+
/**
* Spawns a repair sub agent_operations (parent = the failed run) seeded with the
* failed criteria. Injected by the runtime layer (Phase 7) since it needs full
@@ -125,7 +139,8 @@ export const createRepairRunner = (params: {
// Carry the source run's policy bag (e.g. the task's maxRepairRounds
// override) onto this round so its own auto-repair derives the same cap
// instead of falling back to the rubric/default.
- if (sourceRun?.metadata) await runModel.setMetadata(repairRun.id, sourceRun.metadata);
+ if (sourceRun?.metadata)
+ await runModel.setMetadata(repairRun.id, carriedRunPolicy(sourceRun.metadata));
await runModel.confirmPlan(repairRun.id);
// A repair is the next immutable round of the same business acceptance,
@@ -225,7 +240,6 @@ export const maybeAutoRepair = async (
operationId: string,
workspaceId?: string,
): Promise<{ repairOperationId: string } | null | undefined> => {
- const operationModel = new AgentOperationModel(db, userId, workspaceId);
const run = await new VerifyRunModel(db, userId, workspaceId).findByOperation(operationId);
const plan = (run?.plan ?? []) as VerifyCheckItem[];
if (!run || plan.length === 0) return;
@@ -242,6 +256,19 @@ export const maybeAutoRepair = async (
});
if (stillPending) return;
+ const spawner = await buildRunRepairSpawner(db, userId, operationId, run, workspaceId);
+ return new VerifyRepairService(db, userId, workspaceId).triggerAutoRepair(operationId, spawner);
+};
+
+/** The repair runner for a run, built from its own agent / topic / model. */
+const buildRunRepairSpawner = async (
+ db: LobeChatDatabase,
+ userId: string,
+ operationId: string,
+ run: { metadata?: unknown; plan?: unknown },
+ workspaceId?: string,
+): Promise<RepairSpawner | undefined> => {
+ const operationModel = new AgentOperationModel(db, userId, workspaceId);
const op = await operationModel.findById(operationId);
let taskOperation = op;
let taskDepth = 0;
@@ -249,13 +276,13 @@ export const maybeAutoRepair = async (
taskOperation = await operationModel.findById(taskOperation.parentOperationId);
taskDepth += 1;
}
- const spawner = createRepairRunner({
+ return createRepairRunner({
agentId: op?.agentId,
db,
maxRepairRounds: await resolveMaxRepairRounds(
db,
userId,
- plan,
+ (run.plan ?? []) as VerifyCheckItem[],
run.metadata as VerifyRunMetadata | null,
workspaceId,
),
@@ -266,7 +293,56 @@ export const maybeAutoRepair = async (
userId,
workspaceId,
});
- return new VerifyRepairService(db, userId, workspaceId).triggerAutoRepair(operationId, spawner);
+};
+
+/**
+ * Repair the checks a Goal's Acceptance review sent back, inside the round that
+ * delivered them. The verifiers had passed those checks, so the ordinary
+ * auto-repair never saw a failure: the review paused the Task and the
+ * coordinator started a whole new attempt, in a fresh topic, re-evidencing every
+ * check from nothing. Each attempt fixed the gap it was told about and dropped
+ * evidence an earlier one had (round 8 had the screenshots but no DOM snapshot,
+ * round 9 the snapshot but not the screenshots), so a Task whose work was done in
+ * its first round ran attempt after attempt on evidence alone.
+ *
+ * Returns the repair, or null when none could start (nothing auto-repairable,
+ * the repair cap reached, a superseded round) β€” the review's rejection then
+ * stands as before.
+ */
+export const repairRejectedReview = async (
+ db: LobeChatDatabase,
+ userId: string,
+ operationId: string,
+ rejected: ReviewRejection[],
+ workspaceId?: string,
+): Promise<{ repairOperationId: string } | null> => {
+ if (rejected.length === 0) return null;
+ const run = await new VerifyRunModel(db, userId, workspaceId).findByOperation(operationId);
+ if (!run || ((run.plan ?? []) as VerifyCheckItem[]).length === 0) return null;
+
+ const spawner = await buildRunRepairSpawner(db, userId, operationId, run, workspaceId);
+ return new VerifyRepairService(db, userId, workspaceId).triggerAutoRepair(
+ operationId,
+ spawner,
+ rejected,
+ );
+};
+
+/**
+ * A passed round delivered its Acceptance unless the user rejected it or the
+ * Goal's Acceptance review sent it back. A review-rejected round still reads
+ * `passed` (its verifiers did pass), and counting it as delivered declined the
+ * auto-repair of every later round of the Task, so each gap that one small
+ * repair could close cost another full attempt instead.
+ */
+const isDeliveredRound = (round: {
+ metadata?: unknown;
+ status?: string | null;
+ userDecision?: string | null;
+}): boolean => {
+ if (round.status !== 'passed' || round.userDecision === 'reject') return false;
+ const review = (round.metadata as VerifyRunMetadata | null | undefined)?.goalReview;
+ return !review || review.status === 'passed';
};
// `errored` = the verifier couldn't run (infra), so there's no delivery fault to
@@ -276,12 +352,44 @@ const isFailed = (r: VerifyCheckResultItem | undefined): boolean =>
r.status !== 'errored' &&
(r.status === 'failed' || r.verdict === 'failed' || r.verdict === 'uncertain');
-const buildInstruction = (
- failures: { item: VerifyCheckItem; result: VerifyCheckResultItem | undefined }[],
-): string => {
- const lines = failures.map(({ item, result }, i) => {
- const why = result?.suggestion || result?.toulmin?.reasoning || 'did not pass verification';
- return `${i + 1}. ${item.title} β€” ${why}`;
+/** A check the Acceptance review sent back, by the reviewed round's plan item id. */
+export interface ReviewRejection {
+ checkItemId: string;
+ feedback: string;
+}
+
+interface RepairFailure {
+ item: VerifyCheckItem;
+ result: VerifyCheckResultItem | undefined;
+ /** Set when the Acceptance review, not the verifier, sent the check back. */
+ reviewFeedback?: string;
+}
+
+/**
+ * A repaired check is judged again from only what the repair submits, so its
+ * evidence must be complete, not just the piece the feedback names. A builder
+ * told "the DOM snapshot is missing" re-submitted the snapshot alone and lost
+ * the screenshots that had satisfied the rest of the check.
+ */
+const describeRequiredEvidence = (item: VerifyCheckItem): string | undefined => {
+ const specs = (item.verifierConfig as VerifyAgentPlanConfig | undefined)?.requiredEvidence ?? [];
+ if (specs.length === 0) return;
+ return specs.map((spec) => (spec.hint ? `${spec.type} (${spec.hint})` : spec.type)).join('; ');
+};
+
+const buildInstruction = (failures: RepairFailure[]): string => {
+ const lines = failures.map(({ item, result, reviewFeedback }, i) => {
+ const why = reviewFeedback
+ ? `the Acceptance review sent it back: ${reviewFeedback}`
+ : result?.suggestion || result?.toulmin?.reasoning || 'did not pass verification';
+ const evidence = describeRequiredEvidence(item);
+ return [
+ `${i + 1}. ${item.title} β€” ${why}`,
+ evidence &&
+ ` This check is judged again from only what you submit now. Submit all of its required evidence to item ${item.id}, not only what is missing: ${evidence}.`,
+ ]
+ .filter(Boolean)
+ .join('\n');
});
return [
'The delivery checker found unresolved issues with the previous result. Fix only these, then stop:',
@@ -310,13 +418,20 @@ export class VerifyRepairService {
this.statusService = new VerifyStatusService(db, userId, workspaceId);
}
- /** Collect the auto-repairable failures for a run. */
- async collectRepairable(operationId: string) {
+ /**
+ * Collect the auto-repairable failures for a run: the checks its verifiers
+ * failed, plus the ones the Acceptance review sent back after they passed.
+ */
+ async collectRepairable(
+ operationId: string,
+ reviewRejections: ReviewRejection[] = [],
+ ): Promise<RepairFailure[]> {
const run = await this.runModel.findByOperation(operationId);
if (!run) return [];
const plan = (run.plan ?? []) as VerifyCheckItem[];
const results = await this.resultModel.listByRun(run.id);
const byItem = new Map(results.map((r) => [r.checkItemId, r]));
+ const rejectedBy = new Map(reviewRejections.map((r) => [r.checkItemId, r.feedback]));
// An optional check never gates delivery, so it must not spend a repair
// round either: a passing round whose only gap was an optional video kept
@@ -324,9 +439,15 @@ export class VerifyRepairService {
return plan
.filter(
(item) =>
- item.required !== false && item.onFail === 'auto_repair' && isFailed(byItem.get(item.id)),
+ item.required !== false &&
+ item.onFail === 'auto_repair' &&
+ (isFailed(byItem.get(item.id)) || rejectedBy.has(item.id)),
)
- .map((item) => ({ item, result: byItem.get(item.id) }));
+ .map((item) => ({
+ item,
+ result: byItem.get(item.id),
+ ...(rejectedBy.has(item.id) && { reviewFeedback: rejectedBy.get(item.id) }),
+ }));
}
/**
@@ -344,8 +465,7 @@ export class VerifyRepairService {
return rounds.some(
(round) =>
round.id !== run.id &&
- ((round.roundIndex ?? 0) > (run.roundIndex ?? 0) ||
- (round.status === 'passed' && round.userDecision !== 'reject')),
+ ((round.roundIndex ?? 0) > (run.roundIndex ?? 0) || isDeliveredRound(round)),
);
}
@@ -366,8 +486,9 @@ export class VerifyRepairService {
async triggerAutoRepair(
operationId: string,
spawner?: RepairSpawner,
+ reviewRejections?: ReviewRejection[],
): Promise<{ repairOperationId: string } | null> {
- const failures = await this.collectRepairable(operationId);
+ const failures = await this.collectRepairable(operationId, reviewRejections);
if (failures.length === 0) return null;
if (await this.isSuperseded(operationId)) {
log('op %s round is superseded within its acceptance, not repairing', operationId);
diff --git a/apps/server/src/services/verify/settle.ts b/apps/server/src/services/verify/settle.ts
index e3d65ecc0af..b11150e896a 100644
--- a/apps/server/src/services/verify/settle.ts
+++ b/apps/server/src/services/verify/settle.ts
@@ -20,7 +20,7 @@ import { TaskResultBridgeService } from '@/server/services/taskResultBridge';
import { AcceptanceService } from './acceptanceService';
import { reviewGoalDelivery } from './goalReview';
-import { maybeAutoRepair } from './repairService';
+import { maybeAutoRepair, repairRejectedReview } from './repairService';
import { VerifyReporterService } from './reporter';
import { VerifyStatusService } from './statusService';
import { attachTaskRunToAcceptance, resolveTaskAcceptance } from './taskAcceptance';
@@ -200,6 +200,36 @@ export const driveTaskFromVerify = async (
run.status === 'passed'
? await reviewGoalDelivery(db, userId, taskOperation.taskId, operationId, workspaceId)
: undefined;
+
+ // A rejected check that can be repaired is fixed inside this round, by the
+ // same builder in the same topic, rather than pausing the Task into a whole
+ // new attempt. The repair round settles the Task when it finishes; this run's
+ // drive claim stays stamped so it is never driven twice.
+ if (
+ goalReview?.status === 'rejected' &&
+ goalReview.rejectedChecks?.length &&
+ !task.automationMode
+ ) {
+ const repair = await repairRejectedReview(
+ db,
+ userId,
+ operationId,
+ goalReview.rejectedChecks,
+ workspaceId,
+ ).catch((error) => {
+ log('verify-settle review repair failed for op %s: %O', operationId, error);
+ return null;
+ });
+ if (repair) {
+ log(
+ 'acceptance review rejected β†’ repairing op %s in round (%s)',
+ operationId,
+ repair.repairOperationId,
+ );
+ return;
+ }
+ }
+
const outcome =
goalReview?.status === 'rejected'
? 'failed'
diff --git a/packages/types/src/verify.ts b/packages/types/src/verify.ts
index 9e07f6d9ebf..e472d965d22 100644
--- a/packages/types/src/verify.ts
+++ b/packages/types/src/verify.ts
@@ -669,6 +669,12 @@ export interface VerifyRunMetadata {
goalReview?: {
feedback: string;
predictionIds: string[];
+ /**
+ * The checks of the reviewed round the review sent back, by that round's own
+ * plan item id, with the review's reason. They are what an in-round repair is
+ * asked to fix, instead of the whole Task starting another attempt.
+ */
+ rejectedChecks?: { checkItemId: string; feedback: string }[];
/**
* `unjudgeable` is separate from `rejected` on purpose: it means the review
* could not decide from evidence, not that the delivery fell short. Folding