Skip to content

ROCMAI-84: Modularize crates/rocm-dash-tui/src/app/mod.rs - #476

Merged
jussielo-amd merged 6 commits into
mainfrom
rocmai-84-modularize-dash-tui-app-mod
Oct 5, 2026
Merged

jussielo-amd merged 6 commits into
mainfrom
rocmai-84-modularize-dash-tui-app-mod

Conversation

@jussielo-amd

@jussielo-amd jussielo-amd commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Splits app/mod.rs (8,967 lines) into an app/ directory following the modularization effort's full-domain-extraction convention:
    • types.rs — shared type/enum defs (Focus, ResolvedArgs, connection/tab/chat/replay state, Modal, UpdateStatus, slash/plan/approval payload types). No AppState access.
    • event_loop.rs — terminal lifecycle, signal handling, and the tick loop (run, event_loop, the termination-signal watcher, startup-focus/Updates-tile tick helpers).
    • scrollbar.rs — mouse/scroll hit-testing: resolving a raw MouseEvent against recorded scrollbar tracks, the tab bar, and footer-legend chips into a KeyAction.
    • actions.rs — KeyAction dispatch: handle_key/handle_mouse/tab_bar_hit, apply_action/run_approved reducer glue.
    • mod.rs keeps only AppState and its apply_event-adjacent reducer impl — "the reducer's reason to exist," per the ticket.
  • Pure code motion — no behavior change. crate::app::* paths for the module's public surface are preserved via re-exports from mod.rs, so ui/, apps/rocm, and the dash e2e/example targets that reference them are unaffected.
  • Updates docs/architecture.md's module map in this same PR (not deferred), per the modularization plan's documentation rule.
  • Why: part of the rocm-cli modularization plan (epic ROCMAI-27, Phase 4) to make large, monolithic source files easier to navigate and review.

Design decisions

  • mod.rs's re-exports preserve crate::app::* for the module's public surface — the scope the ticket's acceptance criteria and "no behavior change" actually cover (AppState's public surface used by ui/, plus anything externally reachable). They do not preserve incidental reachability of pub(crate) items that have no caller through crate::app:: — a pub(crate) symbol with zero current callers on that path can't silently break anyone if the path disappears (any real in-crate need would be a compile error, not a runtime regression), so there's nothing for parity to protect there. handle_mouse/tab_bar_hit are the converse case: real pub surface a downstream consumer of the crate could depend on, which is why those got re-added per Copilot's review.

Notes

  • Before starting, re-verified the cluster's actual line boundaries against current main by grep/structure rather than trusting the ticket's (stale, pre-drift) line numbers — the file had grown from 6.7k to 8,967 lines since epic-authoring time.
  • The original's 208 #[test] + 1 #[tokio::test] functions (209 total) were partitioned across the 5 files by what they actually exercise (verified against call-sites), not by position. Test count is unchanged.
  • Sequencing: the epic sequences this (Phase 4) after Phase 3 (agent.rs, ROCMAI-51) to avoid two large concurrent diffs on this crate. ROCMAI-51 is still in progress, so this PR is landing slightly out of the stated order — flagging for awareness; there's no code dependency between the two, just review/merge-overlap risk.

Test plan

  • cargo check --workspace --all-targets — clean.
  • cargo clippy --workspace --all-targets -- -D warnings — clean.
  • cargo test --lib (rocm-dash-tui) — 804 passed, 0 failed, 4 ignored; app-module test count (209) matches pre-refactor exactly.
  • cargo xtask manifest --check — passed.
  • prek hooks (fmt, license headers, etc.) — all passed.
  • Confirmed AppState's public surface used by ui/ views is unaffected (workspace build covers all consumers, including apps/rocm, the dash e2e tests, and the gen_cast/gen_screenshots examples).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The extraction unintentionally removes two public API paths and introduces an unresolved documentation link.

Review effort: Balanced
Findings: 1 High severity · 1 Low severity

Open (2)
What changed in this PR

Modularizes the dashboard’s monolithic application module while preserving its reducer architecture and intended public API.

