Skip to content

fix: 6 connection/auth/diagnostics bugs on the first-run path (retention)#131

Merged
dzianisv merged 1 commit into
mainfrom
fix/connection-auth-diagnostics
Jul 18, 2026
Merged

fix: 6 connection/auth/diagnostics bugs on the first-run path (retention)#131
dzianisv merged 1 commit into
mainfrom
fix/connection-auth-diagnostics

Conversation

@dzianisv

Copy link
Copy Markdown
Owner

Six verified correctness bugs in the connect + failure-diagnosis flow — the exact path where a new user connects or churns. Confirmed against code (and the opencode server's auth middleware); typecheck clean, 197 tests pass.

High impact

  1. Non-ASCII credentials broke auth and hung the UI. btoa is Latin1-only and throws on any non-ASCII char, so a server with a non-ASCII username/password could never connect, and the throw became an unhandled rejection that spun the Connect button forever. Now UTF-8-safe base64 (RFC 7617). ASCII byte-identical. +3 tests.
  2. Diagnostics misdiagnosed auth failures as "no internet". It returned no-internet before checking whether the user's own server was reachable — so a Tailscale user with a wrong password (LAN reachable, no WAN) was told to check their network instead of their password. Now checks root.ok first. +1 test.
  3. Trailing-slash URL failed every request while diagnostics said "works now". An Advanced/Edit URL with a trailing slash produced host:4096//global/health on every call; the probe reconstructed a clean URL and reported success. createClient now strips the trailing slash.

Medium
4. SecureStore failure after a successful test hung the UI (no try/catch) → now caught + alerted.
5. Diagnostics probe used different credentials than the real request (Quick Connect probed with no auth) → now uses buildAuth.
6. A username typed in Advanced mode leaked into Quick Connect, silently overriding the opencode default → Quick Connect no longer reads that state.

i18n en+zh in parity.

🤖 Generated with Claude Code

https://claude.ai/code/session_01T12AhSnQVrSxNnvwfCx2z6

1. buildRequestHeaders: UTF-8-encode Basic-auth credentials before btoa()
   so non-ASCII usernames/passwords don't throw (Hermes' btoa is Latin1-only
   and the throw was an unhandled rejection that hung the connect spinner).

2. diagnostics classify(): check root.ok (server reachable) before
   !internet.ok, so a reachable-but-failing server (e.g. wrong auth) is no
   longer misdiagnosed as "no internet" just because the public-internet
   probe also failed (captive portal, Tailscale-only network, etc).

3. sdk.ts createClient: strip trailing slashes from baseUrl once, so a
   trailing-slash URL from Advanced mode / Edit screen doesn't produce a
   double slash on every request path.

4. add.tsx / [id].tsx: wrap addConnection/updateConnection in try/catch so
   a SecureStore failure after a successful test resets the spinner and
   shows an alert instead of hanging forever. Adds
   connection.shared.alerts.saveFailedTitle/saveFailedMessage (en + zh-Hans).

5. add.tsx / [id].tsx: build the diagnostics probe's auth with buildAuth()
   instead of a hand-rolled expression, so the probe reproduces the real
   request's credentials (previously Quick Connect's password-only case
   sent no auth to the probe at all).

6. add.tsx handleQuickConnect: stop sending the shared `username` state,
   which could carry a stray value typed earlier in Advanced mode and
   silently override the "opencode" default after "Back to Quick".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01T12AhSnQVrSxNnvwfCx2z6
@dzianisv
dzianisv merged commit df4a361 into main Jul 18, 2026
7 checks passed
@dzianisv
dzianisv deleted the fix/connection-auth-diagnostics branch July 18, 2026 23:04
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