feat(mobile): realtime nudge socket for cloud workspaces and hosts

Merged
SA
1mo ago
+555-1

Mobile opens the same org nudge socket the desktop uses. Patches update
agent status and presence in the cached cloud workspace rows without a
refetch; a kind refetches the matching queries. The 30s cloud list poll
runs only while the socket is down.

iOS drops sockets in the background, so the socket closes there and
dials again on return. React Query's focus refetch already covers what
was missed then, so the reconnect refetch runs only after a drop in the
foreground.

Adds EXPO_PUBLIC_REALTIME_URL (defaults to production) and Limrun steps
to the mobile-sim-verification skill.

Realtime Worker in dev

Local dev and the cloud dev stack did not run the realtime Worker. REALTIME_URL pointed at nothing, so nudges were dropped. In a cloud workspace, that meant the desktop sidebar never updated live.

  • bun dev:realtime (apps/realtime/scripts/dev-local.sh) runs the Worker on the worktree's REALTIME_PORT, using the .env nudge secret and API URL. It restarts the Worker when wrangler dev exits.
  • .superset/dev-stack.cloud.sh runs it in its own realtime tmux window.
  • Checked: health answers on the right port, a nudge signed with the .env secret is accepted, and SIGTERM stops it with no workerd processes left.

Existing worktrees: re-run setup. step_write_env (setup.sh, setup.cloud.sh) rewrites .env each run, and setup.local.sh appends its port block each run. Both write EXPO_PUBLIC_REALTIME_URL with the worktree's own REALTIME_PORT.

Verification

Tested on a Limrun iOS simulator against a local API and realtime Worker, signed in as a real account on the workspace Neon branch. Changes went through the API's real agent-status route, and app requests were counted from the Limrun tunnel log.

  • Socket connects after sign-in (101)
  • Idle with socket open: no cloudWorkspace.list requests in 3 min
  • Agent status working, then cleared: the row updated in place with zero app requests
  • Change made while backgrounded: no requests while backgrounded, the change shows on return, and the list is fetched once
  • Worker restarted while the app is open: backoff, reconnect, one refetch
  • Worker down for 75s: the 30s poll comes back, and reconnect retries back off
  • Unit tests for the patch helper, biome clean
  • Expired token on a device. Not tested: each dial fetches a fresh token, and a 4401 close forces a refresh.

This is groundwork for showing diff line counts on the cloud workspace list. Those numbers would reach mobile through this socket.


Summary by cubic

Mobile opens the same org nudge socket the desktop uses, so agent status and presence reach cached cloud workspace rows without a refetch. The 30s cloud list poll runs only while the socket is down or the list query is in error.

Details

  • Patch nudges update the cached rows in place; a nudge kind refetches the matching queries, and an agent status older than the cached row is dropped.
  • A socket counts as connected only after it stays open for 2s, so the Worker refusing a stale org JWT (4401/4403) counts as a failed dial: back off and refresh the token instead of looping.
  • iOS drops sockets in the background, so they close there and redial on return. React Query's focus refetch covers what was missed, so a reconnect refetch runs only after a foreground drop or a failed or hung dial (the 15s timeout).
  • Adds EXPO_PUBLIC_REALTIME_URL (defaults to production), bun dev:realtime, and Limrun steps (including relay port tunneling) to the mobile-sim-verification skill.
  • Local dev and the cloud dev stack now run the realtime Worker so nudges reach the app; without it, REALTIME_URL points at nothing and nudges are dropped.

Summary by CodeRabbit

  • New Features

    • Mobile apps now receive realtime updates to cloud workspace status and host information, reducing reliance on polling while retaining polling when realtime is unavailable.
    • Added a configurable realtime service address for local and hosted environments, with support for running the realtime service locally.
  • Bug Fixes

    • Workspace status and presence updates now appear on the correct workspace, with updated presence details and timestamps.
  • Documentation

    • Expanded simulator verification guidance, including remote iOS testing, realtime setup, and cleanup steps.