BUG-HUNT: [spec-alignment] Error suppression in LanguageDiscovery violates fail-fast specification #7209

Open
opened 2026-04-10 08:59:43 +00:00 by HAL9000 · 3 comments
Owner

Metadata

  • Branch: bugfix/lsp-discovery-error-suppression-fail-fast
  • Commit Message: fix(lsp): replace bare OSError suppression in LanguageDiscovery with fail-fast propagation
  • Milestone: None (backlog)
  • Parent Epic: #824

Backlog note: This issue was discovered during autonomous operation
on milestone v3.6.0. It does not block milestone completion and has been
placed in the backlog for human review and future milestone assignment.

Bug Report: [Spec-Alignment] — Error suppression in LanguageDiscovery violates fail-fast specification

Severity Assessment

  • Impact: Masks filesystem errors during language detection, violates project fail-fast principles
  • Likelihood: Medium (file access errors are common in real deployments)
  • Priority: Medium

Location

  • File: src/cleveragents/lsp/discovery.py
  • Function/Class: LanguageDiscovery._detect_uncached method
  • Lines: ~213-220

Description

The language discovery code suppresses OSError exceptions with a bare except clause, violating the project specification requirement to "not suppress errors - let exceptions propagate to top level" and "no bare catch-all handlers without re-raising".

Evidence

# Layer 2: Content analysis (shebang)
try:
    with open(file_path, encoding="utf-8", errors="replace") as f:
        first_line = f.readline(512)
    lang = _detect_from_shebang(first_line)
    if lang is not None:
        return lang
except OSError:
    pass  # <-- VIOLATION: Suppresses errors, violates fail-fast

This suppresses legitimate errors like permission denied, disk I/O failures, network filesystem timeouts, etc.

Expected Behavior

Per project specification (ADR-005): "Do not suppress errors - let exceptions propagate to top level" and "Only catch exceptions when you can meaningfully handle them (retry, cleanup, context)".

File access errors should either:

  1. Propagate to caller for proper error handling
  2. Be caught only for specific, recoverable cases with appropriate logging

Actual Behavior

All OSError exceptions are silently suppressed, masking real filesystem problems and violating fail-fast principles.

Suggested Fix

Replace with specific error handling or propagation:

try:
    with open(file_path, encoding="utf-8", errors="replace") as f:
        first_line = f.readline(512)
    lang = _detect_from_shebang(first_line)
    if lang is not None:
        return lang
except (PermissionError, FileNotFoundError):
    # These are expected for language detection - continue to next layer
    pass
except OSError as exc:
    # Unexpected I/O errors should propagate
    logger.warning("Language detection I/O error", file=file_path, error=str(exc))
    # Let it propagate or handle appropriately
    raise

Category

spec-alignment

TDD Note

After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: @tdd_issue, @tdd_issue_<this-issue-number>, and @tdd_expected_fail to prove the bug exists before fixing it.

Subtasks

  • Reproduce the error suppression behaviour in LanguageDiscovery._detect_uncached (~line 213-220)
  • Create TDD issue with @tdd_expected_fail test proving the violation
  • Replace bare except OSError: pass with differentiated handling (expected vs unexpected errors)
  • Add structured logging for unexpected I/O errors before re-raising
  • Verify no other bare OSError suppressions exist in discovery.py
  • Update unit tests (Behave) to cover the new error propagation paths
  • Ensure all nox stages pass with coverage ≥ 97%

Definition of Done

  • LanguageDiscovery._detect_uncached no longer silently suppresses unexpected OSError exceptions
  • Expected, recoverable errors (PermissionError, FileNotFoundError) are handled explicitly with a comment justifying the suppression
  • Unexpected OSError variants propagate to the caller (fail-fast)
  • Structured log warning emitted before re-raising unexpected errors
  • Behave BDD unit tests cover: expected suppression paths, unexpected error propagation paths
  • All nox stages pass
  • Coverage >= 97%

Automated by CleverAgents Bot
Supervisor: Bug Detection | Agent: new-issue-creator

