Skip to content

fix(daemon,#408): Windows launcher redirects stdout → daemon.log (was missing) - #408

Merged
joelteply merged 1 commit into
canaryfrom
fix/airc-windows-daemon-log-redirect
May 2, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/airc-windows-daemon-log-redirect

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Direct repro of b69f's 'daemon.log doesn't exist' tonight.

The Windows launcher .bat (generated by 'airc daemon install') invoked airc with NO stdout redirect — so airc's entire event stream went to nowhere. Only daemon.err had launcher restart records. Operator gets 'daemon.log doesn't exist' when they try to read post-mortem.

One-line fix: 1>> daemon.log 2>> daemon.err on the airc invocation. Now stdout (event stream) → daemon.log; stderr (launcher messages) → daemon.err.

Bios-critical: daemon mode is the OS-supervised path that survives Claude session ends — but only useful if its logs exist for debugging.

🤖 Generated with Claude Code

… missing)

The Windows daemon launcher .bat (generated by 'airc daemon install')
called the airc binary with NO stdout redirect:
  "$bash_exe" -c "exec '$airc_bin_unix' connect"

So airc's event stream (the entire stdout output: hosting messages,
peer joins, channel state, beacons) went to NOTHING. Only the
launcher's own restart-record messages reached daemon.err.

Symptom (b69f 2026-05-02): airc daemon-installed on Windows; daemon
"running" per the registry entry; but `airc daemon log` reports
"daemon.log doesn't exist" because no process ever wrote to it.
Operator has no way to see what airc actually did — bios-critical
substrate is opaque on the very platform users need it most.

Fix: 1>> daemon.log 2>> daemon.err on the airc invocation. Now
daemon.log captures the actual airc event stream while daemon.err
keeps the launcher's restart records separate.

Per the global "evidence is for the debugger, not the trash" rule
+ tonight's bios-resilience sweep (everything airc does must be
visible AND self-healing). Daemon mode is the OS-supervised path
that survives Claude session ends — but only useful if its logs
exist.

## Cumulative effect

Tonight's airc sweep now closes:
- Receive path silent failures (#400/#401/#402/#403/#404/#406)
- Self-heal of host rotation (#405/#407)
- Daemon-log invisibility on Windows (THIS PR)

Last remaining bios-fragility I know of: `airc daemon install` on
Windows succeeded BEFORE this fix — so b69f's daemon may be running
right now but wrote nothing all session. After this lands + b69f
re-installs, daemon.log will populate.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 2, 2026 15:47
@joelteply
joelteply merged commit 69be355 into canary May 2, 2026
8 checks passed
@joelteply
joelteply deleted the fix/airc-windows-daemon-log-redirect branch May 2, 2026 15:47

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

Fixes Windows daemon launcher logging so airc connect output is persisted for post-mortem debugging, aligning Windows behavior with macOS (launchd) and Linux/WSL (systemd) daemon installs.

Changes:

  • Update the generated Windows launcher .bat to redirect airc connect stdout to daemon.log and stderr to daemon.err.
  • Add explanatory REM comments describing the missing-log symptom and rationale for the redirects.

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

REM "daemon.log doesn't exist" became a real symptom (b69f
REM 2026-05-02 in #cambriantech). Stderr → daemon.err keeps the
REM launcher's restart records separate from the airc event stream.
"$bash_exe" -c "exec '$airc_bin_unix' connect" 1>> daemon.log 2>> daemon.err
joelteply added a commit that referenced this pull request May 2, 2026
…emon.err (#408 follow-up) (#409)

fix(daemon): Windows launcher uses absolute paths for daemon.log + daemon.err

Direct follow-up to #408. My fix added '1>> daemon.log 2>> daemon.err'
but those are RELATIVE paths. The launcher does 'cd /d "$cwd_win"'
first, so daemon.log lands at <cwd>/daemon.log — NOT at
<scope>/.airc/daemon.log where 'airc daemon status' reports.

Symptom (b69f 2026-05-02 follow-up to #408): file IS being written,
just at the wrong location, so 'airc daemon log' still shows
"daemon.log doesn't exist" when reading the .airc/ scope path.

Fix: use $scope_win\\daemon.log + $scope_win\\daemon.err absolute
paths for all three writes:
  - The main 'airc connect' invocation's stdout/stderr
  - The re-exec branch's launcher message
  - The crash-restart branch's launcher message

scope_win is already computed earlier in _daemon_install_schtasks
as _to_win_path "$scope" — same value 'airc daemon status' reports.

## Tests

- bash syntax clean
- Generated .bat will now write to <abs-scope>\daemon.log instead of
  <cwd>\daemon.log, matching what status reports

## Cumulative

#408 + this PR = daemon log/err visibility fully working on Windows.
b69f's verification will land in their next reinstall.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
… daemon audit, my half) (#410)

fix(daemon,join): #3 status honesty + #5 join-path daemon tip

Two of the 5 daemon bugs from b69f's 2026-05-02 audit:

## #3 STATUS LIES — kill -0 verify + .bat existence check (cmd_daemon.sh)

Pre-fix `airc daemon status` reported "RUNNING (PID N)" whenever
ps-ef awk matched, WITHOUT verifying the matched PID was alive
or the launcher .bat still existed.

Repro (b69f): kill -0 92284 → no-such-process; status said RUNNING.
Causes: ps-ef can report zombie/defunct/stale matches; registry
entry can outlive launcher .bat after partial uninstalls.

Fix: triage in priority order (most-actionable failure mode first):
  1. launcher .bat missing → MISSING_LAUNCHER (reinstall msg)
  2. ps-ef match + kill -0 verified → RUNNING (truly alive)
  3. launcher present, no live pid → STALE/STOPPED

User now sees actual state, not aspirational state.

## #5 JOIN-PATH DAEMON TIP — visibility on daily airc join (cmd_connect.sh)

Pre-fix the daemon-install offer fired only at install.sh +
post-disconnect tip. Daily `airc join` users (the most common
path post-install) never saw the prompt — so daemon mode stayed
opt-in by accident, leaving substrate fragile to Claude session
ends + machine sleep.

Fix: cmd_connect joiner success-path prints the tip if not already
installed. Idempotent silent on installed scopes. Same pattern as
the existing host-success tip at line 1763.

## Cumulative

Tonight's airc daemon UX sweep:
- #408 + #409 = daemon.log actually populates at the right path
- This PR = status doesn't lie + join path nudges install

b69f taking #2 (non-idempotent install) + #4 (crashloop research)
in parallel.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
…udit) (#411)

fix(daemon,install): scope-aware idempotency — install.sh no longer skips when daemon is registered for a DIFFERENT scope (#2 from b69f's daemon audit)

## Why

b69f hit it 2026-05-02:
1. Installed daemon while in /c/.airc-src
2. Re-ran AIRC_INSTALL_YES=1 install.sh from ~/continuum
3. install.sh saw "any airc daemon registered" → no-op'd the prompt
4. ~/continuum had no daemon serving it; surface looked installed
   from `airc daemon status`'s old behavior, but launcher .bat
   pointed at the wrong scope

The cmd_daemon_install function itself IS idempotent (force-overwrites
.bat + reg add //f). The bug was install.sh's coarse pre-check —
`airc_daemon_is_installed` answered "any daemon anywhere?" not "the
daemon for THIS scope?".

Pairs with #410 (Mac's #3 status honesty + #5 join tip) — both make
the daemon stop lying about its own state.

## What

### New: `airc_daemon_is_installed_for_scope <scope>` in lib_daemon_detect.sh

Stricter sibling of `airc_daemon_is_installed`. Returns 0 only when
the registered launcher / unit / plist is wired to the given scope:

- darwin: plist's EnvironmentVariables.AIRC_HOME == scope
- linux/wsl: systemd unit has Environment="AIRC_HOME=<scope>"
- windows: registry value contains <scope>/airc-daemon.bat AND .bat
  exists on disk

Plain `airc_daemon_is_installed` is preserved unchanged for callers
that want "any daemon presence" (post-disconnect tip, status banner).

### install.sh updated

Both branches (AIRC_INSTALL_YES=1 + interactive prompt) now use
`airc_daemon_is_installed_for_scope "$INSTALL_DAEMON_SCOPE"` where
INSTALL_DAEMON_SCOPE mirrors cmd_daemon.sh::_daemon_scope:
${AIRC_HOME:-$(pwd)/.airc}.

Net effect:
- AIRC_INSTALL_YES=1 + already installed for THIS scope → no-op
- AIRC_INSTALL_YES=1 + registered for DIFFERENT scope → reinstall
  (cmd_daemon_install regenerates .bat + reg add //f overwrites)
- Interactive + already installed for THIS scope → skip prompt
- Interactive + registered for DIFFERENT scope → prompt with clearer
  "registered for a different scope; reinstall and wire to <new>?"

## Tests

End-to-end smoke (this branch, on Windows Git Bash):

  $ airc daemon install                        # in ~/continuum
  $ airc_daemon_is_installed_for_scope ~/continuum/.airc; echo $?
  0   ← was 1 pre-fix when registry pointed at different scope
  $ airc_daemon_is_installed_for_scope /tmp/other/.airc; echo $?
  1
  $ airc daemon uninstall
  $ airc_daemon_is_installed_for_scope ~/continuum/.airc; echo $?
  1

Existing 11/11 monitor_formatter tests still pass.

## Pairs with the 5-bug audit

- #1 (#408+#409 Mac): launcher absolute paths
- #2 THIS PR: scope-aware install
- #3+#5 (#410 Mac): status honesty + join-path tip
- #4 still open: Windows crashloop research (b69f next)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request May 2, 2026
…ills 10-min takeover blackout (#4) (#412)

fix(monitor,daemon): skip bearer-state fallback in daemon context — kills 10-min takeover blackout (#4 from b69f's daemon audit)

## Why

Last bug from b69f's 2026-05-02 daemon audit. Repro:

1. Interactive `airc connect` running, writing bearer_state.json
2. Process dies (Claude session end, Ctrl-C, crash)
3. Daemon launcher (.bat / launchd / systemd) starts new airc connect
4. New airc connect calls _monitor_alive_with_bearer_fallback
5. Phase 1 (kill -0 on pidfile PIDs): all dead — falls through to Phase 2
6. Phase 2 (bearer_state freshness): last_recv_ts within 600s window → "yes"
7. New airc connect early-exits "monitor already running"
8. Launcher restarts every 5s, repeats until 600s window expires
9. **10-minute substrate blackout while daemon can't take over**

Then daemon.err fills with hundreds of `airc connect exited. Restarting in 5s.` lines per minute. Joel observed exactly this pattern 2026-05-02 calling the daemon path "brittle as hell."

Phase 2 was added (#370) for Codex sandbox blindness — kill -0 lies in some sandboxes about cross-process visibility. The fallback was supposed to disambiguate. But in daemon context (which sets `AIRC_BACKGROUND_OK=1`), kill -0 is reliable; the fallback only causes false positives.

## What

Three-line skip at the top of Phase 2: when `AIRC_BACKGROUND_OK=1`, trust kill -0 and return "no" if all pidfile PIDs are dead.

```bash
if [ "${AIRC_BACKGROUND_OK:-0}" = "1" ]; then
  echo "no"
  return 0
fi
```

Effect: daemon takeover is immediate (next .bat iteration after interactive death) instead of delayed 10 minutes.

## Why this is safe

- Codex / sandbox sessions don't set `AIRC_BACKGROUND_OK=1` — they get the existing fallback behavior. Phase 2's purpose is preserved for them.
- Daemon launcher (cmd_daemon.sh:233) explicitly sets `AIRC_BACKGROUND_OK=1` before spawning airc connect. That's the marker.
- launchd plist (cmd_daemon.sh:160-162) and systemd unit (cmd_daemon.sh:331) also set it. Cross-platform consistent.
- In daemon context the only thing populating bearer_state is the previously-running airc connect; that connect is now dead (Phase 1 confirmed), so there's no "real but blind" monitor — only a stale state file.

## Out of scope (follow-up)

When daemon legitimately CAN'T take over because another airc connect IS running (user has both interactive + daemon, dual-monitor scenario), the launcher still spams 5s restart cycles. Distinct exit code from "monitor already running" → longer .bat sleep would be the polish. Filing as follow-up; this PR is the hot-path fix.

## Tests

- bash -n passes
- 11/11 monitor_formatter tests pass
- Diff is 3 functional lines + comment; sandbox path unchanged
- Smoke test scaffolding to repro the blackout requires a real Windows daemon install + interactive death; will rely on Mac dogfood + integration suite

## Closes b69f's daemon audit

| Bug | PR |
|-----|----|
| #1 launcher absolute paths | #408 + #409 (Mac) |
| #2 scope-aware install | #411 (b69f) |
| #3 status honesty | #410 (Mac) |
| **#4 daemon takeover blackout** | **THIS PR** |
| #5 join-path tip | #410 (Mac) |

5/5 audit bugs in PRs. Daemon path on Windows should be substantially more honest after merge.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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