Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
5eb84a0
feat(examine,serve): report real GPU/backend support instead of a sta…
r0x0r Oct 14, 2026
65a24f8
test(serve): keep the api key out of summary assertion messages
r0x0r Oct 14, 2026
7162f91
test(runtime): assert the Vulkan-serving remediation where the refusa…
r0x0r Oct 14, 2026
16ccfb3
fix(install): stop the requested-target refusal predicting a backend
r0x0r Oct 14, 2026
49e23e3
fix(bridge): report lemonade's real backend in the codex-bridge inven…
r0x0r Oct 16, 2026
daed78d
Merge branch 'main' into ROCMAI-550-vulkan-support-messaging
r0x0r Oct 16, 2026
bce633d
test(engines): cover the GPU-aware engine inventory on `rocm engines`…
r0x0r Oct 16, 2026
f54a8d2
Merge branch 'main' into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 2, 2026
aba912c
ROCMAI-550: make the device row name a device and examine answer ever…
r0x0r Nov 2, 2026
a426460
ROCMAI-550: resync the advice-scan exclusions with the new device shape
r0x0r Nov 2, 2026
4545d36
ROCMAI-550: drop the engine advice-scan exclusions the shared formatt…
r0x0r Nov 2, 2026
fbd1134
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 2, 2026
cabe979
Merge origin/main (#703) into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 3, 2026
1e4b6cd
ROCMAI-550: pin the support line with a scenario, and stop the device…
r0x0r Nov 3, 2026
ab2b609
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 3, 2026
53b5cdb
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 3, 2026
3807d61
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 4, 2026
5309936
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 5, 2026
74a1496
Merge origin/main, and restore the serve --help sentence the last mer…
r0x0r Nov 5, 2026
c6e6218
fix(examine): point the unknown-tier advice at a surface that shows t…
r0x0r Nov 6, 2026
767c586
fix(examine): stop sending a GPU-less host to a command serve would r…
r0x0r Nov 9, 2026
2ef8add
Merge origin/main, and follow this PR's changes to where main moved them
r0x0r Nov 9, 2026
50ff66a
test(serve): show the Lemonade advice names a command this host is no…
r0x0r Nov 10, 2026
8bde91a
Merge remote-tracking branch 'origin/main' into pr678-r2
r0x0r Nov 10, 2026
c3e6bf2
test(engine): assert the endpoint key file is withheld from plugin ch…
r0x0r Nov 10, 2026
a4dc753
Merge remote-tracking branch 'origin/main' into pr678-r2
r0x0r Nov 10, 2026
5bda371
Merge origin/main into pr678-r2
r0x0r Nov 11, 2026
794e4b6
feat(examine): probe Vulkan instead of inferring it from the gfx table
r0x0r Nov 11, 2026
30144c5
fix(engine): clear the endpoint key file for a child that gets no key
r0x0r Nov 11, 2026
d24a38d
docs(services): condense the device-probe doc blocks to clear the siz…
r0x0r Nov 11, 2026
6eef7b3
docs(examine): correct the support-level section and move items above…
r0x0r Nov 11, 2026
182915c
Merge remote-tracking branch 'origin/main' into pr678-r2
r0x0r Nov 11, 2026
4ff8d08
fix(engine,examine): scope the key-file clearing, and stop claiming V…
r0x0r Nov 11, 2026
c837335
refactor(examine): split the Vulkan probe and the protocol change out…
r0x0r Nov 11, 2026
773129e
feat(examine): probe Vulkan instead of inferring it from the gfx table
r0x0r Nov 11, 2026
90a31c3
fix(examine): decide absence on whether the probe could look, not on …
r0x0r Nov 11, 2026
33162c3
Merge remote-tracking branch 'origin/main' into pr678-r2
r0x0r Nov 11, 2026
06ce905
Merge remote-tracking branch 'origin/ROCMAI-550-vulkan-support-messag…
r0x0r Nov 11, 2026
cc3dc5a
fix(examine): stop promising Vulkan to a host that was probed and sho…
r0x0r Nov 11, 2026
b4479e5
fix(examine): finish removing the split-out work from this PR
r0x0r Nov 11, 2026
3ac4f8b
Merge remote-tracking branch 'origin/ROCMAI-550-vulkan-support-messag…
r0x0r Nov 11, 2026
a4dd8a6
refactor(examine): resolve vulkaninfo through the one PATH lookup
r0x0r Nov 11, 2026
bf2a323
docs(examine): say the support line is printed on every host
r0x0r Nov 11, 2026
60aa288
fix(examine): do not report an unchecked host as having no GPU backend
r0x0r Nov 11, 2026
2ee299a
fix(cli): keep the new examine help text ASCII-only
r0x0r Nov 11, 2026
671fa86
Merge branch 'ROCMAI-550-vulkan-support-messaging' of https://github.…
r0x0r Nov 11, 2026
795ca92
fix(examine): say what the Vulkan probe found, and sync the docs to it
r0x0r Nov 11, 2026
3480803
fix(examine): stop describing hosts the probe did not see that way
r0x0r Nov 11, 2026
d9b16c9
fix(examine): a vulkaninfo that failed has not looked at the host
r0x0r Nov 11, 2026
e443ed6
fix(examine): stop naming a backend for a GPU the catalog does not know
r0x0r Nov 11, 2026
f2be7af
Merge remote-tracking branch 'origin/main' into pr678-r2
r0x0r Nov 11, 2026
2a7d923
Merge branch 'ROCMAI-550-vulkan-support-messaging' of https://github.…
r0x0r Nov 11, 2026
ea647e0
fix(examine): stop a non-AMD enumeration reading as a missing driver
r0x0r Nov 12, 2026
05df6f9
test(examine): split the examine-49 arm the Unknown-tier advice outgrew
r0x0r Nov 12, 2026
6dfdb72
docs(testing): describe the levels this change has, not an unmerged one
r0x0r Nov 12, 2026
e95cb02
Merge branch 'ROCMAI-550-vulkan-support-messaging' of https://github.…
r0x0r Nov 12, 2026
e2ebf99
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 12, 2026
96de042
fix(examine): keep the Vulkan probe out of the cheap gather scope
r0x0r Nov 13, 2026
e2447af
fix(examine): restore the advice check's arms for the two probed Vulk…
r0x0r Nov 13, 2026
816ac1d
fix(serve): skip the device probe for a service that was already running
r0x0r Nov 13, 2026
6de4ad5
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 13, 2026
aaade2d
fix(examine): tie the unverified-Vulkan advice to whether vulkaninfo …
r0x0r Nov 13, 2026
725109d
Merge remote-tracking branch 'origin/ROCMAI-550-vulkan-support-messag…
r0x0r Nov 13, 2026
604faa3
fix(engines): stop `rocm engines` requiring ROCm on a host it says ha…
r0x0r Nov 13, 2026
79f1227
Merge origin/ROCMAI-550-vulkan-support-messaging into split/vulkan-probe
r0x0r Nov 13, 2026
0d5fe99
fix(examine): stop a failed ICD lookup reading as a host with no Vulk…
r0x0r Nov 13, 2026
1bc2bad
fix(cli): stop markdown markup reaching `--help`, and make the Vulkan…
r0x0r Nov 13, 2026
d35ac5f
docs: point the static-catalog note at rocmd's real engine inventory
r0x0r Nov 13, 2026
c7d0ee3
Merge origin/ROCMAI-550-vulkan-support-messaging into split/vulkan-probe
r0x0r Nov 13, 2026
b18772d
Merge branch 'main' into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 16, 2026
da8437e
fix(examine): stop telling a working Adrenalin host to install the dr…
r0x0r Nov 16, 2026
f91322a
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 16, 2026
e7b6513
fix(services): stop the device probe losing a just-published anthropi…
r0x0r Nov 16, 2026
fa9c1fc
docs(services): scope the device-probe wait to the table, not `--json`
r0x0r Nov 16, 2026
0c7e432
fix(examine): stop an SDK for another family being called this GPU's
r0x0r Nov 16, 2026
069ba0e
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 16, 2026
d9af387
Merge the rebased #678 base, and say where confirmed Vulkan absence s…
r0x0r Nov 16, 2026
8fec79c
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 17, 2026
3d59dbc
fix(serve): stop the engine's post-spawn state rewrite dropping the A…
r0x0r Nov 17, 2026
a6fb45c
Merge the updated #678 base
r0x0r Nov 17, 2026
1dc93a4
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 17, 2026
209f90a
Merge the updated #678 base
r0x0r Nov 17, 2026
62190c6
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 17, 2026
47228b1
Merge the updated #678 base, past main's WSL librocdxg work
r0x0r Nov 17, 2026
30f91a0
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 17, 2026
1cd9609
Merge the updated #678 base, past main's runtime-provenance scenario
r0x0r Nov 17, 2026
c97969d
fix(vulkan): do not let a software-only enumeration deny an installed…
r0x0r Nov 17, 2026
21b2383
fix(engines): stop AIM claiming a GPU it was never given, and write s…
r0x0r Nov 17, 2026
fbf0ad3
test(core): reach the two branches the GPU classifier's own suite cou…
r0x0r Nov 17, 2026
b7e77e8
fix(examine): cross-check the no-GPU-backend install advice against d…
r0x0r Nov 17, 2026
1540bda
test(e2e): say that the cross-surface device check cannot fire, and l…
r0x0r Nov 17, 2026
16ccdf9
test(engines): pin the VulkanOnly banner apart from the three no-back…
r0x0r Nov 17, 2026
8b811d6
docs: correct the device-row gating, the gfx_target entry and the Lem…
r0x0r Nov 17, 2026
0cce209
docs(vulkan): describe the evidence model the probe actually has
r0x0r Nov 17, 2026
c809af3
Merge origin/main into ROCMAI-550-vulkan-support-messaging
r0x0r Nov 17, 2026
5fc570f
Merge the updated #678 base, and give its new tests this branch's arity
r0x0r Nov 17, 2026
ab87a90
docs(vulkan): say which ICD evidence actually reaches Inconclusive
r0x0r Nov 17, 2026
f3a33ca
test(vulkan): drive the Windows registry lookup from every lane
r0x0r Nov 17, 2026
bf77372
fix(install): grade the detected-GPU refusal's Vulkan claim by the probe
r0x0r Nov 17, 2026
d02e760
Re-parent onto #678's reworded history
r0x0r Nov 17, 2026
8f37693
docs(examine): point the vulkaninfo-exits-1 note at the scenario that…
r0x0r Nov 17, 2026
7bb830f
Merge the updated #678 base, past main's key-protected vLLM scenario
r0x0r Nov 17, 2026
b658e3c
Merge the updated #678 base, past main's vLLM extension-import scenario
r0x0r Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 44 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -680,13 +680,51 @@ a target yourself with `--family gfx90c`: the request is refused, and no other
family is substituted for it. `rocm examine` reports the same conclusion on a
`rocm_support` line (see [Examine](#examine)).

These GPUs still work with the Vulkan backend, which needs no ROCm SDK.
These GPUs can still work with the Vulkan backend, which needs no ROCm SDK —
but whether they *do* depends on a Vulkan driver being installed, so `rocm
examine` looks for one rather than assuming it. It reads the Vulkan ICD
manifests (the Khronos `Drivers` registry key on Windows) and, where available,
enumerates devices with `vulkaninfo`. A software rasteriser such as lavapipe or
swiftshader does not count as a GPU driver.

`rocm examine` prints that `rocm_support` line on **every** host, not only this
case, at one of three levels: ROCm/HIP-supported, Vulkan-only (the case above),
or unknown. Unknown covers both no GPU detected and a target this build's
catalog does not recognise — detection gaps rather than a verdict about the
hardware, so neither is reported as "no ROCm build".
case, at one of five levels:

| Level | Meaning |
| --- | --- |
| ROCm/HIP-supported | A TheRock package family covers this GPU. |
| Vulkan-only | No ROCm build, **and** either a Vulkan GPU driver was found here, or the platform cannot be probed for one at all (anything other than Linux and Windows, or a summary from an older `rocm remote doctor` that predates the probe). The `rocm_support` line says which of the two it is, and only names a driver when one was actually found. |
| Vulkan-unconfirmed | No ROCm build, and the probe could not reach an answer: nothing was found, and at least one of the two sources — the ICD/registry listing or `vulkaninfo` — never answered. Either one can be the source that went unread (on Windows the registry read is a separate PowerShell call that can fail on its own), and the `vulkan:` line names which. |
| no GPU backend | No ROCm build, **and** the probe looked and found no Vulkan GPU driver. This takes `vulkaninfo`'s own answer: the ICD listing is not exhaustive on either platform, so it never denies a driver by itself. |
| unknown | No GPU detected, or a target this build's catalog does not recognize. |

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.

"a Vulkan GPU driver was found here" is not what Vulkan-only guarantees: an unprobed platform / older remote doctor summary also yields Vulkan-only (render hedges it). Qualify the row.

The last row is a detection gap rather than a verdict about the hardware, which
is why it is not reported as "no ROCm build". Vulkan-unconfirmed is kept
separate from "no GPU backend" for the same reason in the other direction: on
Windows the Khronos `Drivers` key is legacy and `vulkaninfo` is rarely on PATH,
so a working machine can land there, and it has not earned a confirmed "no".

`rocm examine --json` reports the evidence behind this in a `summary.vulkan`
object (status, ICD manifests found, devices enumerated). The host summary is
flattened into the document's `summary` member, so the object is there and not
at the top level. The field is optional, so an older `rocm remote doctor`
summary that predates it reads as unknown rather than as a false "no Vulkan".

The probe runs wherever the full host summary is gathered, not on `rocm examine`
alone: the text and JSON of `rocm examine`, the MCP and bridge snapshots, the
free-form answer, `rocm install driver` and its `--reconcile` form, and `rocmd`'s
host snapshot, MCP and sandbox paths. Each of those pays one `vulkaninfo` (or, on
Windows, one registry read) per gather.

It does not run on the lean scope, `ExamineSummary::gather_without_driver_facts`,
which the runtime-install finalizer uses to read the GPU target: that leaves
`vulkan` as `None`, meaning "not probed", which reads as unknown rather than as a
false "no Vulkan".

`rocm engines` and the `rocm diagnose` finding `info-20-gpu-no-rocm-support` still
speak from the gfx table alone, so they can name Vulkan on a host where `rocm
examine` would say otherwise; spawning `vulkaninfo` (and PowerShell on Windows)
was judged too expensive for a plain listing command.

#### Compiler toolchain (--devel)

Expand Down Expand Up @@ -896,7 +934,7 @@ old date is a hint to look at the driver, not a finding that it is broken. See
Manage multiple side-by-side ROCm runtimes:

```
rocm runtimes list [--json]
rocm runtimes list
rocm runtimes activate <runtime-key> [--restart-services [--yes]]
rocm runtimes rollback [--restart-services [--yes]]
rocm runtimes uninstall <runtime-key> [--yes] [--dry-run]
Expand Down Expand Up @@ -930,13 +968,6 @@ version alone, so one version can appear more than once: a `--devel` install
and a plain one of the same version are two separate runtimes, as are two
installs that resolved different GPU device payloads.

`list --json` prints the same listing as one JSON document on stdout for
scripts: each runtime with its key, version, mode, status and toolchain, its
`provenance` as an object with the same four facts, and `active` and
`rollback_target` flags in place of the `*` and `-` markers. Unset values,
including a provenance fact the text shows as `unrecorded`, are `null`. Fields
may be added in later releases; existing ones are not renamed or removed.

`activate` and `rollback` change which runtime the next install or server
picks up. A server that is already running is not moved: it keeps serving on
the runtime it started with until it is restarted. Both commands count the
Expand Down
1 change: 1 addition & 0 deletions apps/rocm/src/bridge_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pub(crate) fn build_codex_bridge_snapshot(paths: &AppPaths) -> Result<CodexBridg
let gpu_support_level = rocm_core::gpu_support_level(
examine.detected_gfx_target.as_deref(),
examine.compatible_therock_family.as_deref(),
examine.vulkan_status(),
);
Ok(CodexBridgeSnapshot {
protocol: "rocmd-codex-bridge-v0".to_owned(),
Expand Down
44 changes: 13 additions & 31 deletions apps/rocm/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ pub(crate) struct Cli {
pub(crate) enum Command {
/// Check this computer's GPU, ROCm install, engines, and setup folders.
///
/// A `rocm_support` line is printed on every host, at one of three
/// levels: ROCm/HIP-supported, Vulkan-only, or unknown. Vulkan-only covers
/// a GPU that is recognized but has no ROCm build at all (`gfx90c`, the
/// Vega iGPU in Renoir, Lucienne, Cezanne and Barcelo APUs), which still
/// works through Lemonade's Vulkan backend. Unknown covers both no GPU
/// detected and a target this build's catalog does not recognize: those
/// are detection gaps, not a verdict on the hardware, which is why an
/// empty `compatible_therock_family` does not read as a failed probe.
/// A `rocm_support` line is printed on every host, at one of five
/// levels: ROCm/HIP-supported, Vulkan-only, Vulkan-unconfirmed, no GPU
/// backend, or unknown. The three middle levels are decided by probing for
/// a Vulkan driver rather than by the gfx table: a GPU that is recognized
/// but has no ROCm build at all (`gfx90c`, the Vega iGPU in Renoir,
/// Lucienne, Cezanne and Barcelo APUs) runs through Lemonade's Vulkan
/// backend only if a driver is actually installed. Vulkan-unconfirmed means
/// the probe could not reach an answer, which is not the same as finding
/// none. Unknown covers both no GPU detected and a target this build's
/// catalog does not recognize: those are detection gaps, not a verdict on
/// the hardware, which is why an empty `compatible_therock_family` does not
/// read as a failed probe.
Examine {
/// Emit the machine-readable Examination JSON (for diagnosis tooling).
#[arg(long)]
Expand Down Expand Up @@ -1011,11 +1015,7 @@ pub(crate) enum RuntimesCommand {
/// generation and exact GPU target as its manifest recorded them. A fact
/// recorded nowhere, or recorded blank, is shown as `unrecorded`; nothing
/// is guessed from other facts.
List {
/// Print the runtime list as JSON instead of text.
#[arg(long)]
json: bool,
},
List,

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.

Blocking: rocm runtimes list --json is removed here (the json: bool field and its #[arg(long)] are gone, so the subcommand has no JSON mode at all). This is a documented, tested, user-facing CLI contract being dropped — apps/rocm/src/runtimes_cmd.rs loses the RuntimesListing/RuntimeListingEntry serialization (~2000 lines), the regression test runtimes_json_is_a_list_flag is deleted, docs/json-output.md (which documented this as a "frozen" contract) is deleted wholesale, and README.md / docs/manual-testing.md / docs/ux-guidelines.md all drop their references to it.

This PR's title and description are about probing Vulkan instead of inferring it from the gfx table. Removing a scripting-facing --json flag from an unrelated command is a breaking change that isn't mentioned anywhere in the description. Any script currently parsing rocm runtimes list --json will break with no migration path.

Suggested fix: either restore --json for runtimes list, or — if dropping it is an intentional, separate decision — split it out of this PR and call it out explicitly with its own rationale and docs update.

/// Use the selected ROCm runtime by default.
Activate {
/// Runtime key or friendly runtime selector.
Expand Down Expand Up @@ -2165,24 +2165,6 @@ mod tests {
}
}

/// `--json` belongs to `list` alone: bare `rocm runtimes` stays the text
/// listing, so a script has to name the subcommand to get JSON.
#[test]
fn runtimes_json_is_a_list_flag() {
for (args, json) in [(&["list", "--json"][..], true), (&["list"][..], false)] {
match parse_runtimes(args).expect("runtimes list parses").command {
Some(Command::Runtimes {
command: Some(RuntimesCommand::List { json: parsed }),
}) => assert_eq!(parsed, json, "{args:?}"),
other => panic!("expected runtimes list, got {other:?}"),
}
}
assert!(
parse_runtimes(&["--json"]).is_err(),
"`rocm runtimes --json` must be rejected, not read as `list --json`"
);
}

fn parse_serve(args: &[&str]) -> Result<Cli, clap::Error> {
let mut argv = vec!["rocm", "serve", "qwen"];
argv.extend_from_slice(args);
Expand Down
8 changes: 3 additions & 5 deletions apps/rocm/src/dash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ fn runtime_summaries(paths: &AppPaths, config: &RocmCliConfig) -> Vec<RuntimeSum
let active_key = config.active_runtime_key.as_deref();
let prev_key = config.previous_runtime_key.as_deref();
let default_id = config.default_runtime_id.as_deref();
// The dash matches exactly: a runtime is active when its key equals
// active_runtime_key, or, with no active_runtime_key, when it is the single
// runtime whose id equals default_runtime_id; it is the rollback target
// when its key equals previous_runtime_key. docs/json-output.md compares
// these rules with what `rocm runtimes list` marks.
// Mirror `render_runtimes_text`: a runtime is active by an explicit
// active_runtime_key, or — absent one — by being the single manifest whose
// runtime_id matches the configured default_runtime_id.
let default_matches: Vec<&str> = manifests
.iter()
.filter(|m| Some(m.runtime_id.as_str()) == default_id)
Expand Down
1 change: 1 addition & 0 deletions apps/rocm/src/driver_plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ pub(crate) mod tests {
detected_gfx_target: Some("gfx1201".to_owned()),
compatible_therock_family: Some("gfx120X-all".to_owned()),
detected_therock_family: None,
vulkan: None,
driver: rocm_core::DriverSummary {
policy: "linux_official_amd_dkms_wrapper".to_owned(),
status: "amdgpu_missing".to_owned(),
Expand Down
122 changes: 17 additions & 105 deletions apps/rocm/src/engine_ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
//! (`engine_request`, `engine_request_with_env_root`,
//! `engine_stdio_child_request`), the `ScopedEnvVar`/
//! `with_scoped_builtin_engine_env` env-scoping helpers and the
//! `BUILTIN_ENGINE_ENV_LOCK` mutex they serialize on, `builtin_engine_handler`,
//! `builtin_engine_request`, `run_builtin_engine_stdio` with
//! `answer_builtin_engine_stdio`, and the built-in HTTP-serving path
//! `BUILTIN_ENGINE_ENV_LOCK` mutex they serialize on, `builtin_engine_request`,
//! `run_builtin_engine_stdio`, and the built-in HTTP-serving path
//! (`builtin_engine_available`, `run_builtin_engine_serve_http`,
//! `builtin_engine_serve_http_args`).
//!
Expand Down Expand Up @@ -291,37 +290,29 @@ fn with_scoped_builtin_engine_env<R>(
result
}

/// How a built-in engine answers a decoded request.
type BuiltinEngineHandler = fn(EngineRequestEnvelope) -> EngineResponseEnvelope;

/// The handler of the engine built into this binary under `engine`, or `None`.
/// The in-process request path, `rocm __engine-stdio` and
/// [`builtin_engine_available`] all ask it; `run_builtin_engine_serve_http`
/// keeps its own match over the same engines.
fn builtin_engine_handler(engine: &str) -> Option<BuiltinEngineHandler> {
match engine {
"lemonade" => Some(rocm_engine_lemonade::builtin_handle_envelope),
"vllm" => Some(rocm_engine_vllm::builtin_handle_envelope),
"aim" => Some(rocm_engine_aim::builtin_handle_envelope),
_ => None,
}
}

fn builtin_engine_request(
engine: &str,
envelope: &EngineRequestEnvelope,
) -> Option<EngineResponseEnvelope> {
builtin_engine_handler(engine).map(|handle| handle(envelope.clone()))
match engine {
"lemonade" => Some(rocm_engine_lemonade::builtin_handle_envelope(
envelope.clone(),
)),
"vllm" => Some(rocm_engine_vllm::builtin_handle_envelope(envelope.clone())),
"aim" => Some(rocm_engine_aim::builtin_handle_envelope(envelope.clone())),
_ => None,
}
}

pub(crate) fn run_builtin_engine_stdio(engine: &str) -> Result<()> {
let handle = builtin_engine_handler(engine)
.with_context(|| format!("engine `{engine}` is not built into this rocm binary"))?;
let mut input = String::new();
io::stdin()
.read_to_string(&mut input)
.context("failed to read engine stdio request")?;
let response = answer_builtin_engine_stdio(handle, &input);
let envelope: EngineRequestEnvelope =
serde_json::from_str(&input).context("failed to parse engine stdio request")?;
let response = builtin_engine_request(engine, &envelope)
.with_context(|| format!("engine `{engine}` is not built into this rocm binary"))?;
print!("{}", serde_json::to_string(&response)?);
Ok(())
}
Expand Down Expand Up @@ -604,16 +595,8 @@ where
devices
}

/// The answer a built-in engine's `handle` gives to the request `text` read on
/// stdin: the version is judged before the method or payload is decoded (see
/// [`rocm_engine_protocol::answer_engine_request`]), as a separately built
/// engine's `stdio` command does.
fn answer_builtin_engine_stdio(handle: BuiltinEngineHandler, text: &str) -> EngineResponseEnvelope {
rocm_engine_protocol::answer_engine_request(text, handle)
}

pub(crate) fn builtin_engine_available(engine: &str) -> bool {
builtin_engine_handler(engine).is_some()
matches!(engine, "lemonade" | "vllm" | "aim")
}

#[allow(clippy::too_many_arguments)]
Expand Down Expand Up @@ -974,73 +957,6 @@ mod tests {
);
}

/// Every engine built into this binary holds the engine protocol contract on
/// both of its paths: the decoded request `rocm` hands it in-process, and
/// `answer_builtin_engine_stdio`, the function `rocm __engine-stdio <engine>`
/// (which `rocmd` runs) answers request text with. The verb's own stdin
/// reading is not run here; e2e engine-ipc-08 to -12 cover it, for `vllm`
/// only. A refusal reaches the caller through the same
/// `decode_engine_response` as a child's answer, naming the engine's code.
#[test]
fn every_built_in_engine_holds_the_protocol_contract() {
assert!(!builtin_engine_available("not-an-engine"));
assert!(
builtin_engine_request(
"not-an-engine",
&EngineRequestEnvelope::new(EngineMethod::Capabilities, serde_json::json!({}))
)
.is_none()
);
for engine in crate::cli::SUPPORTED_ENGINES {
assert!(builtin_engine_available(engine), "{engine}");
let handle = builtin_engine_handler(engine).expect("built in");
rocm_engine_protocol::engine_contract::assert_engine_holds_protocol_contract(
engine,
|text| answer_builtin_engine_stdio(handle, text),
|envelope| builtin_engine_request(engine, &envelope).expect("built in"),
);
let mut request = EngineRequestEnvelope::new(EngineMethod::Stop, serde_json::json!({}));
request.protocol_version = Some("9.0.0".to_owned());
let refusal = builtin_engine_request(engine, &request).expect("built in");
assert_eq!(
decode_engine_response::<serde_json::Value>(refusal)
.unwrap_err()
.to_string(),
format!(
"incompatible_protocol: this engine speaks engine protocol \
{}; the request was made for protocol 9.0.0, which \
it cannot serve",
rocm_engine_protocol::ENGINE_PROTOCOL_VERSION
),
"{engine}"
);
}
}

/// Each built-in engine id reaches that engine's own handler: its
/// capabilities answer is the one the engine crate itself gives, and the
/// three engines' answers differ, so a swapped mapping shows.
#[test]
fn each_built_in_engine_id_reaches_its_own_engine() {
let capabilities =
|| EngineRequestEnvelope::new(EngineMethod::Capabilities, serde_json::json!({}));
let own: [(&str, BuiltinEngineHandler); 3] = [
("lemonade", rocm_engine_lemonade::builtin_handle_envelope),
("vllm", rocm_engine_vllm::builtin_handle_envelope),
("aim", rocm_engine_aim::builtin_handle_envelope),
];
let mut answers = Vec::new();
for (engine, handle) in own {
let mapped = builtin_engine_handler(engine).expect("built in");
let expected = handle(capabilities()).data;
assert_eq!(mapped(capabilities()).data, expected, "{engine}");
answers.push(expected);
}
assert_ne!(answers[0], answers[1]);
assert_ne!(answers[1], answers[2]);
assert_ne!(answers[0], answers[2]);
}

#[test]
fn engine_plugin_discovery_finds_runtime_binary() -> Result<()> {
let (root, paths) = test_paths("engine-plugin");
Expand Down Expand Up @@ -1120,7 +1036,7 @@ mod tests {
const STOPPED: &str = r#"{"ok":true,"data":{"stopped":true}}"#;

fn envelope(method: EngineMethod, payload: serde_json::Value) -> EngineRequestEnvelope {
EngineRequestEnvelope::new(method, payload)
EngineRequestEnvelope { method, payload }
}

fn stop_request() -> EngineRequestEnvelope {
Expand Down Expand Up @@ -1167,11 +1083,7 @@ mod tests {
assert_eq!(engine.argv(), ["stdio"]);
assert_eq!(
engine.stdin(),
format!(
"{{\"protocol_version\":\"{}\",\"method\":\"stop\",\
\"payload\":{{\"service_id\":\"svc\"}}}}\n",
rocm_engine_protocol::ENGINE_PROTOCOL_VERSION
)
"{\"method\":\"stop\",\"payload\":{\"service_id\":\"svc\"}}\n"
);
}

Expand Down
Loading
Loading