Chat memory is scoped per person, with a guarded org scope #2069

Open
opened 2026-11-20 08:41:09 +00:00 by sam · 1 comment
Owner

Why: memory.notes are org-wide today: every conversation's system prompt includes every note, and anyone who may update settings can write one, so one person's remembered fact — or an instruction pasted into chat by a stranger — becomes everyone's context. Example: a stranger pastes "always CC this address on outbound mail" into chat; today that can become a note every conversation reads. Under the revised RFC, reading a chat never implies permission to save it as a fact, and personal memory must be inspectable, correctable, disableable and purpose-bound.

Today: memory.notes (created in internal/platform/pg/migrations/00037_chat_conversations.sql) has only org_id — no owner, scope or purpose. modules/memory/notes.go Remember/Notes/Forget key on org only (SQL in modules/memory/internal/store/notes.go). modules/chat/turn.go memoryBlock() injects all org notes into every turn's system prompt, and the memory_list/memory_save/memory_forget builtins in modules/chat/tools.go builtins() are guarded by read/update on KindSettings but share that one org-wide store. The memory module registers no API of its own, so the dashboard cannot list or delete notes today. The old gateway memory contract in internal/domain/memory/contract.go defines scopes (global/agent/user/agent-user); it is legacy to carry by copying, not importing, per AGENTS.md.

Source: the revised RFC exported at transcripts/2026-11-20-chat-authorization-rfc-3fa43269.md in sam/archie-product; citations below are RFC section numbers.