Changes:

  • Extracts shared types, event-loop logic, input actions, and scrollbar handling.
  • Retains AppState and reducer logic in mod.rs.
  • Updates the architecture documentation.
File Description
docs/​architecture.md Documents the new module structure.
app/​mod.rs Retains reducer state and re-exports extracted APIs.
app/​types.rs Contains shared application types.
app/​event_loop.rs Contains terminal lifecycle and event processing.
app/​scrollbar.rs Contains mouse and scrollbar hit-testing.
app/​actions.rs Contains input translation and action dispatch.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/rocm-dash-tui/src/app/mod.rs Resolved
Comment thread crates/rocm-dash-tui/src/app/types.rs Resolved
jussielo-amd added a commit that referenced this pull request Oct 1, 2026
Code review on PR #476 caught two more instances of the same bug
classes already fixed once in 96a44fd: NO_CHAT_BACKEND_MSG was moved
to types.rs but dropped from the pub(crate) re-export list, and the
focused_should_exit doc comment's intra-doc link to
focused_close_key_blocked no longer resolves now that the two live in
separate modules (the fn is private to event_loop, so de-link rather
than widen its visibility).

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd marked this pull request as ready for review October 1, 2026 11:29
@jussielo-amd
jussielo-amd requested a review from a team as a code owner October 1, 2026 11:29
jussielo-amd added a commit that referenced this pull request Oct 2, 2026
Code review on PR #476 caught two more instances of the same bug
classes already fixed once in 96a44fd: NO_CHAT_BACKEND_MSG was moved
to types.rs but dropped from the pub(crate) re-export list, and the
focused_should_exit doc comment's intra-doc link to
focused_close_key_blocked no longer resolves now that the two live in
separate modules (the fn is private to event_loop, so de-link rather
than widen its visibility).

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd force-pushed the rocmai-84-modularize-dash-tui-app-mod branch from b02ab85 to c5b5c5e Compare October 2, 2026 05:10
jussielo-amd added a commit that referenced this pull request Oct 2, 2026
Code review on PR #476 caught two more instances of the same bug
classes already fixed once in 96a44fd: NO_CHAT_BACKEND_MSG was moved
to types.rs but dropped from the pub(crate) re-export list, and the
focused_should_exit doc comment's intra-doc link to
focused_close_key_blocked no longer resolves now that the two live in
separate modules (the fn is private to event_loop, so de-link rather
than widen its visibility).

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd force-pushed the rocmai-84-modularize-dash-tui-app-mod branch from c5b5c5e to a5ea2ea Compare October 2, 2026 05:13
Split the 8,967-line app/mod.rs into app/{types,event_loop,scrollbar,actions}.rs
following the full-domain-extraction convention, keeping mod.rs to AppState and
its apply_event/apply_action-adjacent reducer impl. crate::app::* paths for
everything moved out are preserved via re-exports. Updates the architecture
module map in the same PR per the modularization plan's rules.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
Review (Copilot) caught two regressions from the mechanical move:
- handle_mouse/tab_bar_hit were pub at crate::app:: before extraction but
  landed in the private actions module unre-exported, silently shrinking
  the public API surface this PR claims to preserve.
- The ClientMsg intra-doc link in PlannedAction's doc comment stopped
  resolving once the comment moved to types.rs, which doesn't import it.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
Code review on PR #476 caught two more instances of the same bug
classes already fixed once in 96a44fd: NO_CHAT_BACKEND_MSG was moved
to types.rs but dropped from the pub(crate) re-export list, and the
focused_should_exit doc comment's intra-doc link to
focused_close_key_blocked no longer resolves now that the two live in
separate modules (the fn is private to event_loop, so de-link rather
than widen its visibility).

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd force-pushed the rocmai-84-modularize-dash-tui-app-mod branch from a5ea2ea to 94e251d Compare October 2, 2026 06:57
@rominf

rominf commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

🔴 Automated review · pr-review-watcher · a647de4

This automation never files a GitHub approval, so no approving review will
appear here whatever the outcome — the merge decision stays with a human
reviewer.

Summary

