Promotes the Linux backend from probe-only to a live
`org.freedesktop.portal.GlobalShortcuts` session, closing the
gen2 v0.9.3 baseline's last Linux-side code item. Both gaps I
flagged on the review pass are addressed:
* Stop now closes the portal session through the dedicated
`org.freedesktop.portal.Session` interface (not the
request-cancel `Request` interface — that would only abort a
pending Request, not release the bound shortcuts).
* Ten new unit tests cover `classify_shortcuts_value`,
`publish_bound`, `publish_l0`, and the `SHORTCUT_ID` stability
contract using synthesised `OwnedValue` payloads. Live D-Bus
coverage stays in the `linux_portal_smoke` ignored
integration test (RR-PTT-004).
Live session lifecycle (gen2 Q5b — lazy, single backend instance):
1. `start(gate, binding)` spawns one `tokio::spawn` worker that
owns an async `zbus::Connection` (sharing the bridge's
tokio runtime per Q4a).
2. `CreateSession` with fresh random `handle_token` /
`session_handle_token` tokens. The worker awaits the portal
`Response` signal via a `RequestProxy` subscription and
extracts `session_handle` from the results dict.
3. `BindShortcuts(session_handle, [("chanora-ptt", { description
= "Chanora push-to-talk" })], "", {})`. The portal opens its
own system-managed dialog asking the user to choose a key
— Chanora itself never reads raw key events. The audio
engine continues at `L0Focused` while the dialog is open;
the descriptor watch publishes the transition once the
portal returns.
4. On `response_code == 0`: classify the `trigger_description`
substring (heuristic: contains "mouse" -> MouseSideButton,
else Keyboard), publish `L2GlobalHoldToTalk` (or `L3` for
mouse) through the watch sender. The raw trigger_description
string is never logged (DEC-027 / SRS-202).
5. On `response_code == 1` (cancelled) or `>= 2` (failure):
publish `L0Focused` through the watch sender. The user can
retry via the UI "Configure" button (gen2 Q6a).
6. The worker enters a `tokio::select!` loop multiplexing the
`cmd_rx` channel (Rebind / Stop) and the `Activated` /
`Deactivated` signals. Matching signals scoped to this
session handle and `chanora-ptt` shortcut id drive
`gate.set(true/false)`.
7. `Rebind` re-runs `BindShortcuts` on the same session.
8. `Stop` calls `org.freedesktop.portal.Session.Close()` on
the session-handle object path, clears the gate, exits.
UX (gen2 Q3a): when `_pttBackendId == 'gnome-wayland-portal'`,
the Flutter "Configure" button skips the in-app
`_PttBindingCaptureDialog` and shows a SnackBar telling the user
their desktop environment will open its own shortcut dialog.
The button delegates to `setPttBinding(keyboard, "portal")`
which nudges the backend; the portal handles the rest. New ARB
key `pttConfigurePortalRedirect` in en + zh-Hans.
Trait surface (cross-cutting):
* `DesktopPttBackend::descriptor_watch()` is a new trait method
with a default impl returning a never-firing receiver.
Backends with async capability transitions (only the Linux
portal backend today) override it to return the live watch
sender's receiver.
* `chanora_core::ChanoraSession::start_audio` subscribes to the
active backend's `descriptor_watch()` and spawns a forwarder
task that re-emits `SessionEvent::PttCapability` on every
transition. The initial value is emitted synchronously.
`Cargo.toml` (Linux-only):
* `futures-util` (std features, no executor) for stream
consumption on the portal signal subscriptions.
* `rand 0.8` for fresh per-process portal tokens.
* `zbus` continues at v5 with the `tokio` + `blocking-api`
features.
Tests
-----
* `chanora_audio` rises from 8 to 18 unit tests. New
coverage on the Linux module:
- `classify_returns_none_when_shortcut_id_missing`
- `classify_returns_keyboard_for_typical_trigger_description`
- `classify_returns_keyboard_when_trigger_description_missing`
- `classify_detects_mouse_substring`
- `classify_is_case_insensitive_on_mouse_substring`
- `publish_bound_keyboard_publishes_L2_with_keyboard_class`
- `publish_bound_mouse_publishes_L3`
- `publish_bound_none_publishes_L2_keyboard_default`
- `publish_l0_clears_descriptor`
- `shortcut_id_is_stable`
* Workspace total: 67 unit + integration tests, all green with
`CHANORA_DISABLE_KEYRING=1` (was 57 at v1.0.0-rc.4).
* New `crates/chanora_audio/tests/linux_portal_smoke.rs`
ignored integration test (RR-PTT-004 evidence path). Run on
a GNOME-on-Wayland host with
`cargo test -p chanora_audio --test linux_portal_smoke -- --ignored --nocapture`.
Documentation
-------------
* `docs/architecture/desktop-ptt-architecture.md` §5.3 rewritten
to describe the realised lifecycle; v0.9.4 change-history
entry added.
* `docs/governance/product-decision-register.md` v0.9.10
change-history entry recording the code-side promotion. No
decision rows mutate.
* `docs/release/release-readiness-go-nogo-record.md` RR-PTT-004
flipped from `Open` to `Implemented (live trace pending)`;
v0.9.5 change-history entry.
Verification
------------
* `cargo test --workspace`: 67/67 green.
* `cargo deny check`: advisories ok, bans ok, licenses ok,
sources ok.
* `cargo about generate --offline`: zero new warnings.
* `tools/dump_flutter_licenses.sh`: 94 packages, 0 without
LICENSE.
* `flutter analyze`: clean.
* `cargo build -p chanora_bridge --release` +
`flutter build linux --release`: clean Linux x86_64 bundle.
* Live portal trace (RR-PTT-004) — **not run**. The dev shell
is a TTY without a Wayland session. The user will run the
ignored smoke test from inside a GNOME-on-Wayland session
when available.
No Windows / macOS / iOS live verification in this commit (hosts
unavailable). The Windows + macOS backend scaffolds remain in
place reporting their target capability honestly; live OS-call
wiring is queued for their respective platform owners'
reference hosts per `docs/governance/staged-release-plan.md`.
13 KiB
Desktop Push-to-Talk Architecture
| Field | Value |
|---|---|
| Document type | Architecture |
| Version | 0.9.3 |
| Status | Baseline Candidate |
| Language | English |
| Product | Chanora |
| Date | 2026-05-15 |
Owner-resolved review questions from gen2/chanora-desktop-ptt-review-summary-v0.9.2.md are recorded as DEC-023 through DEC-028 in docs/governance/product-decision-register.md.
1. Purpose
Desktop Push-to-Talk (PTT) is the operation by which a user holds a bound keyboard key or mouse button to enable voice transmission and releases it to disable transmission. This document fixes the architecture so the product can describe, implement, verify, and release desktop PTT honestly — every capability claim made to the user is auditable against a live runtime measurement.
The previous architecture treated PTT as a single global behaviour. That over-promised on platforms where the operating system, the user-granted permission set, the display server, or the compositor does not permit unconditional global key capture. This document replaces that with a capability-based model.
2. Architectural Decisions
| ID | Decision | Source |
|---|---|---|
| DEC-023 | Windows Global PTT is P0 / MVP. | Owner ruling 2026-05-15 |
| DEC-024 | macOS Global PTT is P0 / MVP with explicit permission UX flow. | Owner ruling 2026-05-15 |
| DEC-025 | The officially-tested Linux environment for the first public release is GNOME on Wayland (only). | Owner ruling 2026-05-15 |
| DEC-026 | Mouse side buttons are supported in the first desktop PTT release on Windows and macOS; Linux support follows whatever the GlobalShortcuts portal exposes. | Owner ruling 2026-05-15 |
| DEC-027 | The diagnostic export carries capability and availability state only — no raw key codes, scan codes, or virtual-key values ever leave the device. | Owner ruling 2026-05-15 |
| DEC-028 | The missed-key-up watchdog is P0: the audio engine shall self-release transmit_active if the OS suppresses a key-up event. |
Owner ruling 2026-05-15 |
3. Capability Ladder
| Level | Name | Meaning |
|---|---|---|
L0Focused |
Focused PTT | PTT works only while the Chanora window has input focus. Mandatory on every desktop platform per SysRS-296. |
L1GlobalShortcut |
Global shortcut activation | The OS recognises a global accelerator and notifies the application, but hold-to-talk semantics may be approximated rather than guaranteed. |
L2GlobalHoldToTalk |
Global hold-to-talk | Press and release events are delivered while the application is not focused. The common Windows / macOS / GNOME-Wayland-portal MVP target. |
L3GlobalWithMouseButtons |
Global hold-to-talk plus mouse buttons | Includes mouse side buttons (Mouse4 / Mouse5). |
L4DeviceAware |
Device-aware PTT | Backend can distinguish specific input devices. Reserved. No MVP implementation produces L4DeviceAware. |
The reported capability shall match runtime behaviour. A backend that could deliver L2GlobalHoldToTalk but lacks the user-granted permission shall report L0Focused until permission is granted.
4. Component Allocation
+------------------------------------+
| Flutter Voice UI |
| PTT binding-capture sheet |
| VoiceBar PttCapabilityBadge |
+---------------+--------------------+
|
| set_binding(...)
| events_stream() -> BridgeEvent::PttCapability
v
+---------------+--------------------+
| chanora_bridge |
| typed DTOs, no key data crosses |
+---------------+--------------------+
|
v
+------------------------------------+
| chanora_core |
| PttController |
| owns Box<dyn DesktopPttBackend>|
| owns Arc<AudioTransmitGate> |
| publishes PttCapabilityLevel |
| MissedKeyUpWatchdog (tokio task) |
+---------------+--------------------+
|
v
+------------------------------------+
| chanora_audio |
| DesktopPttBackend trait |
| WindowsRawInputBackend |
| WindowsHookBackend |
| MacOSEventTapBackend |
| LinuxGnomeWaylandBackend |
| FocusedPttBackend |
| AudioTransmitGate |
| capture_active / transmit_active |
+------------------------------------+
|
v
+------------------------------------+
| chanora_diagnostics |
| RedactingLogLayer |
| PttSanitizer (drops banned keys) |
+------------------------------------+
The audio engine reads transmit_active once per outbound Opus frame. No code path other than AudioTransmitGate::set flips the value.
5. Per-Platform Strategy
5.1 Windows
Three-level ladder evaluated once at audio-engine start:
WindowsRawInputBackend— preferred. UsesRegisterRawInputDeviceswithRIDEV_INPUTSINKto receive keyboard and mouse events even when Chanora is not focused. Runs a message-only window on its own OS thread so the WndProc is non-blocking. ReportsL2GlobalHoldToTalk(keyboard) orL3GlobalWithMouseButtons(when a mouse side button is bound).WindowsHookBackend— fallback. InstallsWH_KEYBOARD_LLandWH_MOUSE_LLhooks on its own thread. Used when Raw Input registration fails (some constrained environments). ReportsL2GlobalHoldToTalk/L3GlobalWithMouseButtons.FocusedPttBackend— final fallback. ReportsL0Focused.
The chosen rung is fixed for the lifetime of the audio engine; restart of the engine re-evaluates the ladder.
5.2 macOS
Two-level ladder with explicit permission gating:
MacOSEventTapBackend— preferred when Input Monitoring (or Accessibility, depending on macOS version) permission isGranted. Creates aCGEventTapon the main run loop, filtered to keyboard and mouse-button events. ReportsL2GlobalHoldToTalk/L3GlobalWithMouseButtons.FocusedPttBackend— fallback when permission isDenied,Undetermined, or revoked at runtime. ReportsL0Focused.
The audio engine starts immediately on user request; the permission state is queried in parallel and the capability level is upgraded asynchronously through BridgeEvent::PttCapability if the user grants the permission. This avoids blocking voice functionality on a permission prompt.
5.3 Linux
Two-level ladder restricted to the officially-tested environment per DEC-025.
Selection at try_select() time:
- Reads
XDG_SESSION_TYPE(must equalwayland) andXDG_CURRENT_DESKTOP(must containgnomeorgnome-flashback). - Probes
org.freedesktop.portal.GlobalShortcutsvia a blockingversionproperty read.
If either check fails the factory returns None and the caller falls back to FocusedPttBackend at L0Focused.
Live session lifecycle (Q5b — lazy, single backend instance):
start(gate, binding)spawns a workertokio::spawntask. The worker owns its own asynczbus::Connectionand aGlobalShortcutsProxy.- The worker calls
CreateSessionwith freshhandle_token/session_handle_tokenvalues (randomu32per process). The portal returns aRequestobject path; the worker subscribes to theResponsesignal on that path and awaits the session handle from theresultsdict. - The worker then calls
BindShortcuts(session_handle, [("chanora-ptt", { description: "Chanora push-to-talk" })], "", {}). The portal opens its own system-managed dialog asking the user to choose a key — Chanora does not read raw key events. The audio engine continues atL0Focusedwhile the dialog is open (the descriptor watch publishes the transition once the portal returns). - Once
BindShortcutsresolves:- On
response_code == 0: classify thetrigger_descriptionsubstring heuristically (mouse→mouse-side-button; otherwisekeyboard), publishdescriptor() = L2GlobalHoldToTalk(orL3GlobalWithMouseButtonsfor the mouse case) through the watch sender. The trigger_description string itself is never logged. - On
response_code == 1(user cancelled) or> 1(other failure): publishdescriptor() = L0Focusedthrough the watch sender. The user can retry via the UI "Configure" button.
- On
- The worker then enters its long-lived loop, multiplexing on the command channel (
Rebind/Stop) and the portal'sActivated/Deactivatedsignals. Signal payloads scoped to a different session handle or shortcut id are ignored. MatchingActivatedcallsgate.set(true); matchingDeactivatedcallsgate.set(false). rebind(binding)sends a command to the worker which re-runsBindShortcutson the same session. The portal opens its dialog again; the user can pick a new key.stop()(or backend Drop) signals the worker, which callsRequest::Closeon the session handle, callsgate.set(false), and exits.
UX implication on Linux: the in-app _PttBindingCaptureDialog (used by Windows and macOS in MVP) is skipped when the active backend is gnome-wayland-portal. The Flutter "Configure" button calls setPttBinding directly with a sentinel platform_key = "portal" and shows a SnackBar telling the user their desktop will open its own shortcut dialog. This matches the portal's design (DEC-027 / Q3a).
Per DEC-025 the application does not claim Global PTT support on an untested Linux environment. The UI capability badge explicitly notes "Focused PTT — untested compositor for Global PTT" when the user runs Chanora outside GNOME-on-Wayland.
6. Privacy Rule
Per SysRS-302 and SRS-202:
- Raw key codes, scan codes, virtual-key values, keysyms, and key-press timing sequences shall not be logged, persisted, or included in any user-initiated diagnostic export.
- The
PttSanitizerlog-sink decorator enforces this at write time by inspecting field names and dropping records whose field names match a banned list (key_code,scan_code,virtual_key,vk,keysym,keysym_string,key_sequence). The check is structural — it does not rely on a content scan. - The diagnostic export shall name only the capability level (
PttCapabilityLevel::as_str()), the backend identifier (a fixed&'static strper implementation), and the bound input class ("keyboard","mouse-side-button").
7. Audio Gate Rule
Per SRS-201:
capture_active: AtomicBoolis set by the audio engine on input-stream lifecycle transitions (stream opened or closed) and by the platform input-permission state. The PTT subsystem does not writecapture_active.transmit_active: AtomicBoollives insideAudioTransmitGate. The Opus encoder feed reads it once per outbound frame; the gate is the only mutator path.- A muted self-input (per
set_input_muted) forcestransmit_activeto false regardless of the PTT subsystem's wish; this preserves the existing self-mute semantics.
8. Missed-Key-Up Watchdog
Per SRS-203 / DEC-028:
- The audio engine spawns one
MissedKeyUpWatchdogtask per audio session. - It subscribes to
AudioTransmitGate'swatch::Receiver<bool>and notes the timestamp of eachfalse -> truetransition. - On each
true -> falsetransition it clears the timestamp. - If a
truelifetime exceeds the configured ceiling (default 30 s, owner-tunable through a future setting), the watchdog callsAudioTransmitGate::set(false)and emits a sanitised diagnostic line naming only the capability level and backend identifier.
9. Release Readiness
Per SysDes-148 and the release-readiness record:
- Every release artefact carries a per-platform capability-evidence row listing the detected
PttCapabilityLevel, the active backend identifier, and whether the Focused fallback was exercised during verification. - Release notes shall mirror that evidence and shall not over-claim Global PTT support.
10. Traceability
SysRS-296..302
-> SysDes-142..148
-> SRS-195..203
-> SAD-071..079
-> SDD-081..092
Verification coverage:
SDD-081..092 -> SWE4-UV-035..039
SAD-071..079 + SDD-081..092 -> SWE5-IV-015
SRS-195..203 -> SWE6-SV-017
SysDes-142..148 -> SYS4-SIV-016
11. Change History
| Version | Date | Description |
|---|---|---|
| 0.9.3 | 2026-05-15 | Initial baseline-candidate architecture for capability-based desktop Push-to-Talk. Codifies the owner rulings for PTT-OPEN-001 through PTT-OPEN-006 as DEC-023 through DEC-028. |
| 0.9.4 | 2026-05-15 | Promoted the Linux GNOME-Wayland backend from probe-only to the live CreateSession + BindShortcuts + Activated / Deactivated session flow. Owns an async tokio task with a dedicated zbus::Connection; publishes descriptor transitions through a watch::Sender consumed by chanora_core::ChanoraSession::start_audio. Adds the privacy-safe trigger_description classifier and the cancellation / failure path (downgrade to L0Focused + re-emit). Updates the Flutter UI to skip the in-app capture dialog on the portal backend (Q3a) and surface a SnackBar redirecting the user to the desktop's own dialog. |