[AUTO-BUG-2] session tell --stream writes directly to sys.stdout bypassing redaction layer #10460

Closed
opened 2026-04-18 09:50:33 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Commit Message: fix(cli): route session tell --stream output through console to apply redaction
  • Branch Name: fix/session-tell-stream-redaction

Background and Context

session tell --stream in src/cleveragents/cli/commands/session.py (lines 843–848) writes the assistant response directly to sys.stdout using sys.stdout.write(char) in a character-by-character loop. This bypasses the Rich console and the redaction layer.

All other CLI output paths go through format_output() (which calls _redact_data()) or through the Rich console. The streaming path is the only exception.

Current Behavior

Code showing the bug (src/cleveragents/cli/commands/session.py, lines 843–848):

if stream:
    # Simulate streaming by printing character by character
    for char in assistant_content:
        sys.stdout.write(char)  # ← DIRECT STDOUT, NO REDACTION
        sys.stdout.flush()
    sys.stdout.write("\n")

The assistant_content variable contains the first 100 characters of the user's prompt:

assistant_content = (
    f"Acknowledged: {prompt[:100]}"
    if not actor
    else f"[{actor}] Acknowledged: {prompt[:100]}"
)

If the user's prompt contains sensitive data (API keys, passwords, tokens), it will be written directly to stdout without redaction when --stream is used.

Expected Behavior

Streaming output should go through the Rich console (or at minimum through the redaction layer) so that sensitive values are masked before being written to stdout. The fix should use console.print(assistant_content, end="") or equivalent.

Acceptance Criteria

  • session tell --stream no longer writes directly to sys.stdout
  • Streaming output passes through the redaction layer
  • Streaming output is written through the Rich console
  • TDD tests from the blocked-by issue pass
  • nox -s unit_tests passes with coverage ≥ 97%

Subtasks

  • Replace sys.stdout.write(char) loop with console.print(assistant_content, end="") in session.py
  • Verify redaction is applied to streaming output
  • Run nox -s unit_tests to confirm no regressions
  • Verify coverage ≥ 97% via nox -s coverage_report

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Blocked By

#10458


Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(cli): route session tell --stream output through console to apply redaction` - **Branch Name**: `fix/session-tell-stream-redaction` ## Background and Context `session tell --stream` in `src/cleveragents/cli/commands/session.py` (lines 843–848) writes the assistant response directly to `sys.stdout` using `sys.stdout.write(char)` in a character-by-character loop. This bypasses the Rich console and the redaction layer. All other CLI output paths go through `format_output()` (which calls `_redact_data()`) or through the Rich console. The streaming path is the only exception. ## Current Behavior **Code showing the bug** (`src/cleveragents/cli/commands/session.py`, lines 843–848): ```python if stream: # Simulate streaming by printing character by character for char in assistant_content: sys.stdout.write(char) # ← DIRECT STDOUT, NO REDACTION sys.stdout.flush() sys.stdout.write("\n") ``` The `assistant_content` variable contains the first 100 characters of the user's prompt: ```python assistant_content = ( f"Acknowledged: {prompt[:100]}" if not actor else f"[{actor}] Acknowledged: {prompt[:100]}" ) ``` If the user's prompt contains sensitive data (API keys, passwords, tokens), it will be written directly to stdout without redaction when `--stream` is used. ## Expected Behavior Streaming output should go through the Rich console (or at minimum through the redaction layer) so that sensitive values are masked before being written to stdout. The fix should use `console.print(assistant_content, end="")` or equivalent. ## Acceptance Criteria - [x] `session tell --stream` no longer writes directly to `sys.stdout` - [x] Streaming output passes through the redaction layer - [x] Streaming output is written through the Rich console - [x] TDD tests from the blocked-by issue pass - [x] `nox -s unit_tests` passes with coverage ≥ 97% ## Subtasks - [x] Replace `sys.stdout.write(char)` loop with `console.print(assistant_content, end="")` in `session.py` - [x] Verify redaction is applied to streaming output - [x] Run `nox -s unit_tests` to confirm no regressions - [x] Verify coverage ≥ 97% via `nox -s coverage_report` ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. ## Blocked By #10458 --- **Automated by CleverAgents Bot** Agent: new-issue-creator
Author
Owner

Implementation Attempt — Tier 1: Haiku — Success

Fixed the session tell --stream bug where streaming output was writing directly to sys.stdout, bypassing the redaction layer.

Changes made:

  • src/cleveragents/cli/commands/session.py: Replaced sys.stdout.write(char) character-by-character loop with console.print(_escape(assistant_content)). Removed unused import sys statement.
  • features/tdd_session_tell_stream_redaction.feature: Added 3 TDD BDD scenarios verifying the fix (tagged @tdd_issue @tdd_issue_10458).
  • features/steps/tdd_session_tell_stream_redaction_steps.py: Step definitions for the new TDD feature.

Quality gate status: lint ✓, typecheck ✓, unit_tests ✓ (3 new scenarios pass, 35 existing session tests pass), integration_tests ✓

PR: #10734


Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-worker

**Implementation Attempt** — Tier 1: Haiku — Success Fixed the `session tell --stream` bug where streaming output was writing directly to `sys.stdout`, bypassing the redaction layer. **Changes made:** - `src/cleveragents/cli/commands/session.py`: Replaced `sys.stdout.write(char)` character-by-character loop with `console.print(_escape(assistant_content))`. Removed unused `import sys` statement. - `features/tdd_session_tell_stream_redaction.feature`: Added 3 TDD BDD scenarios verifying the fix (tagged `@tdd_issue @tdd_issue_10458`). - `features/steps/tdd_session_tell_stream_redaction_steps.py`: Step definitions for the new TDD feature. **Quality gate status:** lint ✓, typecheck ✓, unit_tests ✓ (3 new scenarios pass, 35 existing session tests pass), integration_tests ✓ **PR:** https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/10734 --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-worker
Author
Owner

Implementation Attempt — Tier 1: Haiku — Success

Fixed the session tell --stream bug where streaming output was writing directly to sys.stdout, bypassing the redaction layer.

Changes made:

  • src/cleveragents/cli/commands/session.py: Replaced sys.stdout.write(char) character-by-character loop with console.print(_escape(assistant_content)). Removed unused import sys statement.
  • features/tdd_session_tell_stream_redaction.feature: Added 3 TDD BDD scenarios verifying the fix (tagged @tdd_issue @tdd_issue_10458).
  • features/steps/tdd_session_tell_stream_redaction_steps.py: Step definitions for the new TDD feature.

Quality gate status: lint ✓, typecheck ✓, unit_tests ✓ (3 new scenarios pass, 35 existing session tests pass), integration_tests ✓

PR: #10734


Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-worker

**Implementation Attempt** — Tier 1: Haiku — Success Fixed the `session tell --stream` bug where streaming output was writing directly to `sys.stdout`, bypassing the redaction layer. **Changes made:** - `src/cleveragents/cli/commands/session.py`: Replaced `sys.stdout.write(char)` character-by-character loop with `console.print(_escape(assistant_content))`. Removed unused `import sys` statement. - `features/tdd_session_tell_stream_redaction.feature`: Added 3 TDD BDD scenarios verifying the fix (tagged `@tdd_issue @tdd_issue_10458`). - `features/steps/tdd_session_tell_stream_redaction_steps.py`: Step definitions for the new TDD feature. **Quality gate status:** lint ✓, typecheck ✓, unit_tests ✓ (3 new scenarios pass, 35 existing session tests pass), integration_tests ✓ **PR:** https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/10734 --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-worker
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#10460
No description provided.