# Quality Fixes Design

## Scope
Fix all issues from code review: error handling, function complexity, code duplication, magic numbers, Drop safety, InputFilter, TOCTOU, dead code.

## Approach: Incremental by risk level

### Phase 1 — Logging & Documentation (low risk)
- Replace `let _ = expr` with `if let Err(e) = expr { tracing::warn!(...) }` everywhere
- Deferred queue: log when dropping old responses
- Document magic numbers with rationale comments
- Remove `ScrollbackLine` from protocol

### Phase 2 — Extract Helpers (low risk)
- `spawn_blocking_with_timeout(fut, label)` in server/mod.rs
- `send_error(stream, msg)` in client_handler.rs
- Cursor clamping helpers in grid.rs

### Phase 3 — Refactor Long Functions (medium risk)
- `connect()` → extract `spawn_signal_handlers()`, `setup_panic_hook()`, `cleanup_terminal()`
- `print()` → extract `handle_combining_mark()`, `handle_autowrap()`, `handle_wide_char()`
- `render_screen_impl()` → extract `render_scrollback_section()`, `render_modes_and_title()`

### Phase 4 — Structural Fixes (medium-high risk)
- `Session::Drop`: use `try_lock()` instead of `lock()`, log if failed
- `InputFilter`: reduce nesting, add edge case tests
- TOCTOU: document as acceptable risk (local unix socket)

## Commit strategy
One commit per phase. Run `cargo test` after each.
