Skip to content

feat(learning): add PostgreSQL storage, scoring, and update contracts - #433

Merged
nshki merged 31 commits into
build/hub/newfrom
nshki/feat/learning/01-storage
Dec 1, 2026
Merged

nshki merged 31 commits into
build/hub/newfrom
nshki/feat/learning/01-storage

Conversation

@nshki

@nshki nshki commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

Hub's learning work needs a package that can keep learnings for a whole team, tell whether they help, and suggest when to change them. Today the package stores learnings only in SQLite or local files, and it can't say whether an agent's use of a learning went well. This is the first of five stacked pull requests that bring Learning v2 to Hub. It establishes the storage and package contracts that later layers build on.

What changes

The replica-learning package can now store everything in PostgreSQL as well as SQLite. It also tracks what happens after a learning is accepted:

  • Each learning belongs to a repository by its GitHub repository ID rather than its name, so a rename doesn't split its history. migrate-scope moves older stores, and import-sqlite copies a stopped Hub SQLite store into PostgreSQL.
  • Agents can report sessions and which learnings they used. The package records what it recalled for each session.
  • Applied learnings can be scored against later evidence. Repeated issues can produce suggested updates for a person to approve.
  • A single analyze command runs the daily loop for one checkout. It labels new comments and suggests learnings. With --commit, it also scores and proposes updates.

The default recurrence rules now allow one prototype and one reviewer. They also count questions, praise, and performance feedback. A checkout using a local store can suggest a learning from one thread or session. Teams can configure the thresholds.

Scoring and suggested updates send evidence to Copilot, and scoring may include screenshots. Known secret patterns are scrubbed, but other confidential Build content may remain. Administrators should consider what they permit before enabling these features.

flowchart LR
  A[Review comments and agent sessions] --> B[analyze]
  B --> C[Suggested learnings]
  C -->|person approves| D[Accepted learnings]
  D --> E[Agents recall and report use]
  E --> F[Scores]
  F -->|evidence disagrees| G[Suggested updates]
  G -->|person approves| D
Loading

Learning CI now starts PostgreSQL and runs the package's database tests. The Hub image smoke check is updated for the package's SDK version. The scripted demo is removed; the Agent Memory Repo consolidator and publisher remain available. Local learning mode and the agent MCP server come in the next layer. Hub changes come in layers 3 to 5.

Copilot AI adaptive review requested due to automatic review settings November 28, 2026 03:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues can expose withdrawn or redacted evidence, bypass screenshot path restrictions, and delete images still referenced by other repositories.

5 open issues
What changed in this PR

This PR establishes the learning-package foundation for Learning v2 in Hub, adding shared storage support and a feedback loop from agent usage to scores and human-approved updates.

Changes:

  • Extends storage contracts for PostgreSQL, repository identity, deletion, and decision consistency.
  • Adds agent-session evidence, usage tracking, screenshots, scoring, and update proposals.
  • Expands regression coverage and database CI, updates architecture guidance, and removes obsolete demos.
