ROCMAI-83: extract common.rs from apps/rocmd/src/lib.rs - #479
jussielo-amd wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The architecture document incorrectly reports the still-open persistence.rs extraction as already present.
Review effort: Balanced
Findings: 1
What changed in this PR
Extracts shared daemon helpers from lib.rs into common.rs without intended behavior changes.
Changes:
- Moves shared snapshot, command, healthcheck, and argument utilities.
- Relocates eight associated unit tests.
- Updates daemon architecture documentation.
| File | Description |
|---|---|
apps/rocmd/src/common.rs |
Adds shared helpers and tests. |
apps/rocmd/src/lib.rs |
Repoints callers to common. |
docs/architecture.md |
Updates modularization status. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| ### `apps/rocmd` — background daemon | ||
|
|
||
| `lib.rs` is **not yet modularized** — see EAI-7768. | ||
| `lib.rs` modularization is in progress (ROCMAI-83, Phase 5 of EAI-7768's sequencing). Extracted so far: `persistence.rs` (`record_event`/`load_managed_services`, the automation-event/audit-log and managed-service-registry I/O shared across the daemon's sandbox, MCP, service-lifecycle, and watcher code) and `common.rs` (helpers shared across ≥2 of those remaining clusters: GPU/amd-smi snapshotting, the bridge-snapshot diagnostic, `CommandCapture`/command-timeout plumbing, and small arg/healthcheck/endpoint-key utilities). Still pending: `cli.rs`, `sandbox.rs`, `mcp.rs`, `service.rs`, `webhook.rs`, and `watchers.rs` — each landing as its own PR. |
There was a problem hiding this comment.
Addressed in 195678b: this branch is now rebased/restacked on top of #477 (rocmai-83-persistence) per AGENTS.md §11 (stacked PRs stay draft until the dependency merges), and the PR has been moved back to draft. By the time this PR's own commit lands, persistence.rs genuinely exists in the branch's history alongside common.rs, so the doc line is now accurate for this branch's actual content rather than describing a sibling PR's files.
Note: GitHub won't let this fork-based PR's base ref point at rocmai-83-persistence directly (that branch only exists on the fork, not on ROCm/rocm-cli), so the base field still shows main even though the branch is rebased on #477's commits — flagging in case that needs a different fix (e.g. pushing the branch to the upstream repo).
r0x0r
left a comment
There was a problem hiding this comment.
Review: code is clean; holding approval on one doc line
The extraction itself verified as pure code motion and I have no concerns with it. One issue in docs/architecture.md is the only thing between this and an approval, and it is a one-line fix.
The doc hunk describes a state this branch is not in
The new text reads "Extracted so far: persistence.rs (…) and common.rs (…)", but apps/rocmd/src/persistence.rs does not exist in this branch — git ls-tree pr-head apps/rocmd/src/ returns only common.rs, lib.rs, main.rs. record_event and load_managed_services are still sitting in lib.rs at lines 4890 and 5004 here.
This matters more than a normal doc nit because of how the five PRs in this phase interact, which is not visible from inside any one of them:
- All five rewrite the same single line of
docs/architecture.md, and all five are branched independently frommain. Four of them are therefore guaranteed to conflict on that line. - Each one's text is a cumulative prefix that assumes the whole earlier sequence has already merged. That only resolves to a true statement if they merge in exactly the order 477 → 479 → 480 → 481 → 483.
- The failure case is quiet rather than loud: if this PR merges before #477, there is nothing on that line to conflict with, so it applies cleanly and
mainends up asserting thatpersistence.rsexists when it does not. The conflict that would have caught it only appears once something else has touched the line.
docs/architecture.md opens by saying it is updated in the same PR as the code it documents and that "a stale-but-plausible-looking note is worse than an explicit prompt to check" — a concrete filename plus a symbol list for a file that is not there is exactly that.
Either of these resolves it:
- Scope the hunk to this branch — say
common.rsonly, and let #480/#481/#483 each append their own module as they land. Self-consistent regardless of merge order, and the conflicts become trivial appends rather than whole-line rewrites. - Keep the cumulative text but gate the merge order, stating the dependency in the PR body (
Depends on #477) so it cannot land first.
(1) is the more robust of the two; (2) relies on reviewers remembering the order at merge time.
Verified clean
- Pure code motion — every moved symbol compared against its original on
main: error handling,?propagation,.context(...)strings, timeout constants, match arms, and the#[must_use]onapply_endpoint_key_envall preserved verbatim. - No silent CPU fallback introduced (AGENTS.md §6) — I looked at this specifically, since this PR moves the GPU-snapshot path.
gather_gpu_snapshot_for_configis byte-identical; theconfig.telemetry.local_inspection_enabled()gate and theamd_smi_available: falsenote-only branch are unchanged, andcapture_amd_smi_jsonkeeps its early return on!output.status.success(). - Call sites — all 15 moved symbols repointed to
common::; no missed site. - Imports — all 15 dropped from
lib.rsare genuinely unreferenced there.TcpStreamlooked like a survivor on a first pass but both remaining uses are fully-qualifiedstd::net::TcpStreamin test code, so there is no missing-import failure under-D warnings. I checked this one by hand rather than trusting the grep. - Visibility —
pub(crate)throughout,CommandCapture's four fields included;find_engine_plugin_binarycorrectly#[cfg(test)]-gated;rocmd_engine_inventorycorrectly stays private to the module. - Tests — 130 test attributes conserved across the branch (122 + 8), matching the claimed 8 moved exactly.
- The ≥2-cluster rule holds for every item — I was ready to flag anything in here used by only one cluster, since that would contradict the module's own stated admission criterion, but each one checks out:
update_check_message(sandbox + watchers),gather_gpu_snapshot_for_config(MCP + watchers),CommandCapture(sandbox + MCP),engine_healthcheck_ready(watchers + service lifecycle),optional_arg(three clusters). Defining the module by a stated rule and then actually honouring it is what keepscommon.rsfrom becoming a junk drawer, which is the usual fate of a module with that name. - Leak scan (AGENTS.md §2) — the one hit is a pre-existing comment containing the English word "private", moved verbatim. Clean.
Non-blocking: test-helper duplication
temp_app_paths, unique_test_root and workspace_test_artifact_dir are byte-identical copies in both common.rs and lib.rs test modules. Same note as on #477: #483 makes a third copy, and Phase 5 has seven target modules, so this ends around eight copies that can each drift independently. One #[cfg(test)] mod test_support; now is cheaper than reconciling them later.
🤖 by agent-hub on AMD AgentHub
7c31085 to
195678b
Compare
|
Addressing the review (195678b):
|
|
🔴 Automated review · pr-review-watcher · 195678b This automation never files a GitHub approval, so no approving review will SummaryThis PR moves the rocmd helpers that several parts of the daemon use from 🚫 Blocking (must fix before merge)
Non-blocking
Stack stateThe parent PR #477 has since merged into |
rominf
left a comment
There was a problem hiding this comment.
🔴 Automated review · pr-review-watcher · 195678b
Requesting changes for one defect: docs/architecture.md:34 still cites cli.rs, sandbox.rs, mcp.rs, service.rs, webhook.rs and watchers.rs in backticks under the apps/rocmd heading, and none of those files exist there. That keeps "Architecture doc path citations are current" red. It also fails windows-build-and-test, through the architecture_doc::tests::run_passes_against_the_real_doc test.
To resolve: name the pending modules without backticks, or drop the list. Also rebase onto main and retarget there now that #477 has merged. Details are in the review comment on this PR.
Second PR of Phase 5 (rocmd modularization, ROCMAI-27): pull the helpers shared across >=2 of the still-inline sandbox/mcp/service/ watchers clusters into their own module, ahead of extracting those clusters themselves. Covers GPU/amd-smi snapshotting, the bridge-snapshot diagnostic, CommandCapture/command-timeout plumbing, and small arg/healthcheck/endpoint-key utilities. No behavior change; call sites repointed to common::. The 8 tests that exercise these helpers directly (not mixed with a not-yet-extracted cluster's own logic) moved into common.rs's own #[cfg(test)] mod in this same PR. Signed-off-by: Jussi Elo <jussi.elo@amd.com>
195678b to
b843952
Compare

Summary
Second PR of Phase 5 (ROCMAI-83, part of the modularization epic ROCMAI-27). Pulls helper groups that are shared across ≥2 of the still-inline
sandbox/mcp/service/watchersclusters into a newcommon.rsmodule, ahead of extracting those clusters themselves in later PRs:gather_gpu_snapshot*,capture_amd_smi_json,run_command_with_timeout) — used by sandbox, mcp, and watchersbuild_bridge_snapshot/print_bridge_snapshot/bridge_engine_inventory/rocmd_engine_inventory) — used by the CLI'sBridgeSnapshotcommand and the MCP dispatcherCommandCapture+ its construction plumbing — constructed in both sandbox and MCP codeoptional_arg,wait_for_port,parse_gpu_indices_arg, and the engine-healthcheck/endpoint-key-guard family — used by bothserviceandwatchersThis module wasn't in the original ticket (which only named
persistence.rs) — these cross-cutting dependencies surfaced during boundary verification against currentmain. Addingcommon.rskeeps each later cluster PR from having to reach across into a sibling cluster file.common::....common.rs's own#[cfg(test)] mod testsin this same PR.docs/architecture.mdupdated in this PR.Independent of #477 (
persistence.rs) — branched separately frommain, not stacked, per the one-off PR approach for this phase.Test plan
cargo build(rocmd, androcm+rocmdtogether to confirm the external API surface is untouched)cargo clippy --workspace --all-targets -- -D warningscargo test -p rocmd— 130 tests, same count as before this change (129 passed + 1 pre-existing ignored)cargo xtask manifest --checkcargo fmt/ prek hooks cleantests/e2e-cucumber(CI)