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
12 changes: 12 additions & 0 deletions .changeset/3389-consumer-frames-without-pong.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-react": minor
---

**Breaking (types, #3389):** `pong` is no longer a frame a consumer can handle. `BrainUiClient` answers its own liveness probes and never handed a `pong` on, so `ServerFrameHandlers` (from `@schlessera/brain-ui-sdk/client`) is now keyed on the new `ConsumerServerMessage` union, which is every `ServerMessage` except `ServerPong`, and its `onAny` receives a `ConsumerServerMessage`.

Migration: delete any `pong` handler you pass in `handlers`; it was never called. A consumer that types its frame handling as `ServerMessage` keeps compiling. To call such code from `onAny`, nothing changes, because a `ConsumerServerMessage` is a `ServerMessage`. Code that switches exhaustively over the frames a handler receives can drop its `pong` case.

Nothing changes on the wire. The host still answers `ping` with `pong`, and `ServerMessage`, `ServerPong` and `parseServerMessage` still include it.

In `@schlessera/brain-ui-react`, the server-frame handler map is now the only router for the voice conversation's own frames: `dialogue_history`, `tool_resolution` and the six `conversation_*` frames reach the conversation client through their map entries, not through its prefilter. The conversation client (`root.connection.conversation`) gains `receive(frame)` for those frames, and `frame()` now passes them through unchanged. Its `permissions` gains `resolution(frame)` for `tool_resolution`, which `permissions.frame()` no longer reads. Nothing changes for the person using voice.
20 changes: 18 additions & 2 deletions api-report/ui-react.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,12 @@ signatures (every public export and the types it is made of)
dialogueNotice: string;
dialogueRestoredThrough: Record<string, number>;
}
ConversationFrame (packages/ui-react/src/hooks/websocket-handlers/types.ts)
export type ConversationFrame = Extract<ConsumerServerMessage, {
type: ConversationFrameType;
}>;
ConversationFrameType (packages/ui-react/src/hooks/websocket-handlers/types.ts)
type ConversationFrameType = "dialogue_history" | "tool_resolution" | "conversation_opened" | "conversation_closed" | "conversation_event" | "conversation_work" | "conversation_output" | "conversation_permission";
ConversationRecognition (packages/ui-react/src/voice/conversation-client.ts)
export type ConversationRecognition = Extract<ConversationWireEvent, {
kind: "input_fragment" | "unassigned_input_fragment";
Expand Down Expand Up @@ -1705,7 +1711,7 @@ signatures (every public export and the types it is made of)
discard(): void;
dispose(): void;
enter(): void;
frame: (message: import("@schlessera/brain-ui-sdk").ServerMessage) => import("@schlessera/brain-ui-sdk").ServerMessage | null;
frame: (message: import("@schlessera/brain-ui-sdk").ConsumerServerMessage) => import("@schlessera/brain-ui-sdk").ConsumerServerMessage | null;
historyOwnerFor: (key: string) => string | undefined;
leave: () => void;
levels: () => {
Expand All @@ -1724,11 +1730,15 @@ signatures (every public export and the types it is made of)
lost(): void;
quiet: () => void;
refresh(): void;
resolution: (message: Extract<import("@schlessera/brain-ui-sdk").ServerMessage, {
type: "tool_resolution";
}>) => void;
state: import("zustand").StoreApi<{
line: string;
records: import("./voice/conversation-permissions.js").VoicePermissionReceipt[];
}>;
};
receive: (message: import("./hooks/websocket-handlers/types.js").ConversationFrame) => void;
recoverOutput(): void;
resume(): void;
reviewUnassigned(): boolean;
Expand Down Expand Up @@ -1763,7 +1773,7 @@ signatures (every public export and the types it is made of)
edit (packages/ui-react/src/lib/answer-delivery/manager.ts)
function edit(requestId: string): void;
frame (packages/ui-react/src/voice/conversation-client.ts)
function frame(message: ServerMessage): ServerMessage | null;
function frame(message: ConsumerServerMessage): ConsumerServerMessage | null;
frame (packages/ui-react/src/voice/conversation-permissions.ts)
function frame(message: ServerMessage): void;
handleServerMessage (packages/ui-react/src/ws-client/inbound.ts)
Expand All @@ -1790,6 +1800,8 @@ signatures (every public export and the types it is made of)
function quiet(): void;
receipt (packages/ui-react/src/lib/answer-delivery/manager.ts)
function receipt(frame: ServerAskAnswerReceipt): void;
receive (packages/ui-react/src/voice/conversation-client.ts)
function receive(message: ConversationFrame): void;
registerContentRendererPack (packages/ui-react/src/content-renderers/register.ts)
export function registerContentRendererPack(pack: ContentRendererPack, module: {
name: string;
Expand All @@ -1799,6 +1811,10 @@ signatures (every public export and the types it is made of)
export function registerUpdateHold(root: BrainUiServices, hold: UpdateHold): () => void;
renderBlockHtml (packages/ui-react/src/components/chat/share-document.tsx)
export function renderBlockHtml(block: Block, trackDisplay?: TrackDisplay): Promise<string>;
resolution (packages/ui-react/src/voice/conversation-permissions.ts)
function resolution(message: Extract<ServerMessage, {
type: "tool_resolution";
}>): void;
retry (packages/ui-react/src/lib/answer-delivery/manager.ts)
function retry(requestId: string): Promise<void>;
retryTurn (packages/ui-react/src/ws-client/turn-retry.ts)
Expand Down
10 changes: 8 additions & 2 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export "." (./src/index.ts)
type ConfigurationCoverageRead
type ConfiguredModule
type ConflictVersionSelection
type ConsumerServerMessage
type ContentRendererDeclaration
type ConversationAudioFormat
type ConversationCapabilities
Expand Down Expand Up @@ -742,6 +743,7 @@ export "./client" (./src/client/index.ts)
type ConfigurationCoverageRead
type ConflictVersionSelection
type ConnectionStatus
type ConsumerServerMessage
type ContentRenderer
type ContentRendererPack
type ContentRendererProps
Expand Down Expand Up @@ -1769,6 +1771,7 @@ export "./protocol" (./src/protocol.ts)
type ClientToolDenial
type ConfigurationCoverageRead
type ConflictVersionSelection
type ConsumerServerMessage
type ConversationAudioFormat
type ConversationCapabilities
type ConversationCloseReason
Expand Down Expand Up @@ -2602,6 +2605,7 @@ export "./server" (./src/server/index.ts)
type ConfirmPattern
type ConfirmPatternSource
type ConflictVersionSelection
type ConsumerServerMessage
type ConversationAudioFormat
type ConversationCapabilities
type ConversationCloseReason
Expand Down Expand Up @@ -7466,6 +7470,8 @@ signatures (every public export and the types it is made of)
}
ConnectionStatus (packages/ui-sdk/src/client/ws-client.ts)
export type ConnectionStatus = "connecting" | "connected" | "disconnected";
ConsumerServerMessage (packages/ui-sdk/src/protocol.ts)
export type ConsumerServerMessage = Exclude<ServerMessage, ServerPong>;
ContentRenderer (packages/ui-sdk/src/client/content-renderers.ts)
export interface ContentRenderer extends StaticRenderer {
Component: ComponentType<ContentRendererProps>;
Expand Down Expand Up @@ -13365,11 +13371,11 @@ signatures (every public export and the types it is made of)
}
ServerFrameHandlers (packages/ui-sdk/src/client/ws-client.ts)
export type ServerFrameHandlers = {
[K in ServerMessage["type"]]?: (frame: Extract<ServerMessage, {
[K in ConsumerServerMessage["type"]]?: (frame: Extract<ConsumerServerMessage, {
type: K;
}>) => void;
} & {
onAny?: (frame: ServerMessage) => void;
onAny?: (frame: ConsumerServerMessage) => void;
};
ServerHandoffDraft (packages/ui-sdk/src/protocol.ts)
export interface ServerHandoffDraft {
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/answer-delivery.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ for the lock ahead of the submitting tab, and a unit test caught that.

Browser WebSocket ping/pong is not exposed to scripts, so the host answers an
application-level `ping` (`private sendProbe`,
`packages/ui-sdk/src/client/ws-client.ts:458`). A replaced socket is retired,
`packages/ui-sdk/src/client/ws-client.ts:459`). A replaced socket is retired,
and every one of its callbacks checks that before it touches the client, so
a late close from a dead socket cannot reset its replacement.

Expand All @@ -200,7 +200,7 @@ runs on a socket that never opened, and `reconnectNow()` does nothing while
one is connecting, so the client waited forever. A connection that has
delivered nothing after 10 seconds, whether still connecting or open, is now
abandoned and retried through the normal backoff (`private abandon`,
`ws-client.ts:492`). This adds no new timeout to a question. The host's turn
`ws-client.ts:493`). This adds no new timeout to a question. The host's turn
deadline stays the only limit on an ask.

## A question whose turn ended (#3356)
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/hardening.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ instead, and treat 8 as the question it was answering.
production (`adapter.adapt(msg)`,
`packages/ui-backend-claude/src/turn-stream.ts:103`) and U33 changes frame
consumption
(`handleServerMessage`, `packages/ui-react/src/ws-client/inbound.ts:188`), the
(`handleServerMessage`, `packages/ui-react/src/ws-client/inbound.ts:214`), the
same symptom could come from either, so they are **0.34.0** (seam) and **0.34.1** (splits), each its own
image. For the same reason the cron bin and emitters (U13/U14) ship as
**0.33.0** with the denylist unchanged and the allowlist (U21) as
Expand Down
16 changes: 16 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ optional `treeRequest`. A strict, voice or autonomous turn on managed storage
now keeps its data tree there, filled by reflinks. Described in
[the package API](integration-contract/package-api.md#managed-turn-data-trees-additive-0450-2911).

## Consumer frames without `pong` (breaking before 1.0, 0.45.0, #3389)

`@schlessera/brain-ui-sdk/protocol` (and the root and `./client` entries that
re-export it) exports `ConsumerServerMessage`: every `ServerMessage` except
`ServerPong`. `ServerFrameHandlers` from `./client` is keyed on it, and its
`onAny` receives one, so a `pong` handler no longer type-checks.
`BrainUiClient` consumes `pong` for liveness and never called such a handler.
This removes a member from a public type and needs the
[recorded ruling](https://github.com/schlessera/brain-kit/issues/3389#issuecomment-6601349605);
it ships in a minor with the `breaking` label. The wire is unchanged: the host
still answers `ping` with `pong`, and `ServerMessage`, `ServerPong` and
`parseServerMessage` keep it. In `@schlessera/brain-ui-react`, the
conversation client gains `receive(frame)` for the eight frames it owns, which
reach it through the handler map instead of its `frame()` prefilter. See
[the package component](integration-contract/package-api.md#consumer-frames-without-pong-breaking-3389).

## JeV reranking through the provider relay (additive, 0.45.0, #3792)

The CLI provider relay gains the `typesafe` family, `x-brain-provider:
Expand Down
30 changes: 30 additions & 0 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,36 @@ 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="consumer-frames-without-pong-breaking-3389"></a>

## Consumer frames without `pong` (breaking before 1.0, #3389)

`@schlessera/brain-ui-sdk/protocol` (and the root and `./client` entries that
re-export it) exports `ConsumerServerMessage`, defined as
`Exclude<ServerMessage, ServerPong>`: the frames `BrainUiClient` hands its
consumer. `ServerFrameHandlers` is keyed on `ConsumerServerMessage["type"]`
and its `onAny` takes a `ConsumerServerMessage`. Before, both were keyed on
`ServerMessage`, so a consumer could register a `pong` handler that the client
never called, because it answers its own probes and returns first. That
handler is now a type error; delete it. Code typed against `ServerMessage`
still accepts every frame the client delivers.

`ServerMessage`, `ServerPong`, `serverPongSchema` and `parseServerMessage` are
unchanged, as is the [liveness exchange](wire.md#interactive-answer-receipts-breaking-910) on the wire.

In `@schlessera/brain-ui-react`, `root.connection.conversation` gains
`receive(frame)` for the frames the conversation client owns:
`dialogue_history`, `tool_resolution`, `conversation_opened`,
`conversation_closed`, `conversation_event`, `conversation_work`,
`conversation_output` and `conversation_permission`. The server-frame handler
map routes them there, and `frame()`, which still sees every inbound frame
first, now returns them unchanged instead of consuming them. `frame()` takes
and returns a `ConsumerServerMessage`. `root.connection.handleServerMessage`
still takes a `ServerMessage` and ignores a `pong` fed to it. The client's
`permissions` likewise gains `resolution(frame)` for `tool_resolution`, which
`permissions.frame()` no longer reads. What voice does with each frame is
unchanged.

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

## Reading a chat deletion's outcome (additive, #3455)
Expand Down
4 changes: 3 additions & 1 deletion docs/integration-contract/wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,9 @@ seconds is abandoned the same way and retried with the normal backoff, which
resets only once a connection delivers a valid frame.
`checkLiveness()` probes at once, for a return to the page, a resume or going
online. `setForeground(false)` pauses the periodic probe. These are targets:
a frozen page runs no timers.
a frozen page runs no timers. The client consumes every `pong` itself: none reaches a
consumer handler or `onAny`, and `ServerFrameHandlers` has no `pong` key
([#3389](package-api.md#consumer-frames-without-pong-breaking-3389)).

**principalKey** is a one-way digest of the principal id, stable per
principal. A client files queued answers under it and never replays an
Expand Down
8 changes: 4 additions & 4 deletions docs/process/test-waits.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ each complete delay and awaiting each actual failed native handshake before
advancing again. One original 20-second failure cap covers the whole drop.
The clock observes the client's `onclose` callback and owns only its final
registered timer: that callback ends with `scheduleReconnect`
(`ws.onclose`, `packages/ui-sdk/src/client/ws-client.ts:267-285`;
`scheduleReconnect`, `packages/ui-sdk/src/client/ws-client.ts:544-551`).
(`ws.onclose`, `packages/ui-sdk/src/client/ws-client.ts:268-286`;
`scheduleReconnect`, `packages/ui-sdk/src/client/ws-client.ts:545-552`).
The test independently checks the three registered delays and the native
connection-attempt/failure counts. A changed registration order or callback
must satisfy those controls; it cannot silently become a shorter policy.
Expand Down Expand Up @@ -231,8 +231,8 @@ case observes that later effect through its retained native window.
The history and queue receiving observer is only a barrier for the current
synchronous production handlers, not a generic asynchronous-handler completion
claim: `session_history` and scoped `status` update the chat store synchronously
(`session_history`, `packages/ui-react/src/hooks/websocket-handlers/chat.ts:444-464`;
`status`, `packages/ui-react/src/hooks/websocket-handlers/chat.ts:458-483`), while
(`session_history`, `packages/ui-react/src/hooks/websocket-handlers/chat.ts:442-462`;
`status`, `packages/ui-react/src/hooks/websocket-handlers/chat.ts:463-488`), while
queue adoption updates the follow-up/draft stores synchronously
(`function queueReport(`, `packages/ui-react/src/ws-client/follow-ups.ts:85-94`). Native protocol
completion, committed store state and the retained observation window serve
Expand Down
3 changes: 0 additions & 3 deletions packages/ui-react/src/hooks/websocket-handlers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type ChatFrame =
| "result"
| "retry_receipt"
| "ask_answer_receipt"
| "pong"
| "message_blocks"
| "message_links"
| "turn_journal"
Expand Down Expand Up @@ -410,8 +409,6 @@ export const chatFrameHandlers = {
// Receipts are connection-wide: they never reach a session's demux.
retry_receipt: (msg, context) => context.retryReceipt(msg),
ask_answer_receipt: (msg, context) => context.answerReceipt(msg),
// The SDK client answers its own probes; a pong never reaches a consumer.
pong: () => {},
message_blocks: (msg, context) => {
// Arrives after `result`, for the turn's own assistant message. An
// answer never waits on it: the markdown is already on screen, and this
Expand Down
21 changes: 11 additions & 10 deletions packages/ui-react/src/hooks/websocket-handlers/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type ConnectionFrame = "safety_history" | "safety_update" | "safety_unavailable"

export const connectionFrameHandlers = {
safety_history: () => {}, safety_update: () => {}, safety_unavailable: () => {},
dialogue_history: () => {},
scope_decision_receipt: (msg, context) => context.state.setScopeDecisionReceipt(msg),
server_hello: (msg, context) => {
context.stores.connection.getState().setSessionProfiles(msg.capabilities?.sessionProfiles === true);
Expand Down Expand Up @@ -41,9 +40,6 @@ export const connectionFrameHandlers = {
inbox_delta: (msg, context) => {
context.stores.inbox.getState().applyDelta(msg);
},
// Root-owned conversation routing consumes permission outcomes before demux;
// ordinary chat progress keeps its existing handlers.
tool_resolution: () => {},
// Pending follow-ups (#1002): a connection-wide frame, never demultiplexed.
session_queue: (msg, context) => context.queueReport(msg),
// Browser invalidation is #3231's: this client does not declare
Expand All @@ -52,16 +48,21 @@ export const connectionFrameHandlers = {
// Sent-row read states (#3155): the account's read client takes the frame
// beside the demux, so nothing here touches a transcript.
attachment_read: () => {},
conversation_opened: () => {},
// The live-service default (#3616): the root conversation client reads it beside the demux.
live_settings: () => {},
// The conversation client reads the selected persona beside the demux (#3617).
live_persona: () => {},
conversation_closed: () => {},
conversation_event: () => {},
conversation_work: () => {},
conversation_output: () => {},
conversation_permission: () => {},
// The voice conversation client owns these frames (#3389): durable voice
// history, permission outcomes and the live conversation itself. The map is
// their only router; nothing here touches a transcript.
dialogue_history: (msg, context) => context.conversation(msg),
tool_resolution: (msg, context) => context.conversation(msg),
conversation_opened: (msg, context) => context.conversation(msg),
conversation_closed: (msg, context) => context.conversation(msg),
conversation_event: (msg, context) => context.conversation(msg),
conversation_work: (msg, context) => context.conversation(msg),
conversation_output: (msg, context) => context.conversation(msg),
conversation_permission: (msg, context) => context.conversation(msg),
location_request: (msg, context) => {
context.requestBrowserLocation(msg);
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-react/src/hooks/websocket-handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerMessage } from "@schlessera/brain-ui-sdk/protocol";
import type { ConsumerServerMessage } from "@schlessera/brain-ui-sdk/protocol";
import { activityFrameHandlers } from "./activity.js";
import { chatFrameHandlers } from "./chat.js";
import { connectionFrameHandlers } from "./connection.js";
Expand Down Expand Up @@ -62,7 +62,7 @@ const serverMessageHandlers = {
...handoffFrameHandlers,
} satisfies ServerMessageHandlerMap<ServerMessageType>;

export function dispatchServerMessage(msg: ServerMessage, context: DispatchContext): void {
export function dispatchServerMessage(msg: ConsumerServerMessage, context: DispatchContext): void {
// The mapped type preserves the message/handler correlation. TypeScript
// loses that correlation at an indexed union access, so restore it only at
// this single composition boundary.
Expand Down
Loading
Loading