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(cli): stop re-ingested acceptance rounds from duplicating every check (#19605)

Arvin Xu87d59465f831
diff --git a/apps/cli/src/commands/acceptanceRun.test.ts b/apps/cli/src/commands/acceptanceRun.test.ts
index a11ac053379..cd81455f013 100644
--- a/apps/cli/src/commands/acceptanceRun.test.ts
+++ b/apps/cli/src/commands/acceptanceRun.test.ts
@@ -24,6 +24,7 @@ describe('acceptance publication with missing evidence', () => {
acceptance: {
attachRun: { mutate: vi.fn() },
ensure: { mutate: vi.fn() },
+ getBundle: { query: vi.fn() },
},
verify: {
createRun: { mutate: vi.fn() },
@@ -50,6 +51,7 @@ describe('acceptance publication with missing evidence', () => {
);
vi.mocked(uploadLocalFile).mockResolvedValue({ id: 'file-1', url: 'https://files.test/1' });
client.acceptance.ensure.mutate.mockResolvedValue({ id: 'acceptance-1' });
+ client.acceptance.getBundle.query.mockResolvedValue({});
client.acceptance.attachRun.mutate.mockResolvedValue({ id: 'run-1', roundIndex: 2 });
client.verify.createRun.mutate.mockResolvedValue({ id: 'run-1' });
client.verify.ingestResult.mutate.mockImplementation(async (input) => ({
diff --git a/apps/cli/src/commands/acceptanceRun.ts b/apps/cli/src/commands/acceptanceRun.ts
index e6750a8a142..26b13f49bab 100644
--- a/apps/cli/src/commands/acceptanceRun.ts
+++ b/apps/cli/src/commands/acceptanceRun.ts
@@ -27,6 +27,7 @@ import {
deriveReportVerdict,
evidenceDescriptionForFile,
type EvidenceType,
+ findIdenticalLatestRound,
genericContextFromResult,
inlineTextEvidenceForFile,
interactionCostFromReportDir,
@@ -37,6 +38,7 @@ import {
printResults,
pullRequestFromBranch,
pullRequestFromResult,
+ reuseSourceCriteria,
scenarioFromResult,
screenProgrammaticTestChecks,
subjectFromEnv,
@@ -720,10 +722,20 @@ async function ingestReportAction(reportDir: string, options: IngestReportOption
}
const requirement = options.requirement ?? subject?.requirement;
+ // The overall conclusion, rendered at the top of the report page. Read up
+ // front so the duplicate check below compares what would land.
+ const conclusion =
+ typeof summary.conclusion === 'string'
+ ? summary.conclusion
+ : typeof summary.note === 'string'
+ ? summary.note
+ : undefined;
+
const client = await getTrpcClient();
let acceptance;
+ let bundle;
if (requestedAcceptanceId) {
- const bundle = await client.acceptance.getBundle.query({ id: requestedAcceptanceId });
+ bundle = await client.acceptance.getBundle.query({ id: requestedAcceptanceId });
acceptance = bundle.acceptance;
// ID-based reads can cross scopes, but creating a run uses the CLI's scope.
// Reject before any writes instead of leaving an unattachable run behind.
@@ -749,14 +761,6 @@ async function ingestReportAction(reportDir: string, options: IngestReportOption
);
}
}
- plan = plan?.map((item) => ({
- ...item,
- sourceCriterionId:
- item.sourceCriterionId ??
- bundle.checks?.find((check) => check.id === item.id || check.planItem?.id === item.id)
- ?.planItem?.sourceCriterionId ??
- undefined,
- }));
subject = {
ref: {
subjectId: acceptance.subjectId,
@@ -772,6 +776,24 @@ async function ingestReportAction(reportDir: string, options: IngestReportOption
? { title: title || goal }
: {}),
});
+ // A subject's acceptance may already hold rounds; this one has to line up
+ // with them exactly as an explicit `--acceptance` round does.
+ bundle = await client.acceptance.getBundle.query({ id: acceptance.id });
+ }
+ plan = reuseSourceCriteria(plan, bundle?.checks);
+
+ const identicalRound = findIdenticalLatestRound(bundle?.rounds, {
+ plan,
+ report: { content, summary: conclusion },
+ });
+ if (identicalRound) {
+ log.error(
+ `This report is identical to round ${identicalRound.roundIndex ?? '?'} (${identicalRound.id}) — nothing new to publish.`,
+ );
+ log.error(
+ ` To replace that round, delete it first: lh acceptance run delete ${identicalRound.id}`,
+ );
+ process.exit(1);
}
// The in-app conversation that ran this harness, if any (env-supplied).
// Strictly the authoring conversation. `--operation` names the Agent Run
@@ -892,14 +914,8 @@ async function ingestReportAction(reportDir: string, options: IngestReportOption
log.warn(`${item.id}: not executed; required evidence not published: ${types.join(', ')}.`);
}
- // 3. Write the report. `summary` is the overall conclusion (rendered at
- // the top of the report page); `content` is the full markdown detail.
- const conclusion =
- typeof summary.conclusion === 'string'
- ? summary.conclusion
- : typeof summary.note === 'string'
- ? summary.note
- : undefined;
+ // 3. Write the report. `summary` is the overall conclusion (read above);
+ // `content` is the full markdown detail.
// A 0-100 quality score lands on overallConfidence (0-1); the report page
// surfaces it as the `score` stat.
const score =
diff --git a/apps/cli/src/commands/verify.test.ts b/apps/cli/src/commands/verify.test.ts
index e950962db83..9b28d546b22 100644
--- a/apps/cli/src/commands/verify.test.ts
+++ b/apps/cli/src/commands/verify.test.ts
@@ -652,7 +652,7 @@ describe('verify ingest-report — every run is an immutable acceptance round',
mockTrpcClient.acceptance = {
attachRun: { mutate: vi.fn() },
ensure: { mutate: vi.fn().mockResolvedValue({ id: 'acceptance-1' }) },
- getBundle: { query: vi.fn() },
+ getBundle: { query: vi.fn().mockResolvedValue({}) },
};
mockTrpcClient.workspace = {
getById: { query: vi.fn().mockResolvedValue({ id: 'workspace-1' }) },
@@ -784,6 +784,78 @@ describe('verify ingest-report — every run is an immutable acceptance round',
);
});
+ it('reuses criteria when the round reaches its acceptance through the subject', async () => {
+ // Regression: only `--acceptance` read the existing checks, so re-ingesting
+ // a topic's report minted fresh criteria and duplicated every check row.
+ mockTrpcClient.acceptance.getBundle.query.mockResolvedValue({
+ checks: [{ id: 'criterion-1', planItem: { id: '1', sourceCriterionId: 'criterion-1' } }],
+ });
+ writeFileSync(
+ path.join(dir, 'result.json'),
+ JSON.stringify({
+ cases: [{ id: '1', name: '标题可编辑', status: 'pass' }],
+ plan: [{ id: '1', title: '标题可编辑' }],
+ }),
+ );
+
+ await run(['ingest-report', dir, '--json']);
+
+ expect(mockTrpcClient.acceptance.getBundle.query).toHaveBeenCalledWith({ id: 'acceptance-1' });
+ expect(mockTrpcClient.verify.createRun.mutate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ plan: [expect.objectContaining({ id: '1', sourceCriterionId: 'criterion-1' })],
+ }),
+ );
+ });
+
+ describe('identical re-ingest', () => {
+ const publishedRound = (content: string) => ({
+ report: { content, summary: '全部通过' },
+ run: { id: 'run-r1', plan: [{ id: '1', title: '标题可编辑' }], roundIndex: 1 },
+ });
+
+ beforeEach(() => {
+ (mockTrpcClient.verify as Record<string, any>).ingestResult = {
+ mutate: vi.fn().mockResolvedValue({ id: 'result-1' }),
+ };
+ writeFileSync(path.join(dir, 'report.md'), '## 备注\n\n首次发布');
+ writeFileSync(
+ path.join(dir, 'result.json'),
+ JSON.stringify({
+ cases: [{ id: '1', name: '标题可编辑', status: 'pass' }],
+ plan: [{ id: '1', title: '标题可编辑' }],
+ summary: { conclusion: '全部通过', failed: 0, passed: 1, total: 1 },
+ }),
+ );
+ });
+
+ it('refuses to stack a round identical to the latest one', async () => {
+ mockTrpcClient.acceptance.getBundle.query.mockResolvedValue({
+ rounds: [publishedRound('## 备注\n\n首次发布')],
+ });
+ const exitSpy = vi.spyOn(process, 'exit').mockImplementation(((code?: number) => {
+ throw new Error(`process.exit ${code}`);
+ }) as never);
+
+ try {
+ await expect(run(['ingest-report', dir, '--json'])).rejects.toThrow('process.exit 1');
+ expect(mockTrpcClient.verify.createRun.mutate).not.toHaveBeenCalled();
+ } finally {
+ exitSpy.mockRestore();
+ }
+ });
+
+ it('publishes the next round once the report actually changed', async () => {
+ mockTrpcClient.acceptance.getBundle.query.mockResolvedValue({
+ rounds: [publishedRound('## 备注\n\n上一轮的报告')],
+ });
+
+ await run(['ingest-report', dir, '--json']);
+
+ expect(mockTrpcClient.verify.createRun.mutate).toHaveBeenCalled();
+ });
+ });
+
it.each([null, 'workspace-1'])(
'appends a re-verification round when both scopes are %s',
async (workspaceId) => {
diff --git a/apps/cli/src/commands/verifyHelpers.ts b/apps/cli/src/commands/verifyHelpers.ts
index 8f44b844dcb..b404dc4aa42 100644
--- a/apps/cli/src/commands/verifyHelpers.ts
+++ b/apps/cli/src/commands/verifyHelpers.ts
@@ -784,6 +784,77 @@ export function planFromResult(result: Record<string, unknown>, droppedIds?: Set
return items;
}
+interface ExistingAcceptanceCheck {
+ id: string;
+ planItem?: { id?: string; sourceCriterionId?: string | null } | null;
+}
+
+/**
+ * Line a new round's plan up with the checks its acceptance already holds.
+ * The server mints a fresh criterion for every item that arrives without one,
+ * and the union keys rows by criterion — so a re-verification that skips this
+ * lands every check as a brand-new row instead of the next entry in its history.
+ */
+export function reuseSourceCriteria<T extends { id: string; sourceCriterionId?: string | null }>(
+ plan: T[] | undefined,
+ checks: ExistingAcceptanceCheck[] | null | undefined,
+): T[] | undefined {
+ if (!plan || !checks?.length) return plan;
+
+ return plan.map((item) => ({
+ ...item,
+ sourceCriterionId:
+ item.sourceCriterionId ??
+ checks.find((check) => check.id === item.id || check.planItem?.id === item.id)?.planItem
+ ?.sourceCriterionId ??
+ undefined,
+ }));
+}
+
+interface ExistingAcceptanceRound {
+ report?: { content?: string | null; summary?: string | null } | null;
+ run: {
+ id: string;
+ plan?: { id: string; title: string }[] | null;
+ roundIndex?: number | null;
+ };
+}
+
+/**
+ * The acceptance's latest round when it already publishes exactly this report.
+ * Re-running the same ingest (a retry loop, a re-sent command) would otherwise
+ * stack identical rounds on the page. Compares what the author wrote — body,
+ * conclusion and plan — not the published counts, which the ingest derives
+ * later from evidence uploads. Only a report with a body counts: without one,
+ * two genuinely different runs of the same plan are indistinguishable here.
+ */
+export function findIdenticalLatestRound(
+ rounds: ExistingAcceptanceRound[] | null | undefined,
+ incoming: {
+ plan?: { id: string; title: string }[];
+ report: { content?: string; summary?: string };
+ },
+): ExistingAcceptanceRound['run'] | undefined {
+ if (!incoming.report.content || !rounds?.length) return undefined;
+
+ const latest = rounds.reduce((a, b) =>
+ (b.run.roundIndex ?? 0) > (a.run.roundIndex ?? 0) ? b : a,
+ );
+ const published = latest.report;
+ if (!published) return undefined;
+
+ const same = (a: unknown, b: unknown) => (a ?? null) === (b ?? null);
+ const planKey = (items: { id: string; title: string }[] | null | undefined) =>
+ JSON.stringify((items ?? []).map(({ id, title }) => [id, title]));
+
+ const identical =
+ same(published.content, incoming.report.content) &&
+ same(published.summary, incoming.report.summary) &&
+ planKey(latest.run.plan) === planKey(incoming.plan);
+
+ return identical ? latest.run : undefined;
+}
+
/**
* The LobeHub conversation this harness is running inside, read off the env the
* agent runtime echoes into the child process. Lets a report published from an