Stewardship
Stewardship records who answers for a shared memory or a document, how often it is reviewed and each review of it.
Stewardship records who answers for a shared memory or a document, how often it is
reviewed and each review of it. A namespace admin names a steward with
stewardship.assign, a person who
can write the namespace records a review of the content they read with
stewardship.review, and every viewer of the namespace reads who maintains what with
stewardship.list and stewardship.get. This page covers the table, how a state is
derived, what a review writes, what erasure removes and the rolling-upgrade rule. The
caller’s side is in
history and provenance.
A state describes attention, never truth. No read, rank, expiry, pin or authorization
path reads a stewardship row or imports the modules that derive a state
(tests/unit/test_stewardship_is_contained.py), so an overdue memory or document is
served and ranked exactly as a current one.
The row
loom.stewardship_events is an append-only MergeTree sorted by
(org, namespace, target_kind, target_key, agent, at). Each row is one event of one
target:
| Column | Holds |
|---|---|
target_kind, target_key, agent |
The target: a shared memory, a document, or the namespace itself. |
at |
When the row was written, to the millisecond. |
event |
assign or review. |
steward, review_every_days |
An assign row: who answers, and the review interval in days. |
result, sha256, target_version |
A review row: the verdict, and the content hash and version it read. |
actor |
Who wrote the row, as the server labels every writer. |
A memory target is the row (agent, target_key) whose user_id and session_id are
-: only a row the whole namespace reads takes a steward. A document target is the
document of the namespace whose source_uri is target_key and whose user_id is -,
stored under the agent - whatever agent a call carries: a document has no agent in its
address. A memory and a document of one name are two targets, since target_kind is
part of the address. The namespace target has no key and is stored under the agent -
too; its steward is the fallback for every item whose own steward cannot act.
The row departs from the identity tuple in two ways, both on purpose:
- No
user_idand nosession_id. A target is a shared row, which has neither, and an assignment is made for the namespace, not for one end user or session. - No
source_class. A row is an administrative act of itsactor, not memory content that entered through a write path, so there is no provenance to downgrade.
The newest assign row of a target is its steward and interval, and the newest review
row is its last review. Nothing is updated in place outside erasure, so no read uses
FINAL. A write of a call that read an earlier row is stamped after it: one millisecond
past the target’s newest row when the clock is not past it (next_at in
server/memory/domain/stewardship.py), so the later write wins on every replica. Two
calls at once can stamp the same millisecond; both statements order such rows by their
other columns, so rows of one millisecond read the same on every call. The insert is
synchronous, and every statement on the table runs with sequential consistency
(own_write_reads), so a list on one replica reads an assignment another replica just
wrote.
How a state is derived
Nothing about a state is stored. Each read derives it from the target’s newest
assignment and review, the live head of the memory or the document, the steward’s direct
grant, the revocation list, the org’s groups and the clock
(state_of, steward_problem in server/memory/domain/stewardship.py). An interval
change, a revoked grant and an edited memory or document therefore show on the next
call.
The live head comes from live_revisions, the read memory.get serves its hash from,
with the whole namespace as its scope (stewardship_heads in
server/memory/app/stewardship.py). A head is reviewable when the row is live, shared,
served by the namespace, not of high sensitivity and at most 16,384 bytes. Under the
Postgres memory authority the read waits until ClickHouse holds what was committed.
ClickHouse can still trail the authority’s head of a key: a write committed after the
wait began, or one whose delivery is parked. Such a memory is live: its head is read
once more, and while ClickHouse still trails, the call answers 503 with a one-second
retry, never missing.
A document’s head comes from document_heads in server/knowledge/store/documents.py,
one statement for every document item of the call. It reads the row’s version, its
stored content_sha256 and its user_id, and never the title or the text. The hash is
the one the write path stored for the title and the text in their canonical form
(sha256_document_text), the value knowledge.get returns and knowledge.dedup_list
groups by; stewardship computes no hash of a document. A head is reviewable when the
document is live, belongs to the namespace itself and stores a hash. Under the Postgres
authority the newer of the committed head and the ClickHouse row answers, so a document
committed and not yet delivered reads as it was committed and the call has nothing to
wait for. A head keeps the whole document row, text included, in one value, and Postgres
reads all of it to answer one key. The statement is therefore sent the version
ClickHouse holds of each document and reads the hash only of a head newer than that.
The first rule that holds is the state:
| State | Holds when |
|---|---|
missing |
The memory or the document has no reviewable head. |
never_reviewed |
The target has no review. |
out_of_date |
The newest review read other content than the live head. |
correction_requested |
The newest review asked for a correction. |
needs_evidence |
The newest review asked for evidence. |
overdue |
The newest review confirmed the content, and the interval has passed. |
due |
The interval passes within 14 days. |
current |
None of the above. |
next_review_at is the time of a confirming review of the live content plus the
interval in force, and null without such a review. It is never stored, so a changed
interval applies at once and no call can push a date out.
A problem says why the named steward cannot act, apart from the state:
| Problem | Holds when |
|---|---|
unassigned |
The item has no steward. |
steward_revoked |
The steward’s sign-in is revoked. |
steward_no_grant |
The steward holds no direct grant of writer or above on the namespace. |
group_inactive |
The steward is a group that no longer exists or has no member. |
responsible is the account that should act: the steward when it is a person with no
problem, else the namespace’s fallback steward when that one has none, else empty. An
item whose stewardship ended names nobody: its steward’s standing is not read.
Assigning
stewardship.assign needs the admin role on the namespace, is audited, and appends a
row only when the steward or the interval differs from the stored one; a repeat answers
changed: false. A field the call leaves out keeps its stored value. An assignment
appends a row and updates none, so a reassignment keeps every review.
- The steward is a Loom account or
group:<id>. An account must hold a direct grant of writer or above on the namespace and be able to sign in; a role carried only by a token is not a grant (direct_rolesinserver/identity/app/direct_roles.py). A group must be live and have a member. The fallback steward is a person. Only a steward that differs from the stored one is checked, so an admin can change the interval of an item whose steward has a problem. - The interval is 30 to 730 days; 0 ends stewardship of the item and keeps its rows.
- An item put under stewardship needs a reviewable head, and a namespace holds at most 500 such items, memories and documents together. A document that is missing or belongs to one user answers 404 in the same words, so the answer does not say which; one stored without a hash answers 422. The ceiling is read and then written without a claim, so concurrent calls can pass it by a few; a list reads up to 1,000 rows and fails past that instead of serving a cut list as whole.
Two calls on one target at once each append a row, and the later one is the assignment. When each sends a different single field, the later row carries the stored value of the field it left out, so one of the two changes is lost.
Reviewing
stewardship.review needs the writer role on the namespace, is audited, and takes a
result (confirmed, correction_requested or needs_evidence) and if_match_sha256,
the content_sha256 that memory.get or, for a document, knowledge.get served with
the text the reviewer read. It appends one review row and changes no value. Being
named the steward grants nothing: any person who can write the namespace reviews, and
the row names who did. The namespace target takes no review.
- The caller is a person. A service account and a call with no principal answer 403:
a review says somebody read the text.
actorcomes from the token; no field of the request names a reviewer or a date. - The item is under stewardship and its head is reviewable, by the read the list
derives
missingfrom (stewardship_heads,document_heads); else 422. - The hash names the live content. The handler reads the head with sequential
consistency, and other content than
if_match_sha256answers 409PRECONDITION_FAILEDwithcurrent_sha256in its detail, never in its message. Nothing is written. - A document’s review writes the review row and nothing else. A document has no
attestation, so no result of its review calls the
memory.verifyhandler, andtarget_versionis the version of the row the head read returned. The hash is compared once, against that read: an edit that lands between the read and the insert leaves a review of the content the reviewer named, and the item readsout_of_dateon the next call. - A memory’s confirm attests. It calls the
memory.verifyhandler with the same hash, which checks it again under its own head fence, so the memory reads verified by the reviewer. The other two results remove a live attestation of the reviewed content through the same handler, so a review that asks for a correction leaves behind no attestation it found. Content nobody attested takes no memory write. - The review row is written last, stamped one millisecond past the target’s newest review when the clock is not past it. A failed attestation or revoke records no review. A failed insert after it leaves the item as it read before; the retry finds the attestation in place, writes the memory no second time and appends the row. The insert is the call’s last statement: the item it answers is built from what the call read before its writes and the row it writes, so a review that was recorded never answers a failure that a retry would turn into a second row.
target_versionof a memory’s review is the version the attestation or the revoke wrote, else the head’s: the live version straight after the review.
Verifying a memory outside a review records no review, and removing a verification does not undo one: the two acts are compared in history and provenance. Two reviews of one item at once each append a row, and the later one is the item’s last review. The attestation and the newest review can disagree in three cases, each until the next review of the item:
- A confirm overlaps a correction request, and attests after the other call found nothing to remove. The memory reads verified by the confirmer under a newest review that asks for a correction.
- A confirm overlaps a correction request that removes the confirm’s attestation and
writes its row before the confirm writes its own. The newest review is the confirm, so
the item reads
currentwhile the memory is not verified. - A confirm’s attestation is written and its review row is not. The memory reads verified by the confirmer, and the item reads as it did before, until the retry.
Cost
A list derives every item of the namespace whatever its filters: one read of the
namespace’s rows, the heads of its items, and one read of the namespace’s grants for
every steward named. A steward with no grant under its own spelling also takes a cached
read of the account’s other spellings. Apart from that read, the number of statements
does not grow with the number of items. OP_BUDGETS_P99_MS in
server/settings/catalog.py holds the budget of each op, and
tests/integration/test_stewardship.py runs a list at the ceiling against it.
Erasure
loom.stewardship_events has a census row and two steps
(server/erasure/store/census.py, server/erasure/store/steps_ledgers.py):
- A namespace erasure deletes the namespace’s rows (
stewardship.delete). - A user erasure blanks the user as steward and replaces the user as
actorwith<erased>(stewardship.scrub), in every spelling of the subject. An assignment made after the step can name the user again: the census counts that row, and a resumed saga runs the step again. The item stays under stewardship and readsunassigned.
A deleted or renamed memory keeps its stewardship rows, and so does a deleted or moved
document: the item reads missing until an admin ends it. Loom deletes only what its
writer asked to delete. A row holds the document’s source_uri and the hash of the
reviewed content, never its title or text.
What fails closed
| Condition | Answer |
|---|---|
| A live replica predates the table, or the fleet is not read | stewardship.assign and stewardship.review answer 503 with a 30-second retry. |
| A review by a service account, or with no principal | 403, nothing written. |
| A review of other content than the memory holds | 409 with the live hash; no attestation, revoke or review. |
| A review of other content than the document holds | 409 with the live hash; no review. |
| A document belongs to one user, or its row stores no hash | It takes no steward (404 for a user’s document, 422 for one without a hash); an item that came to hold such a head reads missing and takes no review. |
| The memory moves under the attestation or the revoke | 503 from the memory’s write fence; no review is recorded. |
| The steward’s grant is revoked or expired | steward_no_grant on the next read, never a silent pass. |
| The steward cannot sign in | steward_revoked on the next read. |
| A memory is revised while its head is read, twice | 503 with a one-second retry, never a guessed state. A review reads its head before it writes, so it has recorded nothing. |
| ClickHouse does not hold a committed write within the wait | 503, never a state from a stale head. |
| ClickHouse trails the authority’s head of a memory, twice | 503 with a one-second retry, never missing or a 422 for a live memory. While the head’s delivery is parked, the call answers this 503 until the delivery is retried (delivery). |
| The namespace holds more items than one list reads | The list fails instead of serving a cut list. |
Rolling upgrades
A build without the table has no erasure step for it. So stewardship.assign and
stewardship.review refuse while any live replica’s schema version is below the table’s
migration, or no heartbeat has been read (require_fleet, STEWARDSHIP_MIGRATION); the
two reads are served. A build that has the table and not stewardship.review answers
404 for it, and reads the review rows a newer replica wrote: its state function and
both statements already read them
(rolling upgrades, rule 87). A build that knows no document
target refuses that kind on its three addressed ops with 422 and leaves the document
rows a newer replica wrote out of its list and its counts, so it serves no document item
under a memory’s name; the same rule says what an operator sees meanwhile. After a
rollback, an erasure the older build runs leaves the rows; the
rollback note says what to run again.
Source entry points
server/memory/domain/stewardship.py— the two vocabularies, the constants and the state function.server/memory/app/stewardship.py— the four handlers,stewardship_heads,require_fleet.server/knowledge/store/documents.py—document_heads, the head read of a document target, withhead_hashesinserver/knowledge/store/pg_documents.pyunder the Postgres authority.server/memory/app/verify.py—handle_memory_verify, which writes and removes the attestation of a review.server/memory/store/stewardship.py— every statement on the table.server/identity/app/direct_roles.py— the direct grant of each subject.server/erasure/store/steps_ledgers.py—delete_stewardship_by_namespace,scrub_stewardship_by_user.
Invariants
- A state is derived on read and never stored.
- No read, rank, expiry, pin or authorization path depends on a stewardship row.
- A revoked or ungranted steward reads as a problem, never as
currentwithout one. - A review binds the hash its caller read; no 2xx answer carries content or a hash.
- A review changes no value, and one of a memory that asks for a correction or for evidence is recorded only after the attestation it found on that content is removed.
- A document’s hash is the one its row stores: stewardship reads it and computes none, and reads no title or text of a document.
- A document that belongs to one user is never a target, and answers as a missing one.
- Every statement on the table binds its scope and runs with sequential consistency.