P1-01: CLI stdin double-read bug — non-JSON piped input silently drops #7

Closed
opened 2026-06-16 13:57:00 +00:00 by Artur · 0 comments
Owner

Severity: P1 (High)
File: decider/cli.py lines 62-67

Problem

When piped input is NOT valid JSON (e.g. plain text), the second sys.stdin.read() returns empty string because stdin is a stream and already consumed by the first read attempt.

try:
    payload = json.loads(sys.stdin.read())
except (json.JSONDecodeError, EOFError):
    situation = sys.stdin.read().strip()  # stdin already consumed → returns ""
    context = ""

This means echo "should I deploy?" | python3 -m decider silently fails with error: situation required.

Fix

Read stdin once, store in variable, then attempt JSON parse:

raw = sys.stdin.read()
if raw:
    try:
        payload = json.loads(raw)
        situation, context = payload.get("situation", ""), payload.get("context", "")
    except json.JSONDecodeError:
        situation = raw.strip()
        context = ""
**Severity**: P1 (High) **File**: `decider/cli.py` lines 62-67 ## Problem When piped input is NOT valid JSON (e.g. plain text), the second `sys.stdin.read()` returns empty string because stdin is a stream and already consumed by the first read attempt. ```python try: payload = json.loads(sys.stdin.read()) except (json.JSONDecodeError, EOFError): situation = sys.stdin.read().strip() # stdin already consumed → returns "" context = "" ``` This means `echo "should I deploy?" | python3 -m decider` silently fails with `error: situation required`. ## Fix Read stdin once, store in variable, then attempt JSON parse: ```python raw = sys.stdin.read() if raw: try: payload = json.loads(raw) situation, context = payload.get("situation", ""), payload.get("context", "") except json.JSONDecodeError: situation = raw.strip() context = "" ```
Artur closed this issue 2026-06-16 13:57:26 +00:00
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
glow-all/decider#7
No description provided.