🤯 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.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
🐛 fix(verify): write generated criteria and reports in the account's language (#22035)
Arvin Xu741eb83ab60c
diff --git a/apps/server/src/services/verify/__tests__/holisticPlan.test.ts b/apps/server/src/services/verify/__tests__/holisticPlan.test.tsindex 0a36982454e..3ff1144fe08 100644--- a/apps/server/src/services/verify/__tests__/holisticPlan.test.ts+++ b/apps/server/src/services/verify/__tests__/holisticPlan.test.ts@@ -13,6 +13,7 @@ const {findByIdsMock,generateObjectMock,getCriteriaMock,+ getUserSettingsMock,setCriteriaMock,setPlanMock,} = vi.hoisted(() => ({@@ -23,6 +24,7 @@ const {findByIdsMock: vi.fn(async () => [] as any[]),generateObjectMock: vi.fn(),getCriteriaMock: vi.fn(async () => [] as any[]),+ getUserSettingsMock: vi.fn(async (): Promise<any> => undefined),setCriteriaMock: vi.fn(),setPlanMock: vi.fn(async (_runId: string, _items: any[]) => {}),}));@@ -53,6 +55,11 @@ vi.mock('@/database/models/verifyCriterion', () => ({};}),}));+vi.mock('@/database/models/user', () => ({+ UserModel: vi.fn(function () {+ return { getUserSettings: getUserSettingsMock };+ }),+}));vi.mock('@/database/models/document', () => ({DocumentModel: vi.fn(function () {return {};@@ -199,4 +206,49 @@ describe('verify plan generation model', () => {expect.any(Object),);});++ /**+ * Regression: a Task's run goal opens with English scaffolding ("Verify only+ * this Task…") around a Chinese brief, and "write in the language of the run+ * goal" produced English check titles on a Chinese account's acceptance page.+ */+ describe('output language', () => {+ const systemPrompt = () =>+ (generateObjectMock.mock.calls.at(-1)![0] as { messages: { content: string }[] }).messages[0]+ .content;+ const taskGoal = 'Verify only this Task: 挤水分 A/C。\n\nRequired Task outcome: 删除死代码';++ it("writes criteria in the account's response language", async () => {+ generateObjectMock.mockResolvedValue({ criteria: [] });+ getUserSettingsMock.mockResolvedValue({ general: { responseLanguage: 'zh-CN' } });++ await new VerifyPlanGeneratorService(db, 'user-1').generateDraftPlan({+ enableAiGeneration: true,+ goal: taskGoal,+ operationId: 'op-1',+ });++ expect(systemPrompt()).toContain(+ 'title, description, instruction and every requiredEvidence hint in zh-CN',+ );+ });++ it('falls back to the goal content language, not its English scaffolding, when unset', async () => {+ generateObjectMock.mockResolvedValue({ criteria: [] });+ getUserSettingsMock.mockResolvedValue({ general: {} });++ await new VerifyPlanGeneratorService(db, 'user-1').generateCriteria({ goal: taskGoal });++ expect(systemPrompt()).toContain('Ignore the English system wording');+ });++ it('does not let a settings read failure block plan generation', async () => {+ generateObjectMock.mockResolvedValue({ criteria: [] });+ getUserSettingsMock.mockRejectedValue(new Error('db down'));++ await new VerifyPlanGeneratorService(db, 'user-1').generateCriteria({ goal: taskGoal });++ expect(systemPrompt()).toContain('Ignore the English system wording');+ });+ });});diff --git a/apps/server/src/services/verify/planGenerator.ts b/apps/server/src/services/verify/planGenerator.tsindex 736d3d0c26b..543e43628c9 100644--- a/apps/server/src/services/verify/planGenerator.ts+++ b/apps/server/src/services/verify/planGenerator.ts@@ -21,6 +21,7 @@ import type { LobeChatDatabase } from '@/database/type';import { AiGenerationService } from '@/server/services/aiGeneration';import { VERIFY_PLAN_MODEL_CONFIG } from './modelConfig';+import { resolveVerifyResponseLanguage } from './responseLanguage';import { RawGeneratedCriteriaSchema } from './schema';const log = debug('lobe-server:verify-plan-generator');@@ -178,6 +179,7 @@ export class VerifyPlanGeneratorService {...chainVerifyPlan({context: params.context,goal: params.goal,+ language: await resolveVerifyResponseLanguage(this.db, this.userId),maxCriteria,}),...VERIFY_PLAN_MODEL_CONFIG,@@ -327,6 +329,7 @@ export class VerifyPlanGeneratorService {context: params.context,existingTitles: params.existingTitles,goal: params.goal,+ language: await resolveVerifyResponseLanguage(this.db, this.userId),maxCriteria: params.maxCriteria,});diff --git a/apps/server/src/services/verify/reporter.ts b/apps/server/src/services/verify/reporter.tsindex e8e4266c467..4a6b36b1e37 100644--- a/apps/server/src/services/verify/reporter.ts+++ b/apps/server/src/services/verify/reporter.ts@@ -17,6 +17,7 @@ import type { LobeChatDatabase } from '@/database/type';import { AiGenerationService } from '@/server/services/aiGeneration';import { countStats, meanConfidence, rollupVerdict } from './reportRollup';+import { resolveVerifyResponseLanguage } from './responseLanguage';import { ReportNarrativeSchema } from './schema';const log = debug('lobe-server:verify-reporter');@@ -98,6 +99,7 @@ export class VerifyReporterService {title: r.checkItemTitle,verdict: r.verdict,})),+ language: await resolveVerifyResponseLanguage(this.db, this.userId),stats,verdict,});diff --git a/apps/server/src/services/verify/responseLanguage.ts b/apps/server/src/services/verify/responseLanguage.tsnew file mode 100644index 00000000000..cea13c90c0d--- /dev/null+++ b/apps/server/src/services/verify/responseLanguage.ts@@ -0,0 +1,25 @@+import { UserModel } from '@/database/models/user';+import type { LobeChatDatabase } from '@/database/type';++/**+ * The language verify text must be written in: the account's explicit+ * `responseLanguage`, the same setting `lh acceptance` enforces on what a+ * builder publishes. Criteria and reports render on the owner's acceptance+ * page, so they follow the owner, not the language of a Task's run goal.+ *+ * Returns `undefined` when the setting is unset or unreadable, so the prompt+ * falls back to the goal's own language and a settings read never blocks a run.+ */+export const resolveVerifyResponseLanguage = async (+ db: LobeChatDatabase,+ userId: string,+): Promise<string | undefined> => {+ try {+ const settings = await new UserModel(db, userId).getUserSettings();+ const value = (settings?.general as { responseLanguage?: unknown } | null | undefined)+ ?.responseLanguage;+ return typeof value === 'string' && value.trim() ? value.trim() : undefined;+ } catch {+ return undefined;+ }+};diff --git a/packages/prompts/src/chains/__tests__/verifyLanguage.test.ts b/packages/prompts/src/chains/__tests__/verifyLanguage.test.tsnew file mode 100644index 00000000000..f3605ec9623--- /dev/null+++ b/packages/prompts/src/chains/__tests__/verifyLanguage.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from 'vitest';++import { chainVerifyPlan, chainVerifyReport } from '../verify';++const taskGoal = 'Verify only this Task: 挤水分 A/C。\n\nRequired Task outcome: 删除死代码';+const system = (chain: { messages: { content: unknown }[] }) => chain.messages[0].content as string;++const report = (language?: string) =>+ chainVerifyReport({+ deliverable: 'done',+ goal: taskGoal,+ items: [],+ language,+ stats: { failed: 0, passed: 0, total: 0, uncertain: 0 },+ verdict: 'passed',+ });++describe('verify output language', () => {+ it('pins plan criteria to the account language when one is given', () => {+ const prompt = system(chainVerifyPlan({ goal: taskGoal, language: 'zh-CN', maxCriteria: 4 }));++ expect(prompt).toContain(+ 'Write title, description, instruction and every requiredEvidence hint in zh-CN, whatever language the run goal is written in.',+ );+ });++ it("falls back to the goal's own content, ignoring its English scaffolding", () => {+ const prompt = system(chainVerifyPlan({ goal: taskGoal, maxCriteria: 4 }));++ expect(prompt).toContain("in the language the user wrote the run goal's own content in");+ expect(prompt).toContain('Ignore the English system wording');+ });++ it('applies the same rule to the round report', () => {+ expect(system(report('ja-JP'))).toContain('Write both fields in ja-JP');+ expect(system(report())).toContain('Ignore the English system wording');+ });+});diff --git a/packages/prompts/src/chains/verify.ts b/packages/prompts/src/chains/verify.tsindex 87b84fa3872..39f929a3d00 100644--- a/packages/prompts/src/chains/verify.ts+++ b/packages/prompts/src/chains/verify.ts@@ -1,11 +1,11 @@import type { VerifyCheckItem, VerifyEvidenceType } from '@lobechat/types';/** Bump when the plan-gen prompt meaningfully changes (tracing partition key). */-export const VERIFY_PLAN_PROMPT_VERSION = 'v3';+export const VERIFY_PLAN_PROMPT_VERSION = 'v4';/** Bump when the judge prompt meaningfully changes. */export const VERIFY_JUDGE_PROMPT_VERSION = 'v3';/** Bump when the report prompt meaningfully changes. */-export const VERIFY_REPORT_PROMPT_VERSION = 'v1';+export const VERIFY_REPORT_PROMPT_VERSION = 'v2';/*** Bump when the review-prediction prompt meaningfully changes. Doubles as part* of the uniqueness key on `verify_review_predictions`, so a bump makes the next@@ -196,12 +196,25 @@ export const REVIEW_PREDICTION_JSON_SCHEMA = {strict: true,};+/**+ * The language rule for user-facing verify text. A Task's run goal is wrapped in+ * English system scaffolding ("Verify only this Task…", "Required Task outcome…")+ * around the user's own words, so "the language of the run goal" reads as+ * English. The account's response language, when set, wins outright.+ */+const verifyOutputLanguageRule = (fields: string, language?: string) =>+ language+ ? `Write ${fields} in ${language}, whatever language the run goal is written in. Keep identifiers, file paths, commands and quoted output as they are.`+ : `Write ${fields} in the language the user wrote the run goal's own content in. Ignore the English system wording around it, such as "Verify only this Task" or "Required Task outcome".`;+export interface PlanPromptInput {/** Optional run context (agent role, repo, constraints). */context?: string;/** Already-mounted criteria titles, so the AI proposes complementary ones. */existingTitles?: string[];goal: string;+ /** The account's response language (e.g. `zh-CN`); the criteria render on its acceptance page. */+ language?: string;maxCriteria: number;}@@ -209,6 +222,7 @@ export const chainVerifyPlan = ({goal,context,existingTitles,+ language,maxCriteria,}: PlanPromptInput) => {const system = [@@ -225,6 +239,7 @@ export const chainVerifyPlan = ({'- description: a one-sentence summary of what this criterion verifies.','- instruction: a detailed, fine-grained judging rubric for this criterion — the exact conditions that constitute a pass, what counts as a fail, the concrete evidence to look for, and edge cases to check. Be specific and thorough, not a one-liner.','- Do not restate criteria already mounted (listed below); propose complementary ones only.',+ `- ${verifyOutputLanguageRule('title, description, instruction and every requiredEvidence hint', language)}`,].join('\n');const user = [@@ -364,6 +379,8 @@ export interface ReportPromptInput {deliverable: string;goal: string;items: ReportPromptItem[];+ /** The account's response language (e.g. `zh-CN`); the report renders on its acceptance page. */+ language?: string;/** Pre-computed rollup so the narrative never contradicts the numbers. */stats: { failed: number; passed: number; total: number; uncertain: number };verdict: string;@@ -378,13 +395,14 @@ export const chainVerifyReport = ({goal,deliverable,items,+ language,stats,verdict,}: ReportPromptInput) => {const system = ['You are writing a delivery-verification report for the user who owns this task.','The overall verdict and the pass/fail/uncertain counts are already decided and given to you — never contradict or recompute them.',- 'Write in the language of the run goal.',+ verifyOutputLanguageRule('both fields', language),'Produce two fields:','- summary: 3-5 sentences for a chat notification — the verdict, what was checked, and the single most important finding.','- content: a full Markdown report. Use a per-criterion section with its verdict, the reasoning, the evidence that backs it, and a concrete next step for anything failed or uncertain. Reference captured artifacts where they support a claim.',