Skip to content

Comments

fix(daemon): propagate snapshot env to process.env for child processes#99

Open
heyalchang wants to merge 1 commit intosteipete:mainfrom
heyalchang:fix/daemon-child-process-env
Open

fix(daemon): propagate snapshot env to process.env for child processes#99
heyalchang wants to merge 1 commit intosteipete:mainfrom
heyalchang:fix/daemon-child-process-env

Conversation

@heyalchang
Copy link

Summary

  • Apply daemon.json snapshot env keys to process.env so child processes (yt-dlp, ffmpeg, deno, tesseract) inherit the correct PATH under launchd/systemd

Fixes #98

Problem

Under launchd, process.env.PATH is /usr/bin:/bin:/usr/sbin:/sbin. The daemon's merged env is used internally to find binaries, but spawnTracked() spawns child processes without passing env — so they inherit the minimal PATH.

This breaks yt-dlp 2025.11.12+ which needs deno for YouTube JS challenges when cookies are enabled, causing "Requested format is not available" on slide extraction.

Change

In src/daemon/cli.ts, after building the merged env, iterate the whitelisted snapshot keys from daemon.json and apply them to process.env:

for (const [key, value] of Object.entries(cfg.env)) {
  if (typeof value === "string") {
    process.env[key] = value;
  }
}

Only the keys from env-snapshot.ts (PATH, API keys, tool paths) are in cfg.env — no arbitrary env vars leak through.

Test plan

  • pnpm -s build passes
  • pnpm test — 272 passed, 0 failures
  • Manual: summarize daemon restart → trigger slides from Chrome extension → verify slides: done in daemon.log

🤖 Generated with Claude Code

Under launchd/systemd the daemon's process.env has a minimal PATH
(e.g. /usr/bin:/bin:/usr/sbin:/sbin). The merged env built from
daemon.json is threaded through internal code but never applied to
process.env, so child processes spawned via spawnTracked() inherit
the minimal environment.

This became a real problem with yt-dlp 2025.11.12+ which requires
deno (or another JS runtime) for YouTube JS challenge solving.
When cookies are enabled, yt-dlp uses authenticated YouTube APIs
that need JS challenges — but deno isn't on the minimal PATH,
causing silent format resolution failures:

  ERROR: Requested format is not available

The fix applies the whitelisted snapshot keys (PATH, API keys,
tool paths) from daemon.json to process.env before starting the
server, so all child processes inherit the correct environment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Daemon: child processes don't inherit merged env (breaks yt-dlp slides under launchd)

1 participant