Skip to content

feat(relay): close an attach-deadline 4404 with the attach-timeout reason - #30658

Closed
Jinwoo-H wants to merge 6 commits into
relay-step6-phone-logs-metricsfrom
relay-step6-attach-timeout-reason
Closed

Jinwoo-H wants to merge 6 commits into
relay-step6-phone-logs-metricsfrom
relay-step6-attach-timeout-reason

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​16 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10

ELI5

Sometimes a phone reaches the right relay cell and the desktop is connected there, but the desktop's data link for this phone never arrives in time. Today the phone hears "host offline" and waits 5 to 15 seconds before trying again. Phones on the latest app update (#30607) already know a more specific reason, "attach-timeout", and redial the same cell once after about a second. This PR makes the cell actually send that reason.

What Changed

  • At the attach deadline in HostSessionRegistry.acceptClientUnfenced, the phone socket is closed with code 4404 and reason attach-timeout (RELAY_PHONE_CLOSE_REASON.HOST_ATTACH_TIMEOUT, added to the contract in fix(mobile): faster relay recovery after an app switch and on a late desktop data link #30607) instead of the generic relay connection rejected.
  • rejectClient's reason parameter is widened to accept a phone close reason. RELAY_HOST_CLOSE_REASON (the set the desktop mirrors for its own control socket) is not touched.
  • The contract exports the matching RelayPhoneCloseReason type.
  • The failed relay-hello frame is byte-for-byte the same: shipped phones parse it with a strict schema and would reject an extra field.

Every other 4404 (the host is genuinely absent) keeps its existing reason.

Why

The phone cannot tell the two 4404s apart today, so it treats a transient desktop data-dial failure like a desktop that has gone away. Putting the reason on the close frame reaches only phones that read it (old phones read close reasons only to look up known ones, and ignore this one), so it is safe to send from every cell. Deliberately not behind the step-6 switch: Jinwoo approved this for the next cell image on all cells ("also in J"), and old phones ignore an unknown close reason (verified in the #30607 review). The "switch off = today's behaviour" rule covers the phone path, not this all-cell change.

Linked Issue

N/A (step 6 of the relay redesign, internal; phone half merged in #30607)

Visual Proof

N/A: relay close reason, no UI.

Testing

  • Automated tests added/updated
  • host-session-client-accept.test.ts: an attach deadline closes with 4404 + attach-timeout, and the relay-hello frame is exactly { type: 'relay-hello', ok: false, code: 4404 }.
  • Relay vitest --maxWorkers=2: 1221 passed; relay-contract tests 41 passed. Relay typecheck clean. Postgres-backed tests not run locally (no test database).

Review

Stacked on #30656 (logs and metrics), which records the same deadline.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Mobile compatibility: old phones throw on the failed hello before the close arrives and ignore unknown reasons; OTA phones from #30607 redial once.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visual proof with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (mobile old/new phones covered above)
  • Relay typecheck and tests pass locally; CI covers the rest

…ason

The phone close reason from #30607 now rides the close frame of the 4404 a cell
sends when the desktop's data leg misses the attach deadline, so OTA phones can
redial the same cell once instead of waiting out the host-offline delay. The failed
relay-hello frame is unchanged, and old phones ignore the reason.
@Jinwoo-H

Copy link
Copy Markdown
Contributor Author

Included in #30666 (merged).

@Jinwoo-H Jinwoo-H closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant