120 lines
6.6 KiB
Markdown
120 lines
6.6 KiB
Markdown
# Remote connection coordinator
|
|
|
|
Current integration: [the source command](command.md) now supplies reader-owned
|
|
consent and connection controls. The original library increment below predates
|
|
that wiring. The [speech transport integration](speech.md) now bridges typed
|
|
presentation/output IPC with bounded queues. Production reader speech ownership
|
|
and an installable Remote package remain pending.
|
|
|
|
Implemented as a source-library increment on 2026-11-03, based on Tentacles
|
|
`63e84e9` and the public Go SDK in reader `573d15d`. The Tentacles branch matched
|
|
`origin/master` after fetch. The reader revision was inspected locally; its
|
|
remote branch was not refreshed for this increment. No reader code changed.
|
|
|
|
`src/coordinator.go` joins relay transport and membership to the reader's
|
|
protocol 1.1 lifecycle API. The original increment supplied only this library;
|
|
the source command now provides the executable, connection controls and core
|
|
consent described above.
|
|
|
|
## Ownership and explicit connection
|
|
|
|
The coordinator owns one SDK `Events()` consumer for its entire lifetime. Its
|
|
parent context must belong to the Tentacle process session. Event-stream EOF
|
|
also cancels it. Do not run a second event consumer alongside it.
|
|
|
|
Core `remote.action` events populate a one-element approval channel for
|
|
UI orchestration. A newer event replaces an unread approval and stops any old
|
|
connection. The coordinator stores its own copy of the approved role/grants.
|
|
Neither receiving an approval nor reading settings starts networking.
|
|
|
|
The subsequent [connection workflow](connection-ui.md) claims a pending action
|
|
once and uses its cancellation context for forms and key-free inspection. That
|
|
context ends on replacement, matching revocation, consumption, disconnect or SDK
|
|
loss. `disconnect_epoch` retires only the original epoch, so stale form cleanup
|
|
cannot revoke a newer action or connection. This does not create local consent
|
|
or replace the reader's expiry check.
|
|
|
|
An explicit `connect` call must provide the matching pending action token and
|
|
epoch, an endpoint with any already-approved pin, and a channel key. It validates
|
|
and freezes TLS options, consumes the pending approval once and schedules a
|
|
background attempt. Repeated/concurrent calls are refused. Failed attempts do
|
|
not restore the approval or retry; a new core action is required.
|
|
|
|
The worker calls public SDK `remote.open` before dialing. The reader checks token
|
|
expiry, role and grants. Denial makes no relay connection. The returned lease
|
|
must have the expected epoch and a 32-character identifier. Reader-facing
|
|
`controller`/`controlled` roles map to relay `master`/`slave` roles internally.
|
|
|
|
Snapshots distinguish opening a lease, connecting, waiting for a peer, and ready
|
|
relay membership. **Ready means one opposite-role relay peer, not active desktop
|
|
control.** Typed speech uses the bounded queues and role/grant checks documented
|
|
in [speech.md](speech.md). Other known desktop payloads are validated, counted
|
|
and discarded without retention. No keyboard/Braille/clipboard effect is exposed.
|
|
|
|
## Liveness and teardown
|
|
|
|
The worker sends `remote.heartbeat` each second, including while TLS/join is
|
|
pending. Heartbeats and the final close use strictly increasing per-lease
|
|
sequence numbers shared with presentation calls. The following stop the relay lifetime:
|
|
|
|
- Explicit Disconnect, coordinator close or parent-context cancellation.
|
|
- A matching-epoch `remote.revoked`, a replacement action or SDK event EOF.
|
|
- Heartbeat failure, TLS/join/read failure, malformed relay messages, invalid
|
|
role/origin or any terminal membership change.
|
|
- Speech queue overflow, reader presentation failure or relay output failure.
|
|
|
|
The socket context is cancelled immediately and peer readiness is cleared before
|
|
waiting for cleanup RPCs. Pending speech is drained immediately. Teardown waits
|
|
for the operation and relay-output workers, then requests `remote.close`; each
|
|
reader call has a two-second deadline. It deliberately does not
|
|
cancel a healthy SDK call during ordinary Disconnect: SDK call cancellation
|
|
retires the entire Tentacle process session. Reader-side lease expiry remains
|
|
independent if communication fails. These bounds are not physical-key recovery
|
|
evidence, and no keyboard service uses this worker yet.
|
|
|
|
`disconnect()` returns a completion barrier. No new connection is admitted until
|
|
the old close finishes. A failed close or invalid lease reply makes the
|
|
coordinator unavailable for the rest of its lifetime. A fresh process/SDK session
|
|
is needed; there is no implicit resume, lease recreation or network retry.
|
|
`close()` additionally stops the event consumer; its `done` channel and the
|
|
Disconnect barrier allow callers to await both owners.
|
|
|
|
Statuses and errors retain no channel key, action token, certificate, server
|
|
diagnostic, RPC message or received desktop content. The current attempt needs
|
|
the supplied key for TLS/join only; it is not saved for reconnection. Clearing a
|
|
Go variable does not promise secure memory erasure. Storage and future local
|
|
Remember key/trust actions retain their separate contract.
|
|
|
|
## Verification and remaining gates
|
|
|
|
Run from this repository (private loopback sockets must be allowed):
|
|
|
|
```sh
|
|
GOCACHE=/tmp/cthulhu-cache GOPROXY=off go test -race ./remote/src -count=1 -timeout=60s
|
|
make check
|
|
```
|
|
|
|
Both passed for this increment. Coordinator fixtures exercise approval denial,
|
|
token reuse/stale epochs, copied role/grants, both roles, payload discard, peer
|
|
departure, explicit fresh reconnection, revoke during open, heartbeat during a
|
|
stalled TLS handshake, SDK EOF, replacement approval, parent cancellation,
|
|
socket closure during a stalled heartbeat, cleanup ordering and failed-close
|
|
admission. A pipe fixture uses the actual public Go SDK for negotiation,
|
|
action/revocation events, open and close against a synthetic host.
|
|
|
|
The original pipe fixture runs in-process; the later connection-workflow fixture
|
|
also exercises a separate SDK process. Neither replaces the reader's existing
|
|
real-child-process SDK/authorizer tests or establish production consent. `make
|
|
check` also verifies existing metadata, command registration and actual-host
|
|
invocation for Hello World, Wormhole and Battery Status. Review the new source
|
|
and these contracts before submission; neither command installs or replaces the
|
|
active reader.
|
|
|
|
Next: production reader output/presentation ownership and delivery policy,
|
|
including applying priority once to assembled utterances and protecting local status. Xorg
|
|
provenance/collision safety and virtual/raw Braille remain open. The source
|
|
command's physical-input procedure remains in [command.md](command.md).
|
|
Audible speech, physical input and
|
|
Braille, real NVDA/Orca sessions and installed-package behavior remain separate
|
|
acceptance gates in the parent plan.
|