Repository navigation
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 25291e01-0146-42cb-ac6d-f5e1dd5c35f5
nshki
force-pushed
the
nshki/feat/hub/score-applied-learnings
branch
from
November 26, 2026 09:10
baf95e9 to
a50a46d
Compare
| used.id, | ||
| "--operation-id", | ||
| run.operationId, | ||
| ...(diffFile ? ["--diff-file", diffFile] : []), |
| try { | ||
| const scored = scoredSchema.parse( | ||
| await dependencies.withLock((signal) => | ||
| dependencies.runCommand( |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical flaws in budget accounting, recovery, and consent enforcement can cause untracked spending, lost scoring requests, and continued evidence processing after opt-out or repository removal.
20 open issues
Expose only fully saved reports to recovery scoring · New Recheck consent and repository availability before each score · New Hold the execution lock through budget check and usage accounting · New Refresh Copilot authority and credentials before each score · New Return original usage when replaying an existing score · New Attribute resumed-run spending to the month it occurs · New Retain built requests while they await scoring capacity · New Use a monotonic token for usage acknowledgement · New Distinguish evaluation grants from prior learning consent · New Make evaluation grant updates recoverable and idempotent · New Clear screenshot access before withdrawing the review grant · New Keep recovery scoring on the scheduled queue · New Normalize screenshot digests before lookup · New Treat screenshot storage errors as retryable failures · New Reserve a bounded cost before scoring to prevent budget overruns · New Pause scoring after a refused Copilot credential · New Rotate recovery batches to prevent stalled requests monopolizing them · New Match the function-suite naming convention · New Test successful scoring and screenshot digest lookup · New Document scoring and request recovery in the worker guide · New
What changed in this PR
Connects Hub’s agent usage reports to the learning package’s automatic scoring, with shared monthly spending and repository consent controls.
Changes:
- Records reported commits and queues scoring after a successful Build.
- Supplies commit diffs and consented screenshots, then records scoring outcomes and costs.
- Exposes monthly spending and manages review-comment evaluation consent.
| File | Description |
|---|---|
hub/server/workers/github-recovery.test.ts |
Adds the commit-diff client mock. |
hub/server/workers/configuration.ts |
Registers the scoring processor. |
hub/server/workers/configuration.test.ts |
Updates processor registration expectations. |
hub/server/utils/start-of-utc-month/index.ts |
Defines UTC monthly budget boundaries. |
hub/server/utils/format-ai-credits/index.ts |
Shares precise credit formatting. |
hub/server/routes/api/learnings/types.ts |
Adds spending to evaluation settings. |
hub/server/routes/api/learnings/index.test.ts |
Updates evaluation settings fixtures. |
hub/server/routes/api/learnings/evaluations/get/index.ts |
Removes the placeholder spending value. |
hub/server/routes/api/learnings/create-learnings-route-dependencies/index.ts |
Reads spending and manages evaluation consent. |
hub/server/routes/api/learnings/create-learnings-route-dependencies/evaluation-settings.db.test.ts |
Covers evaluation consent transitions. |
hub/server/routes/agent-connections/index.ts |
Persists scoring requests from agents. |
hub/server/repositories/learning-score-requests/record-learning-score-request/index.ts |
Creates or refreshes commit requests. |
hub/server/repositories/learning-score-requests/list-ready-learning-score-requests/index.ts |
Finds requests with successful Builds. |
hub/server/repositories/learning-score-requests/list-ready-learning-score-requests/index.db.test.ts |
Covers pagination and repository matching. |
hub/server/repositories/learning-score-requests/delete-learning-score-request/index.ts |
Deletes consumed requests using a timestamp guard. |
hub/server/repositories/learning-score-requests/delete-expired-learning-score-requests/index.ts |
Adds age-based request cleanup. |
hub/server/repositories/learning-evaluation-runs/sum-learning-evaluation-credits/index.ts |
Aggregates recorded evaluation costs. |
hub/server/repositories/learning-evaluation-runs/start-learning-evaluation-run/index.ts |
Creates resumable scoring attempts. |
hub/server/repositories/learning-evaluation-runs/finish-learning-evaluation-run/index.ts |
Saves outcomes and usage costs. |
hub/server/repositories/evaluation-settings/save-repository-evaluation-setting/index.ts |
Persists evaluation grant IDs. |
hub/server/integrations/github/create-github-actions-client/index.ts |
Fetches size-bounded commit diffs. |
hub/server/integrations/github/create-github-actions-client/index.test.ts |
Covers diff requests and size limits. |
hub/server/domains/learning/score-applied-learnings/index.ts |
Implements scoring, evidence preparation, and accounting. |
hub/server/domains/learning/score-applied-learnings/index.test.ts |
Covers failure, budget pause, and interruption. |
hub/server/domains/learning/process-learning-run/index.ts |
Reuses the shared credit formatter. |
hub/server/domains/learning/jobs/score-applied-learnings.ts |
Defines scoring payloads and retries. |
hub/server/domains/learning/create-learning-job-processors/index.ts |
Composes scoring and recovery dependencies. |
hub/server/domains/learning/create-learning-job-processors/index.test.ts |
Updates recovery mocks for requests. |
hub/server/domains/learning/change-evaluation-consent/index.ts |
Generalizes screenshot and review-comment consent. |
hub/server/domains/agent-connections/create-learning-mcp-backend/index.ts |
Requests scoring for reported commits. |
hub/server/domains/agent-connections/create-learning-mcp-backend/index.test.ts |
Covers commit scoring requests. |
hub/schema/repository.prisma |
Adds scoring request and run relations. |
hub/schema/repository-evaluation-setting.prisma |
Adds the evaluation consent grant field. |
hub/schema/migrations/20261225090000_learning_evaluation_runs/migration.sql |
Creates scoring tables, indexes, and consent storage. |
hub/schema/learning-score-request.prisma |
Models unique repository/commit requests. |
hub/schema/learning-evaluation-run.prisma |
Models scoring attempts and spending. |
hub/docs/learning-foundation.md |
Documents scoring, consent, budgets, and recovery. |
Review effort: Max (adaptive)
Comment on lines
+206
to
+209
| // Asked first so a report that lands is never missed. A request whose report failed | ||
| // finds nothing to score and is dropped. | ||
| if (typeof report.commitSha === "string" && /^[0-9a-f]{40}$/.test(report.commitSha)) | ||
| await input.requestScore?.(report.commitSha) |
Comment on lines
+552
to
+555
| isEnabled: async () => { | ||
| const setting = await getRepositoryEvaluationSetting(prisma, request.repositoryId) | ||
| return Boolean(setting?.enabled && setting.evaluationGrantId) | ||
| }, |
| for (const [index, used] of reports.flatMap((report) => report.used).entries()) { | ||
| const run = await dependencies.start(used.id) | ||
| if (run.state !== "RUNNING") continue | ||
| if (!(await dependencies.withinBudget())) return "paused" |
Comment on lines
+116
to
+131
| const scored = scoredSchema.parse( | ||
| await dependencies.withLock((signal) => | ||
| dependencies.runCommand( | ||
| [ | ||
| "score", | ||
| used.id, | ||
| "--operation-id", | ||
| run.operationId, | ||
| ...(diffFile ? ["--diff-file", diffFile] : []), | ||
| ...(hasScreenshots ? ["--screenshots", screenshots] : []), | ||
| ...store, | ||
| ], | ||
| { ...credential, signal, timeoutMs: 10 * 60 * 1000 }, | ||
| ), | ||
| ), | ||
| ) |
Comment on lines
+135
to
+136
| aiCredits: formatAiCredits(scored.usage.nanoAiu), | ||
| copilotRequests: scored.usage.requests, |
Comment on lines
+142
to
+144
| if (!(error instanceof LearningCommandError) || error.code === "cancelled") throw error | ||
| const spent = spentSchema.safeParse(error.result) | ||
| await dependencies.finish(run.id, { |
Comment on lines
+22
to
+24
| orderBy: { id: "asc" }, | ||
| take: limit, | ||
| ...(cursor ? { cursor: { id: cursor }, skip: 1 } : {}), |
| return await operation(new AbortController().signal) | ||
| } | ||
|
|
||
| describe("scoreAppliedLearnings", () => { |
Comment on lines
+96
to
+114
| if (diffFile === undefined) { | ||
| const diff = await dependencies.readDiff() | ||
| diffFile = diff === null ? null : resolve(temporary, "commit.diff") | ||
| if (diffFile) await writeFile(diffFile, diff!, { mode: 0o600 }) | ||
| } | ||
| // A hosted store keeps no screenshot bytes, so Hub hands over the ones whose | ||
| // consent still holds as files named by their digest. | ||
| const screenshots = resolve(temporary, `screenshots-${index}`) | ||
| let hasScreenshots = false | ||
| for (const shot of [used.before, used.after]) { | ||
| if (!shot) continue | ||
| const bytes = await dependencies.readScreenshot(shot.sha256) | ||
| if (!bytes) continue | ||
| await mkdir(screenshots, { recursive: true, mode: 0o700 }) | ||
| await writeFile(resolve(screenshots, `${shot.sha256.slice(7)}.png`), bytes, { | ||
| mode: 0o600, | ||
| }) | ||
| hasScreenshots = true | ||
| } |
| learning.run, | ||
| learning.redact, | ||
| learning.deleteScreenshots, | ||
| learning.score, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
The learning package can now score whether an applied learning helped, but nothing in Hub asks it to. Each score costs AI credits, so Hub needs to run scoring on its own after real work lands and stay within the shared monthly budget that a Hub administrator sets.
What changes
When an agent's
report_usagecall names a commit, Hub remembers that commit. The worker's recovery pass runs every minute. Once the commit has a successful Build, it queues a scoring job. The job asks the store which learnings were used in that commit. It then scores each one against the commit's diff from GitHub and any screenshots whose consent still holds.Hub records every attempt and what it cost, including failed ones. The evaluation settings page now shows real spending for the month, and it already explains when evaluations pause because the budget is reached. When the budget runs out or Copilot is unavailable, requests wait and start again once there is room.
sequenceDiagram participant Agent participant Hub participant Worker participant CLI as replica-learning Agent->>Hub: report_usage with commit Hub->>Hub: remember commit Worker->>Hub: commit has a successful Build? Worker->>CLI: usage --commit loop each used learning, while budget lasts Worker->>Hub: record attempt and operation ID Worker->>CLI: score with diff and screenshots Worker->>Hub: record result and credits endTurning evaluations on now also adds a consent grant that lets the store use the repository's review comments for evaluation. Without it the store refuses to score. Turning evaluations off withdraws that grant.
Needs design review