File Description
packages/​learning/​test/​updates.test.mjs Tests update thresholds and dismissed-issue reconsideration.
packages/​learning/​test/​sqlite-provider.test.mjs Tests indexed reads, corruption checks, and conflicting writes.
packages/​learning/​test/​screenshots.test.mjs Tests image integrity, replacement, and removal.
packages/​learning/​test/​recurrence.test.mjs Covers revised thresholds and stale-label handling.
packages/​learning/​test/​labeling.test.mjs Tests reassessment and repository-ID arguments.
packages/​learning/​test/​json-lines-provider.test.mjs Covers deletion recovery and shared-learning previews.
packages/​learning/​test/​identity.test.mjs Makes reviewer thresholds explicit.
packages/​learning/​test/​fixtures/​json-file-provider.mjs Adds new record streams to the fixture provider.
packages/​learning/​test/​evaluation.test.mjs Tests model routing, scoring, retries, and usage reporting.
packages/​learning/​test/​demo.test.mjs Removes obsolete demo coverage.
packages/​learning/​test/​decision.test.mjs Adds cached repository identity to test setup.
packages/​learning/​test/​config.test.mjs Tests numeric GitHub repository scopes.
packages/​learning/​test/​agent-session.test.mjs Covers session imports, redaction, and canvas notes.
packages/​learning/​test-database/​postgres-v1.sql Adds a PostgreSQL schema fixture.
packages/​learning/​src/​validate.mjs Recognizes new sealed record kinds.
packages/​learning/​src/​updates.mjs Groups recurring issues and drafts learning updates.
packages/​learning/​src/​sources/​hub-review-comments.mjs Adds stable review-thread identity.
packages/​learning/​src/​sources/​agent-sessions.mjs Imports scrubbed session messages and canvas notes.
packages/​learning/​src/​screenshots.mjs Adds local and host-managed screenshot storage.
packages/​learning/​src/​records.mjs Adds record versions, feedback helpers, and title digests.
packages/​learning/​src/​recall.mjs Returns learning scopes and rendered blocks.
packages/​learning/​src/​providers/​in-memory.mjs Adds deletion, indexes, and decision consistency checks.
packages/​learning/​src/​provider-contract.mjs Defines new streams and optional storage capabilities.
packages/​learning/​src/​labeling.mjs Supports session feedback, deduplication, and reassessment.
packages/​learning/​src/​labelers/​copilot.mjs Adds scoring routes and design-label categories.
packages/​learning/​src/​evaluation.mjs Scores reported learning use from available evidence.
packages/​learning/​src/​errors.mjs Clarifies uncertain write outcomes.
packages/​learning/​src/​consolidators/​recurrence.mjs Includes session feedback and broader recurrence defaults.
packages/​learning/​package.json Adds database tests and PostgreSQL dependency.
packages/​learning/​index.mjs Exports new storage capabilities and providers.
packages/​learning/​examples/​demo.mjs Removes the original demonstration script.
packages/​learning/​examples/​agent-memory-repo/​README.md Removes obsolete integration instructions.
packages/​learning/​examples/​agent-memory-repo/​publish.mjs Removes the example publishing command.
packages/​learning/​examples/​agent-memory-repo/​memory-repo.mjs Removes example memory-repository publishing logic.
packages/​learning/​examples/​agent-memory-repo/​dreaming.mjs Removes the example consolidator.
packages/​learning/​examples/​agent-memory-repo/​demo.mjs Removes the integration demonstration.
packages/​learning/​contracts/​v1/​used-learning.schema.json Defines an agent's claimed learning use.
packages/​learning/​contracts/​v1/​usage-report.schema.json Defines retryable usage reports.
packages/​learning/​contracts/​v1/​update-proposal.schema.json Defines evidence-backed wording proposals.
packages/​learning/​contracts/​v1/​update-decision.schema.json Defines human update decisions.
packages/​learning/​contracts/​v1/​screenshot.schema.json Defines screenshot metadata and consent references.
packages/​learning/​contracts/​v1/​score.schema.json Defines scores, evidence inputs, and model routes.
packages/​learning/​contracts/​v1/​provider-manifest.schema.json Expands supported external-host formats.
packages/​learning/​contracts/​v1/​memory-record.schema.json Adds titles and edit/reinstatement metadata.
packages/​learning/​contracts/​v1/​memory-proposal.schema.json Allows proposal titles.
packages/​learning/​contracts/​v1/​invalid/​update-decision.applied-without-version.json Covers missing applied-version rejection.
packages/​learning/​contracts/​v1/​invalid/​score.low-without-issue.json Covers low scores missing an issue.
packages/​learning/​contracts/​v1/​guidance.schema.json Defines guidance requests and session metadata.
packages/​learning/​contracts/​v1/​examples/​used-learning.example.json Illustrates a claimed learning use.
packages/​learning/​contracts/​v1/​examples/​usage-report.example.json Illustrates a session usage report.
packages/​learning/​contracts/​v1/​examples/​update-proposal.example.json Illustrates a proposed wording update.
packages/​learning/​contracts/​v1/​examples/​update-decision.example.json Illustrates an applied update decision.
packages/​learning/​contracts/​v1/​examples/​screenshot.example.json Illustrates screenshot capture metadata.
packages/​learning/​contracts/​v1/​examples/​score.example.json Illustrates a scored learning use.
packages/​learning/​contracts/​v1/​examples/​guidance.example.json Illustrates a guidance request.
packages/​learning/​contracts/​v1/​examples/​delivered-learning.example.json Illustrates delivered learning text.
packages/​learning/​contracts/​v1/​event.schema.json Adds session outcomes and label categories.
packages/​learning/​contracts/​v1/​delivered-learning.schema.json Defines exact delivered text and source scope.
packages/​learning/​contracts/​v1/​collection.schema.json Clarifies migrated snapshot histories.
packages/​learning/​contracts/​v1/​audit-entry.schema.json Adds lifecycle operations and audit subjects.
docs/​adr/​0001-learning-extension-architecture.md Updates storage, identity, evidence, and approval design.
CONTRIBUTING.md Removes the retired demo command.
.github/​workflows/​learning-ci.yml Runs database tests against PostgreSQL.

