Skip to content

feat(hub): store learnings in a dedicated database scoped by repository ID - #437

Draft
nshki wants to merge 19 commits into
nshki/feat/learning/02-local-modefrom
nshki/feat/learning/03-hub-domain
Draft

nshki wants to merge 19 commits into
nshki/feat/learning/02-local-modefrom
nshki/feat/learning/03-hub-domain

Conversation

@nshki

@nshki nshki commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Why

Hub needs to keep learnings safely for each repository before it can show them or share them with agents. Until now, Hub kept them in files next to each checkout, and they were tied to Hub's internal repository ID. This third of five stacked pull requests builds on the local learning mode in #434.

What changes

Hub can now keep learnings in their own PostgreSQL schema with a separate database login. That login can reach only the learning data, not the rest of Hub's database. Learnings are tied to the GitHub repository ID, so renaming a repository keeps its history. Existing installations keep using local SQLite files until an operator moves their history across with the package's import command.

flowchart LR
  Hub[Hub server] -->|Hub login| HubDB[(Hub schema)]
  Hub -->|learning login| LearnDB[(Learning schema)]
  LearnDB --- Scope[Scoped by GitHub repository ID]
Loading

The Azure setup wizard creates the learning login and its Key Vault secret for new installations. For an existing installation, it creates the login but leaves SQLite selected, and the infrastructure guide walks through the one-time move. Hub CI now installs the learning runtime, and the local dev container creates the learning role.

Hub also saves a checkpoint of the review comments each decision-model run used. This stops a learning run that finishes at the same time from changing that input. When combining old and new history shows that some text was removed earlier, the Learnings page now tells admins which learnings to rebuild and which exports may still contain that text. The page now shows that message as Hub sends it, without its own prefix.

Storybook screenshots

Hub/Pages/Learnings / Load Error - light theme, 1440x1000 CSS-pixel viewport (focused alert crop)

Load Error alert

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

Missing PostgreSQL runtime grants prevent the restricted learning login from opening a fresh scope, leaving a critical access failure unresolved.

6 open issues
What changed in this PR

Adds optional PostgreSQL-backed learning storage to Hub, building on local learning mode while keeping existing installations on SQLite until their history is migrated.

Changes:

  • Scope learnings by GitHub repository ID and provision a separate learning database login through Azure and local setup.
  • Persist decision-review checkpoints and report incomplete training-withdrawal discovery.
  • Show migration redaction follow-ups and update CI, coverage, and operating guides.
