Bridge Remote speech through bounded reader assembly

This commit is contained in:
ak47 committed 2026-11-04 14:33:58 -05:00
1 parent 703d44029c
commit 393ff90f00
12 files changed
+890 -93

No files matched your search

+76 -16
View File
@@ -1,9 +1,18 @@
# Typed speech transport and relay conversion
Remote now has a tested conversion boundary between NVDA protocol-v2 speech and
the matching experimental reader's typed speech IPC. This is a prerequisite for
speech integration. The source command still discards desktop payloads and does
not call `remote.present` or send reader output to the relay.
Remote now connects NVDA protocol-v2 speech conversion to the matching
experimental reader's typed speech IPC. Controller sessions call `remote.present`;
controlled sessions send matching `remote.output` events to the relay. The
production reader has no speech worker or output observer connected to these
interfaces yet, so the command remains a relay-testing tool with no audible
speech-service claim. A reader without a presentation owner rejects incoming
speech; Remote closes that connection and its lease instead of silently dropping
the error. No installed or active reader was changed.
The coordinator and assembly increments were based on Tentacles `703d440` (`master`) and reader
`9e15f86` (`testing`), both confirmed current with `git pull --ff-only` on
2026-11-04. The assembly increment changes reader wire/host code and both SDKs
as well as the external coordinator. No production speech worker is enabled.
`src/speech_bridge.go` converts speech, cancel and pause messages. It preserves
text fragments and whitespace, resolved spelling/language state, end-utterance
@@ -17,38 +26,89 @@ Outbound conversion emits NVDA command arrays, resets character/language state
when necessary, and leaves origin IDs to the relay. It validates every payload
through the same typed reader schema before serialization.
These helpers operate on data only. The future coordinator must check relay
membership before conversion, serialize presentation/heartbeat/close operation
sequences, recheck reader lease/epoch and peer readiness before each delivery or
send, and stop work on revocation. Split frames retain priority metadata; atomic
utterance admission and priority/cancel semantics still require reader-owner
integration. No audible pause/resume or priority fidelity is established here.
`src/speech_stream.go` owns per-attempt speech queues. The relay reader checks
membership, peer origin and direction before conversion. Incoming speech requires
the controller role and `remote-present`; observed output requires the controlled
role, `output-observe`, and the exact current lease/epoch. Events received while
waiting for a peer are discarded rather than replayed to a later helper. Received
speech never becomes an observed-output event in the Tentacle.
One worker serializes presentation and heartbeat calls using their shared
monotonic operation sequence. It checks a due heartbeat before each presentation,
including split frames; heartbeats also run during dial/join. A separate worker
serializes relay output in SDK event order. The SDK event consumer never waits
for relay writes or reader calls. Both workers recheck the current attempt,
cancellation and peer readiness before handing off work. Core remains responsible
for checking its lease and output/security policy at actual speech delivery.
Queues admit at most 64 items and 256 KiB of serialized speech across both
directions, including work in flight. A split incoming utterance reserves all
of its frames together or admits none. Overflow stops the connection; no cancel
is selectively dropped. Revocation, replacement, disconnect, SDK EOF, membership
failure and worker failure cancel the socket and clear pending speech. Teardown
waits for both workers before the final sequenced close. An in-flight reader
call retains its independent two-second deadline, so ordinary disconnect does
not cancel a healthy SDK session. In-flight accepted work still needs the
reader's delivery-time context check; closing a queue cannot undo delivered audio.
Split utterances now retain one `utterance` identifier across their reader
calls, equal to the first fragment's operation sequence; only the last sets
`final: true`. Heartbeats may occur between fragments. Core assembles the whole
utterance before admitting one owner delivery, with a single priority and the
original fragment/utterance boundaries. A failed or revoked assembly exposes no
prefix to the owner. Single-frame speech, cancel and pause keep their original
single-call representation. These fields belong only to reader IPC; NVDA relay
frames are unchanged.
The reader independently enforces 64 frames and 256 KiB across staged, queued
and in-flight speech. Its owner must call the delivery's idempotent `Release`
after delivery/discard; stale releases cannot affect replacement leases. Byte
or frame overflow revokes the lease and drops the assembly. The future speech
owner still needs delivery-time policy, local priority and remote cancellation
ownership. Atomic assembly is not backend completion or audible delivery. No
audible pause/resume or priority fidelity is established.
The matching reader adds a disabled-by-default incoming speech mailbox, typed
Go/Python validators and `remote.output` events. See
[its precise contract](../../cthulhu/docs/tentacle-remote-speech.md). These SDK
additions are prerequisites for building this increment; use the matching reader
source, not an older release. The existing connection command remains the only
production entry point and makes no speech-service claim.
source, not an older release. Production output ownership and origin filtering
remain reader responsibilities.
Verification:
```sh
GOCACHE=/tmp/cthulhu-cache GOPROXY=off go test -race ./remote/src -count=1
GOCACHE=/tmp/cthulhu-cache GOPROXY=off go test -race ./remote/src -count=1 -timeout=90s
make check GOPROXY=off
```
Both passed for the assembly increment. Reader wire/host/both-SDK race suites
also passed with a 240-second timeout (the host suite took about 127 seconds),
as did the focused real-host connection race tests and affected-package vet.
Conversion tests exercise spelling/language reset, cancel/pause, priorities,
unsupported commands, whitespace and long escaped multilingual text. Reader
tests send speech through real Go/Python SDK child processes and exercise stale
leases, replay, absent owners, origin restrictions and overflow cancellation.
The repository check also runs the reader's Remote speech host/SDK tests.
Coordinator tests cover FIFO split/cancel/pause, shared heartbeat/present/close
sequences, lease/grant/role checks, pre-peer output, stale output, unavailable
owners, whole-utterance admission bounds and queue cleanup. A blocked reader
presentation and a blocked relay write establish that lifecycle cancellation
can stop the socket without waiting for either effect path. Both-role child
process fixtures exercise actual Go SDK framing, connection forms, storage and
private TLS relay speech together. The reader's real-host/private-relay fixture
now passes long escaped multilingual speech from the source-built command into
one complete test-owner delivery. Reader SDK-process tests also establish no
prefix before finalization, interleaving/priority/replay rejection, heartbeat
progress, assembly retirement, both budget limits and idempotent/stale release.
The repository check runs these reader Remote speech and connection tests.
Existing greeting, Wormhole, Battery Status and connection/consent checks remain
regressions. These checks produce no audible speech and establish no physical
keyboard, Braille or real NVDA/Orca interoperability acceptance.
After the worker/coordinator integration, test ordinary reading, spelling,
After reader-owner integration, test ordinary reading, spelling,
read-all, key echo, stop speech and local status in both roles. Then test lock,
handoff, disconnect and peer loss for stale output and loops, using disposable
desktops before testing installed releases. Those workflows cannot be accepted
from this transport-only increment.
from this transport increment. Keep connection UI warnings until production
speech ownership and acceptance are established.