openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

Device pairing always fails: core waits for a tunnel:registered event the backend never emits

Open oxoxDev opened this issue 5 months ago • 2 comments

Summary

Pairing a phone never completes: openhuman.devices_create_pairing fails with [devices/rpc] tunnel:register failed: [devices/tunnel] timeout waiting for tunnel:registered after a 10s hang. 100% of register attempts fail in production.

Problem

What happens: the core emits tunnel:register then waits for an inbound tunnel:registered Socket.IO event. The backend (tunnel relay) answers tunnel:register only via the Socket.IO ACK callback and never emits a tunnel:registered event, so the core always times out after 10s.

Root cause — cross-component Socket.IO contract mismatch:

  • Backend tunnel:register handler replies with ack({channelId, pairingToken, pairingExpiresAt}) and emits no tunnel:registered event. The ack carries no sessionToken.
  • Core's SocketManager.emit sends a raw event frame with no ack id, and the WS read loop has no Socket.IO ACK arm, so the backend's ack reply is silently dropped.
  • Core's TunnelRegisterResponse additionally expects a sessionToken the backend never mints for the core role (the session token is minted for the client during pairing).

Impact: device/QR pairing (experimental iOS client) is fully broken. Telemetry: 442 events / 36 affected users, first seen 2026-06-18, across app versions 0.57.44 → 0.58.0, production, macOS.

Repro: Settings → Pair phone → register hangs ~10s → error. Reproduces on current main (mismatch present on both sides of main).

Solution (proposed)

Fix the core side to speak the ack the backend already uses:

  1. Add generic Socket.IO ACK support to SocketManager (emit_with_ack) + an ACK arm in the WS read loop, guarded by an is_connected() fast-fail.
  2. Rewrite tunnel_client::emit_register to use the ack; align TunnelRegisterResponse to {channelId, pairingToken, pairingExpiresAt} (drop the phantom sessionToken).
  3. Tokenless tunnel:connect for role:core; remove the now-dead tunnel:registered event plumbing.

No backend change required.

Acceptance criteria

  • [ ] Repro gone — pairing register completes and returns a channel/QR instead of timing out.
  • [ ] Regression safety — unit tests couple the core parser to the backend ack shape (ack parse + register parse) so a future drift fails CI; not-connected path fast-fails.
  • [ ] Diff coverage ≥ 80% — fix PR meets the changed-lines gate.
  • [ ] Pairing manually verified on main against staging.

Related

Sentry: TAURI-RUST-EVC (tauri-rust) Backend tunnel relay: tinyhumansai/backend#709 Core pairing flow: #3452

oxoxDev avatar Jun 30 '26 14:06 oxoxDev

Duplicate of #4355 ("fix(devices): use socket ack for pairing register"), merged 2026-06-30, shipped in v0.58.7. #4355 is the exact fix: SocketManager::emit_with_ack + Socket.IO ACK read arm; tunnel:register reads ack shape {channelId, pairingToken, pairingExpiresAt}; tokenless role:core connect; phantom sessionToken dropped. Sentry TAURI-RUST-EVC flipped resolvedInNextRelease.

oxoxDev avatar Jul 01 '26 07:07 oxoxDev

This issue is not resolved. I am getting this error when I try to pair my IPhone on openhuman v0.63.12.

shiven2001 avatar Aug 10 '26 13:08 shiven2001