Skip to content

fix(cli): prevent GENIE_TUI_PANE env leak to child processes - #923

Merged
namastex888 merged 2 commits into
devfrom
fix/tui-env-leak
Mar 30, 2026
Merged

namastex888 merged 2 commits into
devfrom
fix/tui-env-leak

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Agents spawned from TUI panes inherited GENIE_TUI_PANE=left, causing
genie work, genie spawn etc. to launch the TUI renderer instead
of running the command. Fix: only bare genie (no args) enters TUI
mode, and clear the env var so children never inherit it.

Genie added 2 commits March 30, 2026 07:53
Agents spawned from TUI panes inherit GENIE_TUI_PANE=left, causing
genie.ts to render the TUI instead of running the command. Only enter
TUI mode when there are zero CLI args AND the env var is set.
Only bare `genie` (no args) enters TUI mode. All subcommands (work,
spawn, team, etc.) run normally. Clear the env var after the check
so child processes never inherit it and accidentally enter TUI mode.
@coderabbitai

coderabbitai Bot commented Mar 30, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 92d1b9af-a120-4c01-a86d-421c4447a26b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tui-env-leak

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 and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9621456978

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/genie.ts
await launchTui();
process.exit(0);
}
process.env.GENIE_TUI_PANE = undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove env var instead of assigning undefined

Assigning process.env.GENIE_TUI_PANE = undefined does not clear the variable in Node; it becomes the literal string 'undefined', so child processes still inherit GENIE_TUI_PANE and the leak this commit is trying to prevent remains. This can still alter behavior in any subprocess code that checks presence/truthiness of the variable rather than strict equality with 'left'.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the TUI renderer activation logic in src/genie.ts to ensure it only triggers when no subcommands are provided and clears the GENIE_TUI_PANE environment variable to prevent inheritance by child processes. A review comment suggests simplifying the implementation by consolidating the environment variable cleanup and using a boolean flag to improve readability and reduce redundancy.

Comment thread src/genie.ts
Comment on lines +475 to +481
if (process.env.GENIE_TUI_PANE === 'left' && args.length === 0) {
process.env.GENIE_TUI_PANE = undefined;
const { launchTui } = await import('./tui/index.js');
await launchTui();
process.exit(0);
}
process.env.GENIE_TUI_PANE = undefined;

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.

medium

While the logic is correct, unsetting process.env.GENIE_TUI_PANE in two different places can be simplified. You can determine if TUI renderer mode should be activated, unset the environment variable right away to prevent leaks, and then proceed. This makes the intent clearer and avoids redundancy. Using a dynamic import for the TUI module also helps manage module load-time dependencies and prevent potential circular cycles.

const isTuiRenderer = process.env.GENIE_TUI_PANE === 'left' && args.length === 0;
process.env.GENIE_TUI_PANE = undefined;

if (isTuiRenderer) {
  const { launchTui } = await import('./tui/index.js');
  await launchTui();
  process.exit(0);
}
References
  1. Use dynamic imports (require() or import()) to break circular dependency cycles that would otherwise occur at module load time.

@namastex888
namastex888 merged commit 6a4d413 into dev Mar 30, 2026
6 checks passed
@namastex888
namastex888 deleted the fix/tui-env-leak branch April 10, 2026 16:19
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.

1 participant