Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/learning-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ jobs:
fail-fast: false
matrix:
node: [24, 26]
services:
postgres:
image: postgres:17.12-bookworm
env:
POSTGRES_USER: replica
POSTGRES_PASSWORD: replica
POSTGRES_DB: replica_learning_test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -h 127.0.0.1 -U replica -d replica_learning_test"
--health-interval 5s
--health-timeout 5s
--health-retries 10
defaults:
run:
working-directory: packages/learning
Expand All @@ -29,6 +43,9 @@ jobs:
- run: npm ci --ignore-scripts --engine-strict
- run: npm run schema:check
- run: npm test
- run: npm run test:database
env:
REPLICA_LEARNING_TEST_DATABASE_URL: postgresql://replica:replica@127.0.0.1:5432/replica_learning_test
- run: npm run demo
- run: npm run demo:agent-memory-repo
- name: Brand check environment tests
Expand Down
6 changes: 3 additions & 3 deletions docs/adr/0001-learning-extension-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ We chose this split so that consent and purpose rules exist in one place. If eve

A provider declares a manifest with its contract versions, capabilities, storage kind, and the hosts it sends data to. The store refuses a provider without the seven required capabilities. Optional capabilities, such as semantic, graph, or temporal search, leave room for Graphiti, Mem0, or a Hub provider without changing the contract.

A SQLite provider on the driver built into Node.js 24 is the default. A JSON Lines provider, whose files a person can read, is the reference, and an in-memory provider serves tests. A fourth provider in the tests is written only from the contract, with no imports from the package. All four pass the same conformance suite, which ships as `@github/replica-learning/conformance` and includes adversarial cases: damaged withdrawals, forged approvals, forged evidence pins, and racing replacements.
A SQLite provider on the driver built into Node.js 24 is the default. A PostgreSQL provider uses the package-owned `replica_learning` schema for hosts that need a shared database. A JSON Lines provider, whose files a person can read, is the reference, and an in-memory provider serves tests. Another provider in the tests is written only from the contract, with no imports from the package. The conformance suite ships as `@github/replica-learning/conformance` and includes adversarial cases: damaged withdrawals, forged approvals, forged evidence pins, and racing replacements. The [learning guide](../../packages/learning/README.md#postgresql-storage) describes PostgreSQL setup and retention.

### Consolidation is separate from memory

Expand Down Expand Up @@ -116,7 +116,7 @@ Learning happens first in explicit, inspectable memory. A training-purpose expor
- Inside a checkout, learning data and exports live only under `.replica/`, after following links, and only when Git ignores that exact path. The checkout root and names that merely start with two dots count as inside. Git ignoring a path is not enough, since a dev server or build may still serve it.
- The command asserts identities. An integrating host must pass only identities and repository authority it authenticated.
- The generated validator file is large, as in `packages/controls`.
- SQLite is the default local provider. A host that needs another database implements the provider interface and runs the conformance suite against it.
- SQLite is the default local provider. PostgreSQL is available for a shared database; another provider implements the same interface and runs the conformance suite.
- Copilot credential custody, billing, subprocess isolation, and deployed authentication remain integration decisions for the new Hub layer.

## Alternatives considered
Expand All @@ -128,7 +128,7 @@ Learning happens first in explicit, inspectable memory. A training-purpose expor
- A knowledge graph or vector store as the default. Rejected; the default should be simple and local, and graph or semantic search can arrive as provider capabilities.
- An agent collects comments through the canvas, and a starter skill runs each step. Replaced: a person had to start every step, and every comment passed through an agent session, which cost tokens and could introduce copying errors.
- Billing Copilot to the organization through the App's installation token. Deferred: it needs the App's Copilot requests permission and an installation on every repository in the organization.
- PostgreSQL or Neo4j providers in this version. Deferred: SQLite meets one Hub's needs, and the provider interface and conformance suite let a team add one later.
- Neo4j as a built-in provider. Deferred; the provider interface and conformance suite let a team add one later.
- Model-only consolidation. Kept as a plug-in option; the reference stays deterministic so tests and reviews are reproducible.

## Next steps
Expand Down
16 changes: 15 additions & 1 deletion packages/learning/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Replica learning

`@github/replica-learning` lets Replica learn from review evidence without training a model. It owns the version 1 learning contracts, the memory provider interface, built-in SQLite, JSON Lines, and in-memory providers, two reference consolidators, a conformance suite, the `replica-learning` command, and an example that plugs in [Agent Memory Repo](examples/agent-memory-repo/README.md). It also prepares training for a team that chooses to post-train a [decision model](#decision-model). It isn't published to npm yet, so run it from a Replica checkout with a Node.js version matching `engines.node` in [package.json](package.json).
`@github/replica-learning` lets Replica learn from review evidence without training a model. It owns the version 1 learning contracts, the memory provider interface, built-in SQLite, PostgreSQL, JSON Lines, and in-memory providers, two reference consolidators, a conformance suite, the `replica-learning` command, and an example that plugs in [Agent Memory Repo](examples/agent-memory-repo/README.md). It also prepares training for a team that chooses to post-train a [decision model](#decision-model). It isn't published to npm yet, so run it from a Replica checkout with a Node.js version matching `engines.node` in [package.json](package.json).

The design and its trade-offs are in [ADR 0001](../../docs/adr/0001-learning-extension-architecture.md), and the decision model's in [ADR 0002](../../docs/adr/0002-decision-model-and-rl-environment.md).

Expand Down Expand Up @@ -38,6 +38,7 @@ node <replica-checkout>/packages/learning/bin/replica-learning.mjs doctor
| Command | What it does |
| --- | --- |
| `doctor` | Shows the scope, the provider, where data goes, and why each was chosen |
| `migrate` | Sets up the package-owned PostgreSQL schema using a privileged environment-supplied URL |
| `grants add`, `grants list`, `grants withdraw` | Records, lists, and ends consent for purposes |
| `redact <event-id>` | Removes a comment's text when a person asks: every version and its labels |
| `redact --comment <hub-comment-id>` | Removes the same text for a Hub comment named by its Hub ID. It imports and labels nothing and needs no active grant. `--reason` defaults to the comment being deleted at its source. `removed` in the `--json` output counts the events whose text it removed, 0 when none was left. Run it only while no import or labeling of the same store is in progress |
Expand Down Expand Up @@ -142,6 +143,7 @@ The module must be inside the checkout and export `createMemoryProvider(options)
| Provider | Choose it with | Stores | Redaction |
| --- | --- | --- | --- |
| SQLite, the default | `"sqlite"` | One database file, with the SQLite driver built into Node.js | Yes |
| PostgreSQL | `"postgres"` | The package-owned `replica_learning` schema, using the optional `pg` dependency | Yes |
| JSON Lines | `"jsonl"` | One file per stream that a person can read | Yes |
| In memory | `"in-memory"` | Process memory, for tests | Yes |
| Single file | [`test/fixtures/json-file-provider.mjs`](test/fixtures/json-file-provider.mjs) | One JSON file, written only from the contract with no imports from this package | No |
Expand All @@ -150,6 +152,18 @@ The optional `observation.redact` capability adds `redactRecord`, described in [

Provider queries may filter audit entries with `operations`, together with scope, IDs, and time. An empty operations list matches nothing; omitting it returns every matching operation. Comment removal and imports that erase deleted text read only `evidence.redact` receipts, so their audit reads do not return the repository's growing recall history. SQLite indexes those operations, including when it opens an existing store. JSON Lines still scans the file, but reads it one line at a time and retains only matches; its writes retain only the existing IDs they need to check. No recall audit entries are deleted or compacted.

## PostgreSQL storage

An operator can store learnings in an existing PostgreSQL database instead of a local SQLite file. Set `"memory": { "provider": "postgres" }` in the learning config and supply `REPLICA_LEARNING_DATABASE_URL` to each command. Standard PostgreSQL URLs support DNS names, IPv4, IPv6, and Unix sockets. Remote TCP connections require `sslmode=verify-full`; loopback connections and Unix sockets can use plaintext for local development. Never put a database URL or credential in `config.json`. Installing without optional dependencies keeps SQLite usable; PostgreSQL needs the optional `pg` package.

Before a runtime login uses the database, an operator runs `replica-learning migrate` with `REPLICA_LEARNING_MIGRATION_DATABASE_URL` set to a privileged connection URL. This command does not read the runtime URL or learning config. It creates the `replica_learning` schema, tables, indexes, and its migration ledger in a transaction. Retrying, including concurrent retries, is safe. Run it again before using a package version with new migrations. The runtime checks the ledger but never creates or migrates schema objects.

The migration login needs permission to create the schema and own its objects. Give a separate runtime login only `USAGE` on `replica_learning`, `SELECT` on its migration ledger, `SELECT`, `INSERT`, and `UPDATE` on records, `SELECT` and `INSERT` on memory versions, and `USAGE` on their identity sequences. After each migration, grant these privileges on newly created objects as needed. Restrict database access to trusted hosts: scope is a package-level boundary, not database row-level authorization.

PostgreSQL stores the exact record JSON and indexes scope, IDs, time, episode, and audit operation. A write locks every affected scope until its transaction ends, and stores records and their audit entries together. Memory versions also check the expected prior digest. Redaction removes the payload from the current row, but old row versions may retain it until vacuum. Write-ahead logs and backups can retain it longer. Operators must set vacuum, WAL, backup, and replica retention policies to meet their deletion requirements; redaction does not erase those copies immediately.

For database checks, point `REPLICA_LEARNING_TEST_DATABASE_URL` at a dedicated disposable database and run `npm run test:database`. The test login needs `CREATEDB` and `CREATEROLE`; the tests create and remove their own databases and a restricted login. Never point this command at a database containing real learning data. Learning CI supplies its own PostgreSQL service.

## Label with Copilot

`replica-learning label` with no file labels every comment the labeler has not been asked about, then reports how many it labeled and what Copilot reported it cost. The built-in labeler uses the [Copilot SDK](https://github.com/github/copilot-sdk), an optional dependency that `npm ci` installs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
}
},
"externalCalls": {
"description": "Hosts this provider sends data to. Empty for a provider that stays on the machine.",
"description": "Hosts this provider sends data to, with IPv6 addresses in brackets. Empty for a provider that stays on the machine.",
"type": "array",
"maxItems": 50,
"items": {
"type": "string",
"minLength": 1,
"maxLength": 255,
"pattern": "^[A-Za-z0-9.-]+(?::[0-9]{1,5})?$"
"pattern": "^(?:[A-Za-z0-9._-]+(?::[0-9]{1,5})?|\\[[0-9A-Za-z:.%_-]+\\](?::[0-9]{1,5})?)$"
}
},
"dataRetention": { "type": "string", "minLength": 1, "maxLength": 2000 }
Expand Down
3 changes: 3 additions & 0 deletions packages/learning/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,9 @@ export declare function createSqliteMemoryProvider(options: {
directory: string
file?: string
}): MemoryProvider
export declare function createPostgresMemoryProvider(options: {
connectionString: string
}): MemoryProvider
export declare function createJsonLinesMemoryProvider(options: {
directory: string
lockTimeoutMs?: number
Expand Down
1 change: 1 addition & 0 deletions packages/learning/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export { createJsonLinesMemoryProvider } from "./src/providers/json-lines.mjs"
export { createCopilotLabeler } from "./src/labelers/copilot.mjs"
export { labelComments } from "./src/labeling.mjs"
export { createSqliteMemoryProvider } from "./src/providers/sqlite.mjs"
export { createPostgresMemoryProvider } from "./src/providers/postgres.mjs"
export { brandCheckQuestions } from "./src/decision/questions.mjs"
export { planDecisionTasks } from "./src/decision/tasks.mjs"
export { writeDecisionTaskset } from "./src/decision/taskset.mjs"
Expand Down
165 changes: 161 additions & 4 deletions packages/learning/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading