π€― 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): keep generated criteria when one field is off-schema (#20422)
Arvin Xu0667a8c320b9
diff --git a/apps/server/src/services/verify/__tests__/fixtures/planGenOffSchemaEnums.json b/apps/server/src/services/verify/__tests__/fixtures/planGenOffSchemaEnums.jsonnew file mode 100644index 00000000000..89ae6ba6ad0--- /dev/null+++ b/apps/server/src/services/verify/__tests__/fixtures/planGenOffSchemaEnums.json@@ -0,0 +1,64 @@+{+ "criteria": [+ {+ "title": "Report document is delivered",+ "description": "A report exists.",+ "instruction": "Open it.",+ "verifierType": "agent",+ "required": true,+ "onFail": "auto_repair",+ "requiredEvidence": [+ {+ "type": "document",+ "modality": "document",+ "scope": "deliverable",+ "hint": "the report"+ }+ ]+ },+ {+ "title": "Metrics are computed per group",+ "description": "Metrics table.",+ "instruction": "Check table.",+ "verifierType": "agent",+ "required": true,+ "onFail": "auto_repair",+ "requiredEvidence": [+ {+ "type": "structured",+ "modality": "structured",+ "scope": "task_artifacts",+ "hint": "metrics json"+ },+ {+ "type": "text",+ "modality": "text",+ "scope": "run_evidence",+ "hint": "log"+ }+ ]+ },+ {+ "title": "Charts render",+ "description": "Charts.",+ "instruction": "Look.",+ "verifierType": "llm",+ "required": true,+ "onFail": "manual",+ "requiredEvidence": [+ {+ "type": "hologram",+ "modality": "image",+ "scope": "run_evidence",+ "hint": "unknown type"+ }+ ]+ },+ {+ "title": "Unknown verifier",+ "description": "x",+ "verifierType": "oracle",+ "required": true+ }+ ]+}diff --git a/apps/server/src/services/verify/__tests__/planGenSchema.test.ts b/apps/server/src/services/verify/__tests__/planGenSchema.test.tsnew file mode 100644index 00000000000..e03c40d81d0--- /dev/null+++ b/apps/server/src/services/verify/__tests__/planGenSchema.test.ts@@ -0,0 +1,37 @@+import { describe, expect, it } from 'vitest';++import { RawGeneratedCriteriaSchema } from '../schema';+import offSchemaEnums from './fixtures/planGenOffSchemaEnums.json';++/**+ * DeepSeek does not enforce JSON-schema enums and writes evidence modalities+ * into `type`. In production that failed the whole parse for ~40% of Task+ * acceptances, which then fell back to the single holistic row.+ */+describe('RawGeneratedCriteriaSchema', () => {+ it('keeps criteria whose evidence type is a modality value', () => {+ const parsed = RawGeneratedCriteriaSchema.safeParse(offSchemaEnums);++ expect(parsed.success).toBe(true);+ const criteria = parsed.success ? parsed.data.criteria : [];+ expect(criteria.map((c) => c.title)).toEqual([+ 'Report document is delivered',+ 'Metrics are computed per group',+ 'Charts render',+ ]);+ expect(criteria[0].requiredEvidence?.map((e) => e.type)).toEqual(['markdown']);+ expect(criteria[1].requiredEvidence?.map((e) => e.type)).toEqual(['text', 'text']);+ });++ it('drops an unmappable evidence spec without dropping its criterion', () => {+ const parsed = RawGeneratedCriteriaSchema.parse(offSchemaEnums);++ expect(parsed.criteria[2].requiredEvidence).toEqual([]);+ });++ it('drops only a criterion with an unknown verifier type', () => {+ const parsed = RawGeneratedCriteriaSchema.parse(offSchemaEnums);++ expect(parsed.criteria.some((c) => c.title === 'Unknown verifier')).toBe(false);+ });+});diff --git a/apps/server/src/services/verify/schema.ts b/apps/server/src/services/verify/schema.tsindex 800ebab9bd5..ac0b5b16e08 100644--- a/apps/server/src/services/verify/schema.ts+++ b/apps/server/src/services/verify/schema.ts@@ -13,24 +13,59 @@ import { z } from 'zod';// Plan generation β AI proposes additional check criteria for a run// ============================================+/**+ * Models that do not enforce JSON-schema enums (DeepSeek via forced tool+ * calling) put the evidence *modality* into `type` β `document`, `structured`,+ * `image`. Map those back to the capture type they mean.+ */+const EVIDENCE_TYPE_BY_MODALITY: Record<string, (typeof VERIFY_EVIDENCE_TYPES)[number]> = {+ document: 'markdown',+ image: 'screenshot',+ structured: 'text',+};+const requiredEvidenceSchema = z.object({hint: z.string().optional(),- modality: z.enum(VERIFY_EVIDENCE_MODALITIES).optional(),- scope: z.enum(VERIFY_EVIDENCE_SCOPES).optional(),- type: z.enum(VERIFY_EVIDENCE_TYPES),+ modality: z.enum(VERIFY_EVIDENCE_MODALITIES).optional().catch(undefined),+ scope: z.enum(VERIFY_EVIDENCE_SCOPES).optional().catch(undefined),+ type: z.preprocess(+ (value) => (typeof value === 'string' ? (EVIDENCE_TYPE_BY_MODALITY[value] ?? value) : value),+ z.enum(VERIFY_EVIDENCE_TYPES),+ ),});-/** Lenient parse of the AI plan-gen output; the service filters/normalizes. */+const generatedCriterionSchema = z.object({+ description: z.string().optional(),+ instruction: z.string().optional(),+ onFail: z.enum(VERIFY_ON_FAIL_ACTIONS).optional().catch(undefined),+ // One malformed evidence spec drops that spec, not the criterion.+ requiredEvidence: z+ .array(z.unknown())+ .optional()+ .catch(undefined)+ .transform((items) =>+ items?.flatMap((item) => {+ const parsed = requiredEvidenceSchema.safeParse(item);+ return parsed.success ? [parsed.data] : [];+ }),+ ),+ required: z.boolean().optional().catch(undefined),+ title: z.string(),+ verifierType: z.enum(VERIFY_VERIFIER_TYPES),+});++/**+ * Lenient parse of the AI plan-gen output; the service filters/normalizes.+ *+ * Each criterion is parsed on its own: a single off-schema field used to fail+ * the whole object, the plan came back empty, and the checklist silently+ * collapsed to the one holistic fallback row.+ */export const RawGeneratedCriteriaSchema = z.object({- criteria: z.array(- z.object({- description: z.string().optional(),- instruction: z.string().optional(),- onFail: z.enum(VERIFY_ON_FAIL_ACTIONS).optional(),- requiredEvidence: z.array(requiredEvidenceSchema).optional(),- required: z.boolean().optional(),- title: z.string(),- verifierType: z.enum(VERIFY_VERIFIER_TYPES),+ criteria: z.array(z.unknown()).transform((items) =>+ items.flatMap((item) => {+ const parsed = generatedCriterionSchema.safeParse(item);+ return parsed.success ? [parsed.data] : [];}),),});