## Metadata - **Branch**: `bugfix/lsp-discovery-error-suppression-fail-fast` - **Commit Message**: `fix(lsp): replace bare OSError suppression in LanguageDiscovery with fail-fast propagation` - **Milestone**: None (backlog) - **Parent Epic**: #824 > **Backlog note:** This issue was discovered during autonomous operation > on milestone v3.6.0. It does not block milestone completion and has been > placed in the backlog for human review and future milestone assignment. ## Bug Report: [Spec-Alignment] — Error suppression in LanguageDiscovery violates fail-fast specification ### Severity Assessment - **Impact**: Masks filesystem errors during language detection, violates project fail-fast principles - **Likelihood**: Medium (file access errors are common in real deployments) - **Priority**: Medium ### Location - **File**: `src/cleveragents/lsp/discovery.py` - **Function/Class**: `LanguageDiscovery._detect_uncached` method - **Lines**: ~213-220 ### Description The language discovery code suppresses OSError exceptions with a bare `except` clause, violating the project specification requirement to "not suppress errors - let exceptions propagate to top level" and "no bare catch-all handlers without re-raising". ### Evidence ```python # Layer 2: Content analysis (shebang) try: with open(file_path, encoding="utf-8", errors="replace") as f: first_line = f.readline(512) lang = _detect_from_shebang(first_line) if lang is not None: return lang except OSError: pass # <-- VIOLATION: Suppresses errors, violates fail-fast ``` This suppresses legitimate errors like permission denied, disk I/O failures, network filesystem timeouts, etc. ### Expected Behavior Per project specification (ADR-005): "Do not suppress errors - let exceptions propagate to top level" and "Only catch exceptions when you can meaningfully handle them (retry, cleanup, context)". File access errors should either: 1. Propagate to caller for proper error handling 2. Be caught only for specific, recoverable cases with appropriate logging ### Actual Behavior All OSError exceptions are silently suppressed, masking real filesystem problems and violating fail-fast principles. ### Suggested Fix Replace with specific error handling or propagation: ```python try: with open(file_path, encoding="utf-8", errors="replace") as f: first_line = f.readline(512) lang = _detect_from_shebang(first_line) if lang is not None: return lang except (PermissionError, FileNotFoundError): # These are expected for language detection - continue to next layer pass except OSError as exc: # Unexpected I/O errors should propagate logger.warning("Language detection I/O error", file=file_path, error=str(exc)) # Let it propagate or handle appropriately raise ``` ### Category spec-alignment ### TDD Note After this bug issue is verified, a corresponding Type/Testing issue will be created for TDD. The test will use tags: `@tdd_issue`, `@tdd_issue_<this-issue-number>`, and `@tdd_expected_fail` to prove the bug exists before fixing it. ## Subtasks - [ ] Reproduce the error suppression behaviour in `LanguageDiscovery._detect_uncached` (~line 213-220) - [ ] Create TDD issue with `@tdd_expected_fail` test proving the violation - [ ] Replace bare `except OSError: pass` with differentiated handling (expected vs unexpected errors) - [ ] Add structured logging for unexpected I/O errors before re-raising - [ ] Verify no other bare OSError suppressions exist in `discovery.py` - [ ] Update unit tests (Behave) to cover the new error propagation paths - [ ] Ensure all nox stages pass with coverage ≥ 97% ## Definition of Done - [ ] `LanguageDiscovery._detect_uncached` no longer silently suppresses unexpected OSError exceptions - [ ] Expected, recoverable errors (PermissionError, FileNotFoundError) are handled explicitly with a comment justifying the suppression - [ ] Unexpected OSError variants propagate to the caller (fail-fast) - [ ] Structured log warning emitted before re-raising unexpected errors - [ ] Behave BDD unit tests cover: expected suppression paths, unexpected error propagation paths - [ ] All nox stages pass - [ ] Coverage >= 97% --- **Automated by CleverAgents Bot** Supervisor: Bug Detection | Agent: new-issue-creator
Author
Owner

Verified — Spec alignment bug: error suppression in LanguageDiscovery. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Spec alignment bug: error suppression in LanguageDiscovery. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Spec alignment bug: error suppression in LanguageDiscovery. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Spec alignment bug: error suppression in LanguageDiscovery. MoSCoW: Should-have. Priority: Medium. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Verified — Spec alignment bug: error suppression in LanguageDiscovery. MoSCoW: Should-have. Priority: Medium.


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

✅ **Verified** — Spec alignment bug: error suppression in LanguageDiscovery. 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.

Blocks
#824 Epic: LSP Functional Runtime
cleveragents/cleveragents-core
Reference
cleveragents/cleveragents-core#7209
No description provided.