Skip to content

fix(core): clear api_error instead of latching it - #467

Merged
LargeModGames merged 1 commit into
mainfrom
fix/error-lifecycle
Aug 14, 2026
Merged

LargeModGames merged 1 commit into
mainfrom
fix/error-lifecycle

Conversation

@LargeModGames

@LargeModGames LargeModGames commented Aug 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

App::handle_error is the only writer of api_error, and no site in the repo
cleared it. The TUI hides this because the user dismisses the error route, but
the field itself stays set forever — so anything that renders app state rather
than reacting to a keypress latches the first failure for the life of the
process. This gives the field a lifetime and a dismissal path, both owned by
core/app so they work without a route stack or an Esc key.

  • handle_error stamps a 60s lifetime alongside the message. One edit
    covers all ~88 call sites and changes none of them.
  • clear_api_error() is the single dismissal primitive: it drops the
    message, its lifetime, and every navigation frame still showing it. Clearing
    the string on its own would leave an error page with nothing rendered on it.
  • pop_navigation_stack calls it when the frame it popped was Error, so
    the escape key, the configurable back key and a script's Back all dismiss
    identically with no changes under src/tui/. Keyed on the frame that was
    popped rather than the new top, so pressing d from the error page (the
    recovery the page itself advertises) and coming back still shows the message.
  • update_on_tick retires an expired error next to the existing
    status-message expiry, guarded on the clock alone. Guarding on the route
    would never fire for a consumer that never pops, which is exactly the case
    this exists for. The text moves to the status bar only when the error frame
    is the screen the user is on; one that expired buried under another screen
    goes quietly.
  • drop_error_routes matches on the id and the block. The search key
    rewrites the error frame in place into an input field rather than pushing,
    so an id-only match would delete a frame holding live text-input focus and
    drop the user's next keystrokes into the global bindings.
  • flush_state_save reports to the status bar instead of the error page.
    The tick calls it every frame and a failed save re-arms its own deadline, so
    as a modal an unwritable state dir is an app you cannot escape. The report is
    latched to once per failure run: repeating it at the retry rate would hold
    status_message_is_error, and set_status_message refuses to overwrite a
    live error, so every ordinary status message would be dropped for the rest of
    the session.

CLI behavior is unchanged. It builds no driver and pops no routes, so a
non-empty api_error remains its failure signal.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --no-default-features --features telemetry,tui -- -D warnings
    (also default and headless): clean
  • cargo test --no-default-features --features telemetry,tui: 610 passed
  • cargo test --no-default-features --features telemetry (headless): 329
    passed, zero warnings
  • cargo test (default): 908 passed
  • cargo test --no-default-features --features telemetry,tui,mcp-server: 729
    passed
  • cargo test --no-default-features --features telemetry,tui,ai-dj: 869 passed
  • all-sources CI string with audio-viz swapped for audio-viz-cpal (the leg
    itself is Linux-only): 1344 passed, plus the known pre-existing Windows-only
    infra::local::tests::uri_round_trip failure
  • tools/check_gates_ratchet.sh vs main ok; Cargo.lock untouched
  • The latch regression test was mutation-checked: with the latch removed it
    fails, as it should
  • Manual smoke on Windows: the error page still raises and dismisses; opening
    the device picker from it and coming back preserves the message; the 60s
    backstop retires the page and hands the text to the status bar; a buried
    error frame is cleaned up rather than resurfacing; CLI exit codes unchanged

Additional notes

  • Gates: test floor raised 1373 -> 1385. No coupling counter moves — every
    edit lands in src/core/app/**, outside all of their measurement scopes.
  • The new ### Errors section in the three docs writes down the rule for
    moving a call site off handle_error, since a non-empty api_error is the
    CLI's only failure signal and demoting a CLI-reachable site silently turns a
    failing command into exit 0.
  • Deliberately not included: clearing api_error between the shared CLI
    preamble and the subcommand. It looks like a free fix for a preamble failure
    discarding a subcommand that succeeded, but list --devices performs no
    fetch of its own and reads only the preamble's GetDevices, so clearing
    turns a failed device fetch into "No devices available" and exit 0;
    playback --toggle likewise consumes preamble state and returns (). That
    needs its own change and its own verification.
  • The remaining ~87 handle_error call sites are unconverted on purpose. The
    latched-error defect is closed by the lifetime on the single writer, and a
    broad conversion is a behavioral change per site with a real exit-code trap.

💬 Questions or want to chat with other contributors? Join the spotatui Discord.

Summary by CodeRabbit

  • New Features
    • Added clearer handling for API errors, including automatic expiration after 60 seconds.
    • Expired errors can transition to status messages for limited visibility.
    • Added dismissal behavior that removes related error screens while preserving other navigation.
    • State-save failures now appear in the status bar and are reported once until saving succeeds.
  • Documentation
    • Documented error display, dismissal, expiration, and state-save failure behavior.

`App::handle_error` was the only writer of `api_error` and no site in the
repo cleared it. The TUI hid this because the user dismisses the error
route; a consumer that renders the field from state instead latches the
first failure for the life of the process.

- `handle_error` stamps a 60s lifetime alongside the message.
- `clear_api_error()` is the single dismissal primitive: it drops the
  message, its lifetime, and every navigation frame still showing it.
  Clearing the string alone would leave an error page with nothing on it.
- `pop_navigation_stack` calls it when the frame it popped was `Error`,
  so the escape key, the configurable back key and a script's `Back` all
  dismiss identically, and a frontend with no back key is not the odd one
  out. Keyed on the popped frame, not the new top: opening the device
  picker from the error page and coming back still shows the message.
- `update_on_tick` retires an expired error next to the existing
  status-message expiry, guarded on the clock alone. Guarding on the
  route would never fire for a consumer that never pops, which is the
  case this exists for. The text moves to the status bar only when the
  error frame is the current screen.
- `drop_error_routes` matches on the id *and* the block: the search key
  rewrites the error frame in place to an input field, and removing that
  frame would drop live keystrokes into the global bindings.
- `flush_state_save` reports to the status bar instead of the error
  page. The tick calls it every frame and a failed save re-arms its own
  deadline, so as a modal an unwritable state dir is an inescapable app.
  The report is latched to once per failure run; repeating it at the
  retry rate would hold `status_message_is_error` and silently drop every
  ordinary status message for the rest of the session.

CLI behavior is unchanged: it builds no driver and pops no routes, so a
non-empty `api_error` remains its failure signal.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c0eee7cc-faa6-4319-be25-b2ff206efdf8

📥 Commits

Reviewing files that changed from the base of the PR and between 6e130d0 and d4d1e16.

📒 Files selected for processing (10)
  • .github/copilot-instructions.md
  • AGENTS.md
  • CLAUDE.md
  • src/core/app/construction.rs
  • src/core/app/mod.rs
  • src/core/app/persistence.rs
  • src/core/app/route.rs
  • src/core/app/status.rs
  • src/core/app/tick.rs
  • tools/gates.count

📝 Walkthrough

Walkthrough

Changes

Error lifecycle

Layer / File(s) Summary
API error state and lifecycle
.github/copilot-instructions.md, AGENTS.md, CLAUDE.md, src/core/app/construction.rs, src/core/app/mod.rs, src/core/app/status.rs, src/core/app/route.rs, src/core/app/tick.rs, tools/gates.count
API errors now expire after 60 seconds. Cleanup removes matching error routes and can transfer visible errors to the status bar. Tick and lifecycle tests cover dismissal, expiration, navigation, and route preservation.
Latched state-save failure reporting
src/core/app/construction.rs, src/core/app/mod.rs, src/core/app/persistence.rs
State-save failures now report once per failure run through the status bar. Failed patches remain scheduled for retry, and successful saves reset the reporting latch.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d4d1e

The change gives API errors explicit dismissal and expiry behavior while preserving CLI failure signaling; no actionable merge-blocking risk remains after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant NavigationStack
  participant StatusBar
  App->>App: update_on_tick()
  App->>App: expire_api_error()
  App->>NavigationStack: drop_error_routes()
  App->>StatusBar: transfer expired visible error
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title uses the valid fix(core): prefix, clearly describes the API error lifecycle change, and has a concise imperative subject.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/error-lifecycle
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/error-lifecycle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LargeModGames
LargeModGames merged commit 1604eb8 into main Aug 14, 2026
25 checks passed
@LargeModGames
LargeModGames deleted the fix/error-lifecycle branch August 14, 2026 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant