Skip to content

fix(tunnel): token-based daemon-present probe (fixes silent hsh login skip)#30

Merged
racerxdl merged 1 commit into
mainfrom
teske/fix-daemon-present-detection
Jun 3, 2026
Merged

fix(tunnel): token-based daemon-present probe (fixes silent hsh login skip)#30
racerxdl merged 1 commit into
mainfrom
teske/fix-daemon-present-detection

Conversation

@racerxdl

@racerxdl racerxdl commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Problem

Reported in the field on 0.3.1: hsh login printed only 'Successfully authenticated with Hoop!' and silently did nothing for the daemon, leaving it on a stale/expired token (hsh tunnel refresh then 401'd). One browser, zero daemon output — even though the daemon was running and hsh tunnel status reached it fine.

Root cause

The previous fix used existsSync() on the unix socket path to decide whether the daemon is 'present' (and thus whether the optional daemon leg may skip silently). On the affected host that existsSync returned false for a live daemon, so loginDaemon took the 'genuinely absent → silent skip' branch.

But TunnelClient.connect() (used by hsh tunnel status, which worked) never stats the socket — it keys on a readable control token. So the socket-existsSync discriminator was inconsistent with how the client actually reaches the daemon.

Fix

daemonLooksInstalled() now mirrors connect()'s reachability basis:

  • readable control token → present (connect would succeed)
  • token file present-but-unreadable (perms) or env-pointed → present
  • env-pointed socket, or socket existsSync true → present
  • only the bare-default, nothing-present case → genuinely absent → silent skip

So a live daemon is now always detected as present, and any failure to update it surfaces a warning + non-zero exit instead of a silent skip.

Note on the 401 itself

The token rejection you saw is the known no-refresh-token expiry (already tracked) — OIDC access tokens from sandbox expire well under 12h and the daemon can't renew. This PR doesn't change that; it ensures hsh login actually re-authenticates the daemon (instead of silently skipping) so the user can recover, and hsh tunnel status already hints the re-login.

Testing

  • tests/login-daemon.test.ts rewritten to the token-based contract: present-but-unusable → false; env-pointed socket → false; non-optional → false; genuinely-absent default → silent skip (guarded against boxes with a real daemon).
  • Full suite: 447 pass, typecheck clean.

Automated by MisterMal

Follow-up to the previous fix. The 'is the daemon present?' check that
decides whether hsh login's optional daemon leg may skip silently used
existsSync() on the unix SOCKET path. On at least one user's host that
returned false for a LIVE daemon (hsh tunnel status worked fine), so the
daemon leg of hsh login skipped silently again — leaving the daemon on
its old token with zero output.

Root cause: TunnelClient.connect() never stats the socket; it keys on a
readable control token. The existsSync(socket) discriminator was thus
inconsistent with how connect()/status actually reach the daemon.

Fix: daemonLooksInstalled() now mirrors connect() — a readable control
token (or a present/ env-pointed token file, or an env-pointed socket)
means 'daemon is here; surface any failure'. Only the bare-default,
nothing-present case counts as genuinely absent and skips silently.

Tests updated to the token-based contract: present-but-unusable (readable
token, dead socket) → false; env-pointed socket → false; non-optional →
false; genuinely-absent default path → silent skip (guarded so it never
false-fails on a box that has a real daemon installed).

 🤖 Generated with Mister Maluco

Co-Authored-By: MisterMal <teskeslab@lucasteske.dev>
@racerxdl racerxdl added the bug Something isn't working label Jun 3, 2026
@racerxdl racerxdl merged commit 433735f into main Jun 3, 2026
3 checks passed
@racerxdl racerxdl deleted the teske/fix-daemon-present-detection branch June 3, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant