Skip to content
Open
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
88 changes: 88 additions & 0 deletions docs/architecture/curator.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,88 @@ Each entry is the answer of one function of `server/memory/app/curator_gates.py`
- The model step has two conditions that are not entries: a mode of `assist`, which the `mode` field says, and a namespace whose name is not reserved, which no setting changes.
- The command line and the **Curator** tab list an unmet entry only where the stored mode needs it: none while the mode is `off`, the `pass` entries in any other mode, and the `opinions` entries in `assist`. The settings dialog, where an admin is choosing `assist`, lists every unmet entry but `mode`.

## Drafted answers

A draft is an answer the curator wrote to a question several people asked, from one shared document. Until a person accepts it, it is text nobody has reviewed, so only the namespace's administrators read it. It is stored as a candidate of the [learnings review queue](../features/memory/procedures-and-learnings.md#learnings-review-queue) with `source_kind` `curator_draft`, and never as a memory row: no memory read, search or count holds it, and `memory.proposals` does not list it, because the proposal policy, the advice and the suite checks judge proposals and a draft is judged on the document it cites. This section describes the candidate, its review and the fact it becomes. No pass writes a draft.

### The candidate

| Column | Holds |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `memory_key` | The key the fact is written under, `curator/gap/<k>`. |
| `proposed_value` | The drafted answer. |
| `source_resource_id` | The gap the draft answers. |
| `evidence` | A pointer as JSON, never a quote or a passage: the `kind`, `key`, `version` and `sha256` of the shared document the draft cites, the keys to `recheck`, the `run_id` of the pass that drafted it, and the draft it is a `redraft_of`. |

`learnings.list` lists a draft only to a caller with the admin role on the namespace. For every other caller the row is absent from the list and from the counts of `learnings.quality`, and `memory.lineage` names no such candidate. The filter is part of each statement, so it applies before a limit or a count. An administrator's entry carries `content_sha256`, the server's hash of the drafted answer, and `evidence`, the pointer. An administrator whose grant is revoked stops reading drafts when the replica's grant cache refreshes, as for every read that needs the admin role.

### The review

`learnings.review` decides a draft. The operation needs the admin role, and a draft answers 404 `RESOURCE_NOT_FOUND` to a caller the namespace does not admit as an administrator, as a candidate that does not exist does.

| Decision | Who | What it needs |
| --------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `promote` | A person who administers the namespace, signed in under their own name. | `approved_sha256` equal to the `content_sha256` the list served. An empty or different hash answers 409 `PRECONDITION_FAILED`, which does not return the stored hash. `destination` is `memory` or unset. |
| `reject` | Any caller with the admin role on the namespace, a service account included. | Nothing: `approved_sha256` is ignored. |

- A service account that promotes is refused with 403 `AUTH_INSUFFICIENT`.
- One review of a draft runs at a time: a second answers 503 `OVERLOADED` while the first holds the draft's claim.
- A draft is decided once. A decided draft answers its status to a repeat of the same decision and 409 `PRECONDITION_FAILED` to the other one. Its `promoted` or `rejected` row is what records that the question was drafted, and a later draft of the same question is a new candidate that names it in `redraft_of`.
- Each of these refusals is raised before the write: it stores no memory row and no decision row.

### The fact

A promotion writes the draft through `memory.set` as the curator's namespace-wide row and then records the decision:

| Field | Value |
| ----------------------- | -------------------------------------------------------------------------------------- |
| Identity | `(org, namespace, loom-curator, -, -)` under the draft's `memory_key`, type `semantic` |
| `actor` | The reviewer, from the review's token: accepting the draft is the reviewer's write. |
| `source_class` | `derived` |
| `source_trace` | `curator:<candidate_id>` |
| `source_resource_id` | The `key` of the cited document. |
| `grounding`, `evidence` | `verbatim` and the draft's pointer. No `memory.set` body sets either column. |
| Precondition | `if_match_sha256: absent`: the write lands only where no live row holds the key. |

