fix: spawn desktop engine with resolved env, not the inherited one - #4519
fix: spawn desktop engine with resolved env, not the inherited one#4519praisonai-triage-agent[bot] wants to merge 2 commits into
Conversation
…ixes #4500) venv_resolve::spawn_env strips PYTHONPATH/PYTHONHOME/PYTHONSTARTUP and sets VIRTUAL_ENV/PATH, but had no production caller -- supervisor::start inherited the shell's environment and only added PYTHONUTF8/PYTHONIOENCODING. A user with PYTHONHOME or PYTHONPATH exported got the engine pointed at a foreign stdlib or site-packages, and the module written to prevent exactly that never ran. start now takes the resolved env and applies it with env_clear + envs; main.rs builds it from the already-resolved VenvLayout. Adds a regression test proving a poisoned PYTHONHOME/PYTHONPATH never reaches the spawned child. Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
|
@coderabbitai review |
|
/review |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Greptile SummaryThe PR routes desktop-engine startup through the resolved virtual-environment map and clears inherited Python-specific poisoning variables. Its Unicode-safe collection strategy also drops required variables containing undecodable bytes, which can leave engine subprocess utilities unavailable.
Confidence Score: 4/5The PR should not merge until non-Unicode environment handling preserves operational variables needed by engine subprocesses. The panic is removed, but a non-Unicode Files Needing Attention: src/praisonai-desktop/src-tauri/src/main.rs
|
| Filename | Overview |
|---|---|
| src/praisonai-desktop/src-tauri/src/main.rs | Constructs the resolved spawn environment without panicking on non-Unicode entries, but can discard operational variables such as PATH. |
| src/praisonai-desktop/src-tauri/src/supervisor.rs | Applies the supplied resolved environment after clearing inheritance, correctly enforcing the caller-provided map but amplifying any omitted entries. |
| src/praisonai-desktop/src-tauri/tests/real_venvs.rs | Verifies that poisoned Python environment variables are removed from both the resolved map and an actual child process. |
Reviews (2): Last reviewed commit: "fix: collect inherited env with vars_os ..." | Re-trigger Greptile
|
@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Review changes in this PR. Python SDK: praisonaiagents, praisonai. TypeScript SDK: src/praisonai-ts/. Do NOT modify src/praisonai-rust. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding. Phase 1: Review per AGENTS.md
Phase 2: FIX Valid Issues Phase 3: Final Verdict |
|
Claude finished @MervinPraison's task —— View job Final Architecture Review — PR #4519
ScopeThis PR is confined to Phase 1 — Review
Phase 2 — Issue found & fixedGreptile P1 (valid) — Fix ( let inherited: std::collections::BTreeMap<String, String> = std::env::vars_os()
.filter_map(|(key, value)| Some((key.into_string().ok()?, value.into_string().ok()?)))
.collect();
I independently reviewed Skipped: nothing actionable. Qodo posted only a paused-reviews notice (no findings). No CodeRabbit/Gemini/Copilot findings were present in the thread. Files modified
Note on verification
Verdict✅ Approve (pending CI green). The change is a legitimate, minimal robustness/security fix, and the sole blocking reviewer concern (non-Unicode env abort) is now resolved. I cannot submit a formal GitHub approval for security reasons, but from an architecture standpoint this is good to merge once |
… entries std::env::vars() panics on any non-Unicode env key/value, and the release profile sets panic = "abort", so a single non-Unicode inherited variable would abort the desktop app before the engine started. Switch to vars_os() and drop undecodable entries; spawn_env only handles String, so nothing usable is lost. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
| let inherited: std::collections::BTreeMap<String, String> = std::env::vars_os() | ||
| .filter_map(|(key, value)| Some((key.into_string().ok()?, value.into_string().ok()?))) | ||
| .collect(); |
There was a problem hiding this comment.
If the inherited PATH contains non-Unicode bytes, this conversion omits the entire variable; spawn_env then supplies only the virtual-environment bin directory before env_clear() replaces the child environment, causing engine operations that invoke system tools such as ps, security, or secret-tool by name to fail.
Fixes #4500
Problem
venv_resolve::spawn_env— the whole PYTHONPATH/PYTHONHOME/PYTHONSTARTUP defence — had no production caller. Every caller was a test.supervisor::startinherited the shell's environment and only addedPYTHONUTF8/PYTHONIOENCODING, so a user withPYTHONHOMEorPYTHONPATHexported (conda, distro tooling, a systemd user session) got the engine running against the wrong stdlib or a foreignsite-packages, and the module written to prevent exactly that never ran.Fix (minimal, no new API surface)
supervisor::startnow takes the resolvedenv: &BTreeMap<String, String>and applies it withenv_clear()+envs(env)before its existing UTF-8 vars.main.rsbuilds that env from theVenvLayoutit already resolves, viaspawn_env, collectingstd::env::vars()after settingPRAISONAI_APP_BUNDLEso that var survives the clear.tests/real_venvs.rs: withPYTHONHOME=/nonexistentand a poisonedPYTHONPATHin the inherited map, asserts neither survives into the spawn env and — driven through the real resolved interpreter — that the spawned child sees neither. Skips silently when no venv is present, matching the existing test.Scope
Change is confined to
src/praisonai-desktop/src-tauri(the Tauri desktop shell), a separate crate from the out-of-scopesrc/praisonai-rust. No changes to the Python or TypeScript SDKs.Test plan
cargo test -p praisonai-desktopon a machine with a venv present (CI runners skip the venv-dependent test)Generated with Claude Code