Skip to content

CONTRACT: refactor(ui-react,ui-sdk): route voice-owned frames through the handler map and drop pong from the consumer union - #4067

Merged
schlessera merged 4 commits into
mainfrom
refactor/3389-handler-map-voice-frames
Nov 16, 2026
Merged

schlessera merged 4 commits into
mainfrom
refactor/3389-handler-map-voice-frames

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3389

What changed

The ui-react 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 each have a map entry that hands the frame to the conversation client (context.conversation, backed by its new receive(frame)). The client's frame() prefilter now returns them unchanged instead of consuming them. Separately, pong is no longer a frame a consumer can handle. The SDK exports ConsumerServerMessage (Exclude<ServerMessage, ServerPong>), ServerFrameHandlers and its onAny are keyed on it, and ui-react's map is keyed on it, so the pong: () => {} entry is gone. Nothing changes on the wire: ServerMessage, ServerPong and parseServerMessage keep pong, and the SDK client still consumes it for liveness. Nothing changes for the person using voice.

Why this shape

This follows the maintainer ruling: Q1 A (map entries backed by the conversation client) and Q2 A (drop pong from the consumer union, a breaking type change before 1.0).

The new map entries are dispatched where frame() used to consume these frames, so their order and side effects stay the same:

  • The seven frames the client always consumed (dialogue_history and six conversation_*) are dispatched once, connection-wide, right after frame(), and go no further. Before, frame() returned null for them, so nothing after it saw them. Sending them into the demux instead would record run state for a conversation_work that names a session, and would drop frames whose session has no buffer.
  • tool_resolution was only observed by frame(), then went on to the demux, where it marks its session's run state. It keeps that path. After noteRunState it is dispatched connection-wide, so voice still sees an outcome for a session with no buffer here. The only change is that its permission update now lands after earlier buffered text is flushed.

Alternatives I did not take:

  • Narrowing root.connection.handleServerMessage to ConsumerServerMessage. That would be a second, unruled break to a ui-react input. About 70 test and fixture call sites type their frames as ServerMessage. It keeps taking ServerMessage and ignores a pong fed to it at that boundary.
  • Leaving permissions.frame to see tool_resolution. It is now a separate permissions.resolution, so the prefilter really stops routing it.

The contract index and package-api.md describe the frame()/receive() split, because the conversation client is reachable from createBrainUiRoot. The split falls under the same ruling.

Existing tests touched:

  • In conversation.offline.tsx, three lines handed conversation frames straight to client.frame() to prove late-frame guards (LATE_CLOSE_CANNOT_RESTORE_DIAGNOSTIC and two others). With frame() passing them through, those lines would pass without proving anything, so they now call client.receive(). One cast moved from ServerMessage to ConsumerServerMessage.
  • In ws-client-lifecycle.test.ts, the socket-lease test used { type: "pong" } as an arbitrary frame through onAny, which can no longer carry one. It now uses server_hello. Its casts moved to ConsumerServerMessage.

Proof

bun run check:pr --base origin/main
{"version":1,"kind":"brain-check-pr-receipt","head":"c703538e84ee9524af370ee700856ada3a386880","base":"origin/main","mode":"focused","startedAt":"2026-11-16T07:44:15.018Z","finishedAt":"2026-11-16T07:45:46.284Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":13153.640333000001},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":122.98552600000039},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":90.0356249999968},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":23.4909090000001},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":77857.218838}]}

Failing first. I ran the new tests in packages/ui-react/tests/ws-client-lifecycle.test.ts against origin/main's packages/ui-react/src and packages/ui-sdk/src: 20 pass, 16 fail. Each frame's map test fails on VOICE_FRAME_MAP_ENTRY, because the entries were () => {}. Each frame's socket test fails on VOICE_PREFILTER_PASSES_THROUGH, because frame() consumed the frame, or for tool_resolution on VOICE_FRAME_REACHES_CONVERSATION. The two behaviour tests (durable history lands in voice state; a permission outcome reaches voice without a buffer and still marks run state) pass on main, as behaviour-preservation tests should. With the change: 36 pass, 0 fail.

Mutations, each restored afterwards:

Mutation Result
conversation_work map entry set back to () => {} 2 fail: VOICE_FRAME_MAP_ENTRY, VOICE_FRAME_REACHES_CONVERSATION (conversation_work)
Early CONVERSATION_OWNED dispatch in inbound.ts removed 3 fail: VOICE_FRAME_REACHES_CONVERSATION for dialogue_history and conversation_work (dropped by the demux for a session with no buffer), and the durable-history test
tool_resolution connection-wide dispatch in handleFrame removed 2 fail: VOICE_FRAME_REACHES_CONVERSATION (tool_resolution), and the no-buffer permission test

Type-level. packages/ui-sdk/tests/consumer-frames.test-d.ts checks four things: the parser and ServerMessage keep ServerPong; ConsumerServerMessage has no pong and, together with ServerPong, is exactly ServerMessage; a pong handler is a @ts-expect-error; and onAny comparing against "pong" has no overlap. packages/ui-react/tests/handler-map-frames.test-d.ts checks that the map's key set equals ConsumerServerMessage["type"], has no pong, and that ServerMessageHandlerMap<"pong"> is a type error. Mutations, each restored:

Mutation Result
ConsumerServerMessage = ServerMessage TS2344 in both test-d files and in the map's _EveryFrameClaimed, plus TS2578 unused @ts-expect-error
ServerFrameHandlers keyed on ServerMessage TS2578 at the pong handler
onAny taking ServerMessage TS2578 at the onAny comparison

tsc --noEmit over the whole repo is clean. bun run build passes. api-report/ui-sdk.txt and api-report/ui-react.txt are regenerated with ConsumerServerMessage, receive, permissions.resolution and the retyped frame. scripts/source-browser-dispatch.ts re-audits and re-pins index.ts, chat.ts, connection.ts and inbound.ts, with a note on what changed in each.

Full package suites in the agent sandbox: bun run test packages/ui-sdk gave 1378 pass and 48 fail, and bun run test packages/ui-react gave 2615 pass and 7 fail. Every failure is in a sandbox-only file: the worker sandbox, governed and maintenance workers, staging, and cgroup files (unshare: write failed /proc/self/uid_map), plus api-client-sync.test.ts. None of them imports the changed code. I reran those 13 files on an origin/main worktree. The failing names churn between runs on both trees, and worker-sandbox.test.ts on its own gives identical results on both (31 pass, 4 fail, same names).

Real-browser voice tests (packages/ui-react/tests/browser/conversation*.offline.tsx, dialogue-*.offline.tsx) run in the pinned offline image. Hosted draft heavy feedback (run 43767085844, head 47857b935, base cc326cc64; feedback, not proof):

  • browser (1–3) passed: 81, 124 and 183 test files, all green. Each shard ran conversation.offline.tsx, the voice file this PR changed, among the selected changed files.
  • Also passed: layout (1, 2), runtime, runtime_host, captures, endurance, pack, verify, and unit (1, 2, 4).
  • unit (3) failed, caused by this PR: tests/unit-test-consumers.test.ts › "the whole cross-workspace source class retains every independently discovered unit owner" failed with UNRESOLVED_OWNERSHIP: packages/ui-react/tests/handler-map-frames.test-d.ts. The new type-only file imports @schlessera/brain-ui-sdk/protocol from ui-react tests and had no runnable owner in the census. Like block-contract.test-d.ts, it is checked by the root tsc. The fix is commit 71127b7b7, which lists it with the census's explicit compile-only entrypoints in tests/helpers/unit-consumer-audit.ts. Reproduced failing locally on the same assertion before the fix; after it, bun run test tests/unit-test-consumers.test.ts gives 48 pass, 0 fail. The receipt above is for head c703538e8, the merge of origin/main at fcae4b79d. The only conflict was docs/integration-contract.md, where both sides added an index entry; both are kept. After the merge, the API reports regenerate unchanged, bun run typecheck and bun run build pass, and the repaired citations still anchor.

Collisions (bun scripts/collisions.ts --json --pr <pr>): 36 reports at head 71127b7b7 (29 at 47857b935). Textual overlaps:

The other 31 are closure (shared affected-category) reports only, with no shared lines.

Checklist

  • Focused local preflight/behavioral receipts passed; hosted proof runs at landing.
  • Acceptance criteria from the issue are all met.
  • The PR and ui-react: server-frame handler map still has no-op entries for voice- and SDK-consumed frames #3389 carry milestone 0.45.0.
  • A changeset is included (.changeset/3389-consumer-frames-without-pong.md, minor, names the break).
  • No personal data anywhere in the diff.
  • The integration contract index and package-api.md/wire.md components are updated in this same commit.
  • Docs under docs/ reflect the change. I also repaired seven citations this change moved (answer-delivery.md, hardening.md, test-waits.md).
  • No fail-closed guard added or changed.
  • Nothing on a turn's provider path changed.

Anything left open

Other map entries are still () => {} for frames a client consumes beside the demux: safety_*, attachment_read, live_settings and live_persona. They are out of this issue's scope and filed as #4063 (needs scoping). chat_retired stays inert on purpose until #3231.

🤖 Generated with Claude Code

… the handler map and drop pong from the consumer union (#3389)

The voice conversation client's own frames (dialogue_history,
tool_resolution and the six conversation_* frames) now reach it through
their handler-map entries, backed by a new receive(frame), instead of
being consumed in its frame() prefilter. The map is their only router.
The seven frames frame() used to consume are dispatched connection-wide
at the same point; tool_resolution keeps its run-state path and is
dispatched once after it, also for a session with no buffer.

BREAKING (types): the SDK exports ConsumerServerMessage, every
ServerMessage except ServerPong. ServerFrameHandlers and onAny are
keyed on it, so a pong handler no longer type-checks; the client always
consumed pong for liveness. ui-react's handler map is keyed on it and
loses its pong entry. The wire, ServerMessage and parseServerMessage
keep pong. Maintainer ruling recorded on the issue (Q1 A, Q2 A).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: refactor Structure changes; behaviour does not. No changeset-visible effect. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. area: ui-react React chat/files/voice components, stores, WebSocket transport. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. breaking Breaks a published API or documented behaviour. Needs a maintainer ruling before code. labels Nov 15, 2026
@uploads-sh

uploads-sh Bot commented Nov 15, 2026

Copy link
Copy Markdown

No uploads on this PR yet

This PR changes UI files (packages/ui-react/tests/browser/conversation.offline.tsx). Screenshots help reviewers see what changed.

  • From the CLI: uploads put before.png after.png --pr 4067
  • From an agent: ask it to attach screenshots with uploads.sh
  • By hand: drag images into the PR description and they're imported automatically
Tips for agents

Label each shot so reviewers know what they're seeing. Labels apply to every file in a call, so run one put per shot:

uploads put after.png --pr 4067 --meta path=/settings --state after --caption "Saved settings toast"
uploads put chat.png --pr 4067 --app ios --screen "Chat" --state after

No CLI? With the Uploads MCP, call sign_upload_url for files on disk (or put) with repo, pr: 4067 and the same screen, state and caption fields.

This comment updates with each upload, so you don't need to post the images yourself. A shot or two in the PR description is still welcome. Check what's attached with uploads list --pr 4067. More in the github-screenshots skill or the agent docs.

Workspace admins can turn this comment off in Settings → GitHub · docs

… entrypoint (#3389)

The cross-workspace census requires a runnable owner for every test
importing another workspace. The new ui-react .test-d.ts file is checked
by the root tsc, like block-contract.test-d.ts, so it joins that list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-map-voice-frames

# Conflicts:
#	docs/integration-contract.md
@schlessera
schlessera marked this pull request as ready for review November 16, 2026 08:14
@schlessera
schlessera merged commit 087ffdd into main Nov 16, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: ui-react React chat/files/voice components, stores, WebSocket transport. area: ui-sdk Wire protocol, runtime schemas, the server and client SDK surfaces. breaking Breaks a published API or documented behaviour. Needs a maintainer ruling before code. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: refactor Structure changes; behaviour does not. No changeset-visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-react: server-frame handler map still has no-op entries for voice- and SDK-consumed frames

1 participant