Skip to content

fix: pass real environment to Threaded io for process spawning - #608

Merged
lalinsky merged 3 commits into
lalinsky:mainfrom
beckend:fix/process-spawn-empty-environ
Jul 24, 2026
Merged

lalinsky merged 3 commits into
lalinsky:mainfrom
beckend:fix/process-spawn-empty-environ

Conversation

@beckend

@beckend beckend commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Process spawn fails with FileNotFound for PATH-dependent binaries

processSpawnImpl in src/io.zig created a temporary Io.Threaded with default InitOptions, where environ defaults to .empty. This caused std.process.spawn(rt.io(), ...) to fail with FileNotFound for any binary requiring PATH resolution (e.g. "true", "false", "sleep"), because the Threaded io had no PATH variable to look up.

Root Cause
Io.Threaded.InitOptions.environ defaults to .empty (std/Io/Threaded.zig:1600). With no PATH, the fallback default_PATH (/usr/local/bin:/bin:/usr/bin) misses binaries on NixOS, Homebrew, and other non-standard layouts.

processSpawnImpl/processSpawnPathImpl created Io.Threaded with default
InitOptions (environ = .empty), causing FileNotFound for any binary
requiring PATH resolution (e.g. 'true', 'false', 'sleep').

Add processEnviron() helper that constructs std.process.Environ from the
real process environment (std.c.environ on POSIX, .global on Windows).

Also re-enable ev/test/process_wait.zig with 3 ProcessWait integration
tests and add a negative FileNotFound test to process.zig.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bca6d566-81bc-49aa-80d6-7619f3dde0ce

📥 Commits

Reviewing files that changed from the base of the PR and between 30ca57f and db0c6e8.

📒 Files selected for processing (1)
  • src/ev/test/process_wait.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/ev/test/process_wait.zig

📝 Walkthrough

Walkthrough

Changes

Process spawning now selects an explicit environment for each platform and libc configuration. Tests cover child exit codes, SIGKILL termination, and nonexistent executables.

Process spawning and wait coverage

Layer / File(s) Summary
Process environment wiring
src/io.zig
Adds platform- and libc-specific environment selection and passes it to both process spawn paths.
ProcessWait integration tests
src/ev/test/process_wait.zig
Adds tests for child exit codes 0 and 1, plus SIGKILL termination on non-Windows platforms.
Missing executable validation
src/process.zig
Adds coverage asserting that spawning a nonexistent binary returns error.FileNotFound.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • lalinsky/zio#339: Introduced the ProcessWait functionality exercised by the new integration tests.
  • lalinsky/zio#368: Added child-wait and child-kill logic built on ProcessWait.

Poem

Children wake, then exit on cue,
Codes turn green—or signals through.
Environments find their proper place,
Missing binaries lose the race.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: passing the real environment to Threaded I/O during process spawning.
Description check ✅ Passed The description is clearly about the same process-spawn PATH/FileNotFound fix described by the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/ev/test/process_wait.zig`:
- Around line 7-20: Update the POSIX branches of argv_exit0, argv_exit1, and
argv_kill_self to invoke "sh" by name instead of hard-coding "/bin/sh",
preserving their existing command arguments and Windows branches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fb7362c4-2799-469e-af18-04fd2c0dc393

📥 Commits

Reviewing files that changed from the base of the PR and between a9b8d89 and 4431f31.

📒 Files selected for processing (3)
  • src/ev/test/process_wait.zig
  • src/io.zig
  • src/process.zig

Comment thread src/ev/test/process_wait.zig Resolved
Comment thread src/ev/test/process_wait.zig Resolved
Comment thread src/ev/test/process_wait.zig Resolved
@lalinsky
lalinsky merged commit 760cbef into lalinsky:main Jul 24, 2026
55 of 56 checks passed
@beckend
beckend deleted the fix/process-spawn-empty-environ branch July 24, 2026 08:00
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