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): let the Goal review see every frame of an ordinary check (#20032)

Arvin Xu6774d8bb77b2
diff --git a/apps/server/src/services/verify/__tests__/goalReview.test.ts b/apps/server/src/services/verify/__tests__/goalReview.test.ts
index 4eba3f9c32b..532dd2b133c 100644
--- a/apps/server/src/services/verify/__tests__/goalReview.test.ts
+++ b/apps/server/src/services/verify/__tests__/goalReview.test.ts
@@ -41,6 +41,7 @@ vi.mock('../acceptanceService', async (original) => ({
}),
}));
vi.mock('../reviewPredictor', () => ({
+ GATE_REVIEW_MAX_VISUALS: 12,
REVIEW_PREDICT_CONCURRENCY: 4,
VerifyReviewPredictorService: vi.fn(function () {
return { predict: mocks.predict };
@@ -102,7 +103,12 @@ describe('Goal automatic Acceptance review', () => {
goalReview: { status: 'passed', predictionIds: ['p1'], feedback: '' },
});
expect(mocks.predict).toHaveBeenCalledWith(
- expect.objectContaining({ includeTextEvidence: true, checkResultId: 'result1' }),
+ expect.objectContaining({
+ checkResultId: 'result1',
+ includeTextEvidence: true,
+ // The gate must not judge on the shadow lane's three-frame sample.
+ maxVisuals: 12,
+ }),
);
});
diff --git a/apps/server/src/services/verify/__tests__/goalReviewEvidence.test.ts b/apps/server/src/services/verify/__tests__/goalReviewEvidence.test.ts
index 765f424fdbd..0436a1894fc 100644
--- a/apps/server/src/services/verify/__tests__/goalReviewEvidence.test.ts
+++ b/apps/server/src/services/verify/__tests__/goalReviewEvidence.test.ts
@@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import type { LobeChatDatabase } from '@/database/type';
-import { VerifyReviewPredictorService } from '../reviewPredictor';
+import { GATE_REVIEW_MAX_VISUALS, VerifyReviewPredictorService } from '../reviewPredictor';
const mocks = vi.hoisted(() => ({
result: vi.fn(),
@@ -170,6 +170,30 @@ describe('Goal review evidence', () => {
expect(prediction?.statusReason).toContain('1 more frame(s)');
});
+ /**
+ * Regression: the Goal review attached only the first three frames. A check
+ * carrying four header shots, a close recording and a tooltip shot came back
+ * "unjudgeable β€” open the hidden LocalFile screenshot, GIF and tooltip", and a
+ * delivery whose verifiers had all passed was parked on a person.
+ */
+ it('attaches every frame of an ordinary check when the review gates the Task', async () => {
+ const ids = ['s1', 's2', 's3', 's4', 's5', 'g1', 's6'];
+ mocks.evidence.mockResolvedValue(
+ ids.map((id) => ({ fileId: id, id, type: id.startsWith('g') ? 'gif' : 'screenshot' })),
+ );
+ mocks.file.mockImplementation(async (id: string) => ({ id, size: 10, url: `key-${id}` }));
+ mocks.url.mockImplementation(async ({ id }: { id: string }) => `https://x/${id}`);
+
+ const prediction = await review().predict({
+ ...params,
+ includeTextEvidence: true,
+ maxVisuals: GATE_REVIEW_MAX_VISUALS,
+ });
+ const payload = JSON.stringify(mocks.generate.mock.calls[0][0].messages);
+ for (const id of ids) expect(payload).toContain(`https://x/${id}`);
+ expect(prediction?.statusReason).toBeUndefined();
+ });
+
/**
* Regression: frames went to the provider as links it had to download. A
* provider that could not reach the storage behind them (a bucket on
@@ -188,6 +212,32 @@ describe('Goal review evidence', () => {
expect(mocks.url).not.toHaveBeenCalled();
});
+ /**
+ * Regression: the inline ceiling was per frame only, so a gate review carrying
+ * twelve large frames could build a request body far past provider limits.
+ */
+ it('links the frames past the per-request inline budget', async () => {
+ const size = 4 * 1024 * 1024;
+ const ids = ['s1', 's2', 's3', 's4', 's5'];
+ mocks.evidence.mockResolvedValue(ids.map((id) => ({ fileId: id, id, type: 'screenshot' })));
+ mocks.file.mockImplementation(async (id: string) => ({
+ fileType: 'image/png',
+ id,
+ size,
+ url: `key-${id}`,
+ }));
+ mocks.bytes.mockResolvedValue(new Uint8Array([0x89, 0x50, 0x4e, 0x47]));
+ mocks.url.mockImplementation(async ({ id }: { id: string }) => `https://x/${id}`);
+
+ await review().predict({ ...params, maxVisuals: GATE_REVIEW_MAX_VISUALS });
+ // 15 MiB budget: three 4 MiB frames inline, the fourth and fifth are linked.
+ expect(mocks.bytes).toHaveBeenCalledTimes(3);
+ const payload = JSON.stringify(mocks.generate.mock.calls[0][0].messages);
+ expect(payload).not.toContain('https://x/s3');
+ expect(payload).toContain('https://x/s4');
+ expect(payload).toContain('https://x/s5');
+ });
+
it('links a frame too large to send inline', async () => {
mocks.evidence.mockResolvedValue([{ fileId: 'f1', id: 's1', type: 'screenshot' }]);
mocks.file.mockResolvedValue({
diff --git a/apps/server/src/services/verify/goalReview.ts b/apps/server/src/services/verify/goalReview.ts
index d4fbda0d3a2..489a2f7ed77 100644
--- a/apps/server/src/services/verify/goalReview.ts
+++ b/apps/server/src/services/verify/goalReview.ts
@@ -9,7 +9,11 @@ import type { LobeChatDatabase } from '@/database/type';
import { AcceptanceService, buildAcceptanceCheckUnion } from './acceptanceService';
import { mapWithConcurrency } from './concurrency';
import { resolveGoalReviewModelConfig } from './goalReviewModelConfig';
-import { REVIEW_PREDICT_CONCURRENCY, VerifyReviewPredictorService } from './reviewPredictor';
+import {
+ GATE_REVIEW_MAX_VISUALS,
+ REVIEW_PREDICT_CONCURRENCY,
+ VerifyReviewPredictorService,
+} from './reviewPredictor';
/**
* The startup failures this review can name back to a person. Everything else that
@@ -130,6 +134,9 @@ export const reviewGoalDelivery = async (
checkResultId,
includeTextEvidence: true,
instructionDocumentId: check.planItem?.documentId,
+ // This review gates the Task, so it must see the frames the check
+ // carries rather than the shadow lane's cost-capped sample.
+ maxVisuals: GATE_REVIEW_MAX_VISUALS,
modelConfig,
requirement: acceptance.requirement,
surface: check.surface,
diff --git a/apps/server/src/services/verify/modelFrames.ts b/apps/server/src/services/verify/modelFrames.ts
index 5905bfeb6f8..4d15ba8476e 100644
--- a/apps/server/src/services/verify/modelFrames.ts
+++ b/apps/server/src/services/verify/modelFrames.ts
@@ -11,6 +11,18 @@ const log = debug('lobe-server:verify-model-frames');
*/
export const MAX_INLINE_FRAME_BYTES = 5 * 1024 * 1024;
+/**
+ * Ceiling on the frames inlined into ONE request, summed over raw file size
+ * (~20 MiB once base64-encoded). The per-frame ceiling alone lets a request
+ * carrying many frames grow past provider body limits; frames past this budget
+ * are linked instead, like an oversized frame.
+ */
+export const MAX_INLINE_REQUEST_BYTES = 15 * 1024 * 1024;
+
+/** Whether a frame of this size may be sent inline at all. */
+export const isInlineableFrameSize = (size?: number | null): size is number =>
+ typeof size === 'number' && size > 0 && size <= MAX_INLINE_FRAME_BYTES;
+
interface StoredFrame {
fileType?: string | null;
id: string;
@@ -47,8 +59,10 @@ const sniffImageMimeType = (bytes: Uint8Array): string | undefined => {
export const resolveModelReadableFrameUrl = async (
fileService: FileService,
file: StoredFrame,
+ /** False once the request's inline budget is spent: link the frame instead. */
+ inline = true,
): Promise<string> => {
- if (typeof file.size === 'number' && file.size > 0 && file.size <= MAX_INLINE_FRAME_BYTES) {
+ if (inline && isInlineableFrameSize(file.size)) {
try {
const bytes = await fileService.getFileByteArray(file.url);
const mimeType = file.fileType?.startsWith('image/')
diff --git a/apps/server/src/services/verify/reviewPredictor.ts b/apps/server/src/services/verify/reviewPredictor.ts
index 47728b98b02..318b5ef118a 100644
--- a/apps/server/src/services/verify/reviewPredictor.ts
+++ b/apps/server/src/services/verify/reviewPredictor.ts
@@ -19,7 +19,11 @@ import type { LobeChatDatabase } from '@/database/type';
import { AiGenerationService } from '@/server/services/aiGeneration';
import { FileService } from '@/server/services/file';
-import { resolveModelReadableFrameUrl } from './modelFrames';
+import {
+ isInlineableFrameSize,
+ MAX_INLINE_REQUEST_BYTES,
+ resolveModelReadableFrameUrl,
+} from './modelFrames';
import type { ReviewEvidenceRow } from './reviewEvidence';
import { formatTextEvidence, TEXT_EVIDENCE_TYPES } from './reviewEvidence';
import { describeWithheldEvidence } from './reviewInspection';
@@ -42,6 +46,17 @@ const VISUAL_EVIDENCE_TYPES = new Set(['screenshot', 'gif']);
*/
const MAX_VISUALS = 3;
+/**
+ * Frame cap for a review that GATES a delivery (the Goal review) rather than
+ * proposing a card to a person. There, a withheld frame is not a cheaper
+ * opinion but a wrong outcome: the model rightly answers "I cannot see the
+ * screenshot this criterion asks for", which reads as unjudgeable and parks a
+ * passing delivery on a human. Builders routinely attach one frame per surface
+ * plus a recording and a tooltip shot, so three is well below an ordinary
+ * check; twelve covers that with room while still bounding the request.
+ */
+export const GATE_REVIEW_MAX_VISUALS = 12;
+
/**
* How many checks may be judged at once when a whole acceptance is requested.
*
@@ -59,6 +74,8 @@ export interface PredictReviewParams {
includeTextEvidence?: boolean;
/** The check's detailed judging rubric, when the criterion links one. */
instructionDocumentId?: string | null;
+ /** Frames attached per request; defaults to the shadow-lane cap. */
+ maxVisuals?: number;
modelConfig: { model: string; provider: string };
/** The acceptance's requirement, used as the scope test. */
requirement?: string | null;
@@ -189,7 +206,7 @@ export class VerifyReviewPredictorService {
// frames to attach, which payloads to inline, and what the request had to
// hold back β€” so they cannot disagree about what the check carries.
const evidence = await this.evidenceModel.listByCheckResult(result.id);
- const visuals = await this.resolveVisuals(evidence);
+ const visuals = await this.resolveVisuals(evidence, params.maxVisuals ?? MAX_VISUALS);
// Nothing to look at means nothing this reviewer can honestly say. A
// text-only opinion here would be the model paraphrasing the verifier's own
// reasoning back at the user, which is worse than silence.
@@ -352,17 +369,30 @@ export class VerifyReviewPredictorService {
* in this array, and that index is how a region gets bound back to the
* evidence row it was drawn on.
*/
- private async resolveVisuals(evidence: CheckEvidenceRows) {
+ private async resolveVisuals(evidence: CheckEvidenceRows, maxVisuals: number) {
const visual = evidence
.filter((row) => VISUAL_EVIDENCE_TYPES.has(row.type) && row.fileId)
- .slice(0, MAX_VISUALS);
+ .slice(0, maxVisuals);
+
+ const files = await Promise.all(visual.map((row) => this.fileModel.findById(row.fileId!)));
+
+ // Spend the request's inline budget in evidence order; later frames are
+ // linked, so a many-frame check cannot push the body past provider limits.
+ let inlineBytes = 0;
+ const inline = files.map((file) => {
+ const size = file?.size;
+ if (!isInlineableFrameSize(size) || inlineBytes + size > MAX_INLINE_REQUEST_BYTES)
+ return false;
+ inlineBytes += size;
+ return true;
+ });
const resolved = await Promise.all(
- visual.map(async (row) => {
- const file = await this.fileModel.findById(row.fileId!);
+ visual.map(async (row, index) => {
+ const file = files[index];
if (!file) return null;
return {
- accessUrl: await resolveModelReadableFrameUrl(this.fileService, file),
+ accessUrl: await resolveModelReadableFrameUrl(this.fileService, file, inline[index]),
description: row.description,
evidenceId: row.id,
};