File Description
scripts/​check-ci-workflows/​index.ts Requires learning runtime installation in Hub CI.
scripts/​check-ci-workflows/​index.test.ts Covers the new workflow requirement.
infrastructure/​README.md Documents provisioning, secrets, and migration ordering.
infrastructure/​azure/​variables.tf Validates learning secrets and reference limits.
infrastructure/​azure/​tests/​deployment.tftest.hcl Covers learning runtime and setup configuration.
infrastructure/​azure/​setup.tf Configures learning migrations and runtime grants.
infrastructure/​azure/​roles.tf Adds secret-scoped learning credential access.
infrastructure/​azure/​provision/​tests/​provision.tftest.hcl Covers fresh and learning-only provisioning modes.
infrastructure/​azure/​provision/​main.tf Adds learning-only provisioning support.
infrastructure/​azure/​post/​types.ts Types the optional learning secret reference.
infrastructure/​azure/​post/​index.ts Recognizes deployed learning secret references.
infrastructure/​azure/​post/​index.test.ts Covers preserving learning configuration across reruns.
infrastructure/​azure/​post/​configure/​index.ts Adjusts available secret-reference capacity.
infrastructure/​azure/​installation.tfvars.example Shows optional learning database configuration.
infrastructure/​azure/​install/​secrets/​index.ts Creates learning credentials and provisioning markers.
infrastructure/​azure/​install/​provision/​index.ts Orchestrates fresh and learning-only provisioning.
infrastructure/​azure/​install/​inputs/​index.ts Validates saved learning database inputs.
infrastructure/​azure/​install/​index.ts Selects learning storage during installation.
infrastructure/​azure/​install/​index.test.ts Covers provisioning, cleanup, and retry safeguards.
infrastructure/​azure/​application.tf Supplies the learning runtime secret reference.
hub/​test/​fixtures/​learning/​report-runtime.mjs Reports temporary configuration and failure diagnostics.
hub/​test/​database/​decision-review-snapshot-migration/​index.db.test.ts Covers checkpoint migration and repository isolation.
hub/​server/​utils/​parse-azure-secret-configuration/​types.ts Adds the learning-only entrypoint type.
hub/​server/​utils/​parse-azure-secret-configuration/​index.ts Validates learning provisioning and setup references.
hub/​server/​utils/​parse-azure-secret-configuration/​index.test.ts Covers learning secret validation.
hub/​server/​scripts/​setup/​index.ts Runs learning migrations and grants under setup locking.
hub/​server/​scripts/​setup/​index.test.ts Covers learning setup steps and lock use.
hub/​server/​scripts/​seed-decision-model-walkthrough/​index.ts Binds the fixture to a verified GitHub identity.
hub/​server/​scripts/​provision-learning-database-access/​index.ts Creates the learning login for existing installations.
hub/​server/​scripts/​provision-database-access/​index.ts Includes the learning login in fresh provisioning.
hub/​server/​scripts/​grant-learning-database-access/​index.ts Defines learning runtime database grants.
hub/​server/​scripts/​azure-entrypoint/​run/​index.ts Dispatches learning-only provisioning.
hub/​server/​scripts/​azure-entrypoint/​run/​index.test.ts Covers learning-only entrypoint execution.
hub/​server/​scripts/​azure-entrypoint/​load-secret-environment/​index.test.ts Includes learning password retrieval coverage.
hub/​server/​routes/​api/​learnings/​respond-learning-error/​index.ts Maps unavailable repository scopes to conflicts.
hub/​server/​routes/​api/​learnings/​index.test.ts Covers forwarding migration follow-up messages.
hub/​server/​routes/​api/​learnings/​create-learnings-route-dependencies/​index.ts Resolves and rechecks repository learning scopes.
hub/​server/​repositories/​repository-access/​find-repository-github-id/​index.ts Reads persisted GitHub repository IDs.
hub/​server/​repositories/​learning-runs/​list-due-learning-repositories/​index.ts Requires positive GitHub IDs when scheduling.
hub/​server/​repositories/​learning-runs/​list-due-learning-repositories/​index.db.test.ts Updates scheduling fixtures with GitHub IDs.
hub/​server/​repositories/​learning-runs/​is-learning-run-repository-available/​index.ts Checks positive GitHub repository IDs.
hub/​server/​repositories/​decision-review-snapshots/​save-decision-review-snapshot/​index.ts Conditionally writes checkpoints using the lock connection.
hub/​server/​repositories/​decision-review-snapshots/​save-decision-review-snapshot/​index.db.test.ts Covers stale checkpoint writers.
hub/​server/​repositories/​decision-review-snapshots/​get-decision-review-snapshot/​index.ts Reads repository review checkpoints.
hub/​server/​integrations/​postgres/​with-learning-execution-lock/​index.ts Exposes the lock-owning database connection.
hub/​server/​integrations/​learning/​run-learning-command/​index.ts Supports isolated PostgreSQL commands and diagnostic redaction.
hub/​server/​integrations/​filesystem/​create-filesystem-artifact-storage/​index.test.ts Limits filesystem coverage to Linux.
hub/​server/​index.ts Passes learning database configuration into decision-model services.
hub/​server/​domains/​learning/​review-comment-learning-source/​types.ts Adds scope and legacy digest metadata.
hub/​server/​domains/​learning/​redact-legacy-review-comment/​index.ts Supports redaction of legacy repository scopes.
hub/​server/​domains/​learning/​reconcile-learning-decision-operation/​index.ts Uses current and legacy scope arguments.
hub/​server/​domains/​learning/​reconcile-learning-decision-operation/​index.test.ts Covers reconciliation scope arguments.
hub/​server/​domains/​learning/​read-learning-configuration/​index.ts Reads the optional learning database URL.
hub/​server/​domains/​learning/​process-review-comment-redaction/​index.ts Supports database and legacy-only redaction paths.
hub/​server/​domains/​learning/​process-learning-run/​index.ts Checks scope stability and accepts legacy queued digests.
hub/​server/​domains/​learning/​process-learning-run/​index.test.ts Covers scope drift and legacy run compatibility.
hub/​server/​domains/​learning/​prepare-learning-store/​index.ts Supports PostgreSQL without creating local stores.
hub/​server/​domains/​learning/​prepare-learning-store/​index.test.ts Covers database-backed store preparation.
hub/​server/​domains/​learning/​learning-store-arguments/​index.ts Centralizes numeric and legacy scope arguments.
hub/​server/​domains/​learning/​get-learning-repository-scope/​index.ts Resolves positive GitHub repository scopes.
hub/​server/​domains/​learning/​get-learning-overview/​index.ts Reads database learnings and migration follow-ups.
hub/​server/​domains/​learning/​get-learning-overview/​index.test.ts Covers database reads and persistent follow-up notices.
hub/​server/​domains/​learning/​execute-learning-decision/​index.ts Supports database-backed learning decisions.
hub/​server/​domains/​learning/​execute-learning-decision/​index.test.ts Covers decisions without local stores.
hub/​server/​domains/​learning/​create-review-comment-learning-source/​index.ts Captures scope-bound review snapshots.
hub/​server/​domains/​learning/​create-review-comment-learning-source/​index.test.ts Covers missing IDs and scope changes during capture.
hub/​server/​domains/​learning/​create-learning-job-processors/​index.ts Wires database storage, numeric scopes, and legacy redaction.
hub/​server/​domains/​learning/​create-learning-job-processors/​index.test.ts Covers database redaction and legacy recovery.
hub/​server/​domains/​learning/​create-hub-review-collection/​index.ts Adds scope-bound digests while retaining legacy digests.
hub/​server/​domains/​learning/​create-hub-review-collection/​index.test.ts Covers digest stability and scope sensitivity.
hub/​server/​domains/​decision-model/​types.ts Represents incomplete withdrawal discovery.
hub/​server/​domains/​decision-model/​prepare-decision-taskset/​index.ts Updates the withdrawal discovery interface.
hub/​server/​domains/​decision-model/​create-hub-decision-taskset-source/​index.ts Integrates database learning storage and persistent checkpoints.
hub/​server/​domains/​decision-model/​create-hub-decision-taskset-source/​index.test.ts Covers database consent, scopes, and withdrawal retries.
hub/​server/​domains/​decision-model/​create-decision-model-job-processors/​index.ts Reports pending withdrawal discovery for retry.
hub/​server/​domains/​decision-model/​create-decision-model-job-processors/​index.test.ts Covers discovery retry behavior.
hub/​server/​domains/​decision-model/​create-configured-decision-model-job-processors/​index.ts Passes learning database configuration to workers.
hub/​server/​domains/​artifacts/​create-configured-artifact-storage/​index.test.ts Limits filesystem coverage to Linux.
hub/​server/​domains/​artifacts/​create-artifact-storage/​index.test.ts Gates Linux-dependent filesystem cases.
hub/​script/​check-image/​index.ts Supplies a learning password during image provisioning.
hub/​schema/​repository.prisma Adds the review checkpoint relation.
hub/​schema/​migrations/​20261220160000_add_decision_review_snapshot/​migration.sql Creates the per-repository checkpoint table.
hub/​schema/​decision-review-snapshot.prisma Defines persisted checkpoint metadata.
hub/​docs/​testing-and-operations.md Documents the database-test runtime prerequisite.
hub/​docs/​learning-foundation.md Defines storage migration, scoping, and redaction behavior.
hub/​docs/​development.md Documents local PostgreSQL learning setup and fixture identity.
hub/​docs/​deployment.md Documents learning credentials and setup lifecycle.
hub/​docs/​decision-model-control-plane.md Explains pending withdrawal discovery and recovery.
hub/​docs/​database.md Documents checkpoint storage and learning role separation.
hub/​client/​application/​hub/​view-models/​settings-learnings/​index.ts Displays server-provided notices without a prefix.
hub/​client/​application/​hub/​routes/​learnings-flow.test.tsx Covers follow-up notices after reload.
hub/​.devcontainer/​learning-role.sql Creates the local learning login.
hub/​.devcontainer/​decision-walkthrough.compose.yaml Keeps walkthrough learning storage on SQLite.
hub/​.devcontainer/​compose.yaml Shares the PostgreSQL socket and initializes the learning role.
.github/​workflows/​hub-ci.yml Installs and caches the learning runtime.

