Skip to content

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

Draft
nshki wants to merge 6 commits into
build/hub/newfrom
nshki/feat/learning/01-storage
Draft

nshki wants to merge 6 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 changes only the learning package, so later layers can build Hub features on a reviewed base.

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.
  • Each learning gets a score from later review evidence. When evidence starts to contradict a learning, the package suggests an update 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.
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 removed demo and examples are replaced by the CLI and README. Local learning mode and the agent MCP server come in the next layer. Hub changes come in layers 3 to 5.

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
Copilot AI adaptive review requested due to automatic review settings November 28, 2026 03:25
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711

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
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

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)

…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

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)

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
@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
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

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)

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.

2 participants