Skip to content

serve: the save-area trio for every HRX process, and refuse to start without it (engine#715) - #794

Merged
bong-water-water-bong merged 4 commits into
mainfrom
1bit/hrx-trio-every-process
Nov 2, 2026
Merged

bong-water-water-bong merged 4 commits into
mainfrom
1bit/hrx-trio-every-process

Conversation

@bong-water-water-bong

@bong-water-water-bong bong-water-water-bong commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Engine half of #715, per the orchestrator: the save-area trio is set for every HRX process the engine is responsible for, and an HRX route that would start without it is refused with the recipe.

Why the existing coverage was not enough

#743 put the trio in an HRX backend's environment and in scripts/hw-gate.sh. Two holes were left, and both cost a GPU reset rather than an error message:

  1. A child that exec()s with the inherited environment never got it. Child builds an explicit envp, but run_program and LayaDaemon exec with serve's own environment — so any helper started through them initialised HRX without the trio.
  2. Nothing stopped an accidental start. --hrx-cwsr-placement=off and HRX_SVM=1 are legitimate opt-outs, but the mode they select is the one that page-faults on the first graph replay on a box whose libhsa is the TheRock nightly (docs/hrx.md, the two tables). A typo in a harness earned a fault, not a refusal.

The fault census on #715 is what makes this a release-quality item rather than tidiness: one permission fault per process at first dispatch is the standing condition, and the only row in the census that precedes a reset is the burst signature (9 faults, one pid, one second, ring 40 / vmid 11).

What changes

file change
app/hrx_cwsr.h kCwsrRecipe (the pastable line), cwsr_env_present() (is the trio in this NAME=VALUE list — the value is deliberately not checked, because a caller's value wins everywhere in the engine), apply_cwsr_env_to_self() (set it in our environment, overwrite=0; _putenv_s on Windows)
app/serve.cpp applies it to serve's own environment right after option parsing, so every descendant inherits it however it is spawned and a spawn site added later cannot forget it; and refuses an hrx/auto route when you opted out (--hrx-cwsr-placement=off or HRX_SVM=1) so the trio is absent, printing the recipe. ONEBIT_HRX_NO_TRIO_OK=1 is the acknowledgement for a box whose ROCr does not need the placement. The refusal keys on the opt-out, not on an empty trio: a build whose hrx-system has no HRX_ALLOW_NO_SVM gate also has an empty trio, and the first version that refused on that failed nine route tests in CI (run 41366068194) because they run --device hrx against a stubbed backend. --device cpu/npu are never affected
scripts/hrx-env.sh (new) one definition for the shell side: source scripts/hrx-env.sh --check sets the trio and refuses to continue without it; without --check it just sets it. HRX_SVM=1 opts out loudly
scripts/hw-gate.sh sources the helper instead of carrying its own copy (behaviour unchanged: a caller's value wins)
docs/hrx.md the rule, the recipe, and where the shell helper lives

Verified (no device)

  • tests/hrx_cwsr_test.cpp: all checks passed, with 12 new assertions — the recipe text, the presence check (empty, one-of-three missing, a name that only starts with the same letters, and a caller's non-default values counting as present), and apply-to-self (adds only what is absent; a caller's value survives; the environment is complete afterwards).
  • The block inserted into serve.cpp's main() compiled and run standalone against the real header, four ways: hrx with the trio → one log line, no refusal; hrx with HRX_SVM=1 → refused, recipe and acknowledgement named; the same plus ONEBIT_HRX_NO_TRIO_OK=1 → proceeds; --device cpu → never refused; trio already exported → nothing added.
  • bash -n clean on scripts/hrx-env.sh, scripts/hw-gate.sh, tests/hrx_cwsr_route.sh.
  • tests/hrx_cwsr_route.sh updated for the new behaviour: off and HRX_SVM=1 now expect a refusal (and the recipe in the log), the same cases with ONEBIT_HRX_NO_TRIO_OK=1 expect the old behaviour, --device cpu with off is not refused, and the inherited-environment case is asserted through serve's own log line.

Not verified here, and it is the check that matters

The full engine build and ctest -R hrx_cwsr / tests/hrx_cwsr_route.sh end to end: this worktree has no submodule contents, so there is no 1bit binary to run the route test against. CI is that check, and the route test now asserts the refusal, so a wrong placement of the check in main() shows up there rather than on a box.

Behaviour change worth a reviewer's eye: a serve command line that opted out of the placement (off / HRX_SVM=1) now fails with the recipe unless ONEBIT_HRX_NO_TRIO_OK=1 is set. A command line that never opted out behaves exactly as before. Fix history: the first head (97dff9cc) refused whenever the trio was empty, which broke nine stubbed route tests in CI; a4720d5 narrows it to the deliberate opt-out and re-verifies the gateless-build case explicitly.

@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 5281aad)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

715 - Partially compliant

Compliant requirements:

  • Engine sets the trio itself when it detects the unfavourable capability lines, per process, including test-backend-ops
  • Fail loudly at init with the recipe when an HRX route would start without the trio
  • The trio is applied to serve's own environment, ensuring child processes inherit it
  • The recipe is printed in error messages for users to paste

Non-compliant requirements:

  • Logging the libhsa path + sha256 in the HRX init line is not implemented in this PR
  • The release-runtime question is not addressed in this PR

Requires further human verification:

  • Verification that the libhsa path + sha256 logging is implemented in the HRX init line
  • Verification that the release-runtime question is settled
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect placement decision logging

The announce_cwsr_env function in app/serve.cpp is called before hrx_cwsr_env in multiple places, but it uses a static variable announced to ensure it only logs once. This may lead to incorrect logging behavior if hrx_cwsr_env is called multiple times with different options, as the logging decision is made once and then reused.

void announce_cwsr_env(const Options& o) {
    (void) hrx_cwsr_env(o);
    static bool announced = false;
    if (announced) return;
    announced = true;
    constexpr bool gate = kHrxNoSvmGate;
    const CwsrDecision d = decide_cwsr_placement(o.cwsr_placement, read_cwsr_enable(), gate,
                                                 [](const char* k) { return std::getenv(k); });
    std::fprintf(stderr, "1bit serve: %s\n", d.log.c_str());
}
Potential race condition in `apply_cwsr_env_to_self`

The apply_cwsr_env_to_self function in app/serve.cpp modifies the process environment using setenv or _putenv_s. If multiple threads or processes are modifying the environment concurrently, this could lead to race conditions or inconsistent behavior.

bool ssd_streaming = false;  // --device ds4: stream routed experts from the SSD
std::string mtp;
bool no_mtp = false;  // --no-mtp (or ONEBIT_NO_MTP=1): no drafting from the GGUF's own MTP head (own_mtp_head)
std::string dflash;  // DFlash block-diffusion draft model for the target
int moe_slots = 0;   // --moe-slots N: stream routed experts from the model file, N held in RAM (-1: auto)
int moe_prefetch = 0;   // --moe-prefetch N: gate-ahead prefetch N MoE layers ahead (0: off)
std::string moe_predict;  // --moe-predict off|router|block: what the prefetch predicts with (docs/moe-streaming.md)
std::string moe_subst;  // --moe-subst R: a resident expert scoring at least R x a missing one takes its place
std::string mmproj;  // a vision (or audio) projector: image parts in chat messages
int mtp_max = 0;
std::string mtp_p_min;
int parallel = 0;
std::string embed, rerank;   // RAG: an embedding model and a reranker, served beside the chat model
std::string role;            // "embedding" or "reranking": the model itself is served in that role
std::vector<std::string> npu_opts;   // --npu-opt KEY=VALUE, for a private NPU route
Inconsistent behavior with `--check` option

The hrx-env.sh script's --check option returns with exit code 3, but this is not handled consistently in all calling contexts. This could lead to unexpected behavior if a script or process does not properly handle the exit code.

            return 3 2>/dev/null || exit 3
        fi
    done
fi

…ate opt-out (engine#715)

The trio was already set for serve's own backends (#743) and in scripts/hw-gate.sh's
environment. Two gaps were left, and both cost a GPU reset rather than an error:

  * a child that exec()s with the *inherited* environment never got it. Child builds an
    explicit envp, but run_program and LayaDaemon exec with ours, so any helper started
    through them ran HRX without the trio;
  * nothing stopped a serve that had opted out of the placement from starting anyway.

What changes:

  * app/hrx_cwsr.h: kCwsrRecipe (the pastable line), cwsr_env_present() (is the trio in
    this NAME=VALUE list; the value is not checked, because a caller's value wins
    everywhere in the engine) and apply_cwsr_env_to_self() (put it in *our* environment,
    overwrite=0). Windows gets _putenv_s.
  * app/serve.cpp: apply it to serve's own environment right after option parsing, so
    every descendant inherits it however it is spawned and a future spawn site cannot
    forget it; and refuse an hrx/auto route when the user opted out
    (--hrx-cwsr-placement=off or HRX_SVM=1) and the trio is therefore absent, printing the
    recipe. ONEBIT_HRX_NO_TRIO_OK=1 is the acknowledgement.
  * scripts/hrx-env.sh: one definition for the shell side -- `source ... --check` sets the
    trio and refuses to continue without it -- and scripts/hw-gate.sh now sources it
    instead of carrying its own copy.

The refusal keys on the opt-out, not on "the trio happens to be empty". The first version
keyed on the empty trio and failed nine route tests in CI: those run `--device hrx` against
a stubbed backend, so no HRX ever initialises, and in a build whose hrx-system has no
HRX_ALLOW_NO_SVM gate the resolved trio is legitimately empty. Opt-out is a user decision,
the empty trio in a gateless build is not.

Verified without a device:
  * tests/hrx_cwsr_test.cpp: all checks passed, 12 new assertions over the recipe, the
    presence check (including a name that only starts with the same letters, and a
    caller's non-default values counting as present) and apply-to-self (adds only what is
    absent, a caller's value survives);
  * the block inserted into serve.cpp's main() compiled and run standalone against the real
    header, five ways: hrx with the trio -> one log line, no refusal; a build WITHOUT the
    gate (empty trio, no opt-out) -> not refused, which is the CI case that regressed;
    --hrx-cwsr-placement=off -> refused with the recipe; the same plus
    ONEBIT_HRX_NO_TRIO_OK=1 -> proceeds; --device cpu with off -> never refused;
  * bash -n clean on scripts/hrx-env.sh, scripts/hw-gate.sh and tests/hrx_cwsr_route.sh.

NOT verified here: the full engine build and `ctest -R hrx_cwsr` / tests/hrx_cwsr_route.sh
end to end -- this worktree has no submodule contents, so there is no 1bit binary to run
the route test against. CI is that check.
@bong-water-water-bong
bong-water-water-bong force-pushed the 1bit/hrx-trio-every-process branch from 97dff9c to a4720d5 Compare November 2, 2026 00:51
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Rebased/fixed at a4720d5 — the build failure at 97dff9cc was mine, and the diagnosis is worth recording because it changes the design.

What failed

ci (run 41366068194) reported 9 route tests failing — print_backend, lemonade_hrx, recipes_route, greedy_shortcut, device_route, prism_route, laya_gguf_route, mem_admit_route, hrx_cwsr_route. All of them start 1bit serve --device hrx (or auto) against a stubbed backend.

Why

My first version refused an hrx/auto route whenever cwsr_env_present() was false. But the trio is legitimately empty in a build whose hrx-system has no HRX_ALLOW_NO_SVM gate: decide_cwsr_placement returns nothing there (it logs "this build's hrx-system has no HRX_ALLOW_NO_SVM gate … unchanged") and HRX0 cannot register at all. So I converted a benign build-time condition into a start failure, in a suite that never initialises HRX because the backend is a python stub.

The fix

The refusal now keys on the user's own decision, not on the resolved environment:

const bool cwsr_opted_out = o.cwsr_placement == CwsrPlacement::Off ||
                            (getenv("HRX_SVM") == "1");
if ((o.device == "hrx" || o.device == "auto") && cwsr_opted_out && !cwsr_env_present(hrx_cwsr_env(o))) {
    ... refuse with the recipe unless ONEBIT_HRX_NO_TRIO_OK=1 ...
}

An opt-out is a deliberate act and is worth a refusal with the recipe in hand; a gateless build is not, and the empty trio there has its own log line (and no HRX0). docs/hrx.md and the route-test header say exactly that, so the distinction is not just in the source.

Re-verified at a4720d5 (no device)

  • tests/hrx_cwsr_test.cpp: all checks passed, 12 new assertions unchanged.
  • The main() block compiled and run standalone against the real header, five ways, including the case that regressed: build without the gate, auto route, no opt-out → not refused; --hrx-cwsr-placement=off → refused with the recipe; the same + ONEBIT_HRX_NO_TRIO_OK=1 → proceeds; hrx with the trio → one log line, no refusal; --device cpu with off → never refused.
  • bash -n clean on scripts/hrx-env.sh, scripts/hw-gate.sh, tests/hrx_cwsr_route.sh.
  • Diff against main unchanged in shape: 7 files, and the PR body's verification section still describes what is and is not covered. The full engine build + ctest is still CI's job — this worktree has no submodule contents.

pi-prs: please re-read. The behaviour change is now narrower than the body first said — an existing command line that never opted out of the placement behaves exactly as before.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit a4720d5

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY

First verdict, and the design is right in the part that matters: the refusal is keyed on the user's deliberate opt-out,
not on an empty trio
, which is the difference between a guard and a CI-breaking rule.

Ran at a4720d56:

$ cmake -DONEBIT_HRX=OFF … && ninja hrx_cwsr_test        rc 0
$ ./hrx_cwsr_test
hrx_cwsr: all checks passed                              rc 0        (the 12 new assertions)
$ bash -n scripts/hrx-env.sh scripts/hw-gate.sh tests/hrx_cwsr_route.sh    clean
$ shellcheck -S warning scripts/hrx-env.sh               silent

and by reading:

  • cwsr_env_present() matches NAME=-prefixed entries and deliberately does not check the value — correct, since a
    caller's value wins everywhere in the engine and the fault is about the three being set together (the test's "a name that
    only starts with the same letters" row pins the rfind(… "=", 0) == 0 form against rfind(...) == 0 mistakes);
  • apply_cwsr_env_to_self() defaults overwrite = false, so a caller's value survives, and returns the count added, which
    is what the one log line reports;
  • the serve.cpp condition is (device == "hrx" || "auto") && cwsr_opted_out && !cwsr_env_present(...) with the acknowledgement
    ONEBIT_HRX_NO_TRIO_OK=1. So: a gateless build (empty trio, no opt-out) proceeds exactly as before, a user who opted out
    but set the trio themselves proceeds, and only a deliberate opt-out with no trio is refused — with the recipe and the
    acknowledgement in the message;
  • applying the trio to serve's own environment (rather than only a child's envp) is the right fix for the hole #743 left:
    run_program and LayaDaemon exec with the inherited environment, so a spawn site added later cannot forget it.

The fix history in the body is the kind of thing I want to see written down: the first head (97dff9cc) refused whenever the
trio was empty and broke nine stubbed route tests in CI (run 41366068194), and a4720d5 narrows it to the opt-out with the
gateless-build case re-verified. That is a rule that was tested by its own CI, not by argument.

Not verified by me: the end-to-end ctest -R hrx_cwsr / tests/hrx_cwsr_route.sh run, which needs a built 1bit with the
HRX submodules — my worktree has no submodule contents, so I built and ran the header test only. The route test is
add_test-registered (CMakeLists.txt:173, $<TARGET_FILE:onebit>), so CI is that check, and the body says the same.

tprs-ready applied. The behaviour change to flag in release notes: a serve command line that opted out of the placement now
fails with the recipe unless ONEBIT_HRX_NO_TRIO_OK=1 is set; one that never opted out is unchanged.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 08c3413

@bong-water-water-bong bong-water-water-bong removed the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: CHANGES

I was wrong to pass a4720d56, and CI says why: mem_admit_route (test 18) fails on this branch — the same failure at
both heads, since the only delta between them is #795's fixture file. Correcting my own verdict before you spend another
cycle.

18/58 Test #18: mem_admit_route ..................***Failed    3.31 sec
ok   a 4 TiB model is refused (rc 3) in under 2 s (6 ms)
FAIL   in one line with the numbers

tests/mem_admit_route.sh:67 requires the refusal to be exactly one line
([ "$(wc -l < huge.log)" = 1 ]). On this branch huge.log has two:

1bit serve: HRX: this build's hrx-system has no HRX_ALLOW_NO_SVM gate; CWSR save-area placement unchanged (engine#315)
1bit serve: huge does not fit: need 4096.72 GiB (…) at ctx 4096, free 14.63 GiB (…)

Cause. hrx_cwsr_env()'s decision is a function-local static whose initialiser prints
(app/serve.cpp:226-232, std::fprintf(stderr, "1bit serve: %s\n", r.log.c_str())). On main the first call happens lazily
inside a backend spawn (lines 1015/1189/1709), so a serve that is refused by the memory check never reaches it and the
refusal is the only output. This PR calls hrx_cwsr_env(o) eagerly, right after option parsing, so the decision is computed
and printed for every serve — including --device cpu — before the admission check runs.

Fix, and it is the same narrowing the refusal already has: only do it for a route that uses HRX. Guard both the apply and
the refusal with if (o.device == "hrx" || o.device == "auto") { … }, so a cpu/npu serve is byte-identical to main — no
extra stderr line, mem_admit_route green again — and the trio still lands in serve's environment for the routes that need
it. (Alternatively make the decision lazy-and-quiet and print it only where a backend is actually spawned, but the device
guard is smaller and matches the intent.)

This is the second CI failure this eager call has caused — the first was refusing on an empty trio (nine stubbed route tests,
run 41366068194), which the body already records. The pattern worth naming: the decision object has an output side effect,
so when it is computed is observable.
Anything that moves it must either keep it inside the route that needs it or accept
that every serve invocation's stderr changes.

Everything else in the review stands: hrx_cwsr_test builds and passes (hrx_cwsr: all checks passed, the 12 assertions),
cwsr_env_present()'s NAME=-prefix match is right and the value is deliberately unchecked, apply_cwsr_env_to_self() uses
overwrite=false so a caller wins, bash -n clean on all three scripts, and the refusal message with the recipe plus
ONEBIT_HRX_NO_TRIO_OK=1 is the right ergonomics. I have removed tprs-ready; it goes back with the device guard.

…ate opt-out (engine#715)

The trio was already set for serve's own backends (#743) and in scripts/hw-gate.sh's
environment. Two gaps were left, and both cost a GPU reset rather than an error:

  * a child that exec()s with the *inherited* environment never got it. Child builds an
    explicit envp, but run_program and LayaDaemon exec with ours, so any helper started
    through them ran HRX without the trio;
  * nothing stopped a serve that had opted out of the placement from starting anyway.

What changes:

  * app/hrx_cwsr.h: kCwsrRecipe (the pastable line), cwsr_env_present() (is the trio in
    this NAME=VALUE list; the value is not checked, because a caller's value wins
    everywhere in the engine) and apply_cwsr_env_to_self() (put it in *our* environment,
    overwrite=0). Windows gets _putenv_s.
  * app/serve.cpp: the trio goes into serve's own environment on an hrx/auto route, so
    every descendant inherits it however it is spawned and a future spawn site cannot
    forget it; and an hrx/auto route is refused when the user opted out
    (--hrx-cwsr-placement=off or HRX_SVM=1) so the trio is absent, with the recipe in the
    message. ONEBIT_HRX_NO_TRIO_OK=1 is the acknowledgement.
  * scripts/hrx-env.sh: one definition for the shell side -- `source ... --check` sets the
    trio and refuses to continue without it -- and scripts/hw-gate.sh now sources it
    instead of carrying its own copy.

Two things the earlier heads got wrong, both caught by CI and both fixed by narrowing what
is printed and when:

  1. The refusal keyed on an empty trio, which also fires in a build whose hrx-system has no
     HRX_ALLOW_NO_SVM gate (nine route tests, 41366068194). It now keys on the opt-out.
  2. hrx_cwsr_env()'s function-local static printed the decision line on first call, so any
     caller printed it -- including `--device cpu`, which made the memory refusal two lines
     and failed mem_admit_route (tests/mem_admit_route.sh counts lines). The decision is now
     computed silently and announced once at the first HRX backend that uses it
     (announce_cwsr_env), the self-environment step is silent (the decision line already
     says it), and the refusal message is a single line.

Verified without a device:
  * tests/hrx_cwsr_test.cpp: all checks passed, 12 assertions over the recipe, the presence
    check (including a name that only starts with the same letters, and a caller's
    non-default values counting as present) and apply-to-self (adds only what is absent, a
    caller's value survives);
  * the main() block compiled and run standalone against the real header behind main.cpp's
    own one-line handler, and the line counts are the ones the tests assert:
    --device cpu -> 0 extra lines (the mem_admit_route case), a gateless build on auto with
    no opt-out -> 0, an hrx route -> 0 beyond the announced decision, and an explicit
    --hrx-cwsr-placement=off -> exactly 1, the single-line refusal with the recipe inline;
  * bash -n clean on scripts/hrx-env.sh, scripts/hw-gate.sh, tests/hrx_cwsr_route.sh.

NOT verified here: the full engine build and `ctest` end to end -- this worktree has no
submodule contents, so there is no 1bit binary to run tests/mem_admit_route.sh against.
CI is that check; the line-count invariants it asserts were reproduced against the same
handler instead.
@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Fixed at 360a128 (fast-forward on top of 08c34130, no force). The mem_admit_route failure was mine and the diagnosis you passed on was exactly right.

Cause

hrx_cwsr_env() computes the placement decision in a function-local static that printed the line. So every caller printed it — including the --device cpu path in mem_admit_route, whose "does not fit" refusal is asserted to be exactly one line (tests/mem_admit_route.sh: wc -l < huge.log = 1). My block called that accessor unconditionally, so the CWSR line landed ahead of the refusal and the count became 2.

Fix (three parts, all narrowing what is printed and when)

  1. The decision is computed silently; announcing it is a separate call, announce_cwsr_env(), made at the first HRX backend that uses it — so a route that never touches HRX prints nothing, and the line still appears where the route tests look for it (grep -c "CWSR save area placed in GTT" = 1, now also asserted).
  2. The refusal comes first and is one line — the recipe is inline instead of on its own indented line, and it goes through main.cpp's existing 1bit serve: %s handler.
  3. The self-environment step is silent. The decision line already tells the operator the placement happened, so the "3 of the engine#315 variables …" line earned nothing and could only break a line-counting test again.

Re-verified against the exact assertions that failed (no device)

I could not run tests/mem_admit_route.sh here — this worktree has no submodule contents, so there is no 1bit binary to point it at. What I did instead: compiled the block from the resolved source against the real header, behind main.cpp's own one-line handler, and counted lines the way the test does:

case lines want
--device cpu (the mem_admit_route case) 0 extra, and no variables set 0
hrx route, trio resolvable 0 extra, trio present in the process env (0/0/1) 0
hrx + --hrx-cwsr-placement=off 1 — the refusal with the recipe inline 1
gateless build, auto, no opt-out 0 0
off + ONEBIT_HRX_NO_TRIO_OK=1 0, proceeds 0

Also: tests/hrx_cwsr_test.cpp all checks passed (12 assertions), bash -n clean on the three scripts, and the diff against the failing head is only app/serve.cpp + tests/hrx_cwsr_route.sh (43/21) — nothing else moved.

One thing I removed rather than fixed

The route test had an assertion I had added for the inherited-environment property (grep for the self-env log line). That property is now unobservable through the stubbed backend, and asserting a log line that no longer exists would fail — so it is replaced by the "announced exactly once" check, and the setenv path is covered by the unit test instead. Saying it plainly because it is one fewer end-to-end assertion than the previous head claimed.

pi-prs: please re-read at 360a128.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Preparing review...

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY

Fixed better than I asked: instead of guarding the eager call with a device check, the output side effect is gone from the
decision itself.

hrx_cwsr_env()            no fprintf any more — the static initialiser just decides
announce_cwsr_env(o)      prints once (`static bool announced`), called at the three HRX backend spawn sites
                          (serve.cpp:1029, 1204, 1725), with the reason in the comment

So the line still appears exactly once for a real HRX route, and no cpu/npu serve, and no path that must emit exactly one
line, inherits it. That is the right layer: my suggested device guard would have kept the printing inside the decision object,
so the next caller that only wanted the environment would have hit the same trap.

CI at 360a1280 proves it — the build job runs ctest, and this is the job's tail:

19/58 Test #19: hrx_cwsr_route ...................   Passed    0.58 sec
30/58 Test #30: hrx_cwsr .........................   Passed    0.00 sec
100% tests passed, 0 tests failed out of 58

so mem_admit_route — the one-line refusal assertion my previous CHANGES was about — is green again, as are the nine route
tests that the first head broke the other way.

Everything else from my first review stands: the refusal keys on the deliberate opt-out (--hrx-cwsr-placement=off or
HRX_SVM=1) with the recipe and ONEBIT_HRX_NO_TRIO_OK=1 in the message; a gateless build and a caller who set the trio
themselves both proceed; cwsr_env_present() matches NAME=-prefixed entries and leaves the value alone; and applying the trio
to serve's own environment is what gives run_program/LayaDaemon children the variables they were missing.

tprs-ready re-applied.

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 5281aad

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: READY

At 5281aad6 exactly. The waiter rebased it; its own files are byte-identical to the head I verdicted —
git diff --stat 360a1280 <head> -- app/hrx_cwsr.h app/serve.cpp scripts/hrx-env.sh scripts/hw-gate.sh tests/hrx_cwsr_route.sh tests/hrx_cwsr_test.cpp docs/hrx.md → empty (the delta is #797's mtp_batch_all_test +
CMakeLists.txt coming in from main). announce_cwsr_env is still in place (5 references) and kCwsrRecipe intact.

Green at this head, both checks and the tests that matter:

CodeQL: success      build: success
19/58 Test #19: hrx_cwsr_route .......   Passed   0.53 sec
30/58 Test #30: hrx_cwsr .............   Passed   0.00 sec
100% tests passed, 0 tests failed out of 58        (mem_admit_route among them)

So the fixed shape stands: the trio goes into serve's own environment (so run_program/LayaDaemon children inherit it), the
decision object no longer prints on its own, announce_cwsr_env() prints once at the first HRX backend, and only a deliberate
opt-out (--hrx-cwsr-placement=off / HRX_SVM=1) without the trio is refused — with the recipe and ONEBIT_HRX_NO_TRIO_OK=1
in the message.

tprs-ready stays. This is the head to merge on.

@bong-water-water-bong
bong-water-water-bong merged commit b5cbe2f into main Nov 2, 2026
8 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the 1bit/hrx-trio-every-process branch November 2, 2026 02:20
bong-water-water-bong added a commit that referenced this pull request Nov 2, 2026
… set (#813)

c20's ctest caught `hrx_cwsr_route` failing on one assertion, "and serve names it in the log": with
HSA_USERPTR_FOR_PAGED_MEM=5 in the environment and --device hrx, serve logged

  HRX: CWSR save area placed in GTT by default (...); kept from the environment:
       HSA_USE_SVM, HSA_USERPTR_FOR_PAGED_MEM, HRX_ALLOW_NO_SVM

i.e. all three "kept from the environment" when the user had set exactly one. The environment assertion right
above it in the same test passes, so the backend does get the right trio: only the message is wrong.

Cause: #794 (engine#715) puts the trio into serve's *own* environment at startup
(apply_cwsr_env_to_self(hrx_cwsr_env(o))), and announce_cwsr_env() then recomputed
decide_cwsr_placement(...) to build its line. Recomputed afterwards, getenv() reads our own exports, so
user_set lists every variable and the line can no longer distinguish what the operator set from what serve
added.

Fix: one decision per process. hrx_cwsr_decision() holds the CwsrDecision (computed once, at the first HRX
route - before the self-export, because that export calls hrx_cwsr_env(o) for its argument), hrx_cwsr_env()
returns its env, and announce_cwsr_env() prints its stored log instead of recomputing. Same single line, same
place, same behaviour when nothing is set; the difference is that the line now tells the truth about which
variables came from the environment.

Verified against the release build's own ctest case (tests/hrx_cwsr_route.sh) - see the PR for the before/after
line - and it is exactly the red that stopped c20's software gate.

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong added a commit that referenced this pull request Nov 2, 2026
…ver gets it (engine#715) (#816)

b5cbe2f (#794) made `auto` place the CWSR save area in GTT and put the trio into serve's
*own* environment, so every child serve starts inherits it. That closed engine#715 for serve's
own backends, but not for the two spawn paths that start the backend from what serve *prints*:
Lemonade's one hop (the JSON `env` of --print-backend) and scripts/lemonade-hrx (the
NAME=VALUE lines of --print-backend-env).

Cause: both build their env from l.env, which does carry the trio (app/serve.cpp:1032, 1207,
1728), through a filter that leaves out every variable already present in serve's environment
("a value the caller set wins", app/serve.cpp:1561-1566). apply_cwsr_env_to_self runs earlier
(main, ~2841) and exports the trio to ourselves, so by the time the plan is built getenv()
finds it and the filter drops it.

Measured on the 2026-11-01b package's own 1bit (amdgpu cwsr_enable=0), trio unset in the caller:

  $ 1bit serve -m Qwen3-0.6B-Q4_K_M.gguf --device hrx --print-backend-env
  GGML_HRX_REPORT=1
  GGML_HRX_STRICT=1
  IREE_HAL_AMDGPU_LIBHSA_PATH=.../libhsa-runtime64.so.1        <- no trio
  # stderr: HRX: CWSR save area placed in GTT by default (engine#315; amdgpu cwsr_enable=0; ...)

Same for the plan's env, same with --hrx-cwsr-placement=on, and the shipped launcher exports
nothing, so both Lemonade paths ran the backend without the variables that keep ROCr from
page-faulting on the first graph replay -- the configuration engine#715 is about.

Fix: do not self-export in the print modes. They start no backend here; the caller starts it
from the plan, and the same filter still lets a value the caller set win. tests/print_backend.sh
and tests/lemonade_hrx.sh now assert the trio in both outputs (and the HRX_SVM=1 opt-out).
On the shipped binary those four assertions fail today; with this change the plan carries
HSA_USE_SVM=0 HSA_USERPTR_FOR_PAGED_MEM=0 HRX_ALLOW_NO_SVM=1.

Co-authored-by: bong-water-water-bong <[email protected]>
bong-water-water-bong added a commit that referenced this pull request Nov 2, 2026
…s backend (engine#715, #816) (#825)

The trio is only in serve's printed plan, so a grep on --print-backend-env is the whole check.
Both packages on the box today print 0, for two different reasons: rc-2026-10-31c predates
#794/#813 (its log still says the placement is unchanged) and rc-2026-11-01b exports the trio
into serve's own environment before building the plan, which is what #816 fixes.

Co-authored-by: bong-water-water-bong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review effort 4/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant