Repository navigation
Description
Observed
A hosted instance on kit main 4b8db90de logged the following twice within a few hours, from both a desktop and an Android Chrome client:
[ws] inbound frame rejected reason="parse_error" detail="Invalid frame: target.sessionId Invalid string: must match pattern /^[A-Za-z0-9_-]{1,128}$/"
The rejection is logged by reportDroppedFrame (packages/ui-server/src/ws/host.ts:509-516), called from the parse-error branch of the connection handler (packages/ui-server/src/ws/connection.ts:250-256), which also answers the client with a generic PARSE_ERROR error frame.
Context (reproduced 2026-11-10 at main 3aadc8df5)
The only sender. The only client frame with a target.sessionId is safety_read (clientSafetyReadSchema, packages/ui-sdk/src/safety.ts:66). Its target uses the strict safety id, /^[A-Za-z0-9_-]{1,128}$/ (packages/ui-sdk/src/safety.ts:4, safetyTargetSchema at :9). Every other client frame uses the generic WebSocket id, z.string().min(1).max(MAX_ID_CHARS) (packages/ui-sdk/src/schemas.ts:185), which accepts any characters up to 256. The only safety_read sender is createSafetyClient (packages/ui-react/src/lib/safety-client.ts:4). Its selected (:13) sends read({ sessionId: activeSessionId }) for whatever the chat store has selected. It does this on every server_hello (:18), and on every change of the selection.
The failing value. The chat selection is not always a backend session id. A host-only voice history is selected under the key dialogue:<historyOwnerId>:
- when a voice conversation ends with a retained host-only owner (
packages/ui-react/src/voice/conversation-client.ts:441builds the key,:452selects it); - when the session list shows a retained voice history as a row with
id: "dialogue:<id>"(packages/ui-react/src/stores/session-list-state.ts:56); - after a reload, from the persisted history selection (
readPersistedSessionId,packages/ui-react/src/stores/chat-slices/persistence.ts:53-57).
The colon fails the safety id pattern. A reconnect while such a history is selected sends the rejected frame again, which fits the repeat from two devices. The safety store has already begun that request, so it keeps waiting for a page that never comes.
The safety target has no history-owner form (safetyTargetSchema accepts { sessionId } or { turnId, bindingId } only), so the shipped contract offers no safety read for a host-only history. The existing client already shows unavailable when nothing is selected (selected, safety-client.ts:13).
Reproduction (keyless, local, at 3aadc8df5). Drive the real createSafetyClient with the real createSafetyStore and a minimal chat store. Send it a server_hello with sessionSafetyHistory: true and safetyCapabilities.read: true, then select dialogue:7f9e2c1a-0000-4000-8000-000000000001. Feed every frame it sends through parseClientMessage (packages/ui-sdk/src/schemas.ts:971):
safety_unsubscribe null => accepted
safety_read {"sessionId":"dialogue:7f9e2c1a-0000-4000-8000-000000000001"} => Invalid frame: target.sessionId Invalid string: must match pattern /^[A-Za-z0-9_-]{1,128}$/
That is the hosted log's detail byte for byte. A UUID session id is accepted, and a dialogue_read frame carrying the same dialogue: key passes the generic id. This proves one sufficient sender. It does not prove that the two hosted rejections had no other cause, such as a stored id in an older format. The fix below covers any selection that fails the pattern.
Why it matters
The safety client ignores the PARSE_ERROR reply, and the generic connection handler drops it on purpose for a frame outside a turn (packages/ui-react/src/hooks/websocket-handlers/connection.ts:86-90). The selected chat's safety history therefore stays loading and never says unavailable. The server also logs a warning on every reconnect, which hides real parse failures in the noise.
Scope
- In
createSafetyClient, sendsafety_readonly for a selection that is a valid safety target: not a host-only history key, and matching the safety id pattern. Treat any other selection the way "nothing selected" is treated today: unsubscribe, clear the request and reportunavailablewithout sending a read. - Keep the safety id pattern in one place the client can reuse. Do not copy the regex.
Out of scope
- A safety read for host-only voice histories. That is a new
safetyTargetSchemaform and a contract change. File it separately if it is wanted. - Relaxing the server's safety id pattern or the generic WebSocket id.
- Renaming the
dialogue:selection keys or changing how voice histories are selected or listed. - Logging the rejected frame's
typeon parse errors. The sender is now identified. A separate observability issue can propose this.
Acceptance criteria
- With safety history supported, selecting
dialogue:<owner>(live, from the session list, or restored after reload) and then reconnecting sends nosafety_read, and the safety store readsunavailablerather than stayingloading. Proven inpackages/ui-react/tests/safety-client.test.tsby a test that fails on main. - In the same test file, every frame
createSafetyClientsends, across server hello, selection change, paging and resubscribe, for valid and invalid selections, passesparseClientMessage. - Selecting a backend session id still reads, pages and subscribes exactly as before (the existing safety-client tests keep passing).
- A mutation that sends the read regardless of the target's validity fails the new test on the parse assertion.
Verification
bun run test packages/ui-react/tests/safety-client.test.ts, plus the failing-first and mutation receipts above. Keyless, with no browser or network needed.
Contract impact
None. The client stops sending a frame the published schema already rejects. No CLI, MCP, wire schema or frontmatter change.
Triage 2026-11-10 at main 3aadc8df5: reproduced the rejection exactly with the real safety client and parser. The sender is safety_read for a host-only dialogue: selection. Replaced the needs-scoping list with the scope and criteria above, and removed needs: repro. The fix lives in ui-react, so area: ui-server was dropped. Kept priority: p1 and milestone 0.45.0 as already committed.
Delivery completed — 2026-11-11
Merged #3977 as 3c44ac6fc56d27675dadaf38a16254db53c39f69, parent 0f6296a791061c5343230e303117f8278093340b, tree 405136cad4db123bd175b4e4d8cb598e2e9930ee. Exact-candidate run 43016644219 passed all eight selected jobs at the verified merge checkout 804980cf3fbd7948e7029d1fe7e91dee448b4ab9. Automatic main run 43020467075, attempt 1, passed all 17 selected jobs; actual checkouts were checked in each log. All three real client/parser cases and all 35 actual provider-history cases passed. Four healthy native hosted backend/UID cells, owned cleanup and the separate intentional negative control were independently verified from artifacts.
All four original criteria and required delivery verification are complete. Failing-first/mutation receipts keep their original source execution identities; refreshed source and regression bytes were compared. The published target schema is unchanged. Host-only histories show unavailable, valid backend sessions retain paging/subscription/gap recovery, and milestone 0.45.0 is retained.
Activity
schlessera commentedon Nov 10, 2026
2026-11-10 triage at main
3aadc8df5: reproduced. The only frame withtarget.sessionIdissafety_read. The realcreateSafetyClientsends it with the chat selection as-is. For a host-only voice history, that selection isdialogue:<owner>, andparseClientMessagerejects it with the hosted log's exact detail. The selection comes from conversation end, the session list or a restored selection, and the frame is sent again on every reconnect. Rewrote the body with scope, exclusions, criteria and verification. The fix is client-side: send no read for a non-safety target and reportunavailable. Removedneeds: repro, narrowed the area toui-react, kept p1 and 0.45.0, attached to #3596 (its safety-history client was delivered there by #3604) and marked itagent-ready.schlessera commentedon Nov 11, 2026
Claimed for implementation. Claim token:
claim-1d77d0c0. Branch:fix/3811-safety-history-target.Current-main citations and real client/parser reproduction checked. Direct overlap with own draft #3662 in safety-client source/tests; deliver separately, preserve both during refresh and test their combined tree. Remaining collision entries are affected-test closure, not shared source ownership.