Skip to content

fix(sshd-probe): macOS launchctl print system + osascript admin dialog (PR #156/#157 live-test followups) - #158

Merged
joelteply merged 1 commit into
canaryfrom
fix/sshd-probe-macos-detection
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/sshd-probe-macos-detection

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Two issues caught running the PR #156/#157 sshd work on a real Mac:

Bug 1 — launchctl list (user scope) doesn't show system services

`launchctl list` is user-scope. Never shows system services like `com.openssh.sshd`. Doctor reported [MISSING] even with Remote Login enabled + active sshd-session processes forking.

Fix: `launchctl print system` (no sudo needed). Anchored regex so the service id matches but per-connection session subkeys don't false-positive.

Bug 2 — install.sh sudo fails in non-interactive contexts

Monitor-spawned shells, curl|bash pipes, etc. don't have a TTY. `sudo` then errors with "a terminal is required to read the password." Same situation Joel hit running this through Claude Code's Bash tool.

Fix: TTY detection (`[ -t 0 ] && [ -t 1 ]`). Interactive → sudo. Non-interactive → osascript with native macOS admin GUI dialog and an airc-branded prompt explaining the action.

Live verification

Doctor on this Mac with Remote Login enabled but pre-fix probe reported [MISSING]. Post-fix:

```
[ok] sshd (Remote Login enabled)
```

Why this is critical

Without these fixes, even after a user has Remote Login on, doctor reports MISSING (confusing) and install.sh sudo path can't run from a non-terminal context (most install paths now are non-terminal: Claude Code Bash tool, Monitor, etc.).

…g when non-interactive

Two issues found while running PR #157 live on Mac 2026-04-27:

## Bug 1: launchctl list (user scope) doesn't show system services

Pre-fix probe:
```bash
launchctl list 2>/dev/null | grep -q "com\.openssh\.sshd"
```
Bare `launchctl list` is user-scope. Returns user-launched LaunchAgents
only — never system-level launchd jobs like com.openssh.sshd. The
fallback `systemsetup -getremotelogin` requires sudo to read state.

Net: doctor reported `[MISSING] sshd` even when Remote Login was
fully enabled and active sshd-session processes were forking.

Fix: `launchctl print system` (no sudo needed) lists system services
including com.openssh.sshd when Remote Login is on. Anchor regex on
service-id boundary so we don't false-positive on per-connection
session subkeys (com.openssh.sshd.<UUID>) which exist transiently
even when Remote Login is just toggling.

## Bug 2: install.sh sudo path fails in non-interactive contexts

When install.sh runs from a Monitor-spawned shell or curl|bash pipe,
no TTY is attached. `sudo` then says "a terminal is required to read
the password; either use the -S option to read from standard input or
configure an askpass helper." Same problem as Joel hit running this
from his Claude Code Bash tool.

Fix: detect TTY presence (\`[ -t 0 ] && [ -t 1 ]\`); if interactive,
use sudo. If not, fall through to osascript with the native macOS
admin GUI dialog (with a branded prompt explaining what airc is
doing — Joel 2026-04-27 relay through continuum-b69f).

## Live verification

Pre-fix doctor on this Mac (Remote Login enabled live via osascript):
```
[MISSING] sshd -- needed when you HOST a room
```

Post-fix:
```
[ok] sshd (Remote Login enabled)
```

## Same probe in install.sh

The Darwin branch of \`_ensure_sshd_running\` now:
- detects via launchctl print system (matching doctor)
- splits sudo (TTY) vs osascript (non-interactive) for the elevation
- both paths print airc-branded explanation in the admin prompt
Copilot AI review requested due to automatic review settings April 27, 2026 20:03
@joelteply
joelteply merged commit 4576c18 into canary Apr 27, 2026
2 checks passed
@joelteply
joelteply deleted the fix/sshd-probe-macos-detection branch April 27, 2026 20:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates macOS sshd/Remote Login probing and elevation behavior so airc doctor and install.sh work correctly on real Macs, including non-terminal install contexts.

Changes:

  • macOS sshd detection now uses launchctl print system (system scope) with a more precise match for com.openssh.sshd.
  • install.sh macOS sshd enablement adds a non-interactive path using osascript admin GUI prompt when no TTY is present.
  • Improves inline comments explaining why launchctl list is insufficient on macOS.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
install.sh Detect sshd via launchctl print system; enable Remote Login via sudo when interactive or osascript admin dialog when non-interactive.
airc Fix macOS doctor sshd probe to use launchctl print system and avoid user-scope false negatives.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install.sh
Comment on lines +153 to +163
if [ -t 0 ] && [ -t 1 ]; then
# Interactive shell — sudo can read the password.
if sudo systemsetup -setremotelogin on 2>&1; then
ok "Remote Login enabled."
else
warn "systemsetup failed. Manual: System Settings -> General -> Sharing -> Remote Login."
fi
else
warn "systemsetup failed. Manual fallback: System Settings -> General -> Sharing -> Remote Login (toggle on)."
# Non-interactive (Monitor/pipe/script) — use osascript GUI prompt.
if osascript -e 'do shell script "systemsetup -setremotelogin on" with administrator privileges with prompt "AIRC needs admin to enable Remote Login (sshd) — one-time setup so peers can ssh-tail your messages when you host an airc room."' 2>&1; then
ok "Remote Login enabled."

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TTY detection here is too strict: in common install patterns like curl … | bash, stdin (fd 0) is a pipe so [ -t 0 ] is false even though the user has an interactive controlling TTY and sudo can still prompt via /dev/tty. This will force the osascript GUI path unnecessarily (and can fail on headless/non-GUI sessions). Consider detecting an available controlling terminal (e.g., tty -s or checking /dev/tty) and/or attempting sudo first and only falling back to osascript when sudo errors with “a terminal is required …”/no tty available.

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 27, 2026
…nd-to-end (#177)

fix(msys): export MSYS2_ARG_CONV_EXCL at airc startup — last layer of cross-machine fix (continuum's catch + verify)

continuum-b69f's diagnosis 2026-04-27: even with PR #174 + #176's
argparse `--flags`, MSYS Git Bash on Windows translates argv VALUES
that look like Unix-rooted paths when bash invokes a Windows-native
binary. So `--host-airc-home /Users/joelteply/.airc` arrived at
python.exe as `--host-airc-home C:/Program Files/Git/Users/joelteply/.airc`,
the joiner cached the corrupted path, the SSH command later sent
it to a real Unix host that had no such file. Silent broadcast
failure.

## Fix

```bash
export MSYS2_ARG_CONV_EXCL="${MSYS2_ARG_CONV_EXCL:-/Users/;/home/;/root/}"
```

Set once at airc startup, exported, every airc_core invocation
inherits the same translation policy. Targeted prefix list covers
macOS / Linux / root home prefixes without breaking `/tmp/` or `/c/`
paths (which DO need translation for `--config "$CONFIG"` where
$CONFIG is on the local Windows filesystem). Honors a user override
via the `${...:-...}` default-fallback.

## End-to-end verification

continuum-b69f shipped a test broadcast from Windows after their
local patch:

> WORKING TEST: Windows-Mac airc msg via continuum-msyspatch with
> targeted MSYS exclude. should land!

Verified live in MY host's messages.jsonl on Mac:

```
{"from":"continuum-msyspatch","to":"all","ts":"2026-04-27T23:30:13Z",
 "msg":"WORKING TEST: Windows-Mac airc msg via continuum-msyspatch
 with targeted MSYS exclude. should land!","sig":"..."}
```

**Cross-machine Mac↔Windows airc end-to-end working.** This was the
last bug in the chain that started at PR #153 (Microsoft Store
python3 stub).

## Test posture (Mac, where the env var is a no-op)

- tabs 19/19, identity 19/19, whois 5/5, part_persists 8/8,
  list 4/4, general_sidecar_default 12/12, kick 12/12, events 5/5,
  platform_adapters 11/11, whois_cross_scope 6/6

## Today's full chain of cross-machine fixes

#153 → #154 → #155 → #156 → #157 → #158 → #159 → #160 → #162 →
#164 → #165 → #166 → ... → #176 → this. 27+ PRs to ship a working
cross-machine airc on Windows. Every step revealed a new layer.
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.

2 participants