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(acceptance): refuse a round that writes to an already-accepted check (#18837)

Arvin Xu2a976fb758f1
diff --git a/.agents/acceptance/common-mistakes.md b/.agents/acceptance/common-mistakes.md
index 6d594a64565..154e4db1691 100644
--- a/.agents/acceptance/common-mistakes.md
+++ b/.agents/acceptance/common-mistakes.md
@@ -157,6 +157,26 @@ the image lands unpaired and unlabeled. Publish a fresh round carrying the compl
evidence set instead, and say in `report.md` that it re-publishes the same
observations rather than re-running the cases.
+### L-E11b β€” Publishing a new round onto a check the reviewer already accepted
+
+**Wrong approach:** when new feedback arrives about a check the user has already
+accepted, reuse that check's id for the new work β€” because reusing ids is the rule for
+rejected checks.
+
+**Why it fails:** an accepted verdict is deliberately sticky (`acceptanceService`
+computes `stale` only for rejects, and a test pins that behaviour by name). A later
+result on a settled id therefore inherits the tick: the round publishes green and the
+reviewer is never told there is anything new to look at. Since 2026-08, `attachRun`
+refuses such a round outright β€” the error names the offending ids and nothing is
+written, so a partially attached round cannot happen.
+
+**Correct approach:** read `userReview.action` before writing the plan. `accept` means
+settled: the new work needs a NEW check id, which appears unreviewed and can actually
+be judged. Reuse the id only while the check is rejected or never reviewed. Decide by
+_is the criterion new, and has the old one been accepted_ β€” not by how big the change
+is: a presentation fix on a still-open check reuses its id (\[\[L-E1]]), while a newly
+raised criterion on an accepted check must not.
+
### L-E12 β€” Expressing multimodal disclosure through the `verifier` enum
**Wrong approach:** write a value such as `"verifier": "multimodal LLM"` in a plan
diff --git a/apps/server/src/services/verify/__tests__/acceptanceSettledCheck.test.ts b/apps/server/src/services/verify/__tests__/acceptanceSettledCheck.test.ts
new file mode 100644
index 00000000000..28841f34a24
--- /dev/null
+++ b/apps/server/src/services/verify/__tests__/acceptanceSettledCheck.test.ts
@@ -0,0 +1,164 @@
+// @vitest-environment node
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+const mocks = vi.hoisted(() => ({
+ acceptanceFindById: vi.fn(),
+ attachToAcceptance: vi.fn(),
+ listByAcceptance: vi.fn(),
+ listByRuns: vi.fn(),
+ runFindById: vi.fn(),
+}));
+
+vi.mock('@/database/models/acceptance', () => ({
+ AcceptanceModel: vi.fn(() => ({
+ findById: mocks.acceptanceFindById,
+ findPolicyById: mocks.acceptanceFindById,
+ update: vi.fn(),
+ updatePolicyStatus: vi.fn(),
+ })),
+}));
+
+vi.mock('@/database/models/verifyRun', () => ({
+ VerifyRunModel: vi.fn(() => ({
+ attachToAcceptance: mocks.attachToAcceptance,
+ findById: mocks.runFindById,
+ listByAcceptance: mocks.listByAcceptance,
+ })),
+}));
+
+vi.mock('@/database/models/verifyCheckResult', () => ({
+ VerifyCheckResultModel: vi.fn(() => ({ listByRuns: mocks.listByRuns })),
+}));
+
+vi.mock('@/database/models/verifyEvidence', () => ({ VerifyEvidenceModel: vi.fn(() => ({})) }));
+vi.mock('@/database/models/verifyReport', () => ({
+ VerifyReportModel: vi.fn(() => ({ findByRun: vi.fn().mockResolvedValue(null) })),
+}));
+
+const { AcceptanceService } = await import('../acceptanceService');
+
+const ACCEPTANCE = { id: 'acc-1', status: 'delivered', userId: 'u1', visibility: 'public' };
+
+/** A settled result row: passed, and the reviewer accepted it. */
+const acceptedResult = (checkItemId: string, verifyRunId: string) => ({
+ checkItemId,
+ checkItemTitle: checkItemId,
+ completedAt: new Date('2026-08-01T00:00:00.000Z'),
+ createdAt: new Date('2026-08-01T00:00:00.000Z'),
+ id: `res-${checkItemId}`,
+ required: true,
+ status: 'passed',
+ userDecision: 'accepted',
+ userDecisionDetail: { decidedAt: '2026-08-01T01:00:00.000Z', roundIndex: 1 },
+ verdict: 'passed',
+ verifyRunId,
+});
+
+const planned = (...ids: string[]) => ids.map((id, index) => ({ id, index, title: id }));
+
+const service = () => new AcceptanceService({} as any, 'u1');
+
+beforeEach(() => {
+ vi.clearAllMocks();
+ mocks.acceptanceFindById.mockResolvedValue(ACCEPTANCE);
+ mocks.attachToAcceptance.mockResolvedValue({ id: 'run-2', roundIndex: 2 });
+ // Round 1 accepted `settled-check`; `open-check` was never ruled on.
+ mocks.listByAcceptance.mockResolvedValue([{ acceptanceId: 'acc-1', id: 'run-1', roundIndex: 1 }]);
+ mocks.listByRuns.mockResolvedValue([
+ acceptedResult('settled-check', 'run-1'),
+ { ...acceptedResult('open-check', 'run-1'), userDecision: null, userDecisionDetail: null },
+ ]);
+});
+
+describe('attaching a round that targets an accepted check', () => {
+ it('refuses the round and names the settled check', async () => {
+ mocks.runFindById.mockResolvedValue({
+ acceptanceId: null,
+ id: 'run-2',
+ plan: planned('settled-check'),
+ userId: 'u1',
+ });
+
+ await expect(service().attachRun('run-2', 'acc-1')).rejects.toThrow(/settled-check/);
+ // Nothing may be written: a partially attached round is worse than none.
+ expect(mocks.attachToAcceptance).not.toHaveBeenCalled();
+ });
+
+ it('refuses when the settled check is reached through a superseded id', async () => {
+ // Round 1 ran `old-id`; round 2 replaced it with `settled-check`, whose
+ // result the reviewer accepted. The union folded `old-id` into that row, so
+ // re-running `old-id` now writes straight back into the settled check.
+ mocks.listByAcceptance.mockResolvedValue([
+ { acceptanceId: 'acc-1', id: 'run-1', plan: planned('old-id'), roundIndex: 1 },
+ {
+ acceptanceId: 'acc-1',
+ id: 'run-1b',
+ plan: [{ id: 'settled-check', index: 0, supersedes: ['old-id'], title: 'settled-check' }],
+ roundIndex: 2,
+ },
+ ]);
+ mocks.listByRuns.mockResolvedValue([
+ { ...acceptedResult('old-id', 'run-1'), userDecision: null, userDecisionDetail: null },
+ acceptedResult('settled-check', 'run-1b'),
+ ]);
+ mocks.runFindById.mockResolvedValue({
+ acceptanceId: null,
+ id: 'run-2',
+ plan: planned('old-id'),
+ userId: 'u1',
+ });
+
+ await expect(service().attachRun('run-2', 'acc-1')).rejects.toThrow(/old-id/);
+ expect(mocks.attachToAcceptance).not.toHaveBeenCalled();
+ });
+
+ it("refuses a fresh plan-item id that carries the settled check's sourceCriterionId", async () => {
+ // The union keys rows by `sourceCriterionId ?? id`, so a brand-new physical
+ // id pointing at the same criterion still lands on the settled row.
+ mocks.listByAcceptance.mockResolvedValue([
+ {
+ acceptanceId: 'acc-1',
+ id: 'run-1',
+ plan: [{ id: 'physical-1', index: 0, sourceCriterionId: 'crit-a', title: 'crit-a' }],
+ roundIndex: 1,
+ },
+ ]);
+ mocks.listByRuns.mockResolvedValue([acceptedResult('physical-1', 'run-1')]);
+ mocks.runFindById.mockResolvedValue({
+ acceptanceId: null,
+ id: 'run-2',
+ plan: [{ id: 'physical-2', index: 0, sourceCriterionId: 'crit-a', title: 'crit-a' }],
+ userId: 'u1',
+ });
+
+ // Names the plan item the author can actually edit, not the criterion id.
+ await expect(service().attachRun('run-2', 'acc-1')).rejects.toThrow(/physical-2/);
+ expect(mocks.attachToAcceptance).not.toHaveBeenCalled();
+ });
+
+ it('refuses a new id that declares it supersedes the settled check', async () => {
+ // Superseding folds the accepted row's timeline into the newcomer, so the
+ // new result would render under the accepted verdict just the same.
+ mocks.runFindById.mockResolvedValue({
+ acceptanceId: null,
+ id: 'run-2',
+ plan: [{ id: 'replacement', index: 0, supersedes: ['settled-check'], title: 'replacement' }],
+ userId: 'u1',
+ });
+
+ await expect(service().attachRun('run-2', 'acc-1')).rejects.toThrow(/replacement/);
+ expect(mocks.attachToAcceptance).not.toHaveBeenCalled();
+ });
+
+ it('attaches a round that only touches unreviewed or brand-new checks', async () => {
+ mocks.runFindById.mockResolvedValue({
+ acceptanceId: null,
+ id: 'run-2',
+ plan: planned('open-check', 'brand-new-check'),
+ userId: 'u1',
+ });
+
+ await expect(service().attachRun('run-2', 'acc-1')).resolves.toMatchObject({ roundIndex: 2 });
+ expect(mocks.attachToAcceptance).toHaveBeenCalledOnce();
+ });
+});
diff --git a/apps/server/src/services/verify/acceptanceService.ts b/apps/server/src/services/verify/acceptanceService.ts
index 8ba130762ed..a6a0068cad9 100644
--- a/apps/server/src/services/verify/acceptanceService.ts
+++ b/apps/server/src/services/verify/acceptanceService.ts
@@ -531,6 +531,88 @@ export class AcceptanceService {
return this.attachResolvedRun(runId, acceptance);
};
+ /**
+ * An accepted check is settled and its verdict is sticky: a later result on
+ * the same id inherits the tick, so the round publishes green and the
+ * reviewer is never told there is anything new to look at. That is only safe
+ * while nothing writes to a settled check, which is what this enforces β€”
+ * refusing the whole round rather than letting the write through, because a
+ * partially attached round is harder to reason about than a rejected one.
+ *
+ * The escape hatch is a new check id: a criterion the reviewer has not ruled
+ * on gets its own row and shows up unreviewed, which is what "there is more
+ * to look at here" should look like.
+ */
+ private assertPlanLeavesAcceptedChecksAlone = async (
+ run: VerifyRunItem,
+ acceptanceId: string,
+ ): Promise<void> => {
+ // Every identity by which an incoming item could come to rest on an
+ // existing row. The union keys rows by `sourceCriterionId ?? id`, and a
+ // `supersedes` declaration folds the named row into this one β€” so comparing
+ // physical ids alone lets both routes write into a settled row unblocked.
+ const candidates = new Map<string, string>();
+ for (const item of run.plan ?? []) {
+ const logicalId = item.sourceCriterionId ?? item.id;
+ if (logicalId) candidates.set(logicalId, item.id);
+ if (item.id) candidates.set(item.id, item.id);
+ for (const superseded of item.supersedes ?? []) {
+ if (superseded) candidates.set(superseded, item.id);
+ }
+ }
+ if (candidates.size === 0) return;
+
+ const runs = await this.runModel.listByAcceptance(acceptanceId);
+ if (runs.length === 0) return;
+
+ const results = await this.resultModel.listByRuns(runs.map((item) => item.id));
+ const resultsById = new Map(results.map((result) => [result.id, result]));
+ const resultsByRun = new Map<string, VerifyCheckResultItem[]>();
+ for (const result of results) {
+ if (!result.verifyRunId) continue;
+ const bucket = resultsByRun.get(result.verifyRunId) ?? [];
+ bucket.push(result);
+ resultsByRun.set(result.verifyRunId, bucket);
+ }
+
+ const currentRoundIndex = runs.at(-1)?.roundIndex ?? 0;
+ const checks = buildAcceptanceCheckUnion(
+ runs.map((item) => ({ results: resultsByRun.get(item.id) ?? [], run: item })),
+ );
+
+ // Read the standing verdict exactly the way the page renders it, so the
+ // rule cannot diverge from the tick the reviewer actually sees.
+ const settled = checks.filter((check) => {
+ const { userReview } = buildCheckReviewOverlay(check, resultsById, currentRoundIndex);
+ return userReview?.action === 'accept' && !userReview.stale;
+ });
+
+ // A superseded generation's id is folded into its successor's row, so match
+ // on both β€” re-running `old-id` after `new-id supersedes: [old-id]` was
+ // accepted is the same write to the same settled row.
+ const blocked = new Set<string>();
+ for (const check of settled) {
+ blocked.add(check.id);
+ for (const superseded of check.supersededIds ?? []) blocked.add(superseded);
+ }
+
+ // Report the plan item the author has to change, not the internal identity
+ // it collided through β€” those can differ, and only the former is editable.
+ const offenders = [
+ ...new Set(
+ [...candidates]
+ .filter(([identity]) => blocked.has(identity))
+ .map(([, planItemId]) => planItemId),
+ ),
+ ];
+ if (offenders.length === 0) return;
+
+ throw new Error(
+ `Already accepted, so ${offenders.length === 1 ? 'this check' : 'these checks'} cannot take another result: ` +
+ `${offenders.join(', ')}. An accepted check is settled β€” publish new work under a new check id instead.`,
+ );
+ };
+
private attachResolvedRun = async (
runId: string,
acceptance: AcceptanceItem,
@@ -551,6 +633,8 @@ export class AcceptanceService {
);
}
+ await this.assertPlanLeavesAcceptedChecksAlone(existing, acceptanceId);
+
// Rounds inherit the aggregate's visibility so a private acceptance's new
// round never leaks through its own report URL.
const run = await this.runModel.attachToAcceptance(runId, acceptanceId, acceptance.visibility);