In this range the PR removes the unused pub(crate) use types::NO_CHAT_BACKEND_MSG re-export from app/mod.rs and rewrites the re-export sentence in docs/architecture.md to match. Outcome: no blocking findings. The only leftovers are comments and docs that now disagree with the code.

Re the reply above: the previous round's one blocker, the NO_CHAT_BACKEND_MSG re-export in app/mod.rs, was re-reviewed in this round and not found again. app/mod.rs was read in full: the use line, its comment and the #[allow(unused_imports)] are gone, and every remaining use goes through super::types::.

Reviewed: range 04289b0..HEAD (crates/rocm-dash-tui/src/app/mod.rs read in full, docs/architecture.md), plus the files those changes touch: the pre-split prw-base:app/mod.rs and its list of pub/pub(crate) items, app/{types,event_loop,scrollbar,actions}.rs, the module headers of app/{slash,chat,summary}.rs, and every caller that reaches a re-exported item through crate::app::. The earlier non-blocking points on tests/dash_journeys.rs:16-17 were outside this round's scope and were not checked again.

Verified: cargo clippy -p rocm-dash-tui --all-targets -D warnings passes after touching the sources. cargo test -p rocm-dash-tui --no-fail-fast --tests: lib 803 passed, 3 failed — all three are the known sandbox token-cache-dir failures in agent/clients.rs. dash_characterization (20), dash_journeys (5) and wave0_job_bridge (5) all pass. Nothing in the repo or in the 3 .rs files under apps/ names NO_CHAT_BACKEND_MSG through crate::app::; all its uses go through super::types::. Every other pub(crate) item from before the split is still reachable at crate::app::, apart from ProviderSwitch, which never moved out of mod.rs.

Blocking: 0 · Non-blocking: 8.

🚫 Blocking (must fix before merge)

None.

Non-blocking

  • crates/rocm-dash-tui/src/app/mod.rs:11-12 and :21-23 — These comments say "crate::app::* paths for everything moved out are unchanged" / "crate::app::* paths are unchanged". The code proves otherwise: NO_CHAT_BACKEND_MSG was at crate::app:: before the split and no longer is. The code is right, and so is the new docs/architecture.md wording ("public surface"), so change these comments to match it.
  • crates/rocm-dash-tui/src/app/mod.rs:5-6 — The module doc says this file holds AppState and "its apply_event/apply_action entry points", but apply_action is a free function in actions.rs:61.
  • docs/architecture.md:42 — "app/mod.rs keeps only AppState and its … reducer impl" leaves out ProviderSwitch, HISTORY_CAP and BENCH_CAP, which also stay in mod.rs.
  • docs/architecture.md:42 — The new clause ("a pub(crate) item with no caller through that path isn't re-exported just because it was reachable there pre-split") reads as a note on one decision in this PR, not as architecture. It would sit better as a code comment on the re-export block in mod.rs.
  • crates/rocm-dash-tui/src/app/mod.rs:40-44 — restore_after_session is re-exported under #[allow(unused_imports)] and only a test uses it. Gating it with #[cfg(test)] instead would let the compiler flag it if that test caller disappears — the kind of dead re-export this commit just removed by hand.
  • crates/rocm-dash-tui/src/app/slash.rs:11-13 (not changed by this PR, made stale by the split) — It says SlashOutcome and SlashToolRequest "stay in mod.rs", but both now live in types.rs; only ProviderSwitch stays in mod.rs.
  • crates/rocm-dash-tui/src/app/mod.rs:21-23, types.rs:8, actions.rs:7, scrollbar.rs:7, chat.rs:10 — Each says the code was split out "to keep the core reducer + event loop focused", but the event loop no longer lives in mod.rs.
  • crates/rocm-dash-tui/src/app/mod.rs:2304 — "(mirrors app.rs)" is a stale path: the provider-switch drain it points at is now in event_loop.rs. Commit 04289b0 fixed stale module paths but missed this one; the text predates the PR.

rominf
rominf previously requested changes Oct 2, 2026

@rominf rominf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Automated review · pr-review-watcher · 94e251d

Requesting changes for the two blocking findings in this round's review comment:

  1. Comments in other files still point at the old location. apps/rocm/src/main.rs:29733 names app/mod.rs as the home of startup_focus_gate_only_opens_onboarding_for_explicit_setup_focus, but that test is now in app/event_loop.rs. crates/rocm-dash-tui/tests/dash_journeys.rs:16-17 names src/app/mod.rs for the keystroke tests, which are now in src/app/actions.rs. crates/rocm-dash-tui/src/agent/mod.rs:21-26 describes app as not re-exporting its submodules, which it now does. To resolve: correct the two paths and reword the agent/mod.rs sentence.
  2. crates/rocm-dash-tui/src/app/mod.rs:50-54 adds the pub(crate) use types::NO_CHAT_BACKEND_MSG re-export. Nothing reaches it through that path, and it only compiles cleanly because of #[allow(unused_imports)]. To resolve: delete the re-export and its allow.

The automation withdraws this request itself once a later round confirms both points are fixed.

@jussielo-amd

Copy link
Copy Markdown
Collaborator Author

Addressing the two blocking findings from the automated review round (commit 94e251d):

  1. Fixed in adea8ed — corrected the three stale path references: apps/rocm/src/main.rs and tests/dash_journeys.rs now point at app/event_loop.rs and app/actions.rs respectively (where those tests actually live post-split), and reworded agent/mod.rs's module doc, which previously contrasted itself with app/mod.rs's submodules being "private" — app/mod.rs now re-exports its submodules' public items too, so that contrast was no longer accurate.

  2. Kept intentionally, not fixed — pub(crate) use types::NO_CHAT_BACKEND_MSG (and its #[allow(unused_imports)]) stays. It's unreachable through crate::app:: today because callers use super::types:: directly, but it was reachable through that path pre-split, and the split's explicit goal is that every crate::app::* path that resolved before keeps resolving after — the same reasoning that restored handle_mouse/tab_bar_hit per Copilot's earlier review. Removing it the moment it goes locally-unused would make the re-export list's completeness depend on caller behavior rather than on the pre-split surface. Documented this in the PR description's new "Design decisions" section.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd force-pushed the rocmai-84-modularize-dash-tui-app-mod branch from adea8ed to 04289b0 Compare October 2, 2026 14:00
@jussielo-amd
jussielo-amd requested a review from rominf October 2, 2026 14:44
@rominf

rominf commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Re the reply above, on the two blocking findings from the 94e251d round:

Finding 1 (stale path references) — confirmed fixed at 04289b0. apps/rocm/src/main.rs now names app/event_loop.rs (the test is at event_loop.rs:2118), tests/dash_journeys.rs names src/app/actions.rs, and the agent/mod.rs doc no longer contrasts itself with app.

Finding 2 (pub(crate) use types::NO_CHAT_BACKEND_MSG under #[allow(unused_imports)]) — your facts check out, and the finding still stands.

  • At the base, NO_CHAT_BACKEND_MSG was pub(crate) in app/mod.rs (line 397), so crate::app::NO_CHAT_BACKEND_MSG did resolve before the split — although nothing in the crate used that path then either.
  • Parity is complete: every module-level pub/pub(crate) item from the old app/mod.rs still resolves at crate::app::<name>, and the app/mod.rs header and the PR description both state that rule.
  • The difference from handle_mouse/tab_bar_hit: those are plain pub use in a pub mod, so they are public surface that code outside this crate could depend on, and parity protects something there. NO_CHAT_BACKEND_MSG is crate-private. Any in-crate caller is compiled together with this module, so a path that disappears can't break anyone silently, and the re-export protects no caller. It needs the lint turned off to compile without a warning.

This round's review re-derived the same finding from the code, so it stays blocking and the change request stays in place for this point only. If you and the maintainers decide parity should also cover crate-private paths, a human reviewer can make that call. Otherwise, deleting the comment, the #[allow] and the use line clears it.

@rominf
rominf dismissed their stale review October 2, 2026 14:53

Withdrawing: objection 1 (stale path comments) is fixed at 04289b0. Objection 2 (the documented crate-private NO_CHAT_BACKEND_MSG re-export under allow(unused_imports)) is a style preference with no consequence after merge, so it stays a non-blocking comment rather than a gate.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd

Copy link
Copy Markdown
Collaborator Author

Fair — the public/crate-private distinction is correct and I was conflating two different kinds of parity. Fixed in a647de4: removed the pub(crate) use types::NO_CHAT_BACKEND_MSG re-export, its comment, and the #[allow(unused_imports)].

Also narrowed the architecture doc and PR description's "Design decisions" section so this doesn't recur: the parity guarantee is scoped to the module's public surface (what the ticket's acceptance criteria actually requires), not incidental pub(crate) reachability with zero callers on that path. cargo check/cargo clippy --all-targets -- -D warnings clean on rocm-dash-tui after the removal.

@rominf

rominf commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator

🔴 Automated review · pr-review-watcher · a647de4
Re-reviewed at a647de4 after the reply above: the NO_CHAT_BACKEND_MSG blocker is resolved — Blocking: 0 · Non-blocking: 8. The report is updated in place: #476 (comment)

- Module doc on app/mod.rs no longer claims apply_action is an
  AppState entry point (it's a free fn in actions.rs).
- "crate::app::* paths ... unchanged" claims narrowed to the public
  surface (NO_CHAT_BACKEND_MSG proved the broader claim false);
  moved the re-export completeness rationale out of architecture.md
  (a structure doc, not a decision log) into a comment on the
  re-export block it actually describes.
- architecture.md's "app/mod.rs keeps only AppState ..." now also
  names ProviderSwitch/HISTORY_CAP/BENCH_CAP, which stay there too.
- Dropped "+ event loop" from five submodules' split-rationale
  comments now that event_loop.rs is itself a sibling module, not
  part of mod.rs's core.
- slash.rs's header no longer claims SlashOutcome/SlashToolRequest
  stay in mod.rs; they live in types.rs now, only ProviderSwitch
  stays.
- Fixed a stale "(mirrors app.rs)" test comment to point at
  event_loop.rs, where that logic actually lives post-split.
- Gated the restore_after_session re-export with #[cfg(test)]
  instead of #[allow(unused_imports)], so the compiler (not a
  hand-maintained comment) catches it if its only caller
  disappears.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd

Copy link
Copy Markdown
Collaborator Author

All 8 non-blocking points fixed in 49c0785:

  • mod.rs:5-6 module doc no longer claims apply_action is an AppState entry point (it's a free fn dispatched from actions.rs).
  • mod.rs:11-12/:21-23 and docs/architecture.md:42 narrowed the "crate::app::* unchanged" claim to the public surface, matching what NO_CHAT_BACKEND_MSG's removal actually proved.
  • Moved the "no caller ⇒ not re-exported" rationale out of architecture.md (a structure doc, not a decision log, per its own stated scope) into a comment on the re-export block it describes.
  • architecture.md:42 now also names ProviderSwitch/HISTORY_CAP/BENCH_CAP as staying in mod.rs.
  • Dropped "+ event loop" from the split-rationale comment in mod.rs, types.rs, actions.rs, scrollbar.rs, and chat.rs — event_loop.rs is a sibling module now, not part of what stays "focused" in those files.
  • slash.rs:11-13 no longer claims SlashOutcome/SlashToolRequest stay in mod.rs; only ProviderSwitch does — the other two live in types.rs.
  • mod.rs:2304 test comment "(mirrors app.rs)" now points at event_loop.rs, where the provider-switch drain actually lives post-split.
  • restore_after_session's re-export is now #[cfg(test)]-gated instead of #[allow(unused_imports)], so the compiler catches it as dead if its only caller (launcher.rs's test) ever disappears, rather than relying on a hand-maintained comment.

Verified: cargo check/cargo clippy -p rocm-dash-tui --all-targets -- -D warnings clean, cargo test -p rocm-dash-tui --no-fail-fast --tests 806 passed/0 failed, cargo xtask check-architecture-doc clean.

@jussielo-amd
jussielo-amd added this pull request to the merge queue Oct 5, 2026
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.

3 participants