Skip to content

feat(ai): streaming reasoning think token parser and bounded stream sanitizer #128

Closed

Description

@dan-petty

Problem Statement

Frontier reasoning models and local thinking models (such as DeepSeek-R1, QwQ, Gemma) emit <think>...</think> tokens in streaming SSE responses. Currently, thinking blocks can leak into raw review comments or markdown reports if not cleanly separated from final response payloads. Additionally, unbounded SSE streams can cause memory exhaustion without strict MAX_STREAM_BYTES (50MB) guards.

Proposed Changes

  • Implement a standardized streaming token processor in devops_cli.ai.client.
  • Extract <think> blocks into a structured reasoning scratchpad buffer while streaming clean markdown to the user.
  • Enforce strict MAX_STREAM_BYTES (50MB) stream boundaries and handle SSE reconnects.
  • Support thinking tag extraction across Ollama, Anthropic, and OpenAI streaming formats.

Acceptance Criteria

  • Zero leakage of raw <think> tags into final markdown report artifacts or PR comments.
  • Structured access to agent reasoning scratchpad.
  • Comprehensive unit tests in tests/test_ai_streaming.py.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/aitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions