interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

GitHub aien-dev/CUDApp#251 (code only)

closed derived 46dd1c16233bbcdf #251

Imported from GitHub aien-dev/CUDApp#251 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 183fa4f161de512094e47cd68285dcfde9c53a0c · Head a0acf5b2ee63b5bc33594480b1a71e8ea2ad6e33

cursor[bot] commented on om/pipeline/seal_reuse.om line 27 on 2026-11-02 00:17 UTC

The normalizer is still the copy in om/pipeline/seal_reuse.om. Sharing it with mcc_seal would regenerate the sealed C unit, so this change takes the other option from the review: make test-seal-reuse now links omega_native_mcseal and requires the same digest as omega_native_mcreseal on every case, on a miss and on a hit. Local run on 6e2adc7: 6304 cases, pass. SEAL_REUSE.md says the copy remains and the differential test is the gate.

cursor[bot] commented on om/pipeline/seal-reuse-check.py line 16 on 2026-11-02 00:17 UTC

seal-reuse.so now links src/cudapp_om_closure_reseal.c and src/cudapp_om_closure_seal.c. om/pipeline/seal-reuse-check.py calls omega_native_mcseal on the same bank, QMD, and argument count as omega_native_mcreseal and requires equal digests, including the repeated call that hits the memo and the invalid counts that both refuse. The mutant driver links omega_native_mcseal the same way. Local make test-seal-reuse on 6e2adc7 printed oracle_cases 6304 and pass. The five Omega source mutants still run only where the pinned compiler is present (CUDAPP_OMC_HOST).

cursor[bot] commented on om/q38-head/serving-validation.json line 4 on 2026-11-02 00:17 UTC

No new serving run is in this push. om/q38-head/serving-validation.json is still the earlier O2 screen, not a receipt for 6e2adc7 or for the O3 reseal. The GB10 serving gate on this head is NOT RUN. The host fresh-clone receipt (make test, make test-native-artifact, and the other host gates) will be committed under evidence/ when it finishes; that is not the serving screen.

cursor[bot] commented on src/omega_gpu_q38_graph.c line 287 on 2026-11-02 00:17 UTC

Masked logits are refused when sampling is on. omega_gpu_q38_graph_set_sampling(g, 1) returns OMEGA_GPU_DGRAPH_BAD_ARGS while exact_on is set. omega_gpu_q38_graph_set_exact_head_on now returns that same code instead of enabling the head when sampling is on, and set_exact_head refuses to install while sampling is on (the check is before shape_is, so it does not touch the device). record_final refuses the pair before any launch. graph_read refuses a logits pointer when sampling is on and the last record_final wrote the masked buffer (exact_logits). omega_gpu_q38_graph_test_sampling_guard covers that on a stack object with no device, and tests/gpu_q38_graph_test --host-only calls it. Local result: gpu_q38_graph_test (host-only): 5 checks, 0 failed: PASS. 6e2adc7.

cursor[bot] reviewed (COMMENTED) on 2026-11-02 00:23 UTC

<details> <summary>Stale comment</summary>

<blockquote>

Risk: high. I left a non-blocking comment and did not approve: Security Agent passed with no findings, Bugbot was not running, and this exact-head plus command-seal change is above the medium approval threshold. Human review is needed; drakestapleton was assigned.

<div><a href="https://cursor.com/agents/bc-7d6575c5-2551-4d50-ad04-e9a156dbe08f?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/automations/ca4a13aa-d616-11f1-a7e4-4605a90eab71"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/view-automation-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/view-automation-light.png"><img alt="View Automation" width="141" height="28" src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a> </div>

<sub>Sent by Cursor Approval Agent: Pull Request Router and Approver</sub>

</blockquote>

</details>

cursor[bot] reviewed (COMMENTED) on 2026-11-02 01:00 UTC

Risk: high. I left a non-blocking comment and did not approve: Security Agent passed with no findings, Bugbot was not present, and this exact-head plus command-seal change remains above the medium approval threshold. Human review is needed and no reviewers were assigned.