A `memory.bulk_set` entry sets `grounding` and `evidence` on the row it writes, so neither column proves that a review accepted a row.

A refusal of the write leaves the draft pending and records no decision:

| The write is refused by | The review answers |
| --------------------------------------------------------------------- | -------------------------------------------------- |
| A row now under the key | 409 `PRECONDITION_FAILED` |
| A row under the key that is locked `read_only` and holds another text | 423 `LOCKED` |
| A blacklisted value | 422 `BLACKLISTED` |
| A conflict with a pinned fact | 409 `PINNED_CONFLICT` |
| A text that is, or contains, a value deleted in the namespace | 422 `VALIDATION_FAILED` with `reason: "forgotten"` |
| A text that a row of the namespace already states | 409 `PRECONDITION_FAILED` |

Deleting an accepted fact makes its text a deleted value ([refusal](../features/memory/conflicts-and-refusal.md#refusal-the-blacklist)), so a later draft that restates it is refused: reject that draft.

`memory.set` merges a text that a row already states into that row and stores nothing under the draft's key. The review's answer names that row's key when the reviewer may read it. The merge itself is recorded: it adds one `conflict.merge` count to `loom.memory_drops`, and under the `auto_reinforce` [conflict policy](../features/memory/conflicts-and-refusal.md#namespace-conflict-policy), the default, it records one `evidence` usage event on that row when the reviewer may read it. A repeat of the promotion records both again.

None of these refusals keeps the lease that serializes the private candidate writes of the org, so the next review, redaction or erasure proceeds at once. A review that stopped after the write and before the decision row completes on a repeat: a live row of the curator that carries the draft's trace and content hash is taken as written, and the repeat records the decision without a second write. Rejecting a draft writes no memory.

### Redaction and erasure

Redacting a version of the fact a draft became blanks that draft's candidate: its `proposed_value`, `rationale`, `decision_reason` and `evidence` in every version. The candidate is the one the row's `source_trace` names, read by id, whatever key the fact holds by then. A blanked draft answers `learnings.review` as a missing candidate does. A namespace erasure deletes every row of the namespace in `loom.learnings_queue`, drafts of every status included, in its `learnings_queue.delete` step. A candidate row of a private kind is written under the lease that step takes, so a write and the deletion never overlap.

### Rolling back

A build without drafts lists a `curator_draft` candidate, with its text, to every viewer of the namespace. So `learnings.review` of a draft answers 503 `OVERLOADED` until every live replica has the migration that adds `evidence` ([rolling upgrades](rolling-upgrades.md), rule 104), and a rollback below this build is not supported while a `curator_draft` row of any status exists. Rejecting the drafts does not make a rollback safe: a rejection keeps the draft's text on its status row. Before a rollback:

1. Set `curator_mode` to `off` in every namespace, and let the reviews in flight end.
2. Delete the drafts, and check that none is left:

```sql
ALTER TABLE loom.learnings_queue DELETE WHERE source_kind = 'curator_draft' SETTINGS mutations_sync = 2;
SELECT count() FROM loom.learnings_queue WHERE source_kind = 'curator_draft';
```

3. Roll back.

A fact a draft became is an ordinary memory row. It stays, and the older build serves it as it serves any fact.

## Source entry points

- `server/memory/api/ops_curator.py` (`curator_status`), `server/memory/api/models_curator.py`: the operation and its wire models.
Expand Down Expand Up @@ -544,6 +626,9 @@ Each entry is the answer of one function of `server/memory/app/curator_gates.py`
- `server/memory/app/curator_opinions.py` (`run_step`, `current_opinions`, `hash_prefix`): the model step, the opinions `curator.status` serves and the keyed prefix.
- `server/memory/domain/curator_prompts.py` (`PROMPT_VERSION`, `OPINION_SYSTEM`, `opinion_user`, `parse_opinion`): the prompt, the two sets of codes with their titles, and the parse of an answer.
- `server/memory/store/curator.py` (`opinion_rows`, `opinion_texts`): the proposals a model may be sent, and their cut text.
- `server/memory/domain/definitions.py` (`CURATOR_DRAFT_KIND`, `PRIVATE_CANDIDATE_KINDS`, `CURATOR_DRAFT_MIGRATION`): the kind of a draft, the candidates only an administrator reads, and the number of the migration that adds `evidence`.
- `server/memory/app/curator_draft_review.py` (`require_acceptance`, `fact`, `written`): who may accept a draft, the fact an acceptance writes, and the repeat that finds it written. `server/memory/app/learnings.py` (`handle_learnings_review`): the review.
- `server/memory/app/definition_review.py` (`redact_candidates`): the candidate a redaction blanks.
- `server/memory/domain/curator.py` (the `MODEL_` codes, `OPINIONS_A_PASS`, `OPINION_START_SECONDS`, `OPINION_LOOKBACK_ROWS`, `OPINION_TEXT_MAX`, `OPINION_CALL_SECONDS`, `OPINION_FAILURES_STOP`): the gates' codes and the bounds of the model step.

## Invariants
Expand All @@ -559,6 +644,9 @@ Each entry is the answer of one function of `server/memory/app/curator_gates.py`
- An opinion is a verdict and a reason from closed sets. It changes no advice, no count and no decision, and no code reads it but `curator.status`.
- An opinion is served only on the content the model read, and a stored opinion holds no value and no plain content hash.
- An opinion is readable by whoever can read the proposal: the pass row that stores it is a run every viewer of the namespace may read, and the Runs page shows its metadata. The **Proposals** tab shows it to administrators because `curator.status` is an ADMIN op.
- A draft is read by the namespace's administrators only, in every status, and answers as a missing candidate to everyone else.
- A draft becomes a fact only when a person who administers the namespace accepts the hash of the text they were served. The fact's `actor` is that reviewer, and its `source_class` is `derived`. The curator performs no belief-revision verb: the promotion is the reviewer's Expand.
- A draft's `evidence` holds a pointer and no text of the document it cites.
- A prerequisite is read by one function, which the worker, the model step and `curator.status` all call, and one that cannot be read is not met.
- A pass reads one namespace, and its row carries the identity `(org, namespace, loom-curator, -, -)`.
- A pass does not run when the fleet is not at the mode's migration, the classification cannot be read or the lease is held, and it keeps no count when the erasure ledger cannot be read.
Expand Down
21 changes: 21 additions & 0 deletions docs/architecture/rolling-upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,27 @@ See the [participant lifecycle baseline](cells.md#participant-lifecycle-baseline
`tests/unit/test_code_review_brief_mirror.py` checks N's side, and the mixed-version
gate does not check this rule.

104. **A curator's draft in the review queue** (`evidence` on `loom.learnings_queue`,
migration `139_curator_draft_evidence.sql`): N keeps a candidate of `source_kind`
`curator_draft` from everyone but the namespace's administrators in
`learnings.list`, `learnings.quality` and `memory.lineage`, and stores in
`evidence` a pointer to the document the draft cites. N-1 knows no such kind: it
lists the candidate, with its text, to every viewer of the namespace, counts it,
decides it on `learnings.review` as an ordinary candidate, with no person and no
hash, and writes a status row without `evidence`, which leaves the column's
default. So while any live replica, in every deployment sharing the database, has
a schema version below 139, or no heartbeat has been read, `learnings.review` of a
draft answers 503 `OVERLOADED` with `retry_after_s: 30`, and nothing writes the
kind. The gate protects the roll forward only. A rollback below N is not supported
while a `curator_draft` row of any status exists, and rejecting the drafts does not
make it safe, because a rejection keeps the draft's text on its status row. The way
back is `curator_mode` `off` in every namespace, then the statement that deletes
the rows, then the downgrade
([drafted answers](curator.md#rolling-back)). A fact a draft became is an ordinary
memory row, which N-1 serves as any other.
`tests/unit/test_curator_draft_candidate.py` checks the gate and that its constant
names the migration file; the mixed-version gate does not check this rule.

## What checks them

`scripts/gates/mixed_version.py` (`make test-mixed-version`, the `mixed-version` CI job,
Expand Down
10 changes: 10 additions & 0 deletions docs/features/memory/writing.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,16 @@ not know the code or the server sends none.
Learnings have a review of their own:
[learnings review queue](./procedures-and-learnings.md#learnings-review-queue).

Some candidates of that queue are private: only an administrator of the namespace lists
them, and everyone else gets neither the row nor a count of it. They are the definition
drafts (`source_kind` `knowledge_gap` and `query_history`,
[definition drafts](../../architecture/definition-drafts.md)) and a curator's drafted
answer (`curator_draft`, [drafted answers](../../architecture/curator.md#drafted-answers)).
A drafted answer is not a proposal: `memory.proposals` does not list it and no read
serves it. A person who administers the namespace accepts it with `learnings.review`
and `approved_sha256`, the `content_sha256` `learnings.list` served for it, and it
becomes a fact with that reviewer as its `actor`.

### Deciding proposals from a script

A decision is three calls: list the proposals, read each chosen text whole, decide with
Expand Down
1 change: 1 addition & 0 deletions docs/guides/without-the-dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ are on `agent.account` and `agent.deployment`.
| Review queue (conflicts) | `conflicts.list`, `conflicts.resolve`, `learnings.review` | `agent.conflicts.list()`, `.resolve(...)` |
| Review queue (proposals) | `loom proposals list`, `show <key>`, `accept`, `reject` ([proposals](../features/memory/writing.md#deciding-proposals-from-a-script)) | `agent.client.memory.proposals(...)`, `.proposal_decide(...)` |
| Review queue (definitions) | `memory.definitions.list`, `memory.definitions.disputes`; a definition's team or product: `memory.set` with `applies_to` in its value | `agent.client.memory.definitions_list()`, `.definitions_disputes()` |
| Review queue (drafted answers) | `learnings.list`, `learnings.review approved_sha256=<hash>` ([drafted answers](../architecture/curator.md#drafted-answers)) | `agent.learnings.list(...)`, `.review(..., approved_sha256=...)`, as a signed-in person |
| Copy rules | `memory.copy_rule.set`, `memory.copy_rule.list`, `memory.copy_rule.delete` ([copy rules](../features/namespaces-and-sharing.md#copy-rules)) | `agent.client.memory.copy_rule_set(...)`, `.copy_rule_list(...)`, `.copy_rule_delete(...)`; TypeScript `client.memory.copyRuleSet(...)` |
| Copy rule preview | `loom copy-rule run <id>`, or `memory.copy_rule.run` ([preview a rule](../features/namespaces-and-sharing.md#preview-a-rule)) | `agent.client.memory.copy_rule_run(...)`; TypeScript `client.memory.copyRuleRun(...)`; `loom call memory.copy_rule.run rule_id=<id>` |
| Copy rule run | `loom copy-rule run <id> --apply --revision <n>` ([run a rule](../features/namespaces-and-sharing.md#run-a-rule)) | `agent.client.memory.copy_rule_run({"rule_id": ..., "dry_run": False, "revision": ...})` |
Expand Down
6 changes: 5 additions & 1 deletion docs/operations/upgrades.md
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,11 @@ The rules that let the two builds serve side by side are in

## Rollback

Redeploy the previous image; with the pair, `./redeploy.sh --rollback`. Before rolling
Redeploy the previous image; with the pair, `./redeploy.sh --rollback`. A rollback to a
build that does not know a curator's drafted answers is not supported while a
`curator_draft` row is in `loom.learnings_queue`: set `curator_mode` to `off` in every
namespace and delete those rows first
([drafted answers](../architecture/curator.md#rolling-back)). Before rolling
back to a build without assistant-turn learnings, turn `memory_extract_agent_learnings`
off and delete the rows of `loom.learnings_supporters` and the `assistant_turn` rows of
`loom.learnings_queue`
Expand Down
Loading
Loading