Skip to content

fix(shellexec): avoid false Snap detection and empty XDG_* vars#3402

Open
Jason-Shen2 wants to merge 1 commit into
wavetermdev:mainfrom
Jason-Shen2:fix/shellexec-xdg-snap-empty-vars
Open

fix(shellexec): avoid false Snap detection and empty XDG_* vars#3402
Jason-Shen2 wants to merge 1 commit into
wavetermdev:mainfrom
Jason-Shen2:fix/shellexec-xdg-snap-empty-vars

Conversation

@Jason-Shen2

Copy link
Copy Markdown

Summary

This fixes #3336 with two tightly-scoped changes in pkg/shellexec/shellexec.go:

1. Narrow the Snap detection guard

The previous check os.Getenv("SNAP") != "" fires for any process that inherits $SNAP from a parent — including when Wave is launched from inside a Snap-installed terminal/CLI (e.g. the user snaps Alacritty or nvim and launches Wave from there). In that case Wave itself is not running as a Snap, but the code still wipes the XDG variables and tries to repopulate them from PAM.

Changed the guard to:

if os.Getenv("SNAP_NAME") == "waveterm" {

SNAP_NAME is set by Snapd to the declared snap name for the running snap only; inherited $SNAP from a parent process does not carry the parent's SNAP_NAME across exec when the child is not a snap. This matches the documented Snap environment-variable conventions and ensures the correction only runs when Wave itself is the Snap.

2. Do not explicitly set XDG vars to empty strings

After fetching PAM env vars, any XDG key not present in PAM was left as "" in varsToReplace, and was then passed to shellutil.UpdateCmdEnv. Depending on whether the key already existed in the command env, this either unset the variable or set it to the empty string, both of which break applications that rely on XDG Base Directory spec defaults (e.g. XDG_RUNTIME_DIR being empty caused the reported zsh-autosuggestions panic in uv/pipx-installed tools).

Added a filter that drops keys still holding empty values before calling UpdateCmdEnv. When a key is absent from the map, the child inherits the parent value (or uses spec defaults / shell rc files), which is the correct behavior on non-Snap systems and on Snaps where PAM didn't export that particular variable.

Verification

  • go vet ./pkg/shellexec/ passes.
  • Manually verified that with SNAP set but SNAP_NAME != waveterm, the Snap-correction block is no longer entered.
  • Manually verified that with SNAP_NAME=waveterm and a partial PAM env, missing keys are omitted from varsToReplace rather than set to "".

Fixes #3336

…kip empty XDG values

- Use SNAP_NAME == 'waveterm' instead of checking for any inherited SNAP
  variable, so child Snap processes do not trigger the XDG correction
  logic.
- Remove empty values from varsToReplace before passing to UpdateCmdEnv so
  XDG_*_HOME variables are not explicitly set to empty strings. Previously
  an empty value would either unset the variable or set it to '' (depending
  on prior presence), breaking tools that rely on XDG spec defaults.

Fixes wavetermdev#3336
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


zhenxing.shen seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Jun 29, 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8478b868-5c25-46a8-bd49-ca043358a5bf

📥 Commits

Reviewing files that changed from the base of the PR and between c99022c and fce253b.

📒 Files selected for processing (1)
  • pkg/shellexec/shellexec.go

Walkthrough

In pkg/shellexec/shellexec.go, the Snap-specific XDG environment correction now activates only when SNAP_NAME equals "waveterm" instead of when SNAP is non-empty. A new cleanup loop removes entries with empty string values from varsToReplace before they are applied to the child process environment, preventing XDG keys from being explicitly set to empty strings.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: tighter Snap detection and avoiding empty XDG variables.
Description check ✅ Passed The description matches the code changes and explains the two fixes in the pull request.
Linked Issues check ✅ Passed The changes address #3336 by gating on SNAP_NAME=waveterm and removing empty XDG entries before updating the child environment.
Out of Scope Changes check ✅ Passed The pull request stays narrowly focused on the shellexec XDG environment handling and adds no obvious unrelated changes.
✨ 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.

@Jason-Shen2

Copy link
Copy Markdown
Author

@CLAassistant check

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.

[Bug]: shellexec writes empty XDG_*_HOME when $SNAP is inherited from any snap (not just Wave-as-snap)

2 participants