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
6 changes: 6 additions & 0 deletions .changeset/owner-individual-safety-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
---

Add password-mode owner review of individual finalized safety triggers with durable retries and live authority checks, implementing the approved pre-1.0 change to unconditional restriction.
380 changes: 372 additions & 8 deletions api-report/ui-sdk.txt

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions docs/decisions/session-safety-reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ pins DTOs, explicit numeric bounds, matching, ownership and proof obligations.
[G6](governed-writable-workers.md#untrusted-input-g6) now records every trigger
and restricts unknown/incomplete histories through the durable collection
foundation (#3600). The host-only verdict store (#3601) commits individual
decisions and durable receipts; owner-authorized mutation transport and review capability
remain unavailable until their separate enforcement slices are qualified. This ruling supersedes only
decisions and durable receipts. The owner review transport (#3603) uses that
store through a strict two-phase HTTP boundary, with live password-mode human
authority checked on the acquired transaction and final delivery. Its
capability remains separate from read support and all standing-rule flags.
This ruling supersedes only
unconditional stickiness: a fully observed chat may return to normal **only
after every unresolved trigger has its own committed safe verdict**, complete
versioned detector coverage is established and no recording/capacity failure
Expand Down
16 changes: 15 additions & 1 deletion 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:181-200`).
(`checkHandler`, `packages/ui-server/tests/http-supported-mounts.test.ts:191-210`).
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 @@ -125,6 +125,8 @@ row's real mounting check. They do not establish mounting by themselves.
| `GET /api/sessions/:sessionId/turns/:turnId/journal/:sequence/:side` | `mounted supported handler: GET /api/sessions/:sessionId/turns/:turnId/journal/:sequence/:side` | J |
| `GET /api/journal/configuration-coverage` | `mounted supported handler: GET /api/journal/configuration-coverage` | J |
| `GET /api/sessions/:id/safety` | `mounted supported handler: GET /api/sessions/:id/safety` | S |
| `POST /api/sessions/:id/safety/reviews/prepare` | `mounted supported handler: POST /api/sessions/:id/safety/reviews/prepare` | SR |
| `POST /api/sessions/:id/safety/reviews/:requestId/commit` | `mounted supported handler: POST /api/sessions/:id/safety/reviews/:requestId/commit` | SR |
| `GET /api/sessions/:id/attachment-reads` | `mounted supported handler: GET /api/sessions/:id/attachment-reads` | X |
| `GET /api/sessions/:id/recovery` | `mounted supported handler: GET /api/sessions/:id/recovery` | S |
| `POST /api/queue` | `mounted supported handler: POST /api/queue` | Q |
Expand All @@ -151,6 +153,18 @@ row's real mounting check. They do not establish mounting by themselves.

## Named behavior checks

**SR — Individual safety review.**

The mounted checks use a signed password-owner cookie and matching Origin to
reach both review handlers on the real application. An unavailable history
returns its specific refusal with no prepared request or decision. The
[owner safety review suite](../packages/ui-server/tests/owner-safety-review.test.ts)
additionally exercises successful individual A/B/C verdicts, immutable replay,
live HTTP/WS authority, FULL-writer races, expiry, retirement, capacity and
cross-root handle binding through authenticated loopback transports. Each
mutation operation retains a fresh application/database under the lifetime
audit; review fixtures never share request reservations or verdict state.

J uses the real host admission, tool-completion and terminal observations,
checks authenticated session/turn isolation and reads exact retained CRLF bytes
(`host admission, tool completion and terminal observation`,
Expand Down
76 changes: 74 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, composer-file, session-recovery, attachment-read, 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`: 174 unique declared
The inventory includes the additive Queue intake, poke, scheduled-task, session-draft, composer-file, session-recovery, attachment-read, 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, chat-deletion and individual safety-review routes mounted by `createApp`: 176 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 @@ -157,6 +157,8 @@ client code has a gap. Source owners are listed after the table.
| GET | `/api/agent-policy` | I | Read shared admission policy and reported enforcing limits | Read-only Devices & agents facts; no editor or duplicate policy cache. |
| GET | `/api/policy-proposals/:turnId/:requestId` | I | Read one principal-owned policy request receipt | Same-request reconciliation only; never writes or reactivates approval. |
| GET | `/api/sessions/:id/safety` | S | Read bounded revisioned host safety evidence | Exact authenticated history owner; immutable records, snapshot aggregate/high-water, scoped cursor, explicit coverage/unavailable, no mutation (#3604). |
| POST | `/api/sessions/:id/safety/reviews/prepare` | S | Prepare review of one finalized safety occurrence | Live password-mode human owner, exact Origin and bounded JSON; host-issued body/brain/principal/generation-bound handle (#3603). |
| POST | `/api/sessions/:id/safety/reviews/:requestId/commit` | S | Commit or read back one individual safe verdict | Live owner rechecked on the acquired FULL transaction and final response; immutable receipt plus fresh aggregate, no bulk clear or standing rule (#3603). |
| GET | `/api/sessions/:id/attachment-reads` | S | Read a session's recorded attachment reads, outcome and scope only | Sent-row read states (#3589, #3155); preserve the session and message-reference filters, no text and no provider path. |
| GET | `/api/sessions/:id/recovery` | S | Read a session's latest accepted work and pending interactions | Trackers and independent session clients (#964, D52); preserve the revision ordering, Activity terminal proof, honest unknown and the no-execution boundary. |
| POST | `/api/queue` | S | Queue authenticated CLI intake without filing content | CLI and independent intake clients; preserve explicit key, provenance and queue receipt. |
Expand Down Expand Up @@ -207,7 +209,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 174 declared endpoints are mounted regardless of backend, renderer or
All 176 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 @@ -1933,3 +1935,73 @@ explicit bounded stubs retaining occurrence IDs. The final page means that
snapshot has been assembled, separately from detector completeness. Read
[revisioned delivery](integration-contract/wire.md#session-safety-history-additive-3604)
for reconnect, subscription and client rules.

### Individual safety review

`POST /api/sessions/:id/safety/reviews/prepare` prepares exactly one finalized
occurrence. `POST /api/sessions/:id/safety/reviews/:requestId/commit` commits or
reads back that host-issued handle. Both accept only this strict JSON body:

```json
{
"version": 1,
"session": {
"sessionId": "ithaca",
"historyOwnerId": "voyage",
"historyGeneration": "1"
},
"occurrenceId": "harbour-notice",
"expectedEvidenceRevision": "12",
"verdict": "safe"
}
```

The path and body session must agree. IDs are 1–128 ASCII letters, digits,
underscore or hyphen; revisions are canonical unsigned 64-bit decimal strings.
Bodies are at most 16384 UTF-8 bytes. Query parameters, additional fields,
caller principals/channels, ranges, arrays and standing rules are refused.
An arbitrary caller-generated request ID never prepares a mutation.

Only a live password-mode owner authenticated by password or passkey may
mutate. A signed delegated cookie remains insufficient. Proxy, tailscale and
local/no-auth identities remain read-only. These browser operations require
`application/json` and a present exact matching HTTP(S) `Origin`; fetch metadata
does not override a missing or foreign Origin. The host stamps the reviewer
and channel and binds the prepared body to the served database, principal,
authentication epoch, exact session generation and occurrence. The brain key
uses the existing host-seeded canonical-root partition identity, so two roots
sharing a UI database cannot commit or replay one another's prepared handles.
Live authority
is checked inside the acquired FULL writer transaction after queue/lock waits,
including for receipt replay, and again at response delivery. Retirement and
revocation take precedence over retry readback.

Success is `200` with `{version:1,receipt,currentProjection}`. `receipt` is the
immutable `SafetyReviewReceipt`: `version`, nullable `requestId`/`operationId`,
exact `session`/`occurrenceId`, `stage: prepared|verdict_committed|refused`,
`verdict: unresolved|committed`, nullable historical `projection` and nullable
`reason`. Refused receipts carry no historical normal projection.
`currentProjection` is a separate fresh aggregate, including local pending
input and recorder failure. For example, retrying A's committed receipt after
B and C arrive returns A's original fact alongside two unresolved occurrences;
it never rewrites that fact or clears B/C. The expected evidence revision is
the global history/review revision, separate from scoped admission revisions.

Nonfinalized, already-resolved, stale, conflicting or expired handles return
`409`; unknown/foreign/retired targets return non-disclosing `404`; authority
refusals return `403`, capacity or recording-failure receipts `503`. Refusals
include bounded `{code,reason,retryable:false}` beside the receipt response;
before a receipt exists only that error envelope is returned. Oversized bodies
return `413`, malformed bodies `400`, and non-JSON media types `415`. The
existing auth middleware retains its unauthenticated/expired-cookie `401`
envelope. Every route response is `Cache-Control: no-store`.

Handles expire after 900000 ms; terminal receipts retain their original result
for 86400000 ms after completion. Existing per-principal/brain request and
prepaid verdict bounds apply. The transport additionally allows at most 32
in-flight service requests per principal and 256 per brain. Canonical history
membership includes durably adopted provisional collections, with the same
principal, generation, finalized-exposure and permanent retirement fences in
the writer and SQLite trigger. Resolving a known event cannot repair unknown
detector coverage, recording loss or another unresolved event. No model/voice
tool, WS mutation frame, Settings rule or provider transcript edit is added.
14 changes: 14 additions & 0 deletions docs/integration-contract/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,20 @@ known differing version pair; unknown versions do not imply a mismatch.

## Session safety history read (additive, #3604)

Owner review is separately available through the two-phase
[individual review API](../http-api.md#individual-safety-review)
(#3603). Both supported method/path entries belong to the classified HTTP
inventory, with matching mounted-handler and lifetime coverage. Its exact
request, immutable historical receipt, fresh aggregate, password-mode human
authority, strict Origin/JSON checks, refusal envelopes and
lifetime/capacity bounds are authoritative there. Reviewing A never resolves
later B/C, unknown coverage or failed recording. Prepared authority is checked
on the acquired FULL transaction and final response boundary, including replay.
Migration 084 retains finalized-only SQLite enforcement while accepting the
aggregate's durable canonical/adopted membership; no old decision is rewritten.
This additive transport implements the already approved individual-verdict
semantics and ships with a minor changeset under the pre-1.0 ruling.

`GET /api/sessions/:id/safety` adds the bounded authenticated `SafetyPage`
read defined by [the HTTP specification](../http-api.md#session-safety-sidecars)
and [wire sidecars](wire.md#session-safety-history-additive-3604). Queries never
Expand Down
13 changes: 13 additions & 0 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4959,3 +4959,16 @@ mutation flags false. `ServerHello.safetyCapabilities` is optional. Runtime
client/server frame parsers validate the additive frames. They are concrete
wire DTOs, not a new extension seam. Bounds and recovery semantics are in
[the wire contract](wire.md#session-safety-history-additive-3604).

## Individual owner safety review DTOs (additive, #3603)

`@schlessera/brain-ui-sdk/protocol` adds `SafetyReviewBody`,
`SafetyReviewReceipt` and `SafetyReviewResponse`. `/schemas` adds
`safetyProjectionSchema`, `safetyReviewBodySchema`, `safetyReviewReceiptSchema`
and `safetyReviewResponseSchema`. These strict, bounded DTOs describe the
[two-phase HTTP API](../http-api.md#individual-safety-review); they expose no
model tool or publication seam. Historical receipt projections and fresh
`currentProjection` are distinct. `SafetyCapabilities.review` is boolean and
its read-only reason additionally accepts `owner_required` or null; optional
literal review lifetime/body bounds describe a supporting host. Absent or
unsupported capability remains unavailable and grants no mutation authority.
14 changes: 11 additions & 3 deletions docs/integration-contract/wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -2905,10 +2905,18 @@ not renew the acknowledgement or establish backend/tool entry.

The optional boolean `sessionSafetyHistory` in `server_hello.capabilities`
advertises read-only host sidecars. The optional sibling `safetyCapabilities`
is version 1: `read:true`, `review:false`, `originRules:false`,
is version 1: `read:true`, `review:boolean`, `originRules:false`,
`repositoryRules:false`, `recipientRules:false`,
`readOnlyReason:"review_unavailable"`, detector version 1 and effective page,
frame and cursor limits. Older clients ignore these optional fields; clients
`readOnlyReason:"review_unavailable"|"owner_required"|null`, detector version 1
and effective page, frame and cursor limits. Hosts exposing #3603's individual
HTTP review set `review:true` and a null reason only for the live password-mode
human owner; other callers receive false with `owner_required`. Hosts without
that service retain `SAFETY_READ_CAPABILITIES` and `review_unavailable`.
Review hosts optionally add literal `reviewBodyBytes:16384`,
`reviewLifetimeMs:900000` and `receiptLifetimeMs:86400000` limits. Capability
advertisement grants no authority: every HTTP operation rechecks it, and no WS
review/mutation frame is accepted. Standing-rule flags remain false.
Older clients ignore these optional fields; clients
without both read declarations report unavailable and send no read/unsubscribe
frames to an unsupported host. No verdict endpoint,
mutation authority or fully qualified detector is implied by read support.
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-sdk/src/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { SESSION_SAFETY_CAPABILITY, SAFETY_READ_CAPABILITIES } from "./safety.js";
export type { SafetySessionKey, SafetyTarget, SafetyIdentity, SafetyHistoryProjection, SafetyRecord, SafetyPage, SafetyUpdate, SafetyUnavailable, SafetyCapabilities, ClientSafetyRead, ClientSafetySubscribe, ClientSafetyUnsubscribe, ServerSafetyHistory, ServerSafetyUpdate, ServerSafetyUnavailable } from "./safety.js";
export type { SafetyReviewBody, SafetyReviewReceipt, SafetyReviewResponse, SafetySessionKey, SafetyTarget, SafetyIdentity, SafetyHistoryProjection, SafetyRecord, SafetyPage, SafetyUpdate, SafetyUnavailable, SafetyCapabilities, ClientSafetyRead, ClientSafetySubscribe, ClientSafetyUnsubscribe, ServerSafetyHistory, ServerSafetyUpdate, ServerSafetyUnavailable } from "./safety.js";
import type { ClientSafetyRead, ClientSafetySubscribe, ClientSafetyUnsubscribe, ServerSafetyHistory, ServerSafetyUpdate, ServerSafetyUnavailable, SafetyCapabilities } from "./safety.js";
// ============================================================
// brain-kit chat-UI wire protocol
Expand Down
Loading
Loading