<div><a href="https://cursor.com/agents/bc-f060391a-5bea-481d-b24c-920e357189fb?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/automations/ca4a13aa-d616-11f1-a7e4-4605a90eab71"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/view-automation-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/view-automation-light.png"><img alt="View Automation" width="141" height="28" src="https://cursor.com/assets/images/view-automation-dark.png"></picture></a> </div>

<sub>Sent by Cursor Approval Agent: Pull Request Router and Approver</sub>

Fetch it

A git bundle of the pull request's head, 7080 bytes.

curl -fsSL https://interplane.io/drakestapleton/CUDApp/patches/46dd1c16233bbcdf.bundle -o 46dd1c16233bbcdf.bundle
git fetch 46dd1c16233bbcdf.bundle refs/pull/251/head

Raw bundle · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/CUDApp
251
a0acf5b2ee63b5bc33594480b1a71e8ea2ad6e33
{"kind":"github-import","owner":"aien-dev","repo":"CUDApp","number":251,"url":"https://github.com/aien-dev/CUDApp/pull/251","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:00Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/evidence/Q38-FRESH-20261102/RECEIPT.md b/evidence/Q38-FRESH-20261102/RECEIPT.md
new file mode 100644
index 00000000..db54a718
--- /dev/null
+++ b/evidence/Q38-FRESH-20261102/RECEIPT.md
@@ -0,0 +1,26 @@
+# Fresh-clone host gates for the Qwen3.8 head
+
+Cloned from `https://github.com/aien-dev/CUDApp.git` and checked out detached
+`6e2adc77fef9ff1af8257fe525f37deacc42f59e`. `git status --porcelain` was empty.
+Started 2026-11-02T00:39:39Z. Linux 6.12.94+ x86_64, gcc 13.3.0, GNU Make 4.3.
+No GPU device was opened.
+
+`CUDAPP_MEM_RESERVE_MIB=0` on this VM only. MemAvailable under-reports because
+of the hypervisor balloon, and the default 4096 MiB reserve then refuses the
+Qwen-shaped upload. The platform test unsets the variable and still checks
+the 4096 default. This is not a Spark setting.
+
+This directory was added after that run. It is not an input to `make`.
+The GB10 serving screen is not this receipt.
+
+| Gate | Result | Exit |
+|---|---|---|
+| `make -j4 test` | PASS. Last line: `CUDA++ HOST TESTS PASS (73 targets)` | 0 |
+| `make -j4 test-native-artifact` | PASS. `test_gpu_artifact_export: 47 checks, 0 failed` | 0 |
+| `make -j4 zero-cuda-gate` | PASS. `hello_gpu` needs libm and libc. `gpu_matmul_api_test` needs libc. The self-test rejected a CUDA probe | 0 |
+| `./build/hello_gpu --sim` | PASS. 1048576 elements, 0 wrong. machine-code sha256 `9e28bd9c46f80584d77238a752e99cecddbc8d622ffbe320885ed2f499e1f075` | 0 |
+| `make doctor` | NOT READY, expected on this VM. No NVIDIA module and no `/dev/nvidia*`. GNU make exits 2 when that recipe fails | 2 |
+| GB10 chip and serving | NOT RUN | |
+
+`make test` logs contain intentional `FAIL` lines from mutation tests and
+negative controls. The exit code and the last line are the result.
diff --git a/mk/seal-reuse.mk b/mk/seal-reuse.mk
index 3b6b8fd1..d3a15612 100644
--- a/mk/seal-reuse.mk
+++ b/mk/seal-reuse.mk
@@ -4,9 +4,9 @@ CARRIED_HOST_TESTS += test-seal-reuse
 CUDAPP_SEAL_OPT ?= -O3
 $(OUT_DIR)/cudapp_om_closure_reseal.o: private CFLAGS += $(CUDAPP_SEAL_OPT)
 .PHONY: test-seal-reuse
-$(OUT_DIR)/seal-reuse.so: src/cudapp_om_closure_reseal.c
+$(OUT_DIR)/seal-reuse.so: src/cudapp_om_closure_reseal.c src/cudapp_om_closure_seal.c
 	@mkdir -p $(OUT_DIR)
-	$(CC) $(filter-out -MMD -MP,$(CFLAGS)) $(CUDAPP_SEAL_OPT) -shared -fPIC $< -o $@
+	$(CC) $(filter-out -MMD -MP,$(CFLAGS)) $(CUDAPP_SEAL_OPT) -shared -fPIC $^ -o $@
 test-seal-reuse: $(OUT_DIR)/seal-reuse.so
 	python3 om/pipeline/seal-reuse-check.py $(abspath $(OUT_DIR))/seal-reuse.so
 ifeq ($(CUDAPP_OMC_HOST),1)
diff --git a/om/pipeline/SEAL_REUSE.md b/om/pipeline/SEAL_REUSE.md
index 356b91f5..93d5f951 100644
--- a/om/pipeline/SEAL_REUSE.md
+++ b/om/pipeline/SEAL_REUSE.md
@@ -6,7 +6,7 @@ The native command-list path hashes the driver bank, arguments, and normalized Q
 
 The memo supplies a digest only. Native lease acquisition, revision and epoch checks, recording ownership, completion tracking, and submit-time intent checks still run. It does not admit an artifact or authorize a launch. The cache is caller-owned internal state, never an external serialized credential.
 
-`make test-seal-reuse` compares the result with Python's independent SHA256. It changes every byte of both input arrays, tests every argument count in both directions, includes all-zero images, and checks invalid counts and repeated hits. On a host that runs the pinned Omega compiler, five source mutants prove the oracle catches missing comparisons, a missing count check, a skipped byte, incorrect normalization, and a dirty refusal output. Python is an external verification tool only.
+`make test-seal-reuse` compares the result with Python's independent SHA256, and requires the same digest from `omega_native_mcseal` on every case, both when the memo misses and when it hits. It changes every byte of both input arrays, tests every argument count in both directions, includes all-zero images, and checks invalid counts and repeated hits. On a host that runs the pinned Omega compiler, five source mutants prove the oracle catches missing comparisons, a missing count check, a skipped byte, incorrect normalization, and a dirty refusal output. Python is an external verification tool only.
 
 The full-model speed result remains pending. Initial shared-machine diagnostic data is recorded separately; no default-serving or first-token improvement is asserted here.
 
diff --git a/om/pipeline/seal-reuse-check.py b/om/pipeline/seal-reuse-check.py
index 40dd53c3..69bb9d83 100644
--- a/om/pipeline/seal-reuse-check.py
+++ b/om/pipeline/seal-reuse-check.py
@@ -2,10 +2,11 @@
 # External independent SHA256 oracle for the Omega normalized-command memo.
 import ctypes,hashlib,json,random,sys,time
 from pathlib import Path
-l=ctypes.CDLL(sys.argv[1]);fn=l.omega_native_mcreseal
+l=ctypes.CDLL(sys.argv[1]);fn=l.omega_native_mcreseal;seal=l.omega_native_mcseal
 fn.argtypes=[ctypes.POINTER(ctypes.c_uint64),ctypes.c_void_p,ctypes.c_uint64,ctypes.c_void_p,ctypes.c_uint64,ctypes.c_uint64,ctypes.c_void_p,ctypes.c_uint64,ctypes.c_void_p,ctypes.c_uint64]
+seal.argtypes=[ctypes.POINTER(ctypes.c_uint64),ctypes.c_void_p,ctypes.c_uint64,ctypes.c_void_p,ctypes.c_uint64,ctypes.c_uint64,ctypes.c_void_p,ctypes.c_uint64]
 U=ctypes.c_ubyte
-b=(U*1024)();q=(U*1024)();c=(U*2048)();o=(U*32)();r=ctypes.c_uint64()
+b=(U*1024)();q=(U*1024)();c=(U*2048)();o=(U*32)();r=ctypes.c_uint64();sb=(U*32)();sr=ctypes.c_uint64()
 rng=random.Random(710)
 for a in (b,q):
  for i in range(1024):a[i]=rng.randrange(256)
@@ -18,8 +19,14 @@ def check(n):
  for i in range(32):o[i]=255
  rc=fn(ctypes.byref(r),b,1024,q,1024,n,c,2048,o,32)
  assert rc==0,(rc,n)
- if 1<=n<=32:assert r.value==0 and bytes(o)==digest(n),(n,r.value,bytes(o).hex(),digest(n).hex())
- else:assert r.value==2**64-1 and bytes(o)==bytes(32)
+ src=seal(ctypes.byref(sr),b,1024,q,1024,n,sb,32)
+ assert src==0,(src,n)
+ if 1<=n<=32:
+  assert r.value==0 and bytes(o)==digest(n),(n,r.value,bytes(o).hex(),digest(n).hex())
+  assert sr.value==0 and bytes(sb)==bytes(o),(n,'mcseal',bytes(sb).hex(),bytes(o).hex())
+ else:
+  assert r.value==2**64-1 and bytes(o)==bytes(32)
+  assert sr.value==2**64-1 and bytes(sb)==bytes(32)
  cases+=1
 for n in (0,1,2,10,31,32,33,2**64-1,10):check(n);check(n)
 # Every byte of both inputs: covered mutations must refresh, ignored bytes must retain exact digest.
@@ -39,4 +46,4 @@ elapsed=time.perf_counter_ns()-start
 # Refresh cold memo as well, proving no prior command is required.
 for i in range(2048):c[i]=0
 check(10)
-print(json.dumps({'pass':True,'oracle_cases':cases,'warm_calls':256,'warm_total_ns':elapsed,'all_input_byte_mutations':2048,'oracle':'Python hashlib.sha256 over original normalized byte contract'}))
+print(json.dumps({'pass':True,'oracle_cases':cases,'warm_calls':256,'warm_total_ns':elapsed,'all_input_byte_mutations':2048,'oracle':'Python hashlib.sha256 over original normalized byte contract','differential':'omega_native_mcseal digest equals omega_native_mcreseal on every case, miss and hit'}))
diff --git a/om/pipeline/seal-reuse-mutants.py b/om/pipeline/seal-reuse-mutants.py
index 3f5e157f..8d5acb36 100644
--- a/om/pipeline/seal-reuse-mutants.py
+++ b/om/pipeline/seal-reuse-mutants.py
@@ -28,7 +28,7 @@ with tempfile.TemporaryDirectory(prefix='seal-reuse-mutants-') as t:
   om=t/(name+'.om');om.write_text(prefix+source.replace(old,new))
   c=t/(name+'.c');so=t/(name+'.so')
   with c.open('w') as f:subprocess.run(['sh',str(bridge),'c',str(om)],env=env,stdout=f,check=True)
-  subprocess.run([os.environ.get('CC','cc'),os.environ.get('CUDAPP_SEAL_OPT','-O3'),'-shared','-fPIC',str(c),'-o',str(so)],check=True)
+  subprocess.run([os.environ.get('CC','cc'),os.environ.get('CUDAPP_SEAL_OPT','-O3'),'-shared','-fPIC',str(c),str(root/'src/cudapp_om_closure_seal.c'),'-o',str(so)],check=True)
   p=subprocess.run(['python3',str(root/'om/pipeline/seal-reuse-check.py'),str(so)],capture_output=True,text=True)
   assert p.returncode!=0,name+' escaped oracle'
   assert 'AssertionError' in p.stderr,(name,p.stderr)
diff --git a/om/q38-head/README.md b/om/q38-head/README.md
index 0da213d3..e5c807ff 100644
--- a/om/q38-head/README.md
+++ b/om/q38-head/README.md
@@ -160,7 +160,9 @@ intervals, two threshold reductions, and full-precision masked recheck.
 the pinned Omega Bridge. The C graph adapter only supplies resources and
 dispatches those operations. The feature is opt-in through
 `omega_gpu_q38_graph_set_exact_head`; the original head remains available.
-Disable the feature for sampling, which requires all logits. Full serving
+`omega_gpu_q38_graph_set_sampling(g, 1)` refuses while that head is on, and
+`omega_gpu_q38_graph_read` refuses a logits pointer when sampling is on and the
+last token wrote the masked buffer. Full serving
 qualification is pending; the default path is unchanged.
 
 The Omega plan also supplies an additional 2 GiB admission reserve for the
diff --git a/om/q38-head/budget-check.c b/om/q38-head/budget-check.c
index fb356167..1e4ffbde 100644
--- a/om/q38-head/budget-check.c
+++ b/om/q38-head/budget-check.c
@@ -7,7 +7,9 @@ int main(void) {
     assert(omega_gpu_q38_exact_extra_bytes() == (UINT64_C(2)<<30));
     assert(omega_gpu_q38_graph_set_exact_head(NULL,NULL,NULL,10384) == OMEGA_GPU_DGRAPH_BAD_ARGS);
     assert(!omega_gpu_q38_graph_exact_head_active(NULL));
-    omega_gpu_q38_graph_set_exact_head_on(NULL,1);
+    assert(omega_gpu_q38_graph_set_exact_head_on(NULL,1) == OMEGA_GPU_DGRAPH_BAD_ARGS);
+    assert(omega_gpu_q38_graph_set_sampling(NULL,1) == OMEGA_GPU_DGRAPH_BAD_ARGS);
+    assert(omega_gpu_q38_graph_test_sampling_guard() == 0);
     puts("PASS: exact-head extra admission reserve and null-handle refusals");
     return 0;
 }
diff --git a/src/omega_gpu_q38_graph.c b/src/omega_gpu_q38_graph.c
index ad10394e..91af6f52 100644
--- a/src/omega_gpu_q38_graph.c
+++ b/src/omega_gpu_q38_graph.c
@@ -54,6 +54,8 @@ struct OmegaGpuQ38Graph {
     Kern exact_scale, exact_bound;
     uint64_t exact_info[192];
     int exact_on;
+    int sampling;                        /* 1: logits will be sampled; exact head must stay off */
+    int exact_logits;                    /* last record_final wrote masked exact-head logits */
     /* token state */
     int in_token, failed;
     int xq_layer;                        /* layer whose input-norm x' sits in xq, -1 none */
@@ -250,7 +252,8 @@ uint64_t omega_gpu_q38_exact_extra_bytes(void) {
 }
 int omega_gpu_q38_graph_set_exact_head(OmegaGpuQ38Graph *g, const OmegaGpuFp8Tensor *head,
                                       const float *coef, uint32_t roundings) {
-    if (!g || !head || !coef || g->in_token || !g->final_set || g->exact8 || g->head8 ||
+    /* sampling is checked before shape_is so a host test can refuse a dummy head without a device */
+    if (!g || !head || !coef || g->in_token || !g->final_set || g->exact8 || g->head8 || g->sampling ||
         !shape_is(head, g->cfg.vocab, H) || g->cfg.eps != 1e-6f) return OMEGA_GPU_DGRAPH_BAD_ARGS;
     uint64_t m[16]={1,g->cfg.vocab},result=0,entry[2];
     if (omega_q38_runtime(&result,m,16,cpu_of(g,g->lo.fnorm),H*4,g->exact_info,192) || result!=1 ||
@@ -284,8 +287,17 @@ int omega_gpu_q38_graph_set_exact_head(OmegaGpuQ38Graph *g, const OmegaGpuFp8Ten
     } else {g->exact8=head;g->exact_on=1;}
     omega_gpu_session_unlock();return rc;
 }
-void omega_gpu_q38_graph_set_exact_head_on(OmegaGpuQ38Graph *g,int on) {
-    if(g && !g->in_token)g->exact_on=on && g->exact8;
+int omega_gpu_q38_graph_set_exact_head_on(OmegaGpuQ38Graph *g,int on) {
+    if(!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS;
+    if(on && g->sampling) return OMEGA_GPU_DGRAPH_BAD_ARGS;
+    g->exact_on=on && g->exact8;
+    return OMEGA_GPU_DGRAPH_OK;
+}
+int omega_gpu_q38_graph_set_sampling(OmegaGpuQ38Graph *g, int on) {
+    if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS;
+    if (on && g->exact_on) return OMEGA_GPU_DGRAPH_BAD_ARGS;
+    g->sampling = on ? 1 : 0;
+    return OMEGA_GPU_DGRAPH_OK;
 }
 int omega_gpu_q38_graph_exact_head_active(const OmegaGpuQ38Graph *g) {return g && g->exact8 && g->exact_on;}
 
@@ -477,14 +489,19 @@ int omega_gpu_q38_graph_record_final(OmegaGpuQ38Graph *g) {
     if (!g || !g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS;
     if (g->failed) return OMEGA_GPU_DGRAPH_CHIP_FAIL;
     if (!g->final_set) return fail(g, "q38 graph: final norm not set", OMEGA_GPU_DGRAPH_BAD_ARGS);
+    if (g->exact_on && g->sampling)
+        return fail(g, "q38 graph: exact head masks logits; sampling is on", OMEGA_GPU_DGRAPH_BAD_ARGS);
     const uint64_t x = va_of(g, g->lo.x), hidden = va_of(g, g->lo.hidden), logits = va_of(g, g->lo.logits), token = va_of(g, g->lo.token);
     int rc = OMEGA_GPU_DGRAPH_OK;
     if (!g->hidden_ready) rc = rec_res(g, K_NORM, x, 0, va_of(g, g->lo.fnorm), hidden, g->head8 ? SCALE_2P64 : 1.0f);
-    if (rc == OMEGA_GPU_DGRAPH_OK && g->exact_on)
+    if (rc == OMEGA_GPU_DGRAPH_OK && g->exact_on) {
+        g->exact_logits = 1;
         rc = rec_exact_head(g,hidden,logits);
-    else if (rc == OMEGA_GPU_DGRAPH_OK)
+    } else if (rc == OMEGA_GPU_DGRAPH_OK) {
         rc = g->head8 ? rec_fp8(g, OMEGA_GPU_Q38_K_LM_HEAD, g->head8, va_of(g, g->lo.tabs) + (uint64_t)g->cfg.layers * 64u, hidden, logits)
                       : after_op(g, OMEGA_GPU_Q38_K_LM_HEAD, omega_gpu_bf16_gemv_record(g->cl, g->cfg.lm_head, hidden, logits));
+        if (rc == OMEGA_GPU_DGRAPH_OK) g->exact_logits = 0;
+    }
     uint32_t a0[OMEGA_DEC_AM_WORDS], a1[OMEGA_DEC_AM_WORDS]; memset(a0, 0, sizeof a0); memset(a1, 0, sizeof a1);
     const uint64_t amv = va_of(g, g->lo.am_v), ami = va_of(g, g->lo.am_i);
     put64(a0, OMEGA_DEC_AM_V, logits); put64(a0, OMEGA_DEC_AM_I, 0); put64(a0, OMEGA_DEC_AM_OV, amv); put64(a0, OMEGA_DEC_AM_OI, ami);
@@ -526,6 +543,8 @@ int omega_gpu_q38_graph_token(OmegaGpuQ38Graph *g, const float *x_embed, uint32_
 
 int omega_gpu_q38_graph_read(OmegaGpuQ38Graph *g, float *x, float *hidden, float *logits) {
     if (!g || g->in_token) return OMEGA_GPU_DGRAPH_BAD_ARGS;
+    /* Masked exact-head logits are not a distribution. Sampling must not read them. */
+    if (logits && g->sampling && g->exact_logits) return OMEGA_GPU_DGRAPH_BAD_ARGS;
     omega_gpu_session_lock();
     int rc = omega_gpu_session_sync_to_cpu(&g->buf) == 0 ? OMEGA_GPU_DGRAPH_OK : OMEGA_GPU_DGRAPH_CHIP_FAIL;
     if (rc == OMEGA_GPU_DGRAPH_OK) {
@@ -584,3 +603,31 @@ const char *omega_gpu_q38_graph_kind_name(uint8_t kind) {
                                                               "gate_up", "swiglu", "down", "lm_head", "argmax" };
     return kind < OMEGA_GPU_Q38_K_COUNT ? names[kind] : "?";
 }
+
+/* Stack object only. The dummy head is never dereferenced: sampling is refused first. */
+int omega_gpu_q38_graph_test_sampling_guard(void) {
+    OmegaGpuQ38Graph g;
+    float coef = 0.f, logit = 1.f;
+    const OmegaGpuFp8Tensor *head = (const OmegaGpuFp8Tensor *)(uintptr_t)1;
+    memset(&g, 0, sizeof g);
+    if (omega_gpu_q38_graph_set_sampling(NULL, 1) != OMEGA_GPU_DGRAPH_BAD_ARGS) return 1;
+    if (omega_gpu_q38_graph_set_exact_head_on(NULL, 1) != OMEGA_GPU_DGRAPH_BAD_ARGS) return 2;
+    g.exact8 = head;
+    if (omega_gpu_q38_graph_set_exact_head_on(&g, 1) != OMEGA_GPU_DGRAPH_OK || !g.exact_on) return 3;
+    if (omega_gpu_q38_graph_set_sampling(&g, 1) != OMEGA_GPU_DGRAPH_BAD_ARGS || g.sampling) return 4;
+    if (omega_gpu_q38_graph_set_exact_head_on(&g, 0) != OMEGA_GPU_DGRAPH_OK || g.exact_on) return 5;
+    if (omega_gpu_q38_graph_set_sampling(&g, 1) != OMEGA_GPU_DGRAPH_OK || !g.sampling) return 6;
+    if (omega_gpu_q38_graph_set_exact_head_on(&g, 1) != OMEGA_GPU_DGRAPH_BAD_ARGS || g.exact_on) return 7;
+    g.final_set = 1;
+    g.exact8 = NULL;
+    if (omega_gpu_q38_graph_set_exact_head(&g, head, &coef, 10384) != OMEGA_GPU_DGRAPH_BAD_ARGS || g.exact8 || g.exact_on)
+        return 8;
+    g.exact_on = 1;
+    g.in_token = 1;
+    if (omega_gpu_q38_graph_record_final(&g) != OMEGA_GPU_DGRAPH_BAD_ARGS || !g.failed) return 9;
+    g.in_token = 0;
+    g.failed = 0;
+    g.exact_logits = 1;
+    if (omega_gpu_q38_graph_read(&g, NULL, NULL, &logit) != OMEGA_GPU_DGRAPH_BAD_ARGS || logit != 1.f) return 10;
+    return 0;
+}
diff --git a/src/omega_gpu_q38_graph.h b/src/omega_gpu_q38_graph.h
index 30ae934b..e54192c0 100644
--- a/src/omega_gpu_q38_graph.h
+++ b/src/omega_gpu_q38_graph.h
@@ -94,11 +94,15 @@ int omega_gpu_q38_graph_set_lm_head_fp8(OmegaGpuQ38Graph *g, const OmegaGpuFp8Te
 /* Experimental greedy-only exact recheck. The head and finite nonnegative row coefficients
  * must describe the same compact screen; roundings must equal the Omega plan's 10384.
  * The graph copies coefficients and borrows head. Install after final_norm, before tokens.
- * The original head is retained. Disable for sampled requests needing all logits. */
+ * The original head is retained. Masked logits are not a distribution: sampling must be off
+ * while the exact head is on (omega_gpu_q38_graph_set_sampling refuses that pair, and
+ * graph_read refuses a logits pointer when sampling is on and the last token wrote the mask). */
 int omega_gpu_q38_graph_set_exact_head(OmegaGpuQ38Graph *g, const OmegaGpuFp8Tensor *head,
                                       const float *coef, uint32_t roundings);
 uint64_t omega_gpu_q38_exact_extra_bytes(void);
-void omega_gpu_q38_graph_set_exact_head_on(OmegaGpuQ38Graph *g, int on);
+int omega_gpu_q38_graph_set_exact_head_on(OmegaGpuQ38Graph *g, int on); /* BAD_ARGS if sampling is on */
+/* 1: this graph's logits will be sampled. BAD_ARGS while the exact head is on. */
+int omega_gpu_q38_graph_set_sampling(OmegaGpuQ38Graph *g, int on);
 int omega_gpu_q38_graph_exact_head_active(const OmegaGpuQ38Graph *g);
 /* GDN layers record the a|b GEMV first and the mix GEMV beside it (no barrier between the two; both only read xq), process-wide.
  * 1 (default) or 0 (mix then a|b, each behind a barrier); env AIEN_OMEGA_Q38_OVERLAP_AB when never set. Values are identical. */
@@ -111,7 +115,8 @@ int omega_gpu_q38_graph_begin_token(OmegaGpuQ38Graph *g, const float *x_embed);
 int omega_gpu_q38_graph_record_layer(OmegaGpuQ38Graph *g, uint32_t layer, uint32_t pos);
 int omega_gpu_q38_graph_record_final(OmegaGpuQ38Graph *g);
 int omega_gpu_q38_graph_end_token(OmegaGpuQ38Graph *g, uint32_t *token, OmegaGpuDecodeGraphStats *st);
-/* Takes the lock; copies the device x, hidden and logits (vocab values) of the last token; any pointer may be NULL. */
+/* Takes the lock; copies the device x, hidden and logits (vocab values) of the last token; any pointer may be NULL.
+ * Refuses the logits pointer when sampling is on and the last record_final wrote masked exact-head logits. */
 int omega_gpu_q38_graph_read(OmegaGpuQ38Graph *g, float *x, float *hidden, float *logits);
 /* Test and trace reads of one intermediate of the last token (f32, n values from the start of the buffer). */
 enum { OMEGA_GPU_Q38_BUF_X, OMEGA_GPU_Q38_BUF_XQ, OMEGA_GPU_Q38_BUF_MIX, OMEGA_GPU_Q38_BUF_AB, OMEGA_GPU_Q38_BUF_AGG,
@@ -134,6 +139,8 @@ const char *omega_gpu_q38_graph_kind_name(uint8_t kind);
 void omega_gpu_q38_graph_set_flush_each(OmegaGpuQ38Graph *g, int on);
 /* TEST ONLY: 1 SWIGLU up half off by one, 2 GATHER index + 1, 3 GATE dropped, 4 post-norm without its weight. 0 none. */
 void omega_gpu_q38_graph_test_set_mutant(OmegaGpuQ38Graph *g, int mutant);
+/* TEST ONLY: exact head and sampling refuse each other, and a logits read of a masked buffer refuses. No device. 0 pass. */
+int omega_gpu_q38_graph_test_sampling_guard(void);
 
 #ifdef __cplusplus
 }
diff --git a/tests/gpu_q38_graph_test.c b/tests/gpu_q38_graph_test.c
index 81b5b344..9f33abfc 100644
--- a/tests/gpu_q38_graph_test.c
+++ b/tests/gpu_q38_graph_test.c
@@ -227,6 +227,7 @@ static int host_only(void) {
     OmegaGpuQ38GraphConfig c; memset(&c, 0, sizeof c);
     CHECK(omega_gpu_q38_graph_create(&c, &g) == OMEGA_GPU_DGRAPH_BAD_ARGS && !g, "create refuses an empty config");
     CHECK(omega_gpu_q38_graph_create(NULL, &g) == OMEGA_GPU_DGRAPH_BAD_ARGS, "create refuses NULL");
+    CHECK(omega_gpu_q38_graph_test_sampling_guard() == 0, "exact head refuses sampling, and a masked logits read refuses");
     return g_failed ? 1 : 0;
 }