From 2af73dd764c1523d2c547469ac7d1f1c946e7a47 Mon Sep 17 00:00:00 2001 From: Angus Kola Date: Wed, 4 Nov 2026 17:19:33 -0500 Subject: [PATCH] Keep Remote connected when returning to the desktop --- remote.md | 22 +++++++++++-- remote/README.md | 10 ++++-- remote/command.md | 41 ++++++++++++++++++------ remote/connection-ui.md | 13 ++++++-- remote/speech.md | 15 +++++---- remote/src/connection_ui.go | 12 ++++++- remote/src/connection_ui_test.go | 55 ++++++++++++++++++++++++++++++++ remote/src/coordinator.go | 12 +++++++ tools/check.py | 2 +- 9 files changed, 157 insertions(+), 25 deletions(-) diff --git a/remote.md b/remote.md index 4e1b2b2..a49cdc3 100644 --- a/remote.md +++ b/remote.md @@ -252,6 +252,22 @@ build, the existing speech regression harness and Tentacles `make check` passed. Incoming speech ownership and nonmodal status remain the next implementation steps; this review closes no live release gate. +Sixteenth implementation increment (2026-11-04): explicit Return to desktop now +ends the connection status interaction while retaining a verified, already-open +reader lease. The Remote shortcut reopens status/Disconnect without another +approval or key entry. The terminal `remote_background` contract is exposed by +both SDK representations and checked against process ownership, epoch, deadline +and policy; it neither opens nor renews a lease. Ordinary cancellation retains +its previous cleanup path. Private source-command/reader-host/TLS checks cover +both roles, repeated return/reopening and background disconnect, lock, handoff +and disable. Incoming speech ownership remains pending, as do physical capture +release, ordinary desktop reading, audible speech and interoperability acceptance. +The full Remote and reader host/wire/both-SDK race suites passed (host: about +126 seconds), together with ten repetitions of the source-command connection +race cases, focused shared interaction/consent/observation checks, affected-package +vet, a separate reader build and Tentacles `make check`. +No installed or active reader was replaced and no release gate is complete. + ## 1. Intended result and recommended approach Build a native Go Tentacle named **Remote**, with package ID `remote`, in this @@ -802,7 +818,8 @@ do not claim them from a design diagram. incoming mailbox and both SDKs now have private coverage. The external speech coordinator is connected; limited production ordinary-event output observation now has original-lease and delivery-time policy checks. Incoming speech ownership, - remaining reading producers and modal status detachment remain pending; + remaining reading producers remain pending; explicit status detachment is + implemented, with physical-input/ordinary-reading acceptance still open; see [speech.md](remote/speech.md). Exit: permission denials, timeout/overflow, stale epochs and process failures are @@ -827,7 +844,8 @@ tested; existing Tentacles still install, register, run, disable and update. now connects to the external coordinator, preserving whitespace and UTF-8 across bounded IPC frames. Limited ordinary-event output observation now has explicit private/secret exclusion and ordered cancellation. Incoming ownership, - other reading producers, nonmodal status and audible speech remain pending; + other reading producers and audible speech remain pending. Explicit Return to + desktop now closes status while retaining the original verified lease; connection controls retain their relay-testing scope. - [ ] Demonstrate controlled Cthulhu speech to NVDA and NVDA speech to controlling Cthulhu, then Cthulhu-to-Cthulhu. Verify read-all, spelling and ordinary stop. diff --git a/remote/README.md b/remote/README.md index 9afed02..6302084 100644 --- a/remote/README.md +++ b/remote/README.md @@ -15,7 +15,10 @@ Implemented: Go/Python host coverage. Limited production export now observes explicitly local ordinary accessibility speech after worker policy, with private-origin exclusion and captured-lease/generation checks. Incoming delivery, other reading - producers and modal status detachment remain pending. See [speech.md](speech.md). + producers remain pending. Explicit Return to desktop now releases the status + form while retaining the original approved lease; the shortcut reopens status + and Disconnect. Physical capture/release acceptance remains pending. + See [speech.md](speech.md). - Bounded newline JSON framing, duplicate-key and collection validation, and typed speech, keyboard, membership, clipboard and Braille decoding. - TLS with normal certificate/hostname validation or an already-approved, @@ -71,8 +74,9 @@ A subsequent [reader authorization increment](../../cthulhu/docs/tentacle-remote adds core consent, lock/handoff cancellation and local-only sensitive forms. Injected approval is rejected in private XI2 tests; physical-keyboard approval remains unverified. The source command now requests core consent through typed -interaction requests. Core revokes the original epoch on interaction completion; -bounded cancellation also stops pre-lease inspection on lock/handoff. +interaction requests. Core revokes the original epoch on ordinary interaction completion; +an explicit desktop return retains only the verified already-open lease. +Bounded cancellation also stops pre-lease inspection on lock/handoff. There is no reader desktop service yet. Explicit Trust and remember/Forget pin actions now manage endpoint-bound saved diff --git a/remote/command.md b/remote/command.md index 45d86f1..46c3c90 100644 --- a/remote/command.md +++ b/remote/command.md @@ -10,15 +10,17 @@ The subsequent [speech coordinator increment](speech.md) now connects typed relay speech to presentation IPC and reader output events to relay writes. The matching reader now has limited observation of explicitly local ordinary accessibility speech after worker policy. Incoming speech ownership is still -pending. These controls also hold a modal status form, capturing local keys and -suppressing ordinary application presentation for the connection lifetime. -They retain their relay-testing warnings until status detachment and incoming -speech ownership are implemented and accepted. Receiving speech with no reader +pending. Status now offers **Return to desktop and keep this connection** once +the reader lease opens. The shortcut reopens status and Disconnect; forms capture +local keys only while open. The relay-testing warnings remain until incoming +speech ownership and live acceptance are complete. Receiving speech with no reader owner closes the connection and lease; it does not enable audible delivery. Base revisions checked against maintained upstreams on 2026-11-04: reader `testing` at `4cf3335`, Tentacles `master` at `0c74038`. No installed reader or active desktop session is changed by building or running the private tests. +Explicit Return to desktop requires reader commit `b4896a2` or a descendant +containing its terminal `remote_background` interaction support. ## Ownership and behavior @@ -56,8 +58,14 @@ selection, secret editing, trust, saved keys and status. The coordinator owns the only SDK event consumer and heartbeats the lease before/during networking. All networking remains on its workers. The command never reconnects automatically. -When an interaction ends, core revokes only its original approved epoch, including -unused actions. Stale cleanup cannot revoke replacement consent. On cancellation +When an interaction ends normally, core revokes only its original approved epoch, +including unused actions. Explicit Return to desktop instead returns a terminal +`remote_background` result carrying the opened lease/epoch. Core verifies its +live ownership before releasing the interaction without child cancellation. +Heartbeats continue independently; this action neither renews consent nor starts +another connection. Reopening status requires no second consent. Before lease +open, Return to desktop asks the user to refresh status or disconnect. +Stale cleanup cannot revoke replacement consent. On cancellation or an unfinished exit, a bounded cleanup invocation also retires child setup. This is needed before `remote.open`, when no lease-revocation event exists. Lock/handoff invalidates the interaction's original policy context; returning @@ -95,15 +103,20 @@ GOCACHE=/tmp/cthulhu-go-cache GOPROXY=off CTHULHU_REMOTE_BINARY=/tmp/cthulhu-rem the command host, and runs these real-process application integration cases. They cover both roles, unchecked core consent, denial/empty approval, fresh setup after lock/handoff cancellation, key-free inspection, explicit Trust once, -fresh TLS join and disconnect. A stalled-inspection case verifies cancellation +fresh TLS join, explicit desktop return, repeated status reopening and background +disconnect/lock/handoff/disable. A stalled-inspection case verifies cancellation before a lease exists. Unit/race tests additionally cover invalid requests, fabricated approval without an SDK event, endpoint trust isolation, explicit Remember/Forget pin, failed writes and stale/removed pins. Native form-model coverage verifies empty relay entries do not block Cancel. The complete Remote race suite, existing host/both-SDK conformance race suites, focused application -race tests, vet, reader build and `make check` passed. Existing private Xorg -remote-input and internal-form harnesses also passed, retaining injected-approval +race tests, vet, reader build and `make check` passed. The desktop-return change +also passed ten repetitions of the source-command connection race cases and +focused shared interaction/consent/observation checks. Earlier command increments +passed the private Xorg remote-input and internal-form harnesses, retaining injected-approval rejection, secret/ordinary forms, learn mode and XTerm handoff behavior. +Those native harnesses were not rerun for desktop return; physical capture +release remains unverified. Fixtures use private loopback relays and synthetic local form submissions; they do not exercise physical keyboard input. @@ -143,7 +156,15 @@ Remote alone does not update the reader's consent-interaction support. 4. Cancel while inspection or TLS join stalls; lock/unlock and trigger XTerm handoff during consent, inspection and an established relay connection. Confirm cancellation, no resume, no stale approval and a fresh usable command. -5. Recheck ordinary entries/menus, secret forms, learn mode, remapped shortcuts, +5. After connecting, choose Return to desktop and keep this connection. Confirm + the form disappears, ordinary typing reaches the local application, and + application focus/reading and local Braille resume. Wait at least four seconds, + then press Cthulhu+Ctrl+Shift+R: status must reopen without a new consent/key + prompt. Disconnect must close the relay. Repeat Return to desktop followed by + lock/unlock or XTerm handoff; the old connection must end and never resume. + Incoming audible speech remains unavailable; do not count relay status as a + successful speech test. +6. Recheck ordinary entries/menus, secret forms, learn mode, remapped shortcuts, application key delivery and Hello World/Wormhole/Battery Status. These share the changed host interaction path. Review the diff before any submission. diff --git a/remote/connection-ui.md b/remote/connection-ui.md index e3cf006..b357ae6 100644 --- a/remote/connection-ui.md +++ b/remote/connection-ui.md @@ -25,8 +25,8 @@ library supplies no proof that a submission came from that form or a local key. Pending approval has a context that ends on replacement, matching revocation, consumption, disconnect or SDK loss. A replacement cancels setup and inspection. -The reader remains authoritative for action expiry at `remote.open`; the -protocol currently supplies no event for expiry of an unopened action. Merely +The reader remains authoritative for action expiry at `remote.open`; it also +notifies the coordinator when an unopened action expires or is revoked. Merely keeping a form open does not extend approval. An expired action cannot connect. The workflow's `done` barrier includes its inspection worker. Cancelling it @@ -34,6 +34,15 @@ initiates coordinator cleanup; wait separately on the coordinator's Disconnect barrier before disposing the SDK session/store. Cleanup is scoped to the original epoch: closing an old form cannot retire a newer approval or connection. +Status offers **Return to desktop and keep this connection**. After reader lease +open it returns a terminal `remote_background` result with that lease/epoch; +the reader verifies ownership and releases the interaction without cancellation. +The workflow and heartbeat remain under their original lease/policy lifetime. +The Remote shortcut reopens status/Disconnect. Before open succeeds this action +keeps status open with a refresh/disconnect notice. Ordinary Escape, Cancel and +Disconnect and close continue to end the workflow; this is an explicit exception +for desktop return, not a change to generic form cancellation. + ## Explicit actions - **Connect relay** validates the entered key, or uses a key previously loaded diff --git a/remote/speech.md b/remote/speech.md index 2ca3410..6dce05d 100644 --- a/remote/speech.md +++ b/remote/speech.md @@ -87,11 +87,14 @@ presenter currently opts into export; document/review commands, Say All, context announcements, separate key-name echo and other producers still need source review. Priority and language use defaults; no voice/backend state is sent. -The source command's status form remains modal and captures local keys for the -connection lifetime. Ordinary application presentation is suppressed while it -is open. This observer increment therefore supplies a reader integration path, -not a usable desktop speech session. Status detachment and incoming speech with -separate cancellation ownership remain next steps. Existing UI warnings stay. +The source command now offers explicit Return to desktop after reader lease +open, releasing its status form and interaction slots while heartbeats continue. +The Remote shortcut reopens status/Disconnect. The reader checks the original +process-owned lease; no consent or lifetime is extended. Private source-command +tests cover both roles, repeated desktop return/reopening and background +disconnect/lock/handoff/disable. Physical capture release and ordinary desktop +speech still need acceptance. Incoming speech with separate cancellation +ownership remains the next production step; existing UI warnings stay. Verification: @@ -137,7 +140,7 @@ 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 incoming-owner and status-lifetime integration, test ordinary reading, spelling, +After incoming-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 diff --git a/remote/src/connection_ui.go b/remote/src/connection_ui.go index 49575a4..d363185 100644 --- a/remote/src/connection_ui.go +++ b/remote/src/connection_ui.go @@ -16,7 +16,8 @@ import ( // connectionWorkflow joins the library forms and coordinator for one selected // endpoint and reader action. It is not a local-origin authorizer: the source // command relies on reader-owned consent and sensitive form submissions. -// The owner must cancel ctx on form closure, lock/handoff or process retirement. +// Ordinary form cancellation ends the workflow. An explicit desktop return +// retains it under the reader lease, which lock/handoff or process loss revokes. type connectionWorkflow struct { mu sync.Mutex ctx context.Context @@ -153,6 +154,7 @@ func (w *connectionWorkflow) form_locked() sdk.Interaction { } details.Items = append(details.Items, sdk.ListItem{ID: "status", Label: text}) result.Form = &sdk.Form{Title: "Remote relay status", Elements: []sdk.Element{details, + {ID: "desktop", Label: "Return to desktop and keep this connection", Kind: sdk.Button}, {ID: "refresh", Label: "Refresh connection status", Kind: sdk.Button}, {ID: "disconnect", Label: "Disconnect", Kind: sdk.Button}, {ID: "cancel", Label: "Disconnect and close", Kind: sdk.Button}, @@ -346,6 +348,14 @@ func (w *connectionWorkflow) submit(ctx context.Context, value sdk.Submission) ( return result, nil } case "status": + if value.Activated == "desktop" { + if lease, ok := w.owner.background_lease(w.action.Epoch); ok { + result := security_message("Remote connection controls closed. Press Cthulhu+Control+Shift+R to review status or disconnect. Desktop services remain unavailable.") + result.RemoteBackground = &lease + return result, nil + } + w.notice = "No live reader lease is available. Refresh connection status or disconnect." + } if value.Activated == "disconnect" { w.owner.disconnect_epoch(w.action.Epoch) } diff --git a/remote/src/connection_ui_test.go b/remote/src/connection_ui_test.go index 50956b3..8327d8f 100644 --- a/remote/src/connection_ui_test.go +++ b/remote/src/connection_ui_test.go @@ -174,6 +174,61 @@ func TestConnectionWorkflowConnectUsesLoadedKeyWithoutEcho(t *testing.T) { } } +func TestConnectionWorkflowBackgroundRequiresOpenedLease(t *testing.T) { + opening, release := make(chan struct{}), make(chan struct{}) + c, f := fixtureCoordinator(t, func(ctx context.Context, method string, params, result any) error { + if method == "remote.open" { + close(opening) + select { + case <-release: + case <-ctx.Done(): + return ctx.Err() + } + *result.(*sdk.RemoteLease) = sdk.RemoteLease{Lease: strings.Repeat("b", 32), Epoch: params.(sdk.RemoteOpen).Epoch} + } + return nil + }) + certificate, roots := testCertificate(t, true) + target := testRelay(t, certificate, func(connection net.Conn) { + if relayHandshake(t, connection, controller) == nil { + return + } + io.WriteString(connection, "{\"type\":\"channel_joined\",\"channel\":\"synthetic-fixture\",\"clients\":[]}\n") + io.Copy(io.Discard, connection) + }) + target.roots = roots + w := workflowFixture(t, c, approve(t, c, f, 1, "controller"), target, nil) + workflowSubmit(t, w, "connect", "synthetic-fixture") + awaitDone(t, opening) + nextCall(t, f, "remote.open") + if result := workflowSubmit(t, w, "desktop", ""); result.RemoteBackground != nil || result.Form == nil { + t.Fatal("detached before reader opened its lease") + } + close(release) + awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "waiting" }) + result := workflowSubmit(t, w, "desktop", "") + if !result.Done || result.Form != nil || result.Next != "" || result.RemoteBackground == nil || result.RemoteBackground.Epoch != 1 || result.RemoteBackground.Lease != strings.Repeat("b", 32) { + t.Fatal("desktop return lost or changed its lease identity") + } + if _, ok := c.background_lease(2); ok { + t.Fatal("background request followed another epoch") + } + if w.ctx.Err() != nil { + t.Fatal("returning to desktop cancelled the workflow") + } + nextCall(t, f, "remote.heartbeat") + command := &connectionCommand{coordinator: c, workflow: w} + reopened, err := command.open(t.Context(), nil) + if err != nil || reopened.(sdk.Interaction).Form.Title != "Remote relay status" { + t.Fatal("shortcut did not reopen connection status", err) + } + f.events <- sdk.SessionEvent{Kind: "remote.revoked", Lease: result.RemoteBackground.Lease, Epoch: 1} + awaitStatus(t, c, func(s connectionStatus) bool { return s.state == "failed" }) + if result := workflowSubmit(t, w, "desktop", ""); result.RemoteBackground != nil { + t.Fatal("revoked lease detached again") + } +} + func TestConnectionWorkflowLoadEndpointMismatchAndFailure(t *testing.T) { for _, mode := range []string{"other endpoint", "unsafe credential", "closed store"} { t.Run(mode, func(t *testing.T) { diff --git a/remote/src/coordinator.go b/remote/src/coordinator.go index 1573520..ea53e13 100644 --- a/remote/src/coordinator.go +++ b/remote/src/coordinator.go @@ -124,6 +124,18 @@ func (c *coordinator) snapshot() connectionStatus { return c.status } +// Only an opened, live attempt can outlive its connection form. The reader +// independently checks this lease against the requesting process session. +func (c *coordinator) background_lease(epoch uint64) (sdk.RemoteLease, bool) { + c.mu.Lock() + defer c.mu.Unlock() + a := c.active + if a == nil || a.epoch != epoch || a.ctx.Err() != nil || a.speech == nil { + return sdk.RemoteLease{}, false + } + return a.speech.lease, true +} + func (c *coordinator) clear_pending_locked() { if c.pendingStop != nil { c.pendingStop() diff --git a/tools/check.py b/tools/check.py index b4b3f64..ce3e1e5 100644 --- a/tools/check.py +++ b/tools/check.py @@ -176,7 +176,7 @@ def check_remote(repoRoot): ], cwd=readerRoot, env=environment, timeout=120, check=True) subprocess.run([ "go", "test", "./internal/tentacle", "./internal/tentaclewire", - "-run", "^TestRemoteSpeech", "-count=1", "-timeout=60s", + "-run", "^TestRemote(Speech|Background)", "-count=1", "-timeout=60s", ], cwd=readerRoot, env=environment, timeout=90, check=True)