Review effort: Balanced (adaptive)

Comment thread packages/learning/src/cli.mjs Resolved
Comment thread packages/learning/src/labeling.mjs Resolved
Comment thread packages/learning/src/updates.mjs Resolved
Comment thread packages/learning/src/updates.mjs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cached scores can disclose text derived from withdrawn evidence, and repository deletion can erase screenshots still used by other repositories.

1 open issue
5 resolved since last review

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Unresolved critical issues can expose score text after consent withdrawal, allow image reads outside the permitted directory, and delete screenshots still needed by another scope.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Path-based image opening allows a directory swap to bypass containment

packages/​learning/​src/​cli.mjs:1856

The parent directory can change between the containment check and this pathname-based open; NO_FOLLOW protects only the final component. With concurrent changes to the report directory, the command can read an image outside the allowed directory and later pass it to evaluation. Use a directory-handle-based containment mechanism that remains valid through opening the file, or stage inputs in a directory the report writer cannot modify.

1 resolved since last review

Review effort: Balanced (adaptive)

@nshki

nshki commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the items from the latest review summary in 947e1f3:

  • Screenshots shared by repositories in one data directory. Each repository now leaves a small owner marker beside an image, and an image is removed only when no other repository's marker is left. A repository's old names from a migration count as its own.
  • Kept score text after consent is withdrawn. scoreFor, and so a retried recordScore, now returns a stored score only while its version's evidence still permits review. That is the same rule outcomesFor already used.
  • Folder swaps during report-usage. Node has no way to open a file relative to a held folder, so this can't be fully closed. The containment checks stop wrong or crafted paths. A process that renames folders mid-command already runs with the same access. The code comment and README now say so and ask that the report's folder be kept away from other accounts.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

A critical race between put() and remove() can delete another repository’s image because deletion relies on a stale owner-marker scan without a shared cross-process per-digest lock.

1 open issue

Review effort: Balanced (adaptive)

Comment thread packages/learning/src/screenshots.mjs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to weigh cross-cutting risks in sensitive screenshot retention, session-input handling, terminal output, and failed-reassessment accounting.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

@nshki

nshki commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up: repository deletion now cleans up screenshot files left by failed reports or interrupted removal. Same-scope reports and deletions take a lock, and shared or still-referenced legacy images are retained. The change includes regression coverage for failures, recovery, migration, and concurrent deletion.

Comment thread packages/learning/src/evaluation.mjs Resolved
Comment thread packages/learning/src/updates.mjs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The ignore-rule check accepts tracked store files, allowing private review evidence to be written into files that subsequent commits and pushes can expose.

3 open issues

Review effort: Balanced (adaptive)