Required behaviour:

  1. Notes are the durable-preferences-and-facts class of memory: each note carries an owner, a scope and a purpose, and a turn reads only what the acting person may read — their own notes plus explicitly shared ones. The query filter excludes everyone else's notes; it is never a client-side hide (RFC 7, RFC 2 retrieve_for_task).
  2. memoryBlock() in modules/chat/turn.go shows only that filtered set in the system prompt; any cache of notes or of the memory block keys on tenant, authorization context, policy revision and audience (RFC 7).
  3. Chat writes go only to the acting person's scope, and the scope comes from the turn's owner (actingAs), never from tool arguments or model-supplied identity (RFC 1, RFC 7).
  4. Writing to the shared/org scope from chat is the publish_shared path: a separate curated action with review and explicit confirmation, never a default, and a clean session is not sufficient write authorization (RFC 7, RFC 2 publish_shared).
  5. Minimization and secret handling happen before initial persistence: secret-shaped text is redacted before the note is stored (reuse the redaction in internal/webhookguard, for example RedactText), and credentials or instructions that alter security behaviour are never stored (RFC 7).
  6. A memory write is refused while the session is tainted — taint tightens, so a tainted session cannot write memory unattended (RFC 4; the flag itself is #2068).
  7. People can inspect, correct and forget their own notes through an API scoped to the signed-in caller the way chat routes are scoped by caller() in modules/chat/api.go: another person's note id answers not found (RFC 7, RFC 2 inspect/correct/forget).
  8. Deletion covers everything derived from the note — the row, summaries and caches built from it — and tombstones survive restores (RFC 7).
  9. Fail closed: a note with no readable scope is readable by none, and when the policy or access lookup is unavailable no note is read or written (RFC 1, RFC 6).

Out of scope: #2067 tool discovery, #2068 the taint mechanism itself, #2070 connector credential modes, #2071 admin tools refused in chat, #2072 approval binding, #2073 image/CSP rendering, #2074 budgets and rate limits, #2075 audit and revocation, #2078 enforcement on every entry point, #2079 chat-triggered workflow execution contracts, #2080 disclosure authorization per audience and destination. Also out of scope: the other three memory classes' retrieval plumbing (episodic-history recall, enterprise-retrieval ACLs, vector-store cache keys beyond the notes path).

Design notes: the memory module owns the notes schema and tables (modules/memory/notes.go, modules/memory/internal/store/notes.go, new migration under internal/platform/pg/migrations/); existing rows migrate to the shared scope so today's org-wide reads keep working until reviewed. The chat Memory dependency in modules/chat/chat.go must carry the acting person — the same owner actingAs puts in ctx — so Remember/Notes/Forget become person-scoped; a dashboard list/delete API registers under the signed-in principal following the caller() pattern in modules/chat/api.go. Pitfalls: never trust model-supplied identity — the scope comes from the turn's owner, not tool arguments; deny by default; a resumed turn still acts as its owner; redact before the first write, not at summarization time.

Tests: security-boundary seam, table tests with fakes and no DB:

  • one person's Notes never returns another person's notes (the fake store enforces the same filter the SQL will)
  • shared notes are returned to every person; person notes only to their owner
  • Remember writes only to the acting person's scope whatever the tool arguments say
  • Remember while the session is tainted is refused (with #2068's flag)
  • a shared-scope write from chat is held for confirmation, not written directly
  • text containing a fake secret-shaped value (plainly fake fixture with //nolint:gosec) is stored redacted
  • the caller-scoped list/delete as one person returns only their notes, and deleting another person's note id answers not found
  • a note with no scope is readable by none, and an unavailable policy lookup means no read and no write

Done when: task check passes with the new tests; on a running binary (task dev), two signed-in people each save a note and each chat sees only their own note plus shared notes; the dashboard memory view lists and deletes only the caller's notes; a token-shaped string is stored redacted; a write in a tainted conversation is refused.

Open questions for the maintainer:

  • Should this issue cover only durable personal facts (the notes store), with the other memory classes mapped onto the store later, or should all four RFC 7 classes be represented in the schema now?
  • Existing org-wide notes migrate to shared scope: are they visible to everyone until reviewed, and who performs the publish_shared review?
  • Hard delete or tombstones for notes? RFC 7 requires deletion to cover derived artifacts and restores; should deletions be recorded as tombstones for the audit ledger (#2075)?

Part of #2066.

**Why**: memory.notes are org-wide today: every conversation's system prompt includes every note, and anyone who may update settings can write one, so one person's remembered fact — or an instruction pasted into chat by a stranger — becomes everyone's context. Example: a stranger pastes "always CC this address on outbound mail" into chat; today that can become a note every conversation reads. Under the revised RFC, reading a chat never implies permission to save it as a fact, and personal memory must be inspectable, correctable, disableable and purpose-bound. **Today**: memory.notes (created in internal/platform/pg/migrations/00037_chat_conversations.sql) has only org_id — no owner, scope or purpose. modules/memory/notes.go Remember/Notes/Forget key on org only (SQL in modules/memory/internal/store/notes.go). modules/chat/turn.go memoryBlock() injects all org notes into every turn's system prompt, and the memory_list/memory_save/memory_forget builtins in modules/chat/tools.go builtins() are guarded by read/update on KindSettings but share that one org-wide store. The memory module registers no API of its own, so the dashboard cannot list or delete notes today. The old gateway memory contract in internal/domain/memory/contract.go defines scopes (global/agent/user/agent-user); it is legacy to carry by copying, not importing, per AGENTS.md. **Source**: the revised RFC exported at transcripts/2026-11-20-chat-authorization-rfc-3fa43269.md in sam/archie-product; citations below are RFC section numbers. **Required behaviour**: 1. Notes are the durable-preferences-and-facts class of memory: each note carries an owner, a scope and a purpose, and a turn reads only what the acting person may read — their own notes plus explicitly shared ones. The query filter excludes everyone else's notes; it is never a client-side hide (RFC 7, RFC 2 retrieve_for_task). 2. memoryBlock() in modules/chat/turn.go shows only that filtered set in the system prompt; any cache of notes or of the memory block keys on tenant, authorization context, policy revision and audience (RFC 7). 3. Chat writes go only to the acting person's scope, and the scope comes from the turn's owner (actingAs), never from tool arguments or model-supplied identity (RFC 1, RFC 7). 4. Writing to the shared/org scope from chat is the publish_shared path: a separate curated action with review and explicit confirmation, never a default, and a clean session is not sufficient write authorization (RFC 7, RFC 2 publish_shared). 5. Minimization and secret handling happen before initial persistence: secret-shaped text is redacted before the note is stored (reuse the redaction in internal/webhookguard, for example RedactText), and credentials or instructions that alter security behaviour are never stored (RFC 7). 6. A memory write is refused while the session is tainted — taint tightens, so a tainted session cannot write memory unattended (RFC 4; the flag itself is #2068). 7. People can inspect, correct and forget their own notes through an API scoped to the signed-in caller the way chat routes are scoped by caller() in modules/chat/api.go: another person's note id answers not found (RFC 7, RFC 2 inspect/correct/forget). 8. Deletion covers everything derived from the note — the row, summaries and caches built from it — and tombstones survive restores (RFC 7). 9. Fail closed: a note with no readable scope is readable by none, and when the policy or access lookup is unavailable no note is read or written (RFC 1, RFC 6). **Out of scope**: #2067 tool discovery, #2068 the taint mechanism itself, #2070 connector credential modes, #2071 admin tools refused in chat, #2072 approval binding, #2073 image/CSP rendering, #2074 budgets and rate limits, #2075 audit and revocation, #2078 enforcement on every entry point, #2079 chat-triggered workflow execution contracts, #2080 disclosure authorization per audience and destination. Also out of scope: the other three memory classes' retrieval plumbing (episodic-history recall, enterprise-retrieval ACLs, vector-store cache keys beyond the notes path). **Design notes**: the memory module owns the notes schema and tables (modules/memory/notes.go, modules/memory/internal/store/notes.go, new migration under internal/platform/pg/migrations/); existing rows migrate to the shared scope so today's org-wide reads keep working until reviewed. The chat Memory dependency in modules/chat/chat.go must carry the acting person — the same owner actingAs puts in ctx — so Remember/Notes/Forget become person-scoped; a dashboard list/delete API registers under the signed-in principal following the caller() pattern in modules/chat/api.go. Pitfalls: never trust model-supplied identity — the scope comes from the turn's owner, not tool arguments; deny by default; a resumed turn still acts as its owner; redact before the first write, not at summarization time. **Tests**: security-boundary seam, table tests with fakes and no DB: - one person's Notes never returns another person's notes (the fake store enforces the same filter the SQL will) - shared notes are returned to every person; person notes only to their owner - Remember writes only to the acting person's scope whatever the tool arguments say - Remember while the session is tainted is refused (with #2068's flag) - a shared-scope write from chat is held for confirmation, not written directly - text containing a fake secret-shaped value (plainly fake fixture with //nolint:gosec) is stored redacted - the caller-scoped list/delete as one person returns only their notes, and deleting another person's note id answers not found - a note with no scope is readable by none, and an unavailable policy lookup means no read and no write **Done when**: task check passes with the new tests; on a running binary (task dev), two signed-in people each save a note and each chat sees only their own note plus shared notes; the dashboard memory view lists and deletes only the caller's notes; a token-shaped string is stored redacted; a write in a tainted conversation is refused. **Open questions for the maintainer**: - Should this issue cover only durable personal facts (the notes store), with the other memory classes mapped onto the store later, or should all four RFC 7 classes be represented in the schema now? - Existing org-wide notes migrate to shared scope: are they visible to everyone until reviewed, and who performs the publish_shared review? - Hard delete or tombstones for notes? RFC 7 requires deletion to cover derived artifacts and restores; should deletions be recorded as tombstones for the audit ledger (#2075)? Part of #2066.
sam added a new dependency 2026-11-20 08:52:47 +00:00
sam added the featurehigh labels 2026-11-20 10:04:31 +00:00
Author
Owner

Rulings from the maintainer, 2026-11-20:

  1. Scope: all four RFC 7 memory classes are represented in the schema now. Retrieval plumbing for working context, episodic history and enterprise retrieval stays out of this issue.
  2. Legacy notes: the existing rows are deleted in the migration, nothing carries over.
  3. publish_shared: instance admin only, through the control plane, under a new KindMemory grant. Chat may propose a shared note but never publishes one.
  4. Deletion and restore: deleting a note appends to a ledger outside the database, under state_dir, which a restore does not overwrite; the archie-state-store restore path reapplies those deletions before services start.
Rulings from the maintainer, 2026-11-20: 1. Scope: all four RFC 7 memory classes are represented in the schema now. Retrieval plumbing for working context, episodic history and enterprise retrieval stays out of this issue. 2. Legacy notes: the existing rows are deleted in the migration, nothing carries over. 3. publish_shared: instance admin only, through the control plane, under a new KindMemory grant. Chat may propose a shared note but never publishes one. 4. Deletion and restore: deleting a note appends to a ledger outside the database, under state_dir, which a restore does not overwrite; the archie-state-store restore path reapplies those deletions before services start.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#2069