Why go native on HarmonyOS instead of wrapping a web view
Agents running on my workstation handle long sessions and cron jobs on their own—I do not want to babysit a terminal or route high-risk commands through a third-party cloud proxy. Hermes Relay speaks directly to self-hosted Hermes Gateways in native ArkTS / ArkUI, waking me up only for real decisions.
| Layer | Target & Stack |
|---|---|
| Device & OS | HarmonyOS 7 / API 26 (also verified on API 20+) · Real hardware SGT-AL10 |
| UI & Gestures | Native ArkTS / ArkUI Stage · Root-level custom RelayDrawerHost |
| Sync & Secrets | WebSocket streaming + Authoritative REST reconciliation + AssetStoreKit + Cron |
| Verification Bar | 595 module unit tests + transparent-proxy wire packet captures vs server DB |
Pitfall 1: Replacing the flaky system sidebar with RelayDrawerHost
The built-in system sidebar frequently fought vertical scroll lists for touch ownership, leaking child taps and flickering mid-drag.
I removed it and built a root-level RelayDrawerHost:
- Single continuous
drawerProgress: drives content translation, scrim opacity, and drawer offset from one numeric state, eliminating multi-state flicker - Directional gesture recognizer arbitration: evaluates initial drag vectors to reject vertical-scroll misfires and child click pass-through
- Consistent across API levels: delivers uniform physics across both
API 20+andAPI 26devices
Pitfall 2: Screen-lock clearing stream waiters stranded terminal frames
The subtler bug surfaced whenever I triggered a task and locked the phone: returning minutes later showed the session still spinning on RUNNING even though the gateway had long finished.
# Wire trace & queue diagnosis on SGT-AL10
1. Client sends task prompt over active WebSocket stream
2. Screen locks -> OS suspends stream and clears in-memory stream waiter
3. Gateway pushes terminal frame (WAITING / COMPLETED) -> stranded in queue
4. Screen unlocks -> UI stays frozen on RUNNING until force-restarted
Clearing the in-memory stream waiter severs the consumer from frames already sitting in flight. Both consumer reattachment and authoritative state reconciliation have to happen together.
The Fix: Waiter Registry + Authoritative WAITING > RUNNING Sync
Moved callbacks into a persistent waiter registry that automatically reattaches consumers to active sessions after backgrounding or reconnects.
WAITING > RUNNING priority
On wake/reconnect, reconciles local stream state against authoritative REST snapshots so pending clarifications and failed retry rows never vanish.
Before vs After on real hardware
| Scenario | Before | After |
|---|---|---|
| Vertical scroll vs drawer swipe | System sidebar stole scroll touches and flickered | RelayDrawerHost arbitrates direction with zero flicker |
| Screen-lock mid-stream | Cleared waiter stranded terminal frames; UI stuck |
Registry auto-reattaches + authoritative REST sync, zero drops |
| Cold start after failure | Failed retry context lost on restart | Cold start restores failed retry rows and parallel session state |
| Regression & contract bar | Manual happy-path smoke clicks | 595 module unit tests + SGT-AL10 wire traces vs server DB |
595 unit tests + device wire-level contract verification
To keep the state machine honest as features grew, every runtime switch, batched clarify payload, cron trigger, and fallback path sits behind deterministic tests and hardware captures:
SGT-AL10 (API 26) cross-checked row-for-row against server DB state.Boundaries & honest V1 status
- Zero third-party relay: all sessions, clarifications, and sudo approvals talk directly to isolated user-owned gateways
- Daily personal driver: 595 module tests and hardware wire-level traces pass today
- Explicit open V1 items: a small set of external V1 integration items remain explicitly open and tracked rather than hidden
Takeaway
Shipping an agent client on mobile is less about opening a WebSocket than surviving screen locks, backgrounding, and gesture fights. Driving the drawer from one continuous state and backing streams with a waiter registry plus authoritative REST priority made Hermes Relay reliable enough for daily use.