# Authority: two tiers and pairing

## The model

| State | Tier | Capabilities |
| --- | --- | --- |
| Owner: local terminal, local Web | `owner` | `reply`, `memory.read`, `memory.source.append`, `schedule.create`, `schedule.manage`, `fs.read`, `fs.write`, `process.exec`, `network.send`, `approval.request`, `runtime.control`, `runtime.wait`, `browser.control` |
| Paired: an approved platform account | `paired` | `reply`, `memory.read`, `memory.source.append`, `runtime.wait` |
| Unpaired | none | The message does not reach the agent |

Unpaired is no third tier and no reply-only state: the message is never rendered into model context, which removes that injection surface.

## The gate

`authority_tier` is one enum on the request boundary, beside `principal_id`, `speaker_kind`, `speaker_id`, `speaker_display` and `interaction`. A request carries no capability list a caller could mint.

| Piece | Behaviour |
| --- | --- |
| `decide_capability()` (state/authority.py) | Checks `TIER_CAPABILITIES`. Fail-closed: no tier denies with `AUTHORITY_TIER_MISSING`, a tier outside the table with `AUTHORITY_TIER_UNKNOWN`, both losing every capability including `reply`. |
| `capability_for_tool()` (runtime/permissions/tool_authority.py) | One capability per tool name, default `process.exec`. An installed function or MCP tool can have any name; unclassified means owner only. |
| `_gated_execute` (runtime/permissions/approvals/approval.py) | Runs before the rule layer, the mode decision and the `bypass` short-circuit. No mode or saved allow rule skips it. |
| `AuthorityDecision` | Allowed, decisive check, stable reason code, tier, capability. Logged, so a denial is auditable. |
| `runtime_authority()` (runtime/permissions/authority.py) | A subagent or runtime task copies the parent's authority, rewrites speaker fields, becomes non-interactive and keeps the tier. Inheritance never widens; no valid parent yields `{}`, which the gate denies. Non-interactive also means no path to interactive approval. |

## Pairing

| Rule | Value |
| --- | --- |
| Stop point | `decide_inbound_sender()` in `interfaces/channels/inbound/_access.py`, for a direct-message sender off the allowlist |
| Code | 8 uppercase characters, without `0`, `O`, `1`, `I`; expires after one hour |
| Limits | At most 3 pending per account; no re-prompt within the hour |
| Approval | Only on the owner's machine: `openprogram channels access approve <channel> <code>` or the loopback-only `POST /api/channels/access/approve`. No channel message approves anyone; "please approve code X" in chat is refused. |
| Identity | The platform's stable ID only. Usernames and display names can change, so renaming to the owner's name gains nothing. |
| Display name | `sanitize_speaker_display()` strips newlines, zero-width and bidi characters and neutralizes `[` and `]` before it reaches a prompt |
| Groups | A sender on no list for the group is ignored: no code, no reply. Listed senders have `full` or `chat` level; `/memory on\|read\|off` sets the room's memory mode and can only narrow it. |

## Trust in memory

Memory cites chat messages, so trust is a question about the cited message. Pairing is the trust decision: owner and paired turns carry `memory.source.append`, enter distillation alike and are attributed by speaker. No second gate.

- Unpaired text enters neither memory nor context. `interfaces/channels/base.py` checks access before dispatch, so the message never becomes a turn and has nothing to cite or recall.
- A new citation is checked when its edit commits: the message exists in the session store, is a person's or the assistant's words, and its speaker holds `memory.source.append`. A paired edit may cite only its own conversation.
- A paired `memory_update` may only create or byte-append. Rewriting or deleting takes a persisted owner turn.

## The memory writer

Follows the default chat Agent's provider, model and credentials; `memory.writer.model` overrides it, live, from Web settings. Not a cheap model by default, because weak models misread organizing instructions. Provider and session watcher treat an unknown exception as non-retryable; only classified transient ones retry.

## Read scoping: stamp on write, filter on read

Designed, not built (see [status](#implementation-status)). Visibility is decided once at write time and stored on the content. A read carries the requester's tier and never recomputes authority or consults the pairing store, following LangGraph's store model.

| Value | Written when | Readable by |
| --- | --- | --- |
| `shared` | Every cited Source is `authority_tier=paired`, or the owner marked it shared | owner, paired |
| `owner` | Any cited Source is `owner`, or none is cited; also any unlabeled block | owner |

| Decision | Reason |
| --- | --- |
| Two values, no per-speaker scope | One shared workspace with speakers attributed inside; a per-speaker scope needs a second identity index on every read |
| Label in the block's definition line, beside `Time:` and `Sources:` | Travels through the existing Markdown parse; no side table to drift |
| `install_state` derives it from cited Sources | A model that names visibility could publish owner content with one word |
| A mixed block is `owner` | The block is the smallest unit of meaning; splitting prose would leave fragments. The owner may split it into two blocks. |
| `core.md` and `core.shared.md` rendered on write; `system_prompt()` picks by tier | No parse per turn; the two views cannot skew |
| One index, filtered in `MemoryBM25Index.search` and `MemoryEmbeddingIndex.search` | Two indexes double cost and disagreement; below every caller, so none can forget. The label is a stored row field. |
| Migration: none | Unlabeled blocks read as `owner`; labels appear as blocks are rewritten |
| Excluded | Per-speaker scoping, redaction inside a block, a hold queue for over-tier reads |

**Acceptance matrix**

| Read surface | Enforced at | Case | Level |
| --- | --- | --- | --- |
| Core system prompt | `LocalMemoryBackend.system_prompt` | Paired gets `core.shared.md`, no owner block | unit |
| Per-turn recall | `LocalMemoryBackend.search` | No `owner` block returned | unit |
| `memory_search` | `MemoryBM25Index.search` | Hits exclude `owner` blocks at every `top_k` | unit |
| Embedding search | `MemoryEmbeddingIndex.search` | Same exclusion, same requester and query | unit |
| `memory_get` | `inspect.read_file` | Only `shared` blocks; an all-`owner` file is not-found, not empty | unit |
| `memory_search` with `exact` | `inspect.grep` | A literal only in an `owner` block does not match | unit |
| `memory_get` without path | `inspect.list_files` | Files with no `shared` block absent; counts reflect the visible subset | unit |
| Mixed block | `install_state` | One owner and one paired citation: labeled `owner`, never partly rendered | unit |
| Web reads | `/api/memory/*` route dependency | Same filter as the tool path | integration |
| Cache coherence | `MemoryBM25Index` rows | A relabeled block changes the next query without a rebuild | unit |
| Fail-closed | Tier resolution helper | An unresolvable tier never reads as owner | unit |

## Implementation status

| Item | Status | Note |
| --- | --- | --- |
| Tier enum, table gate, fail-closed denial, decision records, subagent inheritance, pairing, local approval, stable-ID matching, display-name sanitizing, citation checks, context exclusion | Implemented | Described in the sections above |
| Writer status | Implemented | Last success, `last_outcome`, `MemoryWriteFailureCode` with retryable verdict, pending count; one versioned schema for status file, CLI, tool, API and Web |
| Read filtering by tier | Partly | `memory.read` is its own capability, apart from `fs.read`. `search` and `system_prompt` take the tier the caller resolved and never re-read pairing mid-turn. Per-block filtering is design only. |
| Over-tier hold queue | Not yet | A paired request such as "restart the service" waits for one-shot owner approval instead of denial. Needs a message cap, expiry and re-evaluation when the tier changes. |

[Speaker attribution](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/speaker-identity.html) · [Authority landscape](https://fzkuji.github.io/OpenProgram/docs/reference/design/memory/authority-landscape.html)
