Bug: Unhandled exceptions in InputModeRouter command handler crash the TUI #8868

Open
opened 2026-04-14 03:04:35 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: fix(tui): catch command handler exceptions in InputModeRouter.process and return error ModeResult
  • Branch: fix/input-mode-router-command-handler-exception

Background and Context

The InputModeRouter.process method in cleveragents.tui.input.modes.InputModeRouter.process dispatches slash-command input to a _command_handler callable. If that callable raises an exception, the exception propagates uncaught out of process, crashing the TUI entirely.

The relevant code path (commit at time of writing: see feature/slash-command-routing branch):

# cleveragents.tui.input.modes.InputModeRouter.process
if mode == InputMode.COMMAND:
    cmd = text.lstrip()[1:]
    result = self._command_handler(cmd)   # ← no exception handling
    return ModeResult(
        mode=mode,
        expanded_text=text,
        references=[],
        shell_result=None,
        command_result=result,
    )

The ModeResult dataclass already has a command_result: str | None field that is the natural place to surface a human-readable error message when the handler fails. The TUI is a user-facing boundary layer; catching exceptions here constitutes meaningful recovery (displaying an error to the user rather than crashing), which is consistent with the project's exception-handling policy in CONTRIBUTING.md.

Expected Behavior

When _command_handler raises an exception, InputModeRouter.process catches it and returns a ModeResult with:

  • mode set to InputMode.COMMAND
  • command_result set to a human-readable error string (e.g., "Error: <exception message>")
  • shell_result set to None
  • references set to []
  • expanded_text set to the original input text

The TUI remains responsive and displays the error message to the user.

Acceptance Criteria

  • InputModeRouter.process wraps the _command_handler(cmd) call in a try/except Exception block
  • On exception, process returns a ModeResult with command_result containing a descriptive error string (e.g., f"Error: {e}")
  • On exception, the TUI does not crash — the exception is fully contained within process
  • Normal (non-exception) command handler invocations are unaffected
  • BDD scenario: a command handler that always raises is passed to InputModeRouter; calling process with a slash-command returns a ModeResult with a non-None command_result containing the error message
  • BDD scenario: a command handler that raises does not propagate the exception out of process
  • All existing tests continue to pass
  • Test coverage ≥ 97% via nox -s coverage_report

Subtasks

  • Wrap self._command_handler(cmd) in try/except Exception as e in InputModeRouter.process
  • Return a ModeResult with command_result=f"Error: {e}" on exception
  • Tests (Behave): Add scenario — command handler raises, process returns error ModeResult without propagating
  • Tests (Behave): Add scenario — command handler raises, TUI remains responsive (no crash)
  • Tests (Robot): Add integration test for InputModeRouter exception containment
  • Verify coverage ≥ 97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

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 (fix(tui): catch command handler exceptions in InputModeRouter.process and return error ModeResult), followed by a blank line, then additional lines providing relevant implementation details.
  • The commit is pushed to the remote on the branch fix/input-mode-router-command-handler-exception.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(tui): catch command handler exceptions in InputModeRouter.process and return error ModeResult` - **Branch**: `fix/input-mode-router-command-handler-exception` ## Background and Context The `InputModeRouter.process` method in `cleveragents.tui.input.modes.InputModeRouter.process` dispatches slash-command input to a `_command_handler` callable. If that callable raises an exception, the exception propagates uncaught out of `process`, crashing the TUI entirely. The relevant code path (commit at time of writing: see `feature/slash-command-routing` branch): ```python # cleveragents.tui.input.modes.InputModeRouter.process if mode == InputMode.COMMAND: cmd = text.lstrip()[1:] result = self._command_handler(cmd) # ← no exception handling return ModeResult( mode=mode, expanded_text=text, references=[], shell_result=None, command_result=result, ) ``` The `ModeResult` dataclass already has a `command_result: str | None` field that is the natural place to surface a human-readable error message when the handler fails. The TUI is a user-facing boundary layer; catching exceptions here constitutes meaningful recovery (displaying an error to the user rather than crashing), which is consistent with the project's exception-handling policy in CONTRIBUTING.md. ## Expected Behavior When `_command_handler` raises an exception, `InputModeRouter.process` catches it and returns a `ModeResult` with: - `mode` set to `InputMode.COMMAND` - `command_result` set to a human-readable error string (e.g., `"Error: <exception message>"`) - `shell_result` set to `None` - `references` set to `[]` - `expanded_text` set to the original input text The TUI remains responsive and displays the error message to the user. ## Acceptance Criteria - [ ] `InputModeRouter.process` wraps the `_command_handler(cmd)` call in a `try/except Exception` block - [ ] On exception, `process` returns a `ModeResult` with `command_result` containing a descriptive error string (e.g., `f"Error: {e}"`) - [ ] On exception, the TUI does **not** crash — the exception is fully contained within `process` - [ ] Normal (non-exception) command handler invocations are unaffected - [ ] BDD scenario: a command handler that always raises is passed to `InputModeRouter`; calling `process` with a slash-command returns a `ModeResult` with a non-`None` `command_result` containing the error message - [ ] BDD scenario: a command handler that raises does not propagate the exception out of `process` - [ ] All existing tests continue to pass - [ ] Test coverage ≥ 97% via `nox -s coverage_report` ## Subtasks - [ ] Wrap `self._command_handler(cmd)` in `try/except Exception as e` in `InputModeRouter.process` - [ ] Return a `ModeResult` with `command_result=f"Error: {e}"` on exception - [ ] Tests (Behave): Add scenario — command handler raises, `process` returns error `ModeResult` without propagating - [ ] Tests (Behave): Add scenario — command handler raises, TUI remains responsive (no crash) - [ ] Tests (Robot): Add integration test for `InputModeRouter` exception containment - [ ] Verify coverage ≥ 97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## 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 (`fix(tui): catch command handler exceptions in InputModeRouter.process and return error ModeResult`), followed by a blank line, then additional lines providing relevant implementation details. - The commit is pushed to the remote on the branch `fix/input-mode-router-command-handler-exception`. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.7.0 milestone 2026-04-14 03:11:11 +00:00
Author
Owner

Triage Decision: VERIFIED — MoSCoW/Must Have

Real TUI reliability bug: unhandled exceptions in InputModeRouter command handler crash the TUI. Command handlers must be resilient to exceptions to prevent TUI crashes during normal user interaction.

Priority/High — TUI crashes on command input are a critical reliability issue.


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

✅ **Triage Decision: VERIFIED — MoSCoW/Must Have** Real TUI reliability bug: unhandled exceptions in `InputModeRouter` command handler crash the TUI. Command handlers must be resilient to exceptions to prevent TUI crashes during normal user interaction. **Priority/High** — TUI crashes on command input are a critical reliability issue. --- **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#8868
No description provided.