Comment thread packages/learning/src/config.mjs Resolved
Comment thread packages/learning/src/labeling.mjs Resolved
Comment thread packages/learning/src/updates.mjs Resolved
Comment thread packages/learning/src/evaluation.mjs Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved critical issues can allow evidence transmission and screenshot-report success after consent ends, while named-pipe screenshots can block reporting indefinitely.

5 open issues
3 resolved since last review

Review effort: Balanced (adaptive)

Comment thread packages/learning/src/cli.mjs Resolved
Comment thread packages/learning/src/updates.mjs Resolved
Comment thread packages/learning/src/labeling.mjs Resolved
Comment thread packages/learning/src/evaluation.mjs Resolved
nshki and others added 26 commits November 30, 2026 22:28
Removing a screenshot now moves the image aside and checks the owner
markers again before deleting it. A save in another process writes its
marker before it looks for the image, so a save that found the image is
seen by the second check and the image is put back.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Keep score ordering stable when review permission changes and serialize dismissal with score writes. Restore the reusable memory repository example while retaining removal of its scripted demo.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
…named pipes

Local usage reports could send screenshots to Copilot without a consent grant, and a named pipe given as a screenshot made the command wait forever.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Drafting an update now confirms evaluation consent and the learning's current version right before evidence is sent to Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Migrating a repository failed when one of its learnings had been deleted, and a usage report resent after migration was stored twice.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
An edited message without its own time was dated when it was resent instead of when it was first sent.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
…cores

Review comments, reports and Build diffs reach Copilot as evidence. Scoring and
labeling now fence that evidence the way update drafting already does, escaping
"<" so the text cannot close the fence and pose as instructions. Comments that try
to give the labeler orders are replaced with a fixed note before Copilot reads them.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
…valuator

Scoring now checks that each screenshot is a PNG within the size limit and
matches its recorded digest before attaching it. A host that returns the wrong
file for a digest can no longer send it to Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Keep one deterministic event ID when multiple agents label copies of the same comment. Reversing the input now leaves both the proposal and its reviewed evidence unchanged.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
@nshki
nshki force-pushed the nshki/feat/learning/01-storage branch from 43657b1 to a44c928 Compare December 1, 2026 06:28
@nshki
nshki merged commit a5703e1 into build/hub/new Dec 1, 2026
58 checks passed
@nshki
nshki deleted the nshki/feat/learning/01-storage branch December 1, 2026 06:42
nshki added a commit that referenced this pull request Dec 1, 2026
…434)

<!-- Use a conventional commit-style title, such as "fix(hub): retain
prototype history". -->

## Why

<!-- Explain the problem and why this change matters in a short,
plain-English paragraph. Link the issue when applicable. -->

People prototyping alone need a way to turn their feedback into
learnings without deploying Hub. This second of five stacked pull
requests builds on the storage and scoring in #433.

## What changes

<!-- Describe what becomes different for a first-time reader. Explain
necessary terms. Include accurate Mermaid diagrams when they clarify the
proposal, using before/after diagrams when helpful. Add screenshots for
meaningful UI changes. -->
<!-- Omit validation sections, checklists, and routine test/CI summaries
such as "CI is green" or "tests passed". Mention only known verification
gaps that affect the change, not disclaimers about drafting this
description. -->
<!-- For UI changes, prune obsolete and duplicate stories in the
affected catalogues as part of the change. Explain removed UI or
consolidated coverage where needed; see
hub/docs/storybook.md#ui-changes-and-pull-request-evidence. -->

`replica-learning setup` prepares local learning in a prototype checkout
and writes a private MCP configuration. After restarting Copilot CLI
with that configuration, an agent can get accepted guidance, submit
conversations, and report which learnings it used. A person decides
whether to share chats and whether to accept suggestions. Clients with
form support show decisions in forms; other clients provide commands for
the person to run.

Saved feedback is analyzed in the background. The canvas also passes
completed Pick & Polish notes and confirmed replies to the learning
server. The starter ignores `.replica/`, and the setup and canvas guides
explain how to try the flow.


This layer now sits on the latest storage layer. That layer saves an
applied update and its decision together, so the earlier recovery step
for half-finished applies is gone.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants