Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions hub/client/application/hub/learnings-contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions hub/client/application/hub/learnings-contracts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -283,6 +284,7 @@ describe("learningsLibrary()", () => {
{
...score,
id: "score_supports",
source: "reviewer_confirmed",
efficiency: 3,
followed: "followed",
scoredAt: "2026-10-12T00:00:00Z",
Expand All @@ -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)}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
4 changes: 3 additions & 1 deletion hub/client/features/learnings-library/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,9 @@ function OutcomeList({ outcomes }: { outcomes: LearningOutcome[] }) {
<strong>{outcomeLabels[outcome.result]}</strong>
</span>
<span aria-hidden="true">·</span>
<span>Automated assessment</span>
<span>
{outcome.reviewerConfirmed ? "Reviewer-confirmed" : "Automated assessment"}
</span>
<span aria-hidden="true">·</span>
<a href={outcome.buildPath}>{outcome.buildLabel}</a>
<span aria-hidden="true">·</span>
Expand Down
4 changes: 3 additions & 1 deletion hub/client/features/learnings-library/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions hub/client/pages/learnings-page/stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
11 changes: 9 additions & 2 deletions hub/docs/learning-foundation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion hub/schema/learning-evaluation-run.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
22 changes: 22 additions & 0 deletions hub/schema/learning-reviewer-verification.prisma
Original file line number Diff line number Diff line change
@@ -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")
}
4 changes: 4 additions & 0 deletions hub/schema/learning-score-trigger.enum.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum LearningScoreTrigger {
USAGE
REVIEWER_VERIFICATION
}
Original file line number Diff line number Diff line change
@@ -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';
Comment thread
nshki marked this conversation as resolved.
Resolved

-- 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;
15 changes: 8 additions & 7 deletions hub/schema/prototype.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions hub/schema/repository.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ model Repository {
agentScreenshots AgentScreenshot[]
learningEvaluationRuns LearningEvaluationRun[]
learningScoreRequests LearningScoreRequest[]
learningVerifications LearningReviewerVerification[]
decisionModelConfiguration DecisionModelConfiguration?
decisionReviewSnapshot DecisionReviewSnapshot?
decisionTrainingJobs DecisionTrainingJob[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()))
Expand Down
50 changes: 49 additions & 1 deletion hub/server/domains/learning/get-learning-history/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
},
],
Expand All @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions hub/server/domains/learning/get-learning-history/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading