fix(host-service): heal trustd-degraded pty-daemons (gh x509 -26276)

Closed
KI
4mo ago
+321-3

Problem

gh (and other Go/Secure-Transport tools) fail inside Superset terminals with tls: failed to verify certificate: x509: OSStatus -26276, while working fine in a regular terminal.

Root cause: -26276 = the process's macOS Mach bootstrap can't look up com.apple.trustd (the trust-evaluation daemon). The pty-daemon is detached and adopted across app/host-service restarts, so if it ever inherits a bootstrap that can't reach trustd (updater relaunch, a dead login-session port after logout/login), every terminal it spawns is broken — and adoption keeps the bad daemon alive indefinitely.

Reproduced deterministically with no signed build:

sandbox-exec -p '(deny mach-lookup (global-name "com.apple.trustd"))' gh api  →  x509: OSStatus -26276

Note: SSL_CERT_FILE is a no-op for gh here (Go uses the platform verifier), and Node/curl can't self-detect this (they don't use Secure Transport). Only security verify-cert exercises the same path.

Fix (no launchctl asuser, no root)

host-service is a fresh detached:false child of the Aqua Electron app, so a plain daemon spawn from it always reaches trustd. So:

  1. Daemon self-probes trustd at startup (security verify-cert) and reports trustdHealthy in the hello-ack.
  2. host-service, on adopt: if the daemon reports trustd-degraded and host-service self-probes healthy → kill it and respawn fresh (which lands in a healthy bootstrap). If host-service is itself degraded, adopt and let the next healthy launch heal it.
  3. Migration: daemon version 0.2.4 → 0.3.0 — existing daemons smooth-update onto the trustd-aware binary (sessions preserved via fd-handoff), then degraded ones self-report and get respawned on a later adopt. No forced mass session loss.

The probe is conservative: only a clean non-zero exit means degraded (errors/timeouts → healthy), so a flaky probe never triggers a session-destroying respawn.

Test Plan

  • Reproduced -26276 and validated security verify-cert as the discriminator (agrees with the real gh symptom)
  • End-to-end: real daemon spawned under a trustd-deny sandbox is detected (pty_daemon_trustd_degraded_respawn) and replaced with a healthy one
  • Probe unit tests (mutation-checked): 8
  • pty-daemon unit 65, integration 48
  • host-service unit 47, integration 18
  • typecheck + biome clean across pty-daemon, host-service, desktop

Note

Supersedes the detached:false-on-darwin approach in #5429 — that rests on the (empirically refuted) premise that detachment severs the bootstrap, and it removes PTY signal isolation.


Open in Stage

Summary by CodeRabbit

  • New Features

    • Added a macOS reachability probe for the system trust service and exposed the result during the daemon startup/handshake.
    • Daemon servers can now report and update this “trustd healthy” flag after binding (including during handoff).
  • Bug Fixes

    • If an adopted daemon reports it can’t reach the trust service while the host can, it’s automatically terminated and replaced with a fresh daemon.
  • Tests

    • Added coverage for the trustd probe behavior and edge cases.