Bug: Unhandled exceptions in on_input_submitted can crash the TUI #8870

Open
opened 2026-04-14 03:06:33 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Commit Message: fix(tui): wrap on_input_submitted in try/except to prevent TUI crash on unhandled exceptions
  • Branch: bugfix/m8-on-input-submitted-unhandled-exception

Background and Context

The on_input_submitted method in src/cleveragents/tui/app.py does not handle exceptions that may be raised during input processing. This can lead to the TUI crashing if an unexpected error occurs in the InputModeRouter or one of the functions it calls.

The call to mode_router.process(text) on line 185 of src/cleveragents/tui/app.py is not wrapped in a try...except block. Exceptions from _command_handler, run_shell_command, or parse_references will propagate up and terminate the application.

Steps to Reproduce:

  1. Run the CleverAgents TUI.
  2. Enter a command or text that causes an exception in the input processing logic (e.g., a command that fails, or a malformed input that the reference parser doesn't expect).
  3. The TUI will crash.

Expected Behavior

The TUI should catch the exception, display a user-friendly error message in the conversation view, and continue running. Specifically, on_input_submitted should wrap the call to mode_router.process(text) and all subsequent result-handling logic in a try...except Exception block. On catching an exception, it should display a descriptive error message in the #conversation widget and allow the user to continue interacting with the TUI.

Acceptance Criteria

  • on_input_submitted in src/cleveragents/tui/app.py wraps the mode_router.process(text) call and all downstream result-handling in a try...except Exception block.
  • When an exception is raised during input processing, the TUI does not crash.
  • The error is displayed to the user in the #conversation widget with a meaningful message (e.g., "An unexpected error occurred: <exception message>").
  • The TUI remains fully interactive after the error is displayed.
  • The fix does not suppress exceptions silently — the error message is always surfaced to the user.
  • All existing TUI BDD scenarios continue to pass.
  • A new BDD scenario covers the exception-handling path (added via the TDD issue).
  • nox passes with coverage ≥ 97%.

Subtasks

  • Wrap mode_router.process(text) and result-handling in on_input_submitted with try...except Exception as e in src/cleveragents/tui/app.py
  • Display a user-friendly error message in the #conversation widget on exception
  • Tests (Behave): Add BDD scenario for unhandled exception in on_input_submitted (via TDD issue — this issue depends on the TDD issue)
  • 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, followed by a blank line, then additional lines providing relevant details about the implementation.
  • 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.
  • The corresponding TDD issue (prefixed TDD:) has been created, merged, and closed before this fix is implemented.

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit Message**: `fix(tui): wrap on_input_submitted in try/except to prevent TUI crash on unhandled exceptions` - **Branch**: `bugfix/m8-on-input-submitted-unhandled-exception` ## Background and Context The `on_input_submitted` method in `src/cleveragents/tui/app.py` does not handle exceptions that may be raised during input processing. This can lead to the TUI crashing if an unexpected error occurs in the `InputModeRouter` or one of the functions it calls. The call to `mode_router.process(text)` on line 185 of `src/cleveragents/tui/app.py` is not wrapped in a `try...except` block. Exceptions from `_command_handler`, `run_shell_command`, or `parse_references` will propagate up and terminate the application. **Steps to Reproduce:** 1. Run the CleverAgents TUI. 2. Enter a command or text that causes an exception in the input processing logic (e.g., a command that fails, or a malformed input that the reference parser doesn't expect). 3. The TUI will crash. ## Expected Behavior The TUI should catch the exception, display a user-friendly error message in the conversation view, and continue running. Specifically, `on_input_submitted` should wrap the call to `mode_router.process(text)` and all subsequent result-handling logic in a `try...except Exception` block. On catching an exception, it should display a descriptive error message in the `#conversation` widget and allow the user to continue interacting with the TUI. ## Acceptance Criteria - [ ] `on_input_submitted` in `src/cleveragents/tui/app.py` wraps the `mode_router.process(text)` call and all downstream result-handling in a `try...except Exception` block. - [ ] When an exception is raised during input processing, the TUI does **not** crash. - [ ] The error is displayed to the user in the `#conversation` widget with a meaningful message (e.g., `"An unexpected error occurred: <exception message>"`). - [ ] The TUI remains fully interactive after the error is displayed. - [ ] The fix does not suppress exceptions silently — the error message is always surfaced to the user. - [ ] All existing TUI BDD scenarios continue to pass. - [ ] A new BDD scenario covers the exception-handling path (added via the TDD issue). - [ ] `nox` passes with coverage ≥ 97%. ## Subtasks - [ ] Wrap `mode_router.process(text)` and result-handling in `on_input_submitted` with `try...except Exception as e` in `src/cleveragents/tui/app.py` - [ ] Display a user-friendly error message in the `#conversation` widget on exception - [ ] Tests (Behave): Add BDD scenario for unhandled exception in `on_input_submitted` (via TDD issue — this issue depends on the TDD issue) - [ ] 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, followed by a blank line, then additional lines providing relevant details about the implementation. - 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. - The corresponding TDD issue (prefixed `TDD:`) has been created, merged, and closed before this fix is implemented. --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.7.0 milestone 2026-04-14 03:11:10 +00:00
Author
Owner

Triage Decision: VERIFIED — MoSCoW/Must Have

Real TUI reliability bug: unhandled exceptions in on_input_submitted can crash the TUI. TUI event handlers must be resilient to exceptions — any unhandled exception in a Textual event handler will crash the application.

Priority/High — TUI crashes on user 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 `on_input_submitted` can crash the TUI. TUI event handlers must be resilient to exceptions — any unhandled exception in a Textual event handler will crash the application. **Priority/High** — TUI crashes on user input are a critical reliability issue. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

🔄 Re-triage: VERIFIED — MoSCoW/Must Have (labels were reset by another agent)

This issue was previously triaged in Cycle 20. Labels have been re-applied. The triage decision stands: this is a real TUI reliability bug — unhandled exceptions in on_input_submitted can crash the TUI.

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


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

🔄 **Re-triage: VERIFIED — MoSCoW/Must Have** (labels were reset by another agent) This issue was previously triaged in Cycle 20. Labels have been re-applied. The triage decision stands: this is a real TUI reliability bug — unhandled exceptions in `on_input_submitted` can crash the TUI. **Priority/High** — TUI crashes on user 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.

Depends on
Reference
cleveragents/cleveragents-core#8870
No description provided.