diff --git a/hub/client/application/hub/learnings-contracts/index.ts b/hub/client/application/hub/learnings-contracts/index.ts index 2648befad..866b36834 100644 --- a/hub/client/application/hub/learnings-contracts/index.ts +++ b/hub/client/application/hub/learnings-contracts/index.ts @@ -147,6 +147,7 @@ export const learningHistoryResponseSchema = z z .object({ id: z.string().min(1), + source: z.enum(["automated", "reviewer_confirmed"]), efficiency: z.number().int().min(1).max(4), followed: z.enum(["followed", "not_followed", "unclear"]), reasoning: z.string(), diff --git a/hub/client/application/hub/learnings-contracts/types.ts b/hub/client/application/hub/learnings-contracts/types.ts index dded4ce8d..1574a0e47 100644 --- a/hub/client/application/hub/learnings-contracts/types.ts +++ b/hub/client/application/hub/learnings-contracts/types.ts @@ -90,6 +90,8 @@ export interface LearningHistoryResponse { /** How one use of a learning was scored, with the Build it judged. */ export interface LearningOutcomeResponse { id: string + /** Whether a reviewer confirmed the work before it was scored. */ + source: "automated" | "reviewer_confirmed" /** 4 is best. 1 and 2 come with an issue. */ efficiency: number followed: "followed" | "not_followed" | "unclear" diff --git a/hub/client/application/hub/view-models/learnings-library/index.test.ts b/hub/client/application/hub/view-models/learnings-library/index.test.ts index 5ba96e538..2822ec33f 100644 --- a/hub/client/application/hub/view-models/learnings-library/index.test.ts +++ b/hub/client/application/hub/view-models/learnings-library/index.test.ts @@ -250,6 +250,7 @@ describe("learningsLibrary()", () => { }, ] const score = { + source: "automated" as const, reasoning: "The form kept its labels.", issue: null, build: { prototypeId: "17", prototypeName: "Checkout", number: 3 }, @@ -283,6 +284,7 @@ describe("learningsLibrary()", () => { { ...score, id: "score_supports", + source: "reviewer_confirmed", efficiency: 3, followed: "followed", scoredAt: "2026-10-12T00:00:00Z", @@ -298,6 +300,7 @@ describe("learningsLibrary()", () => { ["inconclusive", "The form kept its labels."], ]) expect(result.selected?.outcomes?.[0]).toMatchObject({ + reviewerConfirmed: true, buildPath: "/repositories/2001/prototypes/17?build=3", beforeScreenshotUrl: null, afterScreenshotUrl: `/api/repositories/2001/learnings/screenshots/${"b".repeat(64)}`, diff --git a/hub/client/application/hub/view-models/learnings-library/index.ts b/hub/client/application/hub/view-models/learnings-library/index.ts index 4c0eb0a5b..30915bb3d 100644 --- a/hub/client/application/hub/view-models/learnings-library/index.ts +++ b/hub/client/application/hub/view-models/learnings-library/index.ts @@ -88,6 +88,7 @@ function outcomes(items: LearningOutcomeResponse[], repositoryId: string): Learn id: item.id, result: item.followed !== "followed" ? "inconclusive" : item.efficiency >= 3 ? "supports" : "concern", + reviewerConfirmed: item.source === "reviewer_confirmed", summary: item.issue ?? item.reasoning, buildLabel: `${item.build.prototypeName}, Build ${item.build.number}`, buildPath: `/repositories/${repositoryId}/prototypes/${item.build.prototypeId}?build=${item.build.number}`, diff --git a/hub/client/features/learnings-library/index.tsx b/hub/client/features/learnings-library/index.tsx index 9e679fc8e..26e369951 100644 --- a/hub/client/features/learnings-library/index.tsx +++ b/hub/client/features/learnings-library/index.tsx @@ -576,7 +576,9 @@ function OutcomeList({ outcomes }: { outcomes: LearningOutcome[] }) { {outcomeLabels[outcome.result]} - Automated assessment + + {outcome.reviewerConfirmed ? "Reviewer-confirmed" : "Automated assessment"} + {outcome.buildLabel} diff --git a/hub/client/features/learnings-library/types.ts b/hub/client/features/learnings-library/types.ts index 2ecaad322..d546de431 100644 --- a/hub/client/features/learnings-library/types.ts +++ b/hub/client/features/learnings-library/types.ts @@ -35,11 +35,12 @@ export interface LearningHistoryEntry { reason: string | null } -/** Everything the detail view shows for the selected learning. */ /** How one later Build did with a learning's guidance. */ export interface LearningOutcome { id: string result: "supports" | "concern" | "inconclusive" + /** True when the person who gave the feedback confirmed the change worked. */ + reviewerConfirmed: boolean summary: string buildLabel: string buildPath: string @@ -48,6 +49,7 @@ export interface LearningOutcome { afterScreenshotUrl: string | null } +/** Everything the detail view shows for the selected learning. */ export interface LearningDetail { id: string status: LearningStatus diff --git a/hub/client/pages/learnings-page/stories.tsx b/hub/client/pages/learnings-page/stories.tsx index 5f197559c..86015ca1c 100644 --- a/hub/client/pages/learnings-page/stories.tsx +++ b/hub/client/pages/learnings-page/stories.tsx @@ -225,6 +225,7 @@ const activeDetail: LearningDetail = { { id: "score-3", result: "supports", + reviewerConfirmed: true, summary: "The form kept a single primary button named for its action.", buildLabel: "Checkout, Build 12", buildPath: "/repositories/2001/prototypes/17?build=12", @@ -235,6 +236,7 @@ const activeDetail: LearningDetail = { { id: "score-2", result: "concern", + reviewerConfirmed: false, summary: "The rule did not say which button wins when a form has two equal actions.", buildLabel: "Signup, Build 4", buildPath: "/repositories/2001/prototypes/18?build=4", @@ -245,6 +247,7 @@ const activeDetail: LearningDetail = { { id: "score-1", result: "inconclusive", + reviewerConfirmed: false, summary: "The change did not touch a form, so the guidance did not apply.", buildLabel: "Checkout, Build 11", buildPath: "/repositories/2001/prototypes/17?build=11", diff --git a/hub/docs/learning-foundation.md b/hub/docs/learning-foundation.md index 90ce965a3..ee3607088 100644 --- a/hub/docs/learning-foundation.md +++ b/hub/docs/learning-foundation.md @@ -163,14 +163,21 @@ Turning evaluations on also adds a consent grant that lets the store use the rep When an agent's `report_usage` call names a commit, Hub remembers it. A later report for the same commit is kept for another pass, even if scoring is already running. Once a successful Build exists for that commit, the worker's recovery pass queues a scoring job. For example, an agent applies the learning "Use the shared empty state" in commit `abc123`, a Build for `abc123` succeeds, and Hub asks the store to score that learning against the commit's diff and any screenshots the agent sent. -- Each reported use of a learning is scored once. Hub records the attempt and its cost before asking for the next one, so a crash retries the same operation instead of paying twice. +- Each reported use of a learning gets one automated score, plus at most one reviewer-confirmed score (see below). Hub records the attempt and its cost before asking for the next one, so a crash retries the same operation instead of paying twice. - A failed score is recorded with what it spent and is not retried. A score interrupted by a worker stopping stays running and is retried with the same operation. - When the budget runs out or Copilot is unavailable, the request waits. The recovery pass tries it again each minute and starts scoring once the budget is raised or the next month begins. Requests that never find a successful Build are dropped after 30 days. - Scoring holds the learning execution lock for each command, so agent calls may briefly get a busy reply while a score runs. +When the person who left review feedback resolves their own thread, Hub treats that as verification. It finds the prototype's newest successful Build after the one they commented on, judged by when each Build's workflow started, and asks for that commit to be scored again. Each learning an agent applied in that commit gets one more score that tells the scorer a reviewer confirmed the work. The first score is kept. For example, a reviewer comments on Checkout Build 3, an agent's fix lands in Build 5, and the reviewer resolves the thread. Hub scores Build 5's applied learnings again with that confirmation. + +- Hub keeps the verification for that prototype and commit, so usage reported after the thread is resolved still gets the extra score. A report that names a different prototype doesn't. +- Someone else resolving the thread doesn't count. A thread on the newest Build has no later change to verify, so nothing is scored. +- The scorer gets only the time of the verification, never the thread's text. +- The re-score follows the same budget, retry, and lock rules as the first score. + ### Observed outcomes -An active learning's detail view lists how later Builds did with its current wording, newest first. Each entry reads a score as one result. A score where the agent didn't clearly follow the guidance is "Inconclusive". Otherwise a score of 3 or 4 "Supports the guidance" and 1 or 2 is a "Possible concern". The entry shows the scorer's issue, or its reasoning when there is no issue, and links to the Build it judged. For example, "Possible concern · Automated assessment · Checkout, Build 12" with "The rule did not say where the label goes." +An active learning's detail view lists how later Builds did with its current wording, newest first. Each entry reads a score as one result. A score where the agent didn't clearly follow the guidance is "Inconclusive". Otherwise a score of 3 or 4 "Supports the guidance" and 1 or 2 is a "Possible concern". The entry shows the scorer's issue, or its reasoning when there is no issue, and links to the Build it judged. For example, "Possible concern · Automated assessment · Checkout, Build 12" with "The rule did not say where the label goes." A score made after a reviewer verified the work reads "Reviewer-confirmed" instead, and replaces the earlier score for the same use. - Scores of earlier wording are left out, since they say nothing about the guidance agents get now. Retiring and reinstating a learning keeps its wording, so its scores stay. - A score with no successful Build people can open is left out. diff --git a/hub/schema/learning-evaluation-run.prisma b/hub/schema/learning-evaluation-run.prisma index 900935f11..1db445bcf 100644 --- a/hub/schema/learning-evaluation-run.prisma +++ b/hub/schema/learning-evaluation-run.prisma @@ -9,6 +9,7 @@ model LearningEvaluationRun { repository Repository @relation(fields: [repositoryId], references: [id], onDelete: Cascade) // Attribute columns + trigger LearningScoreTrigger @default(USAGE) state LearningRunState @default(RUNNING) copilotRequests Int @default(0) @map("copilot_requests") aiCredits Decimal @default(0) @map("ai_credits") @db.Decimal(20, 9) @@ -20,7 +21,7 @@ model LearningEvaluationRun { createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3) - @@unique([repositoryId, usedLearningId]) + @@unique([repositoryId, usedLearningId, trigger]) @@index([createdAt]) @@map("learning_evaluation_runs") } diff --git a/hub/schema/learning-reviewer-verification.prisma b/hub/schema/learning-reviewer-verification.prisma new file mode 100644 index 000000000..b324ba5a9 --- /dev/null +++ b/hub/schema/learning-reviewer-verification.prisma @@ -0,0 +1,22 @@ +model LearningReviewerVerification { + // ID columns + id String @id @default(uuid()) @db.Uuid + repositoryId String @map("repository_id") @db.Uuid + prototypeId String @map("prototype_id") @db.Uuid + + // Relations + repository Repository @relation(fields: [repositoryId], references: [id], onDelete: Cascade) + prototype Prototype @relation(fields: [prototypeId], references: [id], onDelete: Cascade) + + // Attribute columns + commitSha String @map("commit_sha") @db.VarChar(64) + verifiedAt DateTime @map("verified_at") @db.Timestamptz(3) + + // Timestamp columns + createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3) + updatedAt DateTime @default(now()) @updatedAt @map("updated_at") @db.Timestamptz(3) + + @@unique([prototypeId, commitSha]) + @@index([repositoryId, commitSha]) + @@map("learning_reviewer_verifications") +} diff --git a/hub/schema/learning-score-trigger.enum.prisma b/hub/schema/learning-score-trigger.enum.prisma new file mode 100644 index 000000000..c6d24aa59 --- /dev/null +++ b/hub/schema/learning-score-trigger.enum.prisma @@ -0,0 +1,4 @@ +enum LearningScoreTrigger { + USAGE + REVIEWER_VERIFICATION +} diff --git a/hub/schema/migrations/20261226090000_reviewer_verified_scores/migration.sql b/hub/schema/migrations/20261226090000_reviewer_verified_scores/migration.sql new file mode 100644 index 000000000..e18e03c23 --- /dev/null +++ b/hub/schema/migrations/20261226090000_reviewer_verified_scores/migration.sql @@ -0,0 +1,36 @@ +-- CreateEnum +CREATE TYPE "LearningScoreTrigger" AS ENUM ('USAGE', 'REVIEWER_VERIFICATION'); + +-- DropIndex +DROP INDEX "learning_evaluation_runs_repository_id_used_learning_id_key"; + +-- AlterTable +ALTER TABLE "learning_evaluation_runs" ADD COLUMN "trigger" "LearningScoreTrigger" NOT NULL DEFAULT 'USAGE'; + +-- CreateTable +CREATE TABLE "learning_reviewer_verifications" ( + "id" UUID NOT NULL, + "repository_id" UUID NOT NULL, + "prototype_id" UUID NOT NULL, + "commit_sha" VARCHAR(64) NOT NULL, + "verified_at" TIMESTAMPTZ(3) NOT NULL, + "created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "learning_reviewer_verifications_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "learning_reviewer_verifications_repository_id_commit_sha_idx" ON "learning_reviewer_verifications"("repository_id", "commit_sha"); + +-- CreateIndex +CREATE UNIQUE INDEX "learning_reviewer_verifications_prototype_id_commit_sha_key" ON "learning_reviewer_verifications"("prototype_id", "commit_sha"); + +-- CreateIndex +CREATE UNIQUE INDEX "learning_evaluation_runs_repository_id_used_learning_id_tri_key" ON "learning_evaluation_runs"("repository_id", "used_learning_id", "trigger"); + +-- AddForeignKey +ALTER TABLE "learning_reviewer_verifications" ADD CONSTRAINT "learning_reviewer_verifications_repository_id_fkey" FOREIGN KEY ("repository_id") REFERENCES "repositories"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "learning_reviewer_verifications" ADD CONSTRAINT "learning_reviewer_verifications_prototype_id_fkey" FOREIGN KEY ("prototype_id") REFERENCES "prototypes"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/hub/schema/prototype.prisma b/hub/schema/prototype.prisma index f19c55be6..08f464732 100644 --- a/hub/schema/prototype.prisma +++ b/hub/schema/prototype.prisma @@ -7,13 +7,14 @@ model Prototype { currentBuildId String? @map("current_build_id") @db.Uuid // Relations - repository Repository @relation(fields: [repositoryId], references: [id], onDelete: Restrict) - author User? @relation(fields: [authorId], references: [id], onDelete: Restrict) - builds Build[] @relation("PrototypeBuilds") - currentBuild Build? @relation("CurrentPrototypeBuild", fields: [currentBuildId, id], references: [id, prototypeId], onDelete: Restrict) - introductions PrototypeIntroduction[] - reviewThreads ReviewThread[] - shareLinks ShareLink[] + repository Repository @relation(fields: [repositoryId], references: [id], onDelete: Restrict) + author User? @relation(fields: [authorId], references: [id], onDelete: Restrict) + builds Build[] @relation("PrototypeBuilds") + currentBuild Build? @relation("CurrentPrototypeBuild", fields: [currentBuildId, id], references: [id, prototypeId], onDelete: Restrict) + introductions PrototypeIntroduction[] + learningVerifications LearningReviewerVerification[] + reviewThreads ReviewThread[] + shareLinks ShareLink[] // Attribute columns branchName String @map("branch_name") @db.VarChar(255) diff --git a/hub/schema/repository.prisma b/hub/schema/repository.prisma index b4579fbbb..5a20bd192 100644 --- a/hub/schema/repository.prisma +++ b/hub/schema/repository.prisma @@ -12,6 +12,7 @@ model Repository { agentScreenshots AgentScreenshot[] learningEvaluationRuns LearningEvaluationRun[] learningScoreRequests LearningScoreRequest[] + learningVerifications LearningReviewerVerification[] decisionModelConfiguration DecisionModelConfiguration? decisionReviewSnapshot DecisionReviewSnapshot? decisionTrainingJobs DecisionTrainingJob[] diff --git a/hub/server/domains/learning/create-learning-job-processors/index.ts b/hub/server/domains/learning/create-learning-job-processors/index.ts index abba7e675..32f5fcbbc 100644 --- a/hub/server/domains/learning/create-learning-job-processors/index.ts +++ b/hub/server/domains/learning/create-learning-job-processors/index.ts @@ -49,6 +49,7 @@ import { finishLearningEvaluationRun } from "../../../repositories/learning-eval import { startLearningEvaluationRun } from "../../../repositories/learning-evaluation-runs/start-learning-evaluation-run/index.ts" import { sumLearningEvaluationCredits } from "../../../repositories/learning-evaluation-runs/sum-learning-evaluation-credits/index.ts" import { deleteExpiredLearningScoreRequests } from "../../../repositories/learning-score-requests/delete-expired-learning-score-requests/index.ts" +import { listLearningReviewerVerifications } from "../../../repositories/learning-reviewer-verifications/list-learning-reviewer-verifications/index.ts" import { deleteLearningScoreRequest } from "../../../repositories/learning-score-requests/delete-learning-score-request/index.ts" import { listReadyLearningScoreRequests } from "../../../repositories/learning-score-requests/list-ready-learning-score-requests/index.ts" import { getCopilotConnectionState } from "../../../repositories/copilot-connection-states/get-copilot-connection-state/index.ts" @@ -606,11 +607,13 @@ export function createLearningJobProcessors(environment: NodeJS.ProcessEnv, logg nodePath: configuration.nodePath, ...options, }), - start: (usedLearningId) => + start: (usedLearningId, trigger) => startLearningEvaluationRun(prisma, { repositoryId: request.repositoryId, usedLearningId, + trigger, }), + verifications: () => listLearningReviewerVerifications(prisma, repository), withinBudget: async () => { const budget = (await initializeEvaluationSetting(prisma)).monthlyBudgetCredits const used = await sumLearningEvaluationCredits(prisma, startOfUtcMonth(new Date())) diff --git a/hub/server/domains/learning/get-learning-history/index.test.ts b/hub/server/domains/learning/get-learning-history/index.test.ts index e45cbf9d5..08257ade0 100644 --- a/hub/server/domains/learning/get-learning-history/index.test.ts +++ b/hub/server/domains/learning/get-learning-history/index.test.ts @@ -138,10 +138,18 @@ describe("getLearningHistory()", () => { }) .mockResolvedValueOnce({ outcomes: [ - { ...outcome, id: "score_old", version: 1 }, { ...outcome, + id: "score_old", + usedLearningId: "use_1", + version: 1, + inputs: ["build_diff"], + }, + { + ...outcome, + usedLearningId: "use_2", version: 2, + inputs: ["build_diff", "screenshots"], after: { sha256: `sha256:${digest}`, route: "/checkout", consentGrantId: "grant-1" }, }, ], @@ -161,11 +169,51 @@ describe("getLearningHistory()", () => { expect(result.outcomes).toEqual([ { ...outcome, + source: "automated", after: { sha256: digest, route: "/checkout", consentGrantId: "grant-1" }, }, ]) }) + it("shows a reviewer-confirmed score in place of the earlier score for the same use", async () => { + const outcome = { + usedLearningId: "use_1", + version: 1, + commitSha: "a".repeat(40), + efficiency: 3, + followed: "followed", + reasoning: "The form kept its labels.", + scoredAt: "2026-11-05T00:00:00.000Z", + } + vi.mocked(runLearningCommand) + .mockResolvedValueOnce({ + withheld: false, + record: {}, + versions: [{ version: 1, state: "accepted", contentDigest: "wording" }], + }) + .mockResolvedValueOnce({ + outcomes: [ + { ...outcome, id: "score_automated", inputs: ["build_diff"] }, + { ...outcome, id: "score_confirmed", inputs: ["build_diff", "reviewer_verification"] }, + ], + }) + + const result = await getLearningHistory({ + applicationRoot: "/app", + cliPath: "/app/replica-learning.mjs", + learningId: "mem_1", + nodePath: "/node", + repositoryId: "11111111-2222-4333-8444-555555555555", + repositoryScope: "github.com/repositories/123", + root: "/private/learning", + staticDirectories: [], + }) + + expect(result.outcomes.map(({ id, source }) => [id, source])).toEqual([ + ["score_confirmed", "reviewer_confirmed"], + ]) + }) + it("separates supporting and opposing comments and counts the ones it cannot show", async () => { const comment = { commentId: 1, diff --git a/hub/server/domains/learning/get-learning-history/index.ts b/hub/server/domains/learning/get-learning-history/index.ts index 652294bcb..a75484183 100644 --- a/hub/server/domains/learning/get-learning-history/index.ts +++ b/hub/server/domains/learning/get-learning-history/index.ts @@ -85,7 +85,9 @@ const outcomesSchema = z z .object({ id: z.string().min(1), + usedLearningId: z.string().min(1), version: z.number().int().positive(), + inputs: z.array(z.string()), commitSha: z.string().regex(/^[0-9a-f]{40}$/), prototypeId: z.string().optional(), efficiency: z.number().int().min(1).max(4), @@ -345,10 +347,17 @@ function currentOutcomes( const current = new Set( versions.filter((entry) => entry.contentDigest === wording).map((entry) => entry.version), ) - return outcomes - .filter((outcome) => current.has(outcome.version)) + const matching = outcomes.filter((outcome) => current.has(outcome.version)) + // A reviewer's confirmation scores the same use again. The newer score replaces the + // earlier one so the use isn't counted twice. + const last = new Map(matching.map((outcome, index) => [outcome.usedLearningId, index])) + return matching + .filter((outcome, index) => last.get(outcome.usedLearningId) === index) .map((outcome) => ({ id: outcome.id, + source: outcome.inputs.includes("reviewer_verification") + ? ("reviewer_confirmed" as const) + : ("automated" as const), commitSha: outcome.commitSha, prototypeId: outcome.prototypeId ?? null, efficiency: outcome.efficiency, diff --git a/hub/server/domains/learning/record-reviewer-verification/index.db.test.ts b/hub/server/domains/learning/record-reviewer-verification/index.db.test.ts new file mode 100644 index 000000000..86386219a --- /dev/null +++ b/hub/server/domains/learning/record-reviewer-verification/index.db.test.ts @@ -0,0 +1,126 @@ +import { describe, expect, it } from "vitest" + +import { prisma } from "../../../integrations/prisma" +import { recordReviewerVerification } from "." + +describe("recordReviewerVerification", () => { + it("asks to score the Build that started last when the reviewer resolves their own thread", async () => { + const repository = await prisma.repository.create({ + data: { defaultBranch: "main", githubRepositoryId: 31n, nameWithOwner: "octo/verified" }, + }) + const prototype = await prisma.prototype.create({ + data: { repositoryId: repository.id, branchName: "checkout" }, + }) + // Hub found Build 3's run late, so it started before Build 2. + const builds = [] + for (const [number, day] of [ + [1, 1], + [2, 3], + [3, 2], + ] as const) { + builds.push( + await prisma.build.create({ + data: { + prototypeId: prototype.id, + number, + state: "successful", + commitSha: String(number).repeat(40), + workflowCreatedAt: new Date(`2026-12-0${day}T00:00:00Z`), + }, + }), + ) + } + const reviewer = await prisma.user.create({ data: {} }) + const thread = await prisma.reviewThread.create({ + data: { + repositoryId: repository.id, + prototypeId: prototype.id, + buildId: builds[0]!.id, + anchor: { kind: "area", route: { pathname: "/" } }, + comments: { + create: { authorId: reviewer.id, authorLogin: "reviewer", body: "Label the field." }, + }, + }, + }) + const verifiedAt = new Date("2026-12-04T00:00:00Z") + + await recordReviewerVerification(prisma, { + threadId: thread.id, + resolverId: reviewer.id, + verifiedAt, + }) + + expect( + await prisma.learningReviewerVerification.findMany({ + where: { repositoryId: repository.id }, + select: { prototypeId: true, commitSha: true, verifiedAt: true }, + }), + ).toEqual([{ prototypeId: prototype.id, commitSha: "2".repeat(40), verifiedAt }]) + expect( + await prisma.learningScoreRequest.findMany({ + where: { repositoryId: repository.id }, + select: { commitSha: true }, + }), + ).toEqual([{ commitSha: "2".repeat(40) }]) + }) + + it("ignores someone else resolving the thread and threads with no later Build", async () => { + const repository = await prisma.repository.create({ + data: { defaultBranch: "main", githubRepositoryId: 32n, nameWithOwner: "octo/unverified" }, + }) + const prototype = await prisma.prototype.create({ + data: { repositoryId: repository.id, branchName: "checkout" }, + }) + const first = await prisma.build.create({ + data: { + prototypeId: prototype.id, + number: 1, + state: "successful", + commitSha: "1".repeat(40), + }, + }) + const latest = await prisma.build.create({ + data: { + prototypeId: prototype.id, + number: 2, + state: "successful", + commitSha: "2".repeat(40), + }, + }) + const reviewer = await prisma.user.create({ data: {} }) + const someoneElse = await prisma.user.create({ data: {} }) + async function createThread(buildId: string) { + return prisma.reviewThread.create({ + data: { + repositoryId: repository.id, + prototypeId: prototype.id, + buildId, + anchor: { kind: "area", route: { pathname: "/" } }, + comments: { + create: { authorId: reviewer.id, authorLogin: "reviewer", body: "Label the field." }, + }, + }, + }) + } + const resolvedByOthers = await createThread(first.id) + const onNewestBuild = await createThread(latest.id) + + await recordReviewerVerification(prisma, { + threadId: resolvedByOthers.id, + resolverId: someoneElse.id, + verifiedAt: new Date(), + }) + await recordReviewerVerification(prisma, { + threadId: onNewestBuild.id, + resolverId: reviewer.id, + verifiedAt: new Date(), + }) + + expect( + await prisma.learningReviewerVerification.count({ where: { repositoryId: repository.id } }), + ).toBe(0) + expect( + await prisma.learningScoreRequest.count({ where: { repositoryId: repository.id } }), + ).toBe(0) + }) +}) diff --git a/hub/server/domains/learning/record-reviewer-verification/index.ts b/hub/server/domains/learning/record-reviewer-verification/index.ts new file mode 100644 index 000000000..7b39ea162 --- /dev/null +++ b/hub/server/domains/learning/record-reviewer-verification/index.ts @@ -0,0 +1,37 @@ +import type { Prisma } from "../../../generated/prisma/client.ts" +import { saveLearningReviewerVerification } from "../../../repositories/learning-reviewer-verifications/save-learning-reviewer-verification/index.ts" +import { recordLearningScoreRequest } from "../../../repositories/learning-score-requests/record-learning-score-request/index.ts" +import { findNewestSuccessfulBuildAfter } from "../../../repositories/prototypes/find-newest-successful-build-after/index.ts" +import { findReviewThreadFeedback } from "../../../repositories/review-comments/find-review-thread-feedback/index.ts" + +/** + * Asks for a fresh score when the person who gave review feedback resolves their own + * thread. That is the clearest sign the change after their feedback worked. The newest + * successful Build after the feedback Build stands in for the change. When there's no + * later Build, nothing changed, so there's nothing to verify. + */ +export async function recordReviewerVerification( + transaction: Pick< + Prisma.TransactionClient, + "build" | "learningReviewerVerification" | "learningScoreRequest" | "reviewThread" + >, + input: { threadId: string; resolverId: string; verifiedAt: Date }, +) { + const thread = await findReviewThreadFeedback(transaction, input.threadId) + if (!thread || thread.authorId !== input.resolverId) return + const later = await findNewestSuccessfulBuildAfter(transaction, { + prototypeId: thread.prototypeId, + after: thread.buildStartedAt, + }) + if (!later) return + await saveLearningReviewerVerification(transaction, { + repositoryId: thread.repositoryId, + prototypeId: thread.prototypeId, + commitSha: later.commitSha, + verifiedAt: input.verifiedAt, + }) + await recordLearningScoreRequest(transaction, { + repositoryId: thread.repositoryId, + commitSha: later.commitSha, + }) +} diff --git a/hub/server/domains/learning/score-applied-learnings/index.test.ts b/hub/server/domains/learning/score-applied-learnings/index.test.ts index 11692d77e..c45674872 100644 --- a/hub/server/domains/learning/score-applied-learnings/index.test.ts +++ b/hub/server/domains/learning/score-applied-learnings/index.test.ts @@ -35,6 +35,7 @@ describe("scoreAppliedLearnings", () => { runCommand, start: () => Promise.resolve({ id: "run-1", operationId: "op-1", state: "RUNNING" }), withinBudget: () => Promise.resolve(true), + verifications: () => Promise.resolve([]), withLock, }) @@ -70,6 +71,7 @@ describe("scoreAppliedLearnings", () => { runCommand, start: () => Promise.resolve({ id: "run-1", operationId: "op-1", state: "RUNNING" }), withinBudget: () => Promise.resolve(false), + verifications: () => Promise.resolve([]), withLock, }) @@ -102,10 +104,66 @@ describe("scoreAppliedLearnings", () => { runCommand, start: () => Promise.resolve({ id: "run-1", operationId: "op-1", state: "RUNNING" }), withinBudget: () => Promise.resolve(true), + verifications: () => Promise.resolve([]), withLock, }), ).rejects.toMatchObject({ code: "cancelled" }) expect(finish).not.toHaveBeenCalled() expect(deleteRequest).not.toHaveBeenCalled() }) + + it("scores a learning once more only with its own prototype's verification", async () => { + const deleteRequest = vi.fn(() => Promise.resolve()) + const start = vi.fn((usedLearningId: string, trigger: string) => + Promise.resolve({ id: `run-${trigger}`, operationId: `op-${trigger}`, state: "RUNNING" }), + ) + const runCommand = vi.fn((arguments_: string[]) => { + if (arguments_[0] === "usage") { + return Promise.resolve({ + reports: [ + { prototypeId: "prototype-2", used: [{ id: "learning-1" }] }, + { prototypeId: "prototype-1", used: [{ id: "learning-2" }] }, + ], + }) + } + return Promise.resolve({ score: { id: "score-1" }, usage: { requests: 1, nanoAiu: 0 } }) + }) + + await scoreAppliedLearnings({ + commitSha: "a".repeat(40), + credential: () => Promise.resolve({ githubToken: "token" }), + deleteRequest, + finish: () => Promise.resolve(), + isEnabled: () => Promise.resolve(true), + now: () => new Date(), + prepare: () => Promise.resolve([]), + readDiff: () => Promise.resolve(null), + readScreenshot: () => Promise.resolve(null), + runCommand, + start, + withinBudget: () => Promise.resolve(true), + verifications: () => + Promise.resolve([ + { prototypeId: "prototype-1", verifiedAt: new Date("2026-12-03T10:00:00.250Z") }, + ]), + withLock, + }) + + expect(start.mock.calls).toEqual([ + ["learning-1", "USAGE"], + ["learning-2", "USAGE"], + ["learning-2", "REVIEWER_VERIFICATION"], + ]) + expect(runCommand).toHaveBeenLastCalledWith( + [ + "score", + "learning-2", + "--operation-id", + "op-REVIEWER_VERIFICATION", + "--reviewer-verified-at", + "2026-12-03T10:00:00.250Z", + ], + expect.anything(), + ) + }) }) diff --git a/hub/server/domains/learning/score-applied-learnings/index.ts b/hub/server/domains/learning/score-applied-learnings/index.ts index bcaaefeb8..b8965c8ae 100644 --- a/hub/server/domains/learning/score-applied-learnings/index.ts +++ b/hub/server/domains/learning/score-applied-learnings/index.ts @@ -12,6 +12,7 @@ const usageSchema = z reports: z.array( z .object({ + prototypeId: z.string().optional(), used: z.array( z .object({ @@ -50,7 +51,10 @@ const scoredSchema = spentSchema.extend({ * Scores each learning agents said they applied in one built commit, one Copilot call at a * time, while the shared monthly budget lasts. Each attempt is recorded with what it cost, * even when it fails, so spending is never undercounted. Returns "paused" when Copilot or - * the budget is unavailable, so the request is kept and tried again later. + * the budget is unavailable, so the request is kept and tried again later. When a reviewer + * verified the commit, each learning is scored once more with that verification, and the + * first score is kept. A report that names a prototype gets only that prototype's + * verification, since two prototypes can share a commit. */ export async function scoreAppliedLearnings(dependencies: { commitSha: string @@ -71,7 +75,11 @@ export async function scoreAppliedLearnings(dependencies: { arguments_: string[], options: { githubToken?: string; signal: AbortSignal; timeoutMs?: number }, ): Promise - start(usedLearningId: string): Promise<{ id: string; operationId: string; state: string }> + start( + usedLearningId: string, + trigger: "USAGE" | "REVIEWER_VERIFICATION", + ): Promise<{ id: string; operationId: string; state: string }> + verifications(): Promise<{ prototypeId: string; verifiedAt: Date }[]> withinBudget(): Promise withLock(operation: (signal: AbortSignal) => Promise): Promise }): Promise<"done" | "paused"> { @@ -85,6 +93,7 @@ export async function scoreAppliedLearnings(dependencies: { if (!credential) return "paused" const store = await dependencies.prepare() const readAt = dependencies.now() + const verifications = await dependencies.verifications() const { reports } = usageSchema.parse( await dependencies.withLock((signal) => dependencies.runCommand(["usage", "--commit", dependencies.commitSha, ...store], { @@ -95,8 +104,18 @@ export async function scoreAppliedLearnings(dependencies: { const temporary = await mkdtemp(resolve(tmpdir(), "replica-learning-score-")) try { let diffFile: string | null | undefined - for (const [index, used] of reports.flatMap((report) => report.used).entries()) { - const run = await dependencies.start(used.id) + const attempts = reports.flatMap((report) => { + const verifiedAt = verifications.findLast( + (verification) => + report.prototypeId === undefined || verification.prototypeId === report.prototypeId, + )?.verifiedAt + return report.used.flatMap((used) => [ + { used, trigger: "USAGE" as const, verifiedAt: undefined }, + ...(verifiedAt ? [{ used, trigger: "REVIEWER_VERIFICATION" as const, verifiedAt }] : []), + ]) + }) + for (const [index, { used, trigger, verifiedAt }] of attempts.entries()) { + const run = await dependencies.start(used.id, trigger) if (run.state !== "RUNNING") continue if (!(await dependencies.withinBudget())) return "paused" if (diffFile === undefined) { @@ -129,6 +148,8 @@ export async function scoreAppliedLearnings(dependencies: { run.operationId, ...(diffFile ? ["--diff-file", diffFile] : []), ...(hasScreenshots ? ["--screenshots", screenshots] : []), + // The package wants microsecond timestamps. + ...(verifiedAt ? ["--reviewer-verified-at", verifiedAt.toISOString()] : []), ...store, ], { ...credential, signal, timeoutMs: 10 * 60 * 1000 }, diff --git a/hub/server/domains/learning/types.ts b/hub/server/domains/learning/types.ts index 2eca01fe8..bdb5e09f1 100644 --- a/hub/server/domains/learning/types.ts +++ b/hub/server/domains/learning/types.ts @@ -108,6 +108,8 @@ export type LearningOutcome = Omit< /** How one use of a learning was scored, as the package recorded it. */ export interface ReportedLearningOutcome { id: string + /** Whether a reviewer confirmed the work before it was scored. */ + source: "automated" | "reviewer_confirmed" commitSha: string prototypeId: string | null /** 4 is best. 1 and 2 come with an issue. */ diff --git a/hub/server/domains/review-comments/create-review-comment-service/index.ts b/hub/server/domains/review-comments/create-review-comment-service/index.ts index 13e55eb29..629b284a8 100644 --- a/hub/server/domains/review-comments/create-review-comment-service/index.ts +++ b/hub/server/domains/review-comments/create-review-comment-service/index.ts @@ -3,6 +3,7 @@ import { recordReviewAnalyticsActivity } from "../../analytics/record-event/inde import { classifyPrismaTransactionError } from "../../../integrations/prisma/classify-transaction-error/index.ts" import { createReviewCommentRepository } from "../../../repositories/review-comments/create-review-comment-repository/index.ts" import type { ReviewPersistenceFailure } from "../../../repositories/review-comments/types.ts" +import { recordReviewerVerification } from "../../learning/record-reviewer-verification/index.ts" import { runWithBoundedRetries } from "../../identity/run-with-bounded-retries/index.ts" import { applyReviewActivity } from "../apply-review-activity/index.ts" import { reviewMentionLogins } from "../create-review-mention-directory/index.ts" @@ -101,6 +102,13 @@ export function createReviewCommentService( threadId, }) } + if (kind === "resolved") { + await recordReviewerVerification(transaction, { + threadId, + resolverId: input.actor.userId, + verifiedAt: new Date(), + }) + } }, } } diff --git a/hub/server/repositories/learning-evaluation-runs/start-learning-evaluation-run/index.ts b/hub/server/repositories/learning-evaluation-runs/start-learning-evaluation-run/index.ts index bc9f1f6ce..7ae0d4f38 100644 --- a/hub/server/repositories/learning-evaluation-runs/start-learning-evaluation-run/index.ts +++ b/hub/server/repositories/learning-evaluation-runs/start-learning-evaluation-run/index.ts @@ -1,17 +1,19 @@ import { randomUUID } from "node:crypto" import type { PrismaClient } from "../../../generated/prisma/client.ts" +import type { LearningScoreTrigger } from "../../../generated/prisma/enums.ts" /** * Starts scoring one used learning, or returns its earlier attempt. An attempt that never - * finished keeps its operation ID, so retrying it can't store a second score. + * finished keeps its operation ID, so retrying it can't store a second score. A reviewer's + * verification is its own trigger, so it earns one more score without repeating the first. */ export function startLearningEvaluationRun( database: Pick, - input: { repositoryId: string; usedLearningId: string }, + input: { repositoryId: string; usedLearningId: string; trigger: LearningScoreTrigger }, ) { return database.learningEvaluationRun.upsert({ - where: { repositoryId_usedLearningId: input }, + where: { repositoryId_usedLearningId_trigger: input }, create: { ...input, operationId: randomUUID() }, update: {}, }) diff --git a/hub/server/repositories/learning-reviewer-verifications/list-learning-reviewer-verifications/index.ts b/hub/server/repositories/learning-reviewer-verifications/list-learning-reviewer-verifications/index.ts new file mode 100644 index 000000000..c1aa377a2 --- /dev/null +++ b/hub/server/repositories/learning-reviewer-verifications/list-learning-reviewer-verifications/index.ts @@ -0,0 +1,12 @@ +import type { PrismaClient } from "../../../generated/prisma/client.ts" + +export function listLearningReviewerVerifications( + database: Pick, + input: { repositoryId: string; commitSha: string }, +) { + return database.learningReviewerVerification.findMany({ + where: input, + orderBy: [{ verifiedAt: "asc" }, { id: "asc" }], + select: { prototypeId: true, verifiedAt: true }, + }) +} diff --git a/hub/server/repositories/learning-reviewer-verifications/save-learning-reviewer-verification/index.ts b/hub/server/repositories/learning-reviewer-verifications/save-learning-reviewer-verification/index.ts new file mode 100644 index 000000000..f62ae4527 --- /dev/null +++ b/hub/server/repositories/learning-reviewer-verifications/save-learning-reviewer-verification/index.ts @@ -0,0 +1,18 @@ +import type { Prisma } from "../../../generated/prisma/client.ts" + +/** + * Keeps when a reviewer confirmed one prototype's commit. It lives apart from the score + * request, so usage reported later for the same commit still gets the confirmation. + */ +export function saveLearningReviewerVerification( + transaction: Pick, + input: { repositoryId: string; prototypeId: string; commitSha: string; verifiedAt: Date }, +) { + return transaction.learningReviewerVerification.upsert({ + where: { + prototypeId_commitSha: { prototypeId: input.prototypeId, commitSha: input.commitSha }, + }, + create: input, + update: { verifiedAt: input.verifiedAt }, + }) +} diff --git a/hub/server/repositories/prototypes/find-newest-successful-build-after/index.ts b/hub/server/repositories/prototypes/find-newest-successful-build-after/index.ts new file mode 100644 index 000000000..27c171856 --- /dev/null +++ b/hub/server/repositories/prototypes/find-newest-successful-build-after/index.ts @@ -0,0 +1,31 @@ +import type { Prisma } from "../../../generated/prisma/client.ts" + +/** + * The prototype's newest successful Build with a commit that started after the given time. + * Build numbers follow the order Hub found the runs, which can differ from when they ran, + * so this compares the workflow's creation time and falls back to the Build's own. + */ +export async function findNewestSuccessfulBuildAfter( + transaction: Pick, + input: { prototypeId: string; after: Date }, +) { + const builds = await transaction.build.findMany({ + where: { + prototypeId: input.prototypeId, + state: "successful", + commitSha: { not: null }, + OR: [ + { workflowCreatedAt: { gt: input.after } }, + { workflowCreatedAt: null, createdAt: { gt: input.after } }, + ], + }, + select: { id: true, commitSha: true, workflowCreatedAt: true, createdAt: true }, + }) + function started(build: (typeof builds)[number]) { + return (build.workflowCreatedAt ?? build.createdAt).getTime() + } + const [newest] = builds.sort( + (left, right) => started(right) - started(left) || right.id.localeCompare(left.id), + ) + return newest?.commitSha ? { commitSha: newest.commitSha } : null +} diff --git a/hub/server/repositories/review-comments/find-review-thread-feedback/index.ts b/hub/server/repositories/review-comments/find-review-thread-feedback/index.ts new file mode 100644 index 000000000..d5e446f39 --- /dev/null +++ b/hub/server/repositories/review-comments/find-review-thread-feedback/index.ts @@ -0,0 +1,24 @@ +import type { Prisma } from "../../../generated/prisma/client.ts" + +/** The thread's prototype, who gave its first comment, and when its Build started. */ +export async function findReviewThreadFeedback( + transaction: Pick, + threadId: string, +) { + const thread = await transaction.reviewThread.findUnique({ + where: { id: threadId }, + select: { + repositoryId: true, + prototypeId: true, + build: { select: { workflowCreatedAt: true, createdAt: true } }, + comments: { where: { rootId: null }, select: { authorId: true }, take: 1 }, + }, + }) + if (!thread) return null + return { + repositoryId: thread.repositoryId, + prototypeId: thread.prototypeId, + authorId: thread.comments[0]?.authorId ?? null, + buildStartedAt: thread.build.workflowCreatedAt ?? thread.build.createdAt, + } +} diff --git a/hub/server/routes/api/learnings/create-learnings-route-dependencies/learning-outcomes.db.test.ts b/hub/server/routes/api/learnings/create-learnings-route-dependencies/learning-outcomes.db.test.ts index f16c9efb0..c78516406 100644 --- a/hub/server/routes/api/learnings/create-learnings-route-dependencies/learning-outcomes.db.test.ts +++ b/hub/server/routes/api/learnings/create-learnings-route-dependencies/learning-outcomes.db.test.ts @@ -60,6 +60,7 @@ describe("learning outcomes", () => { }) } const score = { + source: "automated" as const, efficiency: 3, followed: "followed" as const, reasoning: "The form kept its labels.", @@ -126,6 +127,7 @@ describe("learning outcomes", () => { outcomes: [ { id: "score_with_screenshot", + source: "automated", commitSha, prototypeId: prototype.id, efficiency: 2, diff --git a/hub/test/database/reviewer-verified-scores-migration/index.db.test.ts b/hub/test/database/reviewer-verified-scores-migration/index.db.test.ts new file mode 100644 index 000000000..237d7a939 --- /dev/null +++ b/hub/test/database/reviewer-verified-scores-migration/index.db.test.ts @@ -0,0 +1,151 @@ +import { execFile } from "node:child_process" +import { randomBytes, randomUUID } from "node:crypto" +import { readFile, readdir } from "node:fs/promises" +import { join } from "node:path" +import { fileURLToPath } from "node:url" +import { promisify } from "node:util" +import pg from "pg" +import { describe, expect, it } from "vitest" + +const timeoutMs = 180_000 +const baseMigration = "20261225090000_learning_evaluation_runs" +const migration = "20261226090000_reviewer_verified_scores" + +describe("reviewer verified scores migration", () => { + it( + "keeps existing scores as usage scores and lets one verified score join each", + async () => { + const adminUrl = process.env.TEST_DATABASE_URL + if (!adminUrl) throw new Error("TEST_DATABASE_URL is required.") + const name = `replica_verified_upgrade_${randomBytes(8).toString("hex")}` + const admin = new pg.Client({ connectionString: adminUrl }) + await admin.connect() + let created = false + try { + await admin.query(`CREATE DATABASE ${pg.escapeIdentifier(name)}`) + created = true + const databaseUrl = new URL(adminUrl) + databaseUrl.pathname = name + const database = new pg.Client({ connectionString: databaseUrl.toString() }) + try { + await database.connect() + const hubRoot = fileURLToPath(new URL("../../../", import.meta.url)) + const migrationsRoot = join(hubRoot, "schema/migrations") + const base = (await readdir(migrationsRoot, { withFileTypes: true })) + .filter((entry) => entry.isDirectory() && entry.name <= baseMigration) + .map((entry) => entry.name) + .sort() + expect(base.at(-1)).toBe(baseMigration) + + for (const migrationName of base) { + const sql = await readFile(join(migrationsRoot, migrationName, "migration.sql"), "utf8") + if (migrationName === "20261104190000_entra_oidc_authentication") { + const statements = sql.split("\n") + await database.query(statements.slice(0, 2).join("\n")) + await database.query(statements.slice(2).join("\n")) + } else { + await database.query(sql) + } + } + + const repositoryId = randomUUID() + const runId = randomUUID() + const operationId = randomUUID() + await database.query( + `INSERT INTO repositories (id, github_repository_id, name_with_owner, default_branch) + VALUES ($1, 1001, 'team/scored', 'main')`, + [repositoryId], + ) + await database.query( + `INSERT INTO learning_evaluation_runs + (id, repository_id, used_learning_id, operation_id, state, copilot_requests, + ai_credits, score_id, finished_at) + VALUES ($1, $2, 'use_1', $3, 'SUCCEEDED', 1, 0.5, 'score_1', + '2026-12-01T10:00:00Z')`, + [runId, repositoryId, operationId], + ) + await database.query( + `INSERT INTO learning_score_requests (id, repository_id, commit_sha) + VALUES ($1, $2, $3)`, + [randomUUID(), repositoryId, "a".repeat(40)], + ) + + const run = promisify(execFile) + const prismaCli = join(hubRoot, "node_modules/prisma/build/index.js") + const options = { + cwd: hubRoot, + env: { ...process.env, DATABASE_URL: databaseUrl.toString() }, + timeout: timeoutMs, + } + for (const migrationName of base) { + await run( + process.execPath, + [ + prismaCli, + "migrate", + "resolve", + "--applied", + migrationName, + "--config", + "prisma7.config.ts", + ], + options, + ) + } + await run( + process.execPath, + [prismaCli, "migrate", "deploy", "--config", "prisma7.config.ts"], + options, + ) + + expect( + ( + await database.query( + `SELECT migration_name FROM _prisma_migrations + WHERE migration_name = $1 AND finished_at IS NOT NULL`, + [migration], + ) + ).rows, + ).toEqual([{ migration_name: migration }]) + expect( + ( + await database.query( + `SELECT id, operation_id, trigger, state, score_id, ai_credits::text + FROM learning_evaluation_runs`, + ) + ).rows, + ).toEqual([ + { + id: runId, + operation_id: operationId, + trigger: "USAGE", + state: "SUCCEEDED", + score_id: "score_1", + ai_credits: "0.500000000", + }, + ]) + expect( + (await database.query("SELECT commit_sha FROM learning_score_requests")).rows, + ).toEqual([{ commit_sha: "a".repeat(40) }]) + + const insert = `INSERT INTO learning_evaluation_runs + (id, repository_id, used_learning_id, operation_id, trigger) + VALUES ($1, $2, 'use_1', $3, 'REVIEWER_VERIFICATION')` + await database.query(insert, [randomUUID(), repositoryId, randomUUID()]) + await expect( + database.query(insert, [randomUUID(), repositoryId, randomUUID()]), + ).rejects.toMatchObject({ code: "23505" }) + } finally { + await database.end() + } + } finally { + try { + if (created) await admin.query(`DROP DATABASE ${pg.escapeIdentifier(name)} WITH (FORCE)`) + } finally { + await admin.end() + } + } + }, + timeoutMs, + ) +}) diff --git a/packages/learning/README.md b/packages/learning/README.md index 8f33f0c61..476059dd4 100644 --- a/packages/learning/README.md +++ b/packages/learning/README.md @@ -283,7 +283,7 @@ To use another labeler, set `labeling.labeler` to `{ "module": "./path.mjs" }` e 3. Mostly efficient. 4. Highly efficient. -A score of 1 or 2 also names the main issue. A learning is scored only while the review evidence behind the version the agent received is allowed for evaluation; otherwise the command fails with `unavailable` and spends nothing. Copilot sees the learning text the agent received, the usage report, and the screenshots whose consent still allows evaluation. `--diff-file ` adds the Build's diff, cut at 200,000 characters. A hosted store keeps no screenshot bytes, so the host writes them to a directory as `.png` and names it with `--screenshots `. +A score of 1 or 2 also names the main issue. A learning is scored only while the review evidence behind the version the agent received is allowed for evaluation; otherwise the command fails with `unavailable` and spends nothing. Copilot sees the learning text the agent received, the usage report, and the screenshots whose consent still allows evaluation. `--diff-file ` adds the Build's diff, cut at 200,000 characters. `--reviewer-verified-at