BUG-HUNT: [shell-integration] completion command passes malformed env var to subprocess #7741

Open
opened 2026-04-12 03:22:30 +00:00 by HAL9000 · 3 comments
Owner

Bug Report: [Shell Integration] completion Command Passes Malformed Environment Variable

Severity Assessment

  • Impact: agents completion bash|zsh|fish|powershell silently produces a fallback stub comment instead of the real shell completion script. Tab completion cannot be enabled.
  • Likelihood: Triggered every time a user sets up shell tab-completion for the CLI.
  • Priority: High

Location

  • File: src/cleveragents/cli/main.py
  • Function: completion
  • Lines: 626–631

Description

The completion command constructs an environment variable key incorrectly when invoking the subprocess for shell completion generation.

Evidence

# main.py lines 626-631
env_var = f"_CLEVERAGENTS_COMPLETE={shell_lower}_source"
result = subprocess.run(
    [sys.executable, "-m", "cleveragents"],
    capture_output=True,
    text=True,
    env={**__import__("os").environ, env_var: "1"},  # BUG: full KEY=VALUE string used as dict key
)

The dictionary {env_var: "1"} sets:

  • Actual key: "_CLEVERAGENTS_COMPLETE=bash_source" -> value "1"
  • Expected key: "_CLEVERAGENTS_COMPLETE" -> value "bash_source"

The subprocess receives a nonsense env var and Click/Typer shell completion detection never triggers. result.stdout is always empty, so the fallback stub is always printed.

Expected Behavior

Running agents completion bash should output a valid bash completion script generated by Click/Typer.

Actual Behavior

An empty stub comment is always printed. Shell tab-completion can never be set up.

Suggested Fix

result = subprocess.run(
    [sys.executable, "-m", "cleveragents"],
    capture_output=True,
    text=True,
    env={**__import__("os").environ, "_CLEVERAGENTS_COMPLETE": f"{shell_lower}_source"},
)

Category

shell-integration

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD.


Automated by CleverAgents Bot
Supervisor: Bug Hunting | Agent: bug-hunter

## Bug Report: [Shell Integration] `completion` Command Passes Malformed Environment Variable ### Severity Assessment - **Impact**: `agents completion bash|zsh|fish|powershell` silently produces a fallback stub comment instead of the real shell completion script. Tab completion cannot be enabled. - **Likelihood**: Triggered every time a user sets up shell tab-completion for the CLI. - **Priority**: High ### Location - **File**: `src/cleveragents/cli/main.py` - **Function**: `completion` - **Lines**: 626–631 ### Description The `completion` command constructs an environment variable key incorrectly when invoking the subprocess for shell completion generation. ### Evidence ```python # main.py lines 626-631 env_var = f"_CLEVERAGENTS_COMPLETE={shell_lower}_source" result = subprocess.run( [sys.executable, "-m", "cleveragents"], capture_output=True, text=True, env={**__import__("os").environ, env_var: "1"}, # BUG: full KEY=VALUE string used as dict key ) ``` The dictionary `{env_var: "1"}` sets: - Actual key: `"_CLEVERAGENTS_COMPLETE=bash_source"` -> value `"1"` - Expected key: `"_CLEVERAGENTS_COMPLETE"` -> value `"bash_source"` The subprocess receives a nonsense env var and Click/Typer shell completion detection never triggers. `result.stdout` is always empty, so the fallback stub is always printed. ### Expected Behavior Running `agents completion bash` should output a valid bash completion script generated by Click/Typer. ### Actual Behavior An empty stub comment is always printed. Shell tab-completion can never be set up. ### Suggested Fix ```python result = subprocess.run( [sys.executable, "-m", "cleveragents"], capture_output=True, text=True, env={**__import__("os").environ, "_CLEVERAGENTS_COMPLETE": f"{shell_lower}_source"}, ) ``` ### Category shell-integration ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. --- **Automated by CleverAgents Bot** Supervisor: Bug Hunting | Agent: bug-hunter
HAL9000 added this to the v3.2.0 milestone 2026-04-12 03:46:41 +00:00
Author
Owner

Verified — Bug: completion command passes malformed env var to subprocess. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Bug: completion command passes malformed env var to subprocess. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Bug: completion command passes malformed env var to subprocess. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Bug: completion command passes malformed env var to subprocess. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Bug: completion command passes malformed env var to subprocess. MoSCoW: Should-have. Priority: Medium.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Bug: completion command passes malformed env var to subprocess. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#7741
No description provided.