Skip to content
2 changes: 1 addition & 1 deletion .changeset/3963-dialogue-account-ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@schlessera/brain-ui-server": minor
---

An owner can continue a chat by voice from another device (#3963). Every owner sign-in is its own principal, and a chat's retained voice history belonged to the exact login that started it, so a second login was refused with "Dialogue ownership mismatch". That history now belongs to the account, as its safety history does: another owner login opens voice on it, reads it, binds it and receives its live pages, also after the starting login has been pruned. A typed-first chat's first voice from either login uses the chat's own history owner. A live conversation and its epochs stay with the login that opened them (migration 090 records it), so sharing the history gives no control over another login's conversation. Agents, ambient, system and unknown principals still match only themselves, a pruned or revoked login regains nothing, corrupt or contradictory ownership is refused, coverage stays honestly `legacy` or `partial`, and exact-principal chat deletion is unchanged.
An owner can continue a chat by voice from another device (#3963). Every owner sign-in is its own principal, and a chat's retained voice history belonged to the exact login that started it, so a second login was refused with "Dialogue ownership mismatch". That history now belongs to the account, as its safety history does: another owner login opens voice on it, reads it, binds it and receives its live pages, also after the starting login has been pruned. A typed-first chat's first voice from either login uses the chat's own history owner. A live conversation and its epochs stay with the login that opened them (migration 090 records it), so sharing the history gives no control over another login's conversation. Agents, ambient, system and unknown principals still match only themselves, a pruned or revoked login regains nothing, corrupt or contradictory ownership is refused, coverage stays honestly `legacy` or `partial`, and chat deletion keeps its own admission rule (#4138).
5 changes: 5 additions & 0 deletions .changeset/4138-same-account-chat-deletion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": minor
---

A chat two owner logins used can be deleted by either of them (#4138). Every owner sign-in is its own principal, and explicit chat deletion compared exact principals across the chat's ownership records, so a chat continued by voice from a second device was refused to both logins as `unavailable`. `POST /api/chat-deletions` now admits any usable owner login when every recorded owner (the dialogue owner, each voice epoch, the typed-creation binding, a provisional chat's safety collections) proves that same owner account, also after another login has been pruned. A typed turn's safety collection that no session has bound yet counts as one more record, under a provisional or a session chat's history owner. Migration 091 stores the durable account beside each voice epoch and typed-creation binding, from the principal's own row, and backfills legacy rows only where a principal row still proves it. A record of another account, a pruned login with no stored account, or corrupt or contradictory evidence still refuses that chat alone. The caller is checked from its own current row against the current clock at admission and at commit, so a login that expires while the request waits is refused; revoked, expired, agent, ambient and system callers stay `unauthorized`. The operation, its receipt and its retry key stay with the login that started it, original attribution is never rewritten, and live conversation and epoch control, busy refusal, stale review, permanent fences and per-store outcomes are unchanged. No request, receipt or refusal shape changes.
69 changes: 65 additions & 4 deletions docs/decisions/chat-history-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ open implementation scope lives in the tracker.
Only an authenticated owner may delete its own chat. Preserve exact principal
ownership and recheck current authorization, including revocation, at admission
and across asynchronous boundaries. No cross-principal power, reassignment,
agent authority or arbitrary filesystem authority follows.
agent authority or arbitrary filesystem authority follows. The
[same-account amendment](#same-account-deletion--2026-11-17-4138) narrows the
exact-principal rule for one case: another current login of the same owner
account may delete a chat whose every ownership record proves that account.
Ambient authentication requires an explicit owner mapping; otherwise deletion
is unavailable. Read access, labels, voice recognition and conversation content
are not authorization. Existing [principal boundaries](session-principals.md)
Expand Down Expand Up @@ -91,10 +94,10 @@ prompt, title, label or transcript text. The bridge offers the creator only on
a new turn that is not host work and whose authorization is current
(`const creator`, `packages/ui-server/src/ws/bridge-capabilities/emission.ts:143`). The write worker
binds it only in the transaction that first creates the session's row
(`upsertSession(row: SessionRow)`, `packages/ui-server/src/ws/session-catalog-writes.ts:169-178`).
(`upsertSession(row: SessionRow)`, `packages/ui-server/src/ws/session-catalog-writes.ts:170-182`).
`resolveChat` counts the row as one more ownership record beside dialogue
owners and voice epochs, so records that disagree still refuse as ambiguous
(`const creator`, `packages/ui-server/src/ws/chat-lifecycle.ts:91-92`). Like the
owners and voice epochs, so records of different accounts still refuse as
ambiguous (`const creator`, `packages/ui-server/src/ws/chat-lifecycle.ts:102-103`). Like the
permanent fences, the row is identity data and stays after a deletion cleans
the chat's stores.

Expand Down Expand Up @@ -126,6 +129,64 @@ the endpoint and store cleanup this record feeds.
This adds no wire shape: the `POST /api/chat-deletions` request, receipt and
refusal shapes are unchanged, and the row is internal storage.

## Same-account deletion — 2026-11-17 (#4138)

**Decided by the maintainer on 2026-11-17**:
[#4138 ruling](https://github.com/schlessera/brain-kit/issues/4138#issuecomment-6943093310),
option B. Every owner sign-in mints its own principal
([session principals](session-principals.md)), and a chat's retained history
belongs to the account, so a second login of the same owner continues it by
voice ([#3963](https://github.com/schlessera/brain-kit/issues/3963)). Deletion
still compared exact principal IDs across the chat's ownership records, so a
chat two logins had used was refused to both of them as ambiguous ownership.

**The amendment.** Any currently authorized owner login may explicitly delete a
chat when every deletion-relevant ownership record is verified as belonging to
that same owner account. This narrowly amends the exact-principal deletion
rule under [Authority and extent](#authority-and-extent). Shared read access
alone never grants deletion authority.

- **Which records.** Every record `resolveChat` consults: the canonical
dialogue owner, each recorded voice conversation epoch, the typed-creation
binding and every safety collection a typed turn left under any of the
chat's history owners before a session bound it, for a provisional chat and
a backend session's chat alike (`resolveChat`, `packages/ui-server/src/ws/chat-lifecycle.ts:87-146`).
Each must prove the caller's account; one that does not refuses the whole chat
(`chatOwnedBy`, `packages/ui-server/src/ws/chat-lifecycle.ts:158-160`).
- **What proves an account.** The record principal's current row, or the
durable account the server stored beside the record when it wrote it
(`principal_account`, migrations 089 and 091). Migration 091 adds that
column to `conversation_epochs` and `chat_session_owners`, and the writers
fill it from the principal's own row. A pruned historical login is
recognized only through that stored evidence. Missing, corrupt or
contradictory evidence, a stored account that a live row disagrees with, or
records of mixed accounts refuse as `unavailable`, within that chat only.
Legacy rows are backfilled only where a principal row still proved the
account at upgrade; the others stay unknown and keep refusing.
- **What authorizes the caller.** Only its own current principal row, re-read
at admission and again in the commit transaction, each time against the
current clock rather than the time the request was stamped, so a login that
expires while the request waits on the catalog or the writer is refused. A revoked, expired or
pruned caller gains nothing from any record's stored account. Agent,
ambient and system principals have no account that holds across auth modes,
so their records match only themselves and they never gain an account-wide
exception.
- **What stays exact.** The operation, its receipt and its retry key belong to
the login that started it: another login of the account reads
`not_admitted` and cannot retry it. The lifecycle records that initiating
login; no record's original principal is rewritten or reassigned. Live
conversation and epoch controls stay with the exact login that opened them.
Busy refusal, stale generation and backend review, the permanent fences and
per-store outcomes are unchanged. The `chat_retired` frame still goes to the
initiating login's capable connections; every other reader, another login's
devices included, already refuses the retired chat.

Exact-principal-only deletion was rejected because it strands shared chats.
Creator-only deletion was rejected because a missing first login still strands
them and it needs another durable creator model. No request, receipt or
refusal shape changes; the admission semantics in
[the HTTP reference](../http-api.md#explicit-chat-deletion-additive-3230) do.

## Compatibility and rejected alternatives

This decision approves the explicit retention exception, not a shipped machine
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ The brain's git history stays the durable record of its content.
- **The Activity recorder and its rollups** price those events under the
[cost-tracking rules](cost-tracking.md). An unknown price is never counted as
zero. The session total that counts unknown as zero
(`msg.costUsd ?? 0`, `packages/ui-server/src/ws/session-catalog.ts:511`)
(`msg.costUsd ?? 0`, `packages/ui-server/src/ws/session-catalog.ts:512`)
must not feed any budget.

**Enforcement:**
Expand Down
22 changes: 16 additions & 6 deletions docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1362,19 +1362,29 @@ recorded owner; the same answer whichever), 409 `stale` (the backend or
generation differs from `expected`), 409 `unsupported` (the chat's backend does
not advertise and implement native removal) or 409 `busy` (a running or starting
turn, queued follow-ups or unsettled live-conversation work; stop or finish it
first). A chat's recorded owner is its dialogue owner, its voice conversation's
principal or, since #3337 (additive), the authenticated principal whose typed
request created its backend session. A typed chat whose session already existed
before that binding (or that the host first saw on a resume) has no recorded
owner and stays `unavailable`; none is backfilled. Otherwise the chat is
retired and the answer is 200 with the SDK's
first). A chat's recorded owners are its dialogue owner, each voice
conversation's principal and, since #3337 (additive), the authenticated
principal whose typed request created its backend session. A typed chat whose
session already existed before that binding (or that the host first saw on a
resume) has no recorded owner and stays `unavailable`; none is backfilled.
Since #4138, any usable owner login is admitted when **every** recorded owner
is the same owner account: the caller's own login, or another owner login
proven by its current principal row or by the durable account the server stored
beside that record when it wrote it, which outlives the login's pruning. A
record of another account (an agent, an ambient or a system principal), a
pruned login with no stored account, or corrupt or contradictory evidence is
`unavailable`, for that chat only. Stored evidence never authorizes the caller,
which is still checked from its own current row at admission and again at
commit. Otherwise the chat is retired and the answer is 200 with the SDK's
`ChatDeletionReceipt`: `operationId`, the terminal `generation`, the overall
`status`, each selected store's outcome (`native` for a backend session,
`dialogue`, `tasks`, `projections`, `drafts`) and `retained`, which always lists
`independent_content`, `effects_and_audit`, `provider_copies`, `backups` and
`offline_devices`. `status` is `removed` only when every selected store confirmed
removal; `pending`, `partial` and `unknown` say cleanup is not confirmed, and
repeating the same `operationId` retries it. A host restart also resumes it.
The operation stays the initiating login's: another login of the same account
that sends its `operationId` gets 404 `unavailable` and retries nothing.
The handler re-checks the principal after its asynchronous steps and answers a
revoked one with the guard's 401, disclosing nothing. A storage failure before a
receipt exists is 500 `{ error: "CHAT_DELETION_FAILED", message }`, never a
Expand Down
14 changes: 14 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,20 @@ answer as for a chat that does not exist. The session catalog's
No request, receipt, frame or field shape changes, and paging and retention of
undeleted chats are unchanged. This ships in a minor.

## Same-account chat deletion (additive, #4138)

`POST /api/chat-deletions` ([HTTP](http-api.md#explicit-chat-deletion-additive-3230))
now admits any usable owner login when every recorded owner of the chat proves
that same owner account, so a chat two owner logins used, by voice or by typing,
is deleted by either of them, also after the other login is pruned. A chat with
a record of another account, or with missing, corrupt or contradictory account
evidence, still refuses as `unavailable`. The operation, its receipt and its
retry key stay with the login that started it. Agent, ambient, system, revoked
and expired callers are still `unauthorized`. No request, receipt, refusal or
frame shape changes, and live conversation and epoch control is unchanged
([decision](decisions/chat-history-deletion.md#same-account-deletion--2026-11-17-4138)).
This ships in a minor.

## Native history removal (additive, #3229)

`BackendCapabilities.historyRemoval?` and the optional
Expand Down
3 changes: 2 additions & 1 deletion docs/integration-contract/wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -2856,7 +2856,8 @@ What stays exact:
which before this change was always the opening login.
- An agent, ambient, system or unknown principal matches only itself. A
pruned, expired or revoked login regains nothing: the caller is still a
current, authorized login. Exact-principal chat deletion is unchanged.
current, authorized login. Chat deletion by another login of the account
follows its own rule ([#4138](../integration-contract.md#same-account-chat-deletion-additive-4138)).
- History whose login was pruned before it stored an account stays unknown
and refused. Corrupt or contradictory stored evidence matches nobody, its
own principal included, and refuses only that chat.
Expand Down
15 changes: 9 additions & 6 deletions docs/plans/chat-history-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Approval supplies no automatic expiry, routine live cutoff or implementation
release commitment.

**Built (#3228):** the internal, content-free retirement ledger and gate
(`retireChat`, `packages/ui-server/src/ws/chat-lifecycle.ts:169-202`;
(`retireChat`, `packages/ui-server/src/ws/chat-lifecycle.ts:204-244`;
migration `073_chat_lifecycle.sql`). It re-reads owner authority in the
serialized writer, resolves the exact identity set from recorded dialogue
owners, aliases and voice epochs, refuses unknown/foreign/stale/unsupported/busy
Expand Down Expand Up @@ -60,10 +60,10 @@ The bridge offers the creator only on a new, non-host-work turn whose
authorization is current
(`const creator`, `packages/ui-server/src/ws/bridge-capabilities/emission.ts:143`). The write worker
binds the creator only in the transaction that creates the session's row
(`upsertSession(row: SessionRow)`, `packages/ui-server/src/ws/session-catalog-writes.ts:169-178`).
(`upsertSession(row: SessionRow)`, `packages/ui-server/src/ws/session-catalog-writes.ts:170-182`).
`resolveChat` counts the binding as one more ownership record beside dialogue
owners and voice epochs, so a disagreement among them still refuses as ambiguous
(`const creator`, `packages/ui-server/src/ws/chat-lifecycle.ts:91-92`). A typed
(`const creator`, `packages/ui-server/src/ws/chat-lifecycle.ts:102-103`). A typed
chat's owner can now delete it through `POST /api/chat-deletions`. A chat whose
session existed before the binding still refuses as `unavailable`, and so does a
native-only session the host first sees on a resume. A foreign principal gets
Expand Down Expand Up @@ -94,7 +94,10 @@ for native layout and removal; browser clients invalidate their projections.
There is no generic storage plugin, second dialogue store or replacement timeline.

Only an authenticated owner may delete its own chat, with exact principal
ownership and current authorization at admission and asynchronous boundaries.
ownership and current authorization at admission and asynchronous boundaries
(narrowed by the [same-account amendment](../decisions/chat-history-deletion.md#same-account-deletion--2026-11-17-4138):
another login of the same owner account deletes a chat whose every ownership
record proves that account).
Agent principals cannot delete history. Ambient authentication requires an
explicit owner mapping; without one deletion is unavailable. Neither labels,
history-read access nor speech grants authority. No cross-principal deletion
Expand Down Expand Up @@ -198,9 +201,9 @@ must be tested through their installed runtime, not inferred from directory name
`070_conversation_result_facts.sql` retain epochs, detailed JSON receipts
(including submitted context), bounded result facts and independently consumed
native/task/request identities. Content retention and identity retention differ
(`saveConversationTask`, `packages/ui-server/src/ws/conversation-storage.ts:37-77`).
(`saveConversationTask`, `packages/ui-server/src/ws/conversation-storage.ts:40-80`).
Loading may return receipts/results even without a current provider session
(`loadConversation`, `packages/ui-server/src/ws/conversation-storage.ts:78-105`).
(`loadConversation`, `packages/ui-server/src/ws/conversation-storage.ts:81-108`).
Clear receipt/result content while preserving replay refusal under a new lifecycle
fence; do not cascade away consumed identities and then allow their reuse.
- **Session projections.** `sessions` title and `034_session_labels.sql` label/source;
Expand Down
26 changes: 26 additions & 0 deletions packages/ui-server/migrations/091_chat_ownership_account.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- A chat's deletion ownership keeps the account that owned it after the login
-- that wrote a record is pruned (#4138), as 089 did for its safety history
-- and dialogue owner. Explicit deletion admits any current owner login when
-- every ownership record of the chat proves that same account; a voice epoch
-- or a typed-creation binding whose login was pruned proved nothing, so a
-- chat two logins used became undeletable once either aged out.
--
-- `principal_account` sits beside each record's `principal_id`. The server
-- writes it from the principal row when the record is written: 'owner' for an
-- owner login, NULL for a principal whose account is only itself (an agent,
-- an ambient identity, a system principal). `principal_id` stays the
-- attribution and is never rewritten. The account is evidence, not a
-- credential: the caller still has to be a current, authorized owner login,
-- and live epoch control stays with the exact login that opened it.
--
-- Legacy rows gain an account only from verified evidence: a principal row
-- that still exists and is an owner login. A row whose principal is already
-- gone keeps NULL and stays unknown, so its chat keeps refusing deletion.
-- Nothing is owner by default. IN over a NULL principal_id is not true, so a
-- record without a principal stays NULL as well.
ALTER TABLE conversation_epochs ADD COLUMN principal_account TEXT;
ALTER TABLE chat_session_owners ADD COLUMN principal_account TEXT;
UPDATE conversation_epochs SET principal_account='owner'
WHERE principal_id IN (SELECT id FROM principals WHERE kind='owner');
UPDATE chat_session_owners SET principal_account='owner'
WHERE principal_id IN (SELECT id FROM principals WHERE kind='owner');
Loading
Loading