Skip to content

Add resource documents: revisioned texts on a resource, governed by its SpiceDB permissions - #90

Draft
josephschorr wants to merge 6 commits into
mainfrom
resource-documents
Draft

josephschorr wants to merge 6 commits into
mainfrom
resource-documents

Conversation

@josephschorr

@josephschorr josephschorr commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Motivation

An agent that maintains shared, long-lived knowledge had nowhere to keep it. Memory pools hold only append-only observation entries, so an agent that wants one current text per resource (and to revise or remove parts of it) could not express that, and could not have the text governed by the same SpiceDB resource that governs the pool.

The shape of the need: one agent keeps a living document per resource and rewrites it on each run, people need to be able to correct it, another agent needs to read it, and an admin needs to see how it changed and who changed it.

Summary of changes

Resource documents: named, mutable-by-revision texts that live in a resource's memory pool.

  • Storage. A new signed, append-only memory kind document_revision. A document is its chain of revisions; there is no head record. A write names the revision it was based on and is refused with 409 if that is no longer the latest (or leaves a gap). Limits: 256 KiB text, 512-byte summary, lowercase names.
  • Permissions. Two new permissions on the resource type: write_document (slottable) and view_document (the audience; never slottable, refused at admission if a class tries). Pools now distinguish memory write grants from document write grants, and a table limits which kinds may enter a resource pool.
  • Tools. read_document, write_document and list_documents, behind an opt-in documents capability.
  • Authorship. Each revision records the session, the agent class and the acting subject: the requester of the turn the write happens on, else the session's run-as subject. The server binds the author's session to the token's session.
  • Leakage gate. Reading a document taints the session with the resource's view_document audience; a write is checked against it.
  • Search. Memory kinds can opt out of search; document revisions do, so they are never indexed or returned by search_memory.
  • Admin console. A Documents page under Audit (gated by view_audit): list, current text, revision history with authors, and a bounded line diff.
  • Docs. site/content/docs/resource-documents.mdx.
  • Unrelated fix found on the way (last commit): limited sqlite memory queries now order newest-first with a stable tie-break; the in-memory search provider had the matching bug when kinds were excluded.

Alternatives considered

  • Files in a workspace or repository. Ruled out: not governed by the SpiceDB resource, and no per-revision author.
  • A mutable head record plus history. Ruled out in favour of revisions only: "create N+1 if absent" gives the write-if-unchanged check without a second record to keep consistent, and the log is the audit trail.
  • Reusing slot_grant_write_memory for document writes. Ruled out: a class allowed to append observations should not thereby be able to rewrite a document.

Provenance

  • Author (person, or model and version): Joseph Schorr
  • Harness or tooling, with version:
  • Person who read the diff:

Ship gate

  • mage test:unit
  • mage test:integration
  • mage test:e2e

Results:

mage test:unit: exit 0, 576 packages
mage test:integration: NOT RUN
mage test:e2e: NOT RUN (a resourcepool document scenario was added under test/e2e/scenarios/resourcepool/document_test.go and compiles with the e2e tag; it has not been executed)

Exercised by hand on OAP Desktop built from this branch: an agent class with the documents capability and a write_document slot created and revised documents on three resources across about a dozen sessions, including concurrent writers (the stale write was refused and the session re-merged).

Regeneration

  • Changed a +kubebuilder:rbac marker or a CRD-shaping field → n/a believed, not re-checked
  • Edited anything under config/** → not re-checked
  • Changed a cobra command or a CRD schema → mage docs:cli / mage docs:crd not run
  • mage fmt:check not re-run on the final head

The docs site build (pnpm check && pnpm build in site/) has not been run.

Coverage

  • This adds user-visible behavior. An e2e scenario was added; no bronzethread bundle exercises it yet.
  • This touches authorization and the SpiceDB schema; mage test:integration and mage test:e2e have not been run.

Before requesting review

  • The PR holds a single change (plus the small query-ordering fix it exposed, in its own commit).
  • A person has read every line of the diff.

Known gaps, not addressed here: a delegated child session's write names the parent's starter; the 64-bit name hash in revision ids is not collision-checked in a few lookups; there is no way for a class to constrain a document's shape, so a model can land a junk revision (seen twice in testing; the next write corrected it).

@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openagentprimitives Ready Ready Preview Dec 3, 2026 10:08pm UTC

Request Review

A limited query had no ORDER BY, so which rows it returned was up to
sqlite. Order by created_at descending with the entry id as a stable
tie-break.
A resource document is a chain of signed, append-only revisions in the
resource's memory pool; there is no head record. A write names the
revision it was based on and is refused if that is no longer the
latest. Pools tell document write grants apart from memory write
grants, a table limits which kinds may enter a resource pool, and a
kind can opt out of search, which document revisions do.
write_document is a slottable permission on the resource type;
view_document is the audience and is refused as a slot at admission.
Reading a document taints the session with the audience, and a write
is checked against it.
read_document, write_document and list_documents, offered only to a
class that opts into the documents capability. A revision's author is
the session, the agent class and the requester of the turn the write
happens on, else the session's run-as subject.
Lists resource documents and shows a document's current text, its
revision history with authors, and a bounded line diff between
revisions. Gated by view_audit.

This branch was successfully deployed

1 active deployment
Preview — 8ff26e4e Deployed Dec 3, 2026 by vercel[bot]
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.

1 participant