Skip to content

serve: decide the CWSR placement once, so the log names what the user set (c20 gate red) - #813

Merged
bong-water-water-bong merged 1 commit into
mainfrom
fix/cwsr-decision-line
Nov 2, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
fix/cwsr-decision-line

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes the one non-infrastructure red that stopped c20's software gate. ctest failed hrx_cwsr_route on tests/hrx_cwsr_route.sh:111, "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 (engine#315; amdgpu cwsr_enable=0; …); kept from the environment:
     HSA_USE_SVM, HSA_USERPTR_FOR_PAGED_MEM, HRX_ALLOW_NO_SVM

— all three "kept from the environment" when the user set exactly one. The environment assertion immediately above it in the same test passes (auto: a value the user set wins, the other two are still added), so the backend gets 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, on the first HRX route — which is before the self-export, because that export takes hrx_cwsr_env(o) as its argument), hrx_cwsr_env() returns its env, and announce_cwsr_env() prints its stored log instead of recomputing. Same single line, same place, unchanged when nothing is set; the line now tells the truth about which variables came from the environment.

Why this blocked the release run, and what it does not change: the red is in the software gate's ctest, so package, the hardware gate and QEMU were not run for c20 (rc-2026-11-01b). Nothing else in that run was red: the parallel batch was 57/58 and the serial engine-test set 9/10, the other failure (hybrid_kvshare_route) being a timing assertion (share 1.074 ms vs the test's share 0.x ms) that then passed 3/3 on a clean re-run — a separate, much smaller issue I am not touching here.

Verified by reproducing the exact case outside ctest (serve + the test's fake backend, HSA_USERPTR_FOR_PAGED_MEM=5, clean env): before, the line lists all three; after, it names only HSA_USERPTR_FOR_PAGED_MEM, which is what the test asserts.

… set

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.
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

794 - Partially compliant

Compliant requirements:

  • Engine sets the save-area trio for every HRX process and refuses to start without it
  • The trio is applied to serve's own environment right after option parsing so every descendant inherits it
  • Refuses an hrx/auto route when the user opted out and prints the recipe
  • ONEBIT_HRX_NO_TRIO_OK=1 acknowledges a box whose ROCr does not need the placement
  • The change is verified with tests (tests/hrx_cwsr_test.cpp and tests/hrx_cwsr_route.sh)

Non-compliant requirements:

  • None

Requires further human verification:

  • None

715 - Partially compliant

Compliant requirements:

  • Engine sets the trio itself when it detects unfavourable capability lines
  • Fail loudly at init with the recipe so no lane can measure off a faulting path
  • Log the libhsa path + sha256 in the HRX init line of every run

Non-compliant requirements:

  • Settle the release-runtime question

Requires further human verification:

  • Settle the release-runtime question

315 - Partially compliant

Compliant requirements:

  • None

Non-compliant requirements:

  • Fix intermittent HSA memory fault / NaN logits under varied-length requests on HRX
  • Address the pre-existing GLM varied-length fault on the public HRX path

Requires further human verification:

  • The fix addresses the root cause of the issue, but hardware testing is required to confirm the fix in the actual environment
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Incorrect CWSR placement logging

The previous implementation of announce_cwsr_env recomputed the CWSR placement decision after the trio had been applied to the process's environment, which caused it to report all variables as "kept from the environment" instead of distinguishing those set by the user. This led to incorrect logging in test cases, where the log message incorrectly indicated that all trio variables were set by the environment rather than by the user.

void announce_cwsr_env(const Options& o) {
    static bool announced = false;
    if (announced) return;
    announced = true;
    std::fprintf(stderr, "1bit serve: %s\n", hrx_cwsr_decision(o).log.c_str());
}

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Verified on the box against the release build's own ctest case (so the PR claim is measured, not reasoned): copied this app/serve.cpp into the c20 tree at c85596a, rebuilt the onebit target only, and ran the test:

Start 19: hrx_cwsr_route
1/1 Test #19: hrx_cwsr_route ...................   Passed    1.05 sec
100% tests passed, 0 tests failed out of 1

Before the patch, the same test on the same tree: FAIL and serve names it in the log. The tree was then restored to pristine c85596a (nothing of this fix is left in the c20 checkout — the candidate must be main + the pin, and #813 is not merged yet).

For the record, the before/after line on the failing case (HSA_USERPTR_FOR_PAGED_MEM=5, --device hrx, clean environment):

before: … ; kept from the environment: HSA_USE_SVM, HSA_USERPTR_FOR_PAGED_MEM, HRX_ALLOW_NO_SVM
after:  … ; kept from the environment: HSA_USERPTR_FOR_PAGED_MEM

That is the assertion's expectation, and it is also simply the truth: the operator set one variable, serve added the other two.

@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

The red gate is green at this head, and the fix is the right shape — one decision per process, printed from the stored copy.

Ran (host build, no HRX submodules — the route test drives serve with the fake backend):

$ ninja onebit hrx_cwsr_test                    rc 0
$ ctest -R 'hrx_cwsr' --output-on-failure
19/58 Test #19: hrx_cwsr_route .........   Passed   0.72 sec      <- the assertion that stopped c20
30/58 Test #30: hrx_cwsr ...............   Passed   0.00 sec
100% tests passed, 0 tests failed out of 2

Cause and fix, and it is a bug I should have caught in #794. I read announce_cwsr_env() there — I even quoted its body —
and did not notice that it recomputed decide_cwsr_placement(...) after apply_cwsr_env_to_self() had already exported the
trio into serve's own environment: getenv() then reports our own exports, so user_set lists all three and the line can no
longer distinguish what the operator set from what serve added. #813 stores the CwsrDecision in a function-local static
(hrx_cwsr_decision()), returns its env from hrx_cwsr_env(), and prints its stored log. Because the self-export takes
hrx_cwsr_env(o) as an argument, the decision is computed before the export — which is the ordering that makes the line
truthful. One line, same place, unchanged when nothing is set.

That is also why the environment assertion above it in the same test kept passing: the backend got the right trio all along;
only the message lied. Worth saying plainly, because a wrong log line is exactly the kind of thing that makes the next
investigation chase the wrong variable.

Release context I checked rather than accepted: the red was in the software gate's ctest, so package, hw_gate and QEMU
never ran for rc-2026-11-01b; the rest of that run was 57/58 in the parallel batch and 9/10 in the serial engine set, with
hybrid_kvshare_route's share 1.074 ms timing assertion passing 3/3 on a clean re-run. So this really is the one blocker, and
it is fixed at the assertion that failed.

build and CodeQL are green on this head. tprs-ready applied — this is the head to merge on, and I would merge it before
anything else tonight.

@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
@bong-water-water-bong
bong-water-water-bong merged commit a5271d9 into main Nov 2, 2026
10 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/cwsr-decision-line branch November 2, 2026 11:58
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 3/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