Skip to content

refactor(rocm): move the comfyui dispatch function out of main.rs - #938

Closed
jussielo-amd wants to merge 1 commit into
mainfrom
refactor-comfyui-dispatch-out-of-main
Closed

jussielo-amd wants to merge 1 commit into
mainfrom
refactor-comfyui-dispatch-out-of-main

Conversation

@jussielo-amd

Copy link
Copy Markdown
Collaborator

Summary

rocm comfyui was the one command whose dispatch function (the match over ComfyuiCommand that renders status, logs and the models path and runs install, start and stop, recording an audit event for each) was still defined in apps/rocm/src/main.rs, about 160 lines away from everything else about ComfyUI, while the sibling commands (services, config, automations, engines, runtimes, install, setup and others) already keep theirs in their own module. This moves it into apps/rocm/src/comfyui.rs, next to the code it calls, as a pure move. Delivers ROCMAI-833, and with the clap-tree move in the merged #889 it completes ROCMAI-858 (main.rs is now under the 1,500 production-line limit).

The module-organization text in docs/architecture.md and in AGENTS.md section 6 said the clap command enum and its dispatch function usually stay in main.rs, and that comfyui() was the example. The clap tree already moved to cli.rs in #889, so that text was already half out of date; this change makes both texts say what the code now does, in the same commit as the move.

What moved

Symbol From To
fn comfyui(command: Option<ComfyuiCommand>) -> Result<()> apps/rocm/src/main.rs pub(crate) fn run(command: Option<ComfyuiCommand>) -> Result<()> in apps/rocm/src/comfyui.rs

The body is unchanged apart from import paths: the comfyui:: prefix on calls into the module (render_status, render_models_path, render_logs, install, start, stop, ComfyUiInstallOptions, ComfyUiStartOptions) is dropped because they are now local, and comfyui.rs gains use crate::cli::ComfyuiCommand; and use crate::cli_audit::record_cli_audit_event;, the same direct import services_cmd.rs, config_cmd.rs and install_cmd.rs use. Reaching cli_audit directly means no new edge back into main.rs, so no new module cycle. In main.rs the one arm of dispatch() becomes Some(Command::Comfyui { command }) => comfyui::run(command) (the name follows remote::run and bootstrap::run), the now-unused ComfyuiCommand import is dropped, and a comment that said main.rs itself calls record_cli_audit_event is trimmed because it no longer does.

Docs updated in the same commit: the module-organization convention and the main.rs and comfyui.rs entries in docs/architecture.md (the comfyui() handler is no longer listed under main.rs; the comfyui.rs entry now says the dispatch function lives there while the enum stays in cli.rs), and the new-subsystems bullet in AGENTS.md section 6.

Verification

Ran: cargo fmt --all --check; cargo clippy -p rocm --all-targets -- -D warnings on Linux; cargo test -p rocm --no-fail-fast; the leaf-name diff of cargo test -p rocm --bin rocm -- --list and -- --list --ignored against clean origin/main (both empty: 1,516 tests and 8 ignored before and after); cargo xtask manifest --check; cargo xtask check-crate-edges; lychee (offline, repo config) on docs/architecture.md and AGENTS.md; the leak scan against origin/main; a conflict-marker grep.

Not run: the Windows clippy cross-check could not build locally (the aws-lc-sys C build for x86_64-pc-windows-msvc needs a Windows C toolchain that is not installed here), so the Windows lane is the check; the moved code has no cfg gates. The tests/e2e-cucumber comfyui scenarios were not run locally; CI carries them.

User-visible behaviour

None, so no new scenario: this is an internal relocation. The existing comfyui scenarios in tests/e2e-cucumber/features/ exercise the same dispatch path and are expected to stay green unmodified. The function has no unit tests of its own to move.

Notes for reviewers

One commit. Reading order: apps/rocm/src/comfyui.rs (the function, directly after ComfyUiStartOptions), the one-line arm in main.rs, then the three documentation edits. git diff --color-moved shows the body as moved apart from the dropped comfyui:: prefixes. Besides the docs hotspot (docs/architecture.md is edited by many open PRs, expect a mechanical rebase), #923 also touches apps/rocm/src/comfyui.rs, in a different region.

The `comfyui` dispatch function (the match over `ComfyuiCommand`, about 160
lines) moves from `apps/rocm/src/main.rs` into `apps/rocm/src/comfyui.rs` as
`comfyui::run`, next to the code it calls, the way `remote::run` and
`bootstrap::run` are named. It is a pure move: the body is unchanged apart
from dropping the `comfyui::` prefix on calls that are now local, and the
module reaches `record_cli_audit_event` through `crate::cli_audit` like its
sibling command modules, so no new module cycle appears. The one arm of
`dispatch()` now calls `comfyui::run(command)`.

The clap command tree already lives in `cli.rs`, so the convention text that
said the command enum and its dispatch function usually stay in `main.rs`
(with `comfyui()` as the example) is updated in the same change:
docs/architecture.md (module-organization convention, the `main.rs` entry and
the `comfyui.rs` entry) and AGENTS.md section 6.

Signed-off-by: Jussi Elo <jussi.elo@amd.com>
@jussielo-amd
jussielo-amd marked this pull request as ready for review November 5, 2026 21:57
@jussielo-amd
jussielo-amd requested a review from a team as a code owner November 5, 2026 21:57
@jussielo-amd
jussielo-amd requested review from r0x0r and a balanced review from Copilot November 5, 2026 21:57

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.

🟢 Approval recommended

The ComfyUI dispatcher relocation has no active review issues.

No open issues 🎉

What changed in this PR

Moves the ComfyUI command dispatcher from main.rs into its domain module, following the earlier clap-tree extraction and aligning ComfyUI with sibling commands. The relocation preserves command behavior and audit logging.

Changes:

  • Relocates the handler as comfyui::run and updates the top-level dispatch call and imports.
  • Updates architecture documentation and contributor guidance to reflect where command enums and dispatch functions live.
File Description
docs/​architecture.md Updates module-organization guidance and the main/ComfyUI module descriptions.
apps/​rocm/​src/​main.rs Delegates to comfyui::run, removes the old handler, and cleans up imports and a comment.
apps/​rocm/​src/​comfyui.rs Hosts the relocated dispatcher with direct command-type and audit imports.
AGENTS.md Aligns dispatch-placement guidance with the module structure.

Review effort: Balanced

@jussielo-amd

Copy link
Copy Markdown
Collaborator Author

Superseded by #936: this pull request's commits are included in that branch (head a920d07), and #936's description covers this change. Closing so the review happens in one place.

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.

2 participants