Skip to content

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

Open
nshki wants to merge 31 commits into
build/hub/newfrom
nshki/feat/learning/01-storage
Open

nshki wants to merge 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 and others added 7 commits November 28, 2026 20:31
The learning package gains what Hub needs to keep and judge learnings:
- a PostgreSQL provider, scope migration to GitHub repository IDs
- contracts and store support for agent sessions, recall deliveries,
  usage reports, scores, and suggested updates
- an analyze command that runs labeling, consolidation, and scoring

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: 836fcecf-e7a9-4975-acd2-bf761098f711
Refuse hard-linked screenshots, check who sent a resent message before
its text, let a later relabel replace a no-label judgment, rank update
evidence by score time before capping it, and keep each drafting run's
proposals together with the newest score it read.

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

A repository migration can keep two copies of the same Hub comment. The
recurrence consolidator now weighs a labeler's no-label judgment against
its labels across those copies, so a later reassessment that finds no
label stops an older label from proposing its theme.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Repositories that share a local data directory now each leave an owner
marker beside a screenshot image, so deleting one repository keeps images
another still uses.

A kept score is returned only while its version's evidence still permits
review, matching outcomesFor, so a retried score no longer hands back
reasoning built on withdrawn evidence.

The screenshot path comment and README now say the containment checks do
not stop a process that renames folders under the report mid-command.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
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
@nshki
nshki force-pushed the nshki/feat/learning/01-storage branch from ee88882 to 5535bc9 Compare November 29, 2026 04:37
@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
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352

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 because a concurrent deletion race can retain deleted learning text without an audit record, while label merging can produce input-order-dependent proposal digests.

No open issues 🎉

Review effort: Balanced (adaptive)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Comment thread packages/learning/src/evaluation.mjs Resolved
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

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

Ordinary fenced code examples are misclassified as model-control attempts, causing valid feedback to be replaced and, when no label is returned, marked completed so subsequent runs skip it.

1 open issue

Review effort: Balanced (adaptive)

Comment thread packages/learning/src/untrusted.mjs Resolved
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
Comment thread packages/learning/src/updates.mjs Resolved
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

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 because screenshot storage can proceed after consent withdrawal or expiry, alongside reliability issues affecting scoring, conversation context, and evidence determinism.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
@nshki
nshki added this pull request to stack #446 November 30, 2026 21:32
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352

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

Merging retained copies of the same Hub comment is order-dependent, causing proposal evidence IDs and review digests to change when input order is reversed.

1 open issue

Review effort: Balanced (adaptive)

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 marked this pull request as ready for review December 1, 2026 01:39
@nshki
nshki requested a review from a team as a code owner December 1, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants