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
13 changes: 13 additions & 0 deletions .changeset/chat-deletion-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-sdk": minor
---

An owner can read one chat deletion's outcome with
`GET /api/chat-deletions/:operationId` (#3455), so a client that lost the reply
to `POST /api/chat-deletions` can ask what happened without deleting anything.
It answers the current receipt, including `pending`, `partial` and `unknown`
cleanup, or one content-free 404 `not_admitted` when nothing is retired under
that operation for the caller. The read never admits a deletion, retries or
resumes cleanup, and reveals nothing about other principals' operations. The SDK
adds `ChatDeletionNotAdmitted`.
10 changes: 10 additions & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export "." (./src/index.ts)
CHAT_DELETION_CAPABILITY
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionNotAdmitted
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
Expand Down Expand Up @@ -582,6 +583,7 @@ export "./client" (./src/client/index.ts)
COMPUTE_TOOL_CONTRACTS
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionNotAdmitted
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
Expand Down Expand Up @@ -1459,6 +1461,7 @@ export "./protocol" (./src/protocol.ts)
CHAT_DELETION_CAPABILITY
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionNotAdmitted
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
Expand Down Expand Up @@ -2170,6 +2173,7 @@ export "./server" (./src/server/index.ts)
COMPUTE_TOOL_CONTRACTS
CONVERSATION_CAPABILITY_KEYS
CONVERSATION_LIMITS
type ChatDeletionNotAdmitted
type ChatDeletionOutcome
type ChatDeletionReceipt
type ChatDeletionRefusal
Expand Down Expand Up @@ -6182,6 +6186,12 @@ signatures (every public export and the types it is made of)
has(cacheName: string): Promise<boolean>;
open(cacheName: string): Promise<CacheLike>;
}
ChatDeletionNotAdmitted (packages/ui-sdk/src/protocol.ts)
export interface ChatDeletionNotAdmitted {
error: "CHAT_DELETION_NOT_ADMITTED";
reason: "not_admitted";
message: string;
}
ChatDeletionOutcome (packages/ui-sdk/src/protocol.ts)
export type ChatDeletionOutcome = "pending" | "partial" | "unknown" | "removed";
ChatDeletionReceipt (packages/ui-sdk/src/protocol.ts)
Expand Down
1 change: 1 addition & 0 deletions api-report/ui-server.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,7 @@ signatures (every public export and the types it is made of)
createChatDeletion (packages/ui-server/src/ws/chat-deletion.ts)
export function createChatDeletion(deps: ChatDeletionDeps): {
delete(input: Omit<RetireChatInput, "at" | "removableBackends">): Promise<ChatDeletionResult>;
read(operationId: string, principalId: string): Promise<ChatDeletionReceipt | null>;
reconcile(): Promise<void>;
};
createConsoleLoggerProvider (packages/ui-server/src/observability/loggers.ts)
Expand Down
10 changes: 8 additions & 2 deletions docs/http-api-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fake backends and injected transports keep the checks keyless.

