Skip to content

feat(hub): store learnings in Postgres - #379

Draft
nshki wants to merge 18 commits into
nshki/feat/learning/postgres-providerfrom
nshki/feat/hub/learning-postgres
Draft

nshki wants to merge 18 commits into
nshki/feat/learning/postgres-providerfrom
nshki/feat/hub/learning-postgres

Conversation

@nshki

@nshki nshki commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Why

Hub needs durable learning storage that can be shared across its processes. Existing SQLite installations should keep their history and remain usable until an operator chooses to move it.

What changes

When a learning database URL is configured, Hub passes it privately to the learning command and uses a separate PostgreSQL login. An offline import copies existing SQLite history and its migration mappings without changing the source. It refuses to overwrite an occupied destination or hide a known unimported store.

The draft proposes storing the review snapshot checkpoint in Hub's database when PostgreSQL is selected. Hub writes it using the same connection that holds the execution lock. SQLite continues to use its existing checkpoint file. Switching back from PostgreSQL needs a separate verified migration.

New Azure installations provision the learning login and secret. Existing installations remain on SQLite until an operator provisions the login and performs the documented cutover. The wizard changes are in a separate commit for @weastler.

The Azure installation has not been exercised in a deployment.

Storybook screenshots

No Hub or canvas presentation changes.

@nshki
nshki added this pull request to stack #367 November 25, 2026 19:18
@nshki
nshki requested an adaptive review from Copilot November 25, 2026 19:19

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

Critical migration and PostgreSQL integration defects can modify retained SQLite data, bypass import safeguards, and break provisioning, existing tests, and learning workflows.

9 open issues
What changed in this PR

Adds PostgreSQL-backed learning storage so Hub processes can share durable history, alongside an offline SQLite import path and separate learning database credentials.

Changes:

  • Routes Hub learning and decision-model commands through private PostgreSQL configuration.
  • Adds SQLite history import, migration mappings, import receipts, and database regression coverage.
  • Extends Azure provisioning, local development setup, and operator cutover documentation.
File Description
packages/​learning/​test-database/​postgres.test.mjs Covers imports, upgrades, rollback, and concurrency.
packages/​learning/​test-database/​postgres-v1.sql Pins the original schema for upgrade checks.
packages/​learning/​src/​providers/​sqlite.mjs Validates stored rows and inventories scopes.
packages/​learning/​src/​providers/​postgres.mjs Adds mappings, imports, and write guards.
packages/​learning/​src/​providers/​postgres-database.mjs Adds mapping and import-receipt tables.
packages/​learning/​src/​config.mjs Adds import orchestration and storage guards.
packages/​learning/​src/​cli.mjs Exposes the offline import command.
packages/​learning/​README.md Documents privileges and SQLite import.
infrastructure/​README.md Documents provisioning and operator cutover.
infrastructure/​azure/​variables.tf Validates separate learning secret references.
infrastructure/​azure/​tests/​deployment.tftest.hcl Checks learning credentials and setup wiring.
infrastructure/​azure/​setup.tf Supplies learning migration and grant settings.
infrastructure/​azure/​roles.tf Grants access to the learning secret.
infrastructure/​azure/​provision/​tests/​provision.tftest.hcl Covers fresh and learning-only provisioning.
infrastructure/​azure/​provision/​main.tf Supports both provisioning modes.
infrastructure/​azure/​post/​types.ts Types the optional learning secret.
infrastructure/​azure/​post/​index.ts Includes learning references in deployment checks.
infrastructure/​azure/​post/​index.test.ts Covers preservation of learning configuration.
infrastructure/​azure/​post/​configure/​index.ts Adjusts the available secret-reference limit.
infrastructure/​azure/​installation.tfvars.example Shows optional learning database configuration.
infrastructure/​azure/​install/​secrets/​index.ts Creates learning secrets and provisioning markers.
infrastructure/​azure/​install/​provision/​index.ts Orchestrates learning-role provisioning and cleanup.
infrastructure/​azure/​install/​inputs/​index.ts Validates saved learning settings.
infrastructure/​azure/​install/​index.ts Selects learning storage during installation.
infrastructure/​azure/​install/​index.test.ts Covers provisioning, recovery, and backend selection.
infrastructure/​azure/​application.tf Passes the runtime learning secret reference.
hub/​test/​fixtures/​learning/​report-runtime.mjs Reports subprocess configuration and failure cleanup.
hub/​server/​utils/​parse-azure-secret-configuration/​types.ts Adds the learning-only provisioning mode.
hub/​server/​utils/​parse-azure-secret-configuration/​index.ts Validates learning-related startup references.
hub/​server/​utils/​parse-azure-secret-configuration/​index.test.ts Covers the new reference contracts.
hub/​server/​scripts/​setup/​index.ts Runs learning migrations and runtime grants.
hub/​server/​scripts/​setup/​index.test.ts Checks learning setup under the lock.
hub/​server/​scripts/​provision-learning-database-access/​index.ts Creates the learning login for existing installations.
hub/​server/​scripts/​provision-database-access/​index.ts Creates the learning login during fresh provisioning.
hub/​server/​scripts/​grant-learning-database-access/​index.ts Grants learning-schema runtime privileges.
hub/​server/​scripts/​azure-entrypoint/​run/​index.ts Dispatches learning-only provisioning.
hub/​server/​scripts/​azure-entrypoint/​run/​index.test.ts Checks provisioning inputs and workload isolation.
hub/​server/​integrations/​learning/​run-learning-command/​index.ts Supplies private PostgreSQL configuration and credentials.
hub/​server/​integrations/​learning/​run-learning-command/​index.test.ts Covers credential isolation, guards, and cleanup.
hub/​server/​index.ts Passes learning storage into decision-model composition.
hub/​server/​domains/​learning/​redact-legacy-review-comment/​index.ts Forwards PostgreSQL credentials for legacy redaction.
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 Enables redaction without local PostgreSQL configuration files.
hub/​server/​domains/​learning/​process-review-comment-redaction/​index.test.ts Covers database-backed legacy redaction dispatch.
hub/​server/​domains/​learning/​prepare-learning-store/​index.ts Skips local store creation for PostgreSQL.
hub/​server/​domains/​learning/​prepare-learning-store/​index.test.ts Checks preparation without local directories.
hub/​server/​domains/​learning/​get-learning-overview/​index.ts Reads PostgreSQL learnings without local configuration.
hub/​server/​domains/​learning/​get-learning-overview/​index.test.ts Covers database overview reads and missing SQLite stores.
hub/​server/​domains/​learning/​execute-learning-decision/​index.ts Sends decisions to the selected database.
hub/​server/​domains/​learning/​execute-learning-decision/​index.test.ts Covers decisions without local store creation.
hub/​server/​domains/​learning/​create-learning-job-processors/​index.ts Threads database configuration through learning workers.
hub/​server/​domains/​learning/​create-learning-job-processors/​index.test.ts Checks database-backed worker redaction.
hub/​server/​domains/​decision-model/​create-hub-decision-taskset-source/​index.ts Uses configured learning storage for taskset operations.
hub/​server/​domains/​decision-model/​create-hub-decision-taskset-source/​index.test.ts Checks database-backed training consent reads.
hub/​server/​domains/​decision-model/​create-configured-decision-model-job-processors/​index.ts Passes learning storage into decision-model workers.
hub/​docs/​learning-foundation.md Explains storage selection and migration safeguards.
hub/​docs/​development.md Documents local learning-role setup.
hub/​docs/​deployment.md Documents learning credentials and setup lifecycle.
hub/​docs/​database.md Describes the separate learning runtime role.
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 Configures local learning database credentials and initialization.

Review effort: Max (adaptive)

Comment thread packages/learning/src/config.mjs Resolved
Comment thread packages/learning/src/config.mjs Resolved
Comment thread hub/.devcontainer/compose.yaml Resolved
Comment thread hub/.devcontainer/compose.yaml Resolved
Comment thread packages/learning/src/config.mjs Resolved
nshki and others added 14 commits November 25, 2026 12:53
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 836fcecf-e7a9-4975-acd2-bf761098f711
@nshki
nshki force-pushed the nshki/feat/hub/learning-postgres branch from c5ed62f to 311bdbc Compare November 25, 2026 21:09
nshki and others added 4 commits November 25, 2026 16:52
Write PostgreSQL checkpoints on the advisory-lock connection and migrate them after the existing Hub schema.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 50605b0b-6b69-4743-b6d9-6918b6c9878a
Hub database tests run the learning command and need its optional PostgreSQL driver.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 50605b0b-6b69-4743-b6d9-6918b6c9878a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 50605b0b-6b69-4743-b6d9-6918b6c9878a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 50605b0b-6b69-4743-b6d9-6918b6c9878a
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.

4 participants