Review effort: Max (adaptive)

@nshki
nshki force-pushed the nshki/feat/learning/02-local-mode branch 2 times, most recently from d128501 to 0b0c118 Compare November 30, 2026 08:51
nshki and others added 11 commits November 30, 2026 03:49
…ry ID

Hub now keeps learnings in their own PostgreSQL database with a separate
login, scoped by GitHub repository ID so renames keep their history. Azure
installs provision the learning login and secret, Hub CI installs the
learning runtime, and decision review snapshots are fenced against
concurrent learning checkpoints.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 459b160c-a7ab-4c14-8a06-098ca9096352
A new repository scope writes through triggers that maintain the decision
tables, and deleting learnings needs DELETE. The grant script missed those,
so the restricted login could not open a fresh scope. It now matches the
package's documented runtime privileges, and a database test runs real
commands as that login.

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

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
…work left

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 the focused database test aligned with the Hub formatter.

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
@nshki
nshki force-pushed the nshki/feat/learning/03-hub-domain branch from f6d05fb to 27d7b2a Compare November 30, 2026 12:22
@nshki
nshki requested an adaptive review from Copilot November 30, 2026 12:24
Keep fixture reports to an explicit non-sensitive environment allowlist. Report credential presence without logging values.

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.

Comment thread packages/learning/src/store.mjs Resolved
nshki and others added 4 commits November 30, 2026 05:20
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

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

Azure releases can lose existing learning history, while repository disconnection can prevent deletion of withdrawn private training data and derived runtime copies indefinitely.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity Allow maintenance deletion for withdrawals after repository disconnection

hub/​server/​domains/​decision-model/​create-hub-decision-taskset-source/​index.ts:920

When a training withdrawal is discovered after repository disconnection, the empty administrator grants make this branch skip deletion, leaving exported private data and derived runtime copies retained indefinitely. Retries cannot progress without restoring administrator access, which processDecisionRuntimeDeletion() also requires. Add a narrowly scoped maintenance deletion path authorized by the recorded withdrawal and saved training jobs, rather than requiring restored repository access.

High severity Require durable storage before releasing an existing Azure installation

infrastructure/​azure/​install/​index.ts:265

[P1] For an existing Azure installation without learning_database_secret, this branch keeps SQLite selected but still releases the app after removing all old replicas. application.tf mounts no persistent learning storage, so any history on those replicas is lost. Block the release until that history is recovered and verified or persistent storage is provided; the manual first-install example at infrastructure/azure/installation.tfvars.example:15–20 must also select durable storage.

Medium severity Declare redactionFollowUps on the public LearningStore interface

packages/​learning/​src/​store.mjs:5324

The public LearningStore interface in packages/learning/index.d.mts does not declare this method, although createLearningStore() returns that interface. TypeScript consumers therefore cannot call the new lightweight follow-up lookup without a type error. Add a matching redactionFollowUps(context) declaration with its result type so the runtime API and shipped declarations stay aligned.

8 resolved since last review

Review effort: Max (adaptive)

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

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

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