Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chat-identity-retirement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": patch
---

The UI database gains an internal, content-free ledger of retired chat identities (#3228, migration `073_chat_lifecycle.sql`). Nothing retires a chat yet: there is no endpoint, backend removal or UI, and no content is deleted. Once a later release retires a chat, its session, dialogue owners and aliases, conversations and consumed task and request identities stay refused permanently, across restarts and in operational backups taken afterwards. An operational backup taken before a retirement still restores that chat's text; the recovery documentation states this limit.
56 changes: 56 additions & 0 deletions api-report/ui-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ signatures (every public export and the types it is made of)
cancelActiveTurns(): boolean;
close(): Promise<void>;
}
CHAT_STORES (packages/ui-server/src/ws/chat-lifecycle.ts)
const CHAT_STORES: readonly ["native", "dialogue", "tasks", "projections", "drafts"];
CapturedLog (packages/ui-server/src/observability/types.ts)
export interface CapturedLog {
scope: string;
Expand All @@ -443,6 +445,18 @@ signatures (every public export and the types it is made of)
attributes: FlatAttributes;
timestamp: number;
}
ChatRetirementStatus (packages/ui-server/src/ws/chat-lifecycle.ts)
export type ChatRetirementStatus = "pending" | "partial" | "unknown" | "removed";
ChatStore (packages/ui-server/src/ws/chat-lifecycle.ts)
export type ChatStore = (typeof CHAT_STORES)[number];
ChatStoreOutcome (packages/ui-server/src/ws/chat-lifecycle.ts)
export type ChatStoreOutcome = "pending" | "partial" | "unknown" | "removed";
ChatTarget (packages/ui-server/src/ws/chat-lifecycle.ts)
export type ChatTarget = {
sessionId: string;
} | {
ownerId: string;
};
ClaudeUsageEvidence (packages/ui-server/src/ws/claude-usage-accounting.ts)
export interface ClaudeUsageEvidence {
title?: TitleEvidence;
Expand Down Expand Up @@ -1636,6 +1650,42 @@ signatures (every public export and the types it is made of)
failureMessage: string;
prompt: string;
}
RetireChatInput (packages/ui-server/src/ws/chat-lifecycle.ts)
export interface RetireChatInput {
operationId: string;
principalId: string;
target: ChatTarget;
expected: {
backendId: string | null;
generation: number;
};
removableBackends: readonly string[];
at: number;
}
RetireChatResult (packages/ui-server/src/ws/chat-lifecycle.ts)
export type RetireChatResult = {
status: "refused";
reason: RetireRefusal;
} | {
status: "retired";
lifecycleId: string;
operationId: string;
generation: number;
identities: RetiredChatIdentities;
cleanup: ChatRetirementStatus;
stores: Partial<Record<ChatStore, ChatStoreOutcome>>;
};
RetireRefusal (packages/ui-server/src/ws/chat-lifecycle.ts)
export type RetireRefusal = "unauthorized" | "unavailable" | "stale" | "unsupported" | "busy";
RetiredChatIdentities (packages/ui-server/src/ws/chat-lifecycle.ts)
export interface RetiredChatIdentities {
sessions: string[];
dialogueOwners: string[];
conversations: string[];
tasks: string[];
requests: string[];
nativeTasks: string[];
}
RunRollupRow (packages/ui-server/src/activity/store.ts)
export interface RunRollupRow {
runId: string;
Expand Down Expand Up @@ -1745,6 +1795,12 @@ signatures (every public export and the types it is made of)
dialogueAppend?(input: DialogueAppend): Promise<import("@schlessera/brain-ui-sdk/protocol").DialogueRecord>;
dialogueBind?(conversationId: string, principalId: string, sessionId: string): Promise<DialogueOwner | null>;
dialogueRead?(principalId: string, target: DialogueTarget): Promise<import("@schlessera/brain-ui-sdk/protocol").DialoguePage | null>;
retireChat?(input: RetireChatInput, busy: (identities: RetiredChatIdentities) => boolean): Promise<RetireChatResult>;
chatRetirement?(operationId: string, principalId: string): Promise<RetireChatResult | null>;
recordChatCleanup?(lifecycleId: string, store: ChatStore, outcome: Exclude<ChatStoreOutcome, "pending">): Promise<ChatRetirementStatus>;
chatRetired?(target: ChatTarget | {
conversationId: string;
}): boolean;
saveConversationEpoch?(state: import("./conversation-storage.js").StoredConversationEpoch): Promise<void>;
saveConversationTask?(principalId: string, receipt: import("@schlessera/brain-ui-sdk/protocol").ConversationWorkReceipt, facts?: string): Promise<void>;
loadConversation?(id: string, principalId: string): Promise<import("./conversation-storage.js").StoredConversation | null>;
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 @@ -1899,7 +1899,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:447`)
(`msg.costUsd ?? 0`, `packages/ui-server/src/ws/session-catalog.ts:485`)
must not feed any budget.

**Enforcement:**
Expand Down
9 changes: 9 additions & 0 deletions docs/inbox-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ marks incomplete continuity explicitly; it restores no microphone consent,
audio, executable native response or permission grant. Re-indexing Markdown
cannot recreate missing dialogue.

Retired chat identities (#3228) are minimized fences without content: the
chat, its former session, dialogue owners and aliases, conversations, consumed
task and request identities, the owner, terminal generation and per-store
cleanup outcomes. They are permanent within the installation. A backup taken
after a retirement restores them, and the restored host still refuses those
identities. **A backup taken before a retirement restores the chat's text and
predates its fence**: an older recovery point can bring deleted history back.
That limit is accepted; no ledger outside the image replays later retirements.

Activity spans/rollups preserve observed spend; principal records preserve
identity attribution. Other UI state, including sessions, authentication
records and settings, travels with the same image. The turn journal keeps its
Expand Down
25 changes: 18 additions & 7 deletions docs/plans/chat-history-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ This is the implementation design for [#3180](https://github.com/schlessera/brai
source-audited against main `6fa3ec1305e8b52991252d6a28959a68c56be1c1` on
2026-11-01. The [binding decision](../decisions/chat-history-deletion.md)
records the approved authority, extent and permanent-fence/backup policy.
Deletion runtime, endpoint and UI are not built. Approval supplies no automatic
expiry, routine live cutoff or implementation release commitment.
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:153-186`;
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
targets before retiring, and makes later dialogue/task writers and readers
refuse the retired identities. It removes no content and reports every store
pending until that store's owner confirms removal. A typed native-only chat
with no recorded owner refuses as unknown ownership; no ownership is backfilled.
Native removal, host-copy cleanup, the endpoint and UI are not built.

## Selected local lifecycle

Expand Down Expand Up @@ -113,16 +124,16 @@ must be tested through their installed runtime, not inferred from directory name
Payloads include independent recognition/output evidence and backend range text;
hashes/order/identity are not substitutes for erasing the payload. An owner can
start unbound, bind to a backend session or merge into an existing owner through
aliases (`bindDialogue`, `packages/ui-server/src/ws/dialogue-storage.ts:169-212`).
aliases (`bindDialogue`, `packages/ui-server/src/ws/dialogue-storage.ts:173-219`).
Resolve the complete alias/conversation set transactionally; do not delete only
the current session key or confuse a provisional owner ID with a backend ID.
- **Task recovery and facts.** `069_conversation_tasks.sql` and
`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:35-71`).
(`saveConversationTask`, `packages/ui-server/src/ws/conversation-storage.ts:37-77`).
Loading may return receipts/results even without a current provider session
(`loadConversation`, `packages/ui-server/src/ws/conversation-storage.ts:72-98`).
(`loadConversation`, `packages/ui-server/src/ws/conversation-storage.ts:78-105`).
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 Expand Up @@ -178,8 +189,8 @@ must be tested through their installed runtime, not inferred from directory name
handoff preparation, classifier callbacks, DialogueJournal routing/pending writes,
ConversationHost receipts/results/output and frozen startup envelopes can retain
or publish text. Catalog optimistic maps precede worker acknowledgements
(`rowEffects`, `packages/ui-server/src/ws/session-catalog.ts:227-240`;
`activeDialogueEpochs`, `packages/ui-server/src/ws/session-catalog.ts:269-272`).
(`rowEffects`, `packages/ui-server/src/ws/session-catalog.ts:243-256`;
`activeDialogueEpochs`, `packages/ui-server/src/ws/session-catalog.ts:285-288`).
Both submission and worker commit need a generation check.
- **Browser state.** Chat buffers/history chunks, shared timeline, session
title/list cache, dialogue pages/cursors, recognition/generated/unsaved tails,
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/navigation-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ implementation. Any PR moving these lines owns their citation repairs.

- Host resume: (`case "session_resume": {`, `packages/ui-server/src/ws/dispatch.ts:648-712`).

- Catalog activity: (`persistSessionStub(sessionId, promptText, providerId, backendId) {`, `packages/ui-server/src/ws/session-catalog.ts:441-448`).
- Catalog activity: (`persistSessionStub(sessionId, promptText, providerId, backendId) {`, `packages/ui-server/src/ws/session-catalog.ts:479-486`).

- Session summary shape: (`export interface ChatSession {`, `packages/ui-sdk/src/protocol.ts:1576-1592`).

Expand Down
47 changes: 47 additions & 0 deletions packages/ui-server/migrations/073_chat_lifecycle.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
-- Retired chat identities (#3228). Content-free and permanent within the
-- installation: no prompt, result, title, recognition, attachment, hash of
-- short text or free-form error is stored here. Nothing references a content
-- table, so no content cascade or retention eviction can remove a fence.
-- One row per retired chat: its canonical identity (a backend session ID, or
-- a provisional dialogue owner ID), exact owner and terminal generation.
CREATE TABLE chat_lifecycles (
id TEXT PRIMARY KEY,
kind TEXT NOT NULL CHECK (kind IN ('session', 'provisional')),
principal_id TEXT NOT NULL,
backend_id TEXT,
generation INTEGER NOT NULL CHECK (generation > 1),
operation_id TEXT NOT NULL UNIQUE,
retired_at INTEGER NOT NULL
);
-- Every identity the retirement consumed: negative lookups that refuse
-- adoption, admission, writes and replay under any of them.
CREATE TABLE chat_retired_identities (
kind TEXT NOT NULL CHECK (kind IN ('session', 'dialogue_owner', 'conversation', 'task', 'request', 'native_task')),
id TEXT NOT NULL,
lifecycle_id TEXT NOT NULL REFERENCES chat_lifecycles(id),
PRIMARY KEY (kind, id)
);
CREATE INDEX chat_retired_identities_lifecycle ON chat_retired_identities(lifecycle_id);
-- Per-store cleanup under the retirement's intent. Only store categories and
-- outcomes; completion needs every selected store to confirm removal.
CREATE TABLE chat_retirement_stores (
lifecycle_id TEXT NOT NULL REFERENCES chat_lifecycles(id),
store TEXT NOT NULL CHECK (store IN ('native', 'dialogue', 'tasks', 'projections', 'drafts')),
outcome TEXT NOT NULL CHECK (outcome IN ('pending', 'partial', 'unknown', 'removed')),
updated_at INTEGER NOT NULL,
PRIMARY KEY (lifecycle_id, store)
);
CREATE TRIGGER chat_lifecycles_permanent BEFORE DELETE ON chat_lifecycles
BEGIN SELECT RAISE(ABORT, 'chat lifecycle fences are permanent'); END;
CREATE TRIGGER chat_lifecycles_terminal BEFORE UPDATE ON chat_lifecycles
BEGIN SELECT RAISE(ABORT, 'chat lifecycle fences are permanent'); END;
CREATE TRIGGER chat_retired_identities_permanent BEFORE DELETE ON chat_retired_identities
BEGIN SELECT RAISE(ABORT, 'chat lifecycle fences are permanent'); END;
CREATE TRIGGER chat_retired_identities_fixed BEFORE UPDATE ON chat_retired_identities
BEGIN SELECT RAISE(ABORT, 'chat lifecycle fences are permanent'); END;
CREATE TRIGGER chat_retirement_stores_permanent BEFORE DELETE ON chat_retirement_stores
BEGIN SELECT RAISE(ABORT, 'chat lifecycle fences are permanent'); END;
-- A confirmed removal is never reopened; other outcomes may only move forward.
CREATE TRIGGER chat_retirement_stores_removed BEFORE UPDATE ON chat_retirement_stores
WHEN OLD.outcome = 'removed' AND NEW.outcome != 'removed'
BEGIN SELECT RAISE(ABORT, 'a confirmed store removal cannot be reopened'); END;
Loading
Loading