Each ordinary row runs the named `mounted supported handler: METHOD PATH` test
in [http-supported-mounts.test.ts](../packages/ui-server/tests/http-supported-mounts.test.ts)
(`checkHandler`, `packages/ui-server/tests/http-supported-mounts.test.ts:174-193`).
(`checkHandler`, `packages/ui-server/tests/http-supported-mounts.test.ts:177-196`).
The explicit [lifetime audit](../packages/ui-server/tests/helpers/http-mount-lifetimes.ts)
permits a bounded group of immutable readers to share startup, with a new owner
per case. Principal enumeration, activity ownership, CLI dispatch, caches,
Expand Down Expand Up @@ -116,6 +116,7 @@ row's real mounting check. They do not establish mounting by themselves.
| `GET /api/sessions/:sessionId/turns/:turnId/revert` | `mounted supported handler: GET /api/sessions/:sessionId/turns/:turnId/revert` | RV |
| `GET /api/sessions/:sessionId/turns/:turnId/revert/:operationId` | `mounted supported handler: GET /api/sessions/:sessionId/turns/:turnId/revert/:operationId` | RV |
| `POST /api/chat-deletions` | `mounted supported handler: POST /api/chat-deletions` | CD |
| `GET /api/chat-deletions/:operationId` | `mounted supported handler: GET /api/chat-deletions/:operationId` | CD |
| `POST /api/sessions/:sessionId/turns/:turnId/revert` | `mounted supported handler: POST /api/sessions/:sessionId/turns/:turnId/revert` | RV |
| `GET /api/sessions/:sessionId/turns/:turnId/journal` | `mounted supported handler: GET /api/sessions/:sessionId/turns/:turnId/journal` | J |
| `GET /api/sessions/:sessionId/turns/:turnId/journal/:sequence/preview` | `mounted supported handler: GET /api/sessions/:sessionId/turns/:turnId/journal/:sequence/preview` | J |
Expand Down Expand Up @@ -526,4 +527,9 @@ unbound draft controls, replay refusal, honest partial/unknown outcomes, restart
reconciliation, and the endpoint's owner, agent, ambient, foreign, stale and revoked
cases. [The WebSocket host test](../packages/ui-server/tests/ws-chat-deletion.test.ts)
covers busy refusal, a resume held across retirement, admission and recovery refusal
and targeted `chat_retired` delivery.
and targeted `chat_retired` delivery. The same file covers the read-only operation
lookup (#3455): the owner's receipt, partial progress, a restart and a retry, one
byte-identical `not_admitted` for unknown, foreign, refused, agent and ambient
callers, a read admitting and cleaning nothing, and revocation during the read;
[the real-host test](../packages/ui-server/tests/chat-deletion-http.test.ts) repeats
the owner, foreign, agent and unknown answers through `createApp` and cookies.
28 changes: 26 additions & 2 deletions docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ compatibility guarantee. Authentication requirements are a separate property.
A public liveness probe can be supported; an authenticated settings route can
be internal.

The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, session-recovery interactive HTML preview, saved-audio transcription, human-started hygiene-review, governance-event, roadblock-report, reference-grant, Apify-state, Apify-policy, retained-journal/user-revert, untrusted-mark and chat-deletion routes mounted by `createApp`: 168 unique declared
The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, session-recovery interactive HTML preview, saved-audio transcription, human-started hygiene-review, governance-event, roadblock-report, reference-grant, Apify-state, Apify-policy, retained-journal/user-revert, untrusted-mark and chat-deletion routes mounted by `createApp`: 169 unique declared
method/path pairs, plus the conditional SPA fallback. It describes the current
implementation, including limitations, rather than a proposed redesign.
Unknown response fields must be tolerated. There is no HTTP API revision
Expand Down Expand Up @@ -146,6 +146,7 @@ client code has a gap. Source owners are listed after the table.
| GET | `/api/sessions/:sessionId/turns/:turnId/revert` | S | Read latest original history receipt | Bound to current principal/session/source turn; never retries effects. |
| GET | `/api/sessions/:sessionId/turns/:turnId/revert/:operationId` | S | Reconcile one original operation | Same bound identity; missing receipt stays unavailable. |
| POST | `/api/chat-deletions` | S | Delete the caller's own chat's local history | Authenticated owner only; stable caller operation identity; content-free per-store outcomes (#3230). |
| GET | `/api/chat-deletions/:operationId` | S | Read one deletion operation's current receipt | Read-only and owner-scoped; one content-free `not_admitted` for every miss (#3455). |
| POST | `/api/sessions/:sessionId/turns/:turnId/revert` | S | Start a user-only journaled revert or restoration | Stable caller operation identity; raw stale-state comparison; gate and shared server locks. |
| GET | `/api/sessions/:sessionId/turns/:turnId/journal` | S | Read retained turn observations | Exact session/turn ownership; nullable unknown facts and explicit expiry. |
| GET | `/api/sessions/:sessionId/turns/:turnId/journal/:sequence/preview` | S | Read a bounded text preview | Raw UTF-8 bytes; explicit size/line/binary fallback, no coercion. |
Expand Down Expand Up @@ -201,7 +202,7 @@ Authentication factories live in [auth.ts](../packages/ui-server/src/middleware/
[passkeys.ts](../packages/ui-server/src/middleware/passkeys.ts) and
[principals.ts](../packages/ui-server/src/middleware/principals.ts).
[app.ts](../packages/ui-server/src/app.ts) owns prefixing and middleware order.
All 168 declared endpoints are mounted regardless of backend, renderer or
All 169 declared endpoints are mounted regardless of backend, renderer or
speech-provider availability: unavailable capabilities return the responses
below rather than removing their handlers. Only static serving is conditional.

Expand Down Expand Up @@ -1076,6 +1077,29 @@ reported deletion. Receipts and errors carry no chat text, title, raw path or
free-form failure. No success claims secure erasure, provider forgetting or an
undone effect, and an older backup can restore deleted text.

**GET /api/chat-deletions/:operationId** (additive, #3455) reads one operation's
outcome without re-admitting it, so a client that lost a POST's reply can ask
what happened. It only reads: it never admits a deletion, retries or resumes
cleanup, and it adds no authority. For the authenticated caller it answers 200
with the current `ChatDeletionReceipt` when a retirement is recorded under that
`operationId` for that principal; `status` and `stores` reflect the latest
recorded cleanup, so a read after a restart or a retry shows progress. Every
other case is 404 with the SDK's `ChatDeletionNotAdmitted`, `{ error:
"CHAT_DELETION_NOT_ADMITTED", reason: "not_admitted", message }`, byte-identical
whether the operation is unknown, another principal's, a refused attempt (refusals
are not recorded) or asked by a principal that cannot own one (an agent, or an
ambient caller without an owner mapping). It never echoes a title, session id,
history owner id or backend. `not_admitted` means nothing was retired under
that operation at the moment of the read: a request still in transit can be
admitted afterwards, and `chat_retired` then follows as usual. The read waits
for committed catalog writes. An `operationId` longer than 2048 characters is
400 `{ error: "INVALID_CHAT_DELETION", message }`; unauthenticated is 401; a
principal revoked between the lookup and the response gets the guard's 401, not
the receipt; a storage failure is 500 `{ error: "CHAT_DELETION_FAILED", message }`,
which reports neither outcome. Every response is `Cache-Control: no-store`. A
host without the route answers its ordinary not-found, which carries no
`reason`, so a client can tell an older host from `not_admitted`.

Draft routes refuse a draft bound to a deleted chat with 410
`{ error: "DRAFT_CHAT_RETIRED", message }`, list omits it, and `GET` answers 404.

Expand Down
11 changes: 11 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ same-commit update of the index or relevant authoritative component. How they ar

The reasoning is in [decisions/contract-versioning.md](decisions/contract-versioning.md).

## Reading a chat deletion's outcome (additive, #3455)

`GET /api/chat-deletions/:operationId` ([HTTP](http-api.md#explicit-chat-deletion-additive-3230))
lets an owner who lost a deletion's reply read its current `ChatDeletionReceipt`
without re-admitting it. It only reads and adds no authority. Every miss is one
content-free 404 `ChatDeletionNotAdmitted` (`reason: "not_admitted"`): an
unknown operation, another principal's, a refused attempt, or a caller that cannot
own one. The SDK exports that type
([package API](integration-contract/package-api.md#reading-a-chat-deletions-outcome-additive-3455)).
`POST /api/chat-deletions` and the receipt are unchanged. This ships in a minor.

## Hosted external compute (additive, 0.45.0, #3108)

A hosted chat turn reaches external compute through six host-executed bridge
Expand Down
12 changes: 12 additions & 0 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ passes its origin to `startInferenceRelay` as the new internal
origin, and a turn without a relay refuses to start. The first-party
Claude and pi backends implement all three.

<a id="reading-a-chat-deletions-outcome-additive-3455"></a>

## Reading a chat deletion's outcome (additive, #3455)

`@schlessera/brain-ui-sdk/protocol` (and the root and `./client` entries that
re-export it) exports `ChatDeletionNotAdmitted`, the 404 body of
`GET /api/chat-deletions/:operationId` when nothing is retired under that
operation for the caller. In `@schlessera/brain-ui-server`, the chat deletion
service gains `read(operationId, principalId)`, which returns the caller's
current receipt or null and never admits or cleans up. Semantics are in the
[HTTP](../http-api.md#explicit-chat-deletion-additive-3230) component.

<a id="explicit-chat-deletion-additive-3230"></a>

## Explicit chat deletion (additive, #3230)
Expand Down
6 changes: 4 additions & 2 deletions docs/plans/chat-history-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ restart reconciliation remains with the endpoint work.
**Built (#3230):** the coordinated deletion and its endpoint
([HTTP](../http-api.md#explicit-chat-deletion-additive-3230),
[wire](../integration-contract/wire.md#explicit-chat-deletion-additive-3230)).
One operation (`createChatDeletion`, `packages/ui-server/src/ws/chat-deletion.ts:46-104`)
One operation (`createChatDeletion`, `packages/ui-server/src/ws/chat-deletion.ts:46-114`)
refuses busy work, retires the chat, ends its live epochs, notifies the owner's
capable clients, then asks the native store and each host store to remove their
copies; restart reconciliation resumes any unconfirmed store under the original
operation. Host stores (`cleanChatStore`, `packages/ui-server/src/ws/chat-store-cleanup.ts:80-88`)
operation. `GET /api/chat-deletions/:operationId` (#3455) reads that operation's
current receipt for its owner and admits, retries and cleans nothing; every miss
is one content-free `not_admitted`. Host stores (`cleanChatStore`, `packages/ui-server/src/ws/chat-store-cleanup.ts:80-88`)
confirm removal only by reading back that nothing selected remains: dialogue
records, task receipt text and result facts, session title/label and the text,
digest and classification projections, and positively bound drafts with their
Expand Down
18 changes: 17 additions & 1 deletion packages/ui-sdk/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2400,7 +2400,10 @@ export interface ChatDeletionRequest {
expected: { backendId: string | null; generation: number };
}

/** `POST /api/chat-deletions` success: the chat is retired; `status` says how far cleanup got. */
/**
* `POST /api/chat-deletions` success, and `GET /api/chat-deletions/:operationId`
* for a recorded operation: the chat is retired; `status` says how far cleanup got.
*/
export interface ChatDeletionReceipt {
operationId: string;
/** The retired chat's terminal history generation. */
Expand All @@ -2410,6 +2413,19 @@ export interface ChatDeletionReceipt {
retained: ChatDeletionRetained[];
}

/**
* `GET /api/chat-deletions/:operationId` miss (additive, #3455), answered with
* 404: nothing is retired under this operation for the caller at the moment of
* the read. The same bytes answer an unknown operation, another principal's
* and a refused attempt. A request still in transit may be admitted later, and
* `chat_retired` then follows as usual.
*/
export interface ChatDeletionNotAdmitted {
error: "CHAT_DELETION_NOT_ADMITTED";
reason: "not_admitted";
message: string;
}

/**
* Server → Client (additive, #3230). The owner retired this chat. Clear every
* local projection of it and stop resending, autosaving or retrying for it; a
Expand Down
32 changes: 31 additions & 1 deletion packages/ui-server/src/routes/chat-deletions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hono } from "hono";
import type { ChatDeletionRefusal, ChatDeletionRequest } from "@schlessera/brain-ui-sdk/protocol";
import type { ChatDeletionNotAdmitted, ChatDeletionRefusal, ChatDeletionRequest } from "@schlessera/brain-ui-sdk/protocol";
import type { AppEnv } from "../app-env.js";
import type { Principal } from "../db/principals.js";
import type { ChatDeletion } from "../ws/chat-deletion.js";
Expand All @@ -16,6 +16,13 @@ const REFUSALS: Record<ChatDeletionRefusal, { status: 403 | 404 | 409; message:
busy: { status: 409, message: "This chat has work in progress. Stop or finish it first; nothing was deleted." },
};

/**
* One answer for every operation the caller has no retirement under: unknown,
* another principal's, a refused attempt, or a caller that cannot own one.
*/
const NOT_ADMITTED: ChatDeletionNotAdmitted = { error: "CHAT_DELETION_NOT_ADMITTED", reason: "not_admitted",
message: "Nothing is deleted under this operation. A request still on its way can be admitted later." };

function parse(body: unknown): ChatDeletionRequest | null {
if (!body || typeof body !== "object" || Array.isArray(body)) return null;
const { operationId, target, expected } = body as Record<string, unknown>;
Expand Down Expand Up @@ -58,5 +65,28 @@ export function createChatDeletionRoutes(deps: { deletion: ChatDeletion; princip
return c.json({ error: "CHAT_DELETION_REFUSED", reason: result.reason, message: refusal.message }, refusal.status);
}
return c.json(result.receipt);
})
/**
* `GET /api/chat-deletions/:operationId` (additive, #3455): the caller's
* current receipt for one operation, so a client that lost a POST's reply
* can ask without re-admitting it. Read-only: no admission, retry or
* cleanup. Anything else, including another principal's operation or an
* agent or ambient caller, is the same content-free `not_admitted`.
*/
.get("/chat-deletions/:operationId", async (c) => {
c.header("Cache-Control", "no-store");
const principal = c.get("principal");
if (!principal) return c.json({ error: "Authentication required", authRequired: true }, 401);
const operationId = c.req.param("operationId");
if (!id(operationId)) return c.json({ error: "INVALID_CHAT_DELETION", message: "Name one operation ID." }, 400);
let receipt;
try {
receipt = principal.kind === "owner" ? await deps.deletion.read(operationId, principal.id) : null;
} catch {
return c.json({ error: "CHAT_DELETION_FAILED", message: "The host could not read this deletion. Nothing is reported either way; try again." }, 500);
}
// Revoked while the catalog was read: the caller learns nothing.
if (!deps.principalValid(principal)) return c.json({ error: "Authentication required", authRequired: true }, 401);
return receipt ? c.json(receipt) : c.json(NOT_ADMITTED, 404);
});
}
10 changes: 10 additions & 0 deletions packages/ui-server/src/ws/chat-deletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ export function createChatDeletion(deps: ChatDeletionDeps) {
const current = await catalog.chatRetirement(result.operationId, input.principalId);
return { status: "retired", receipt: chatDeletionReceipt((current ?? result) as Retired) };
},
/**
* The caller's current receipt for one operation, or null when nothing is
* retired under it for this principal (#3455). A pure read: it never
* admits, retries or resumes cleanup, and it waits for committed catalog
* writes as `chatRetirement` does.
*/
async read(operationId: string, principalId: string): Promise<ChatDeletionReceipt | null> {
const current = await deps.catalog.chatRetirement?.(operationId, principalId);
return current?.status === "retired" ? chatDeletionReceipt(current) : null;
},
/**
* Restart reconciliation: finish every retirement a store has not
* confirmed, under its original operation. Fences were already durable;
Expand Down
Loading
Loading