scarlett: keep refusal reasons for cached refusals #129

Manually merged
github merged 1 commit from gh-pr/129/head into gh-pr/129/base 2026-11-26 06:33:11 +00:00
Owner

@⁠absceptual on GitHub · 2026-11-25 00:38 UTC · original
absceptual:scarlett/cached-refusal-reasons → main · +138 −17 · 9 files · 1 commits · merged 2026-11-25 00:39 UTC

An .unsupported marker holds only the request key. Once a refusal is cached, every later preparation reports it as cached_reason_unavailable, so a warm run cannot rank its refusals. In #39, the 3,966 preparation refusals in a tester's log could not be ranked for this reason, and the tester was asked to run a separate emitter pass with tools/triage_scarlett_shaders.py instead.

This change keeps the reason with the marker:

  • When xshader refuses a request (exit 65), compile_request writes the emitter's last stderr line to <key>.reason, capped at 512 bytes, and then publishes the marker. xshader prints the refusal as that last line.
  • On a cached refusal, compile_request reads <key>.reason without following links and raises ShaderRefused(reason, cached=True, remembered=True). refusal_bucket and the top-ten reason list in preparation use it like a fresh refusal.
  • The .unsupported marker still contains exactly the key, so the D3D12 provider's cached_refusal check is unchanged.
  • A marker without a usable reason file (one written by an older build, one over 512 bytes, or a symlink) is still reported as cached_reason_unavailable.
  • The preparation summary now reads "N with a reason, M cached before reasons were kept" instead of "N new, M cached (reason unavailable)", because cached refusals can now have reasons.
  • normalize_refusal and refusal_detail each had a copy of the code that strips the xshader failed (65): prefix and takes the last line. Both now call refusal_line in shader_diagnostics, which the new code also uses.

The reason file stays in the local cache. The aggregate line still prints only fixed bucket labels, and the top-ten list prints normalized reasons as it already did for fresh refusals. docs/PROJECTSCARLETT.md is updated to match.

Tests: tests/test_refusal_reasons.py checks that a warm refusal keeps the same bucket as the fresh one without running xshader again, that the marker still holds only the key, that a missing, oversized or symlinked reason file falls back to cached_reason_unavailable, and that a long reason is capped. The expected bucket in test_runtime_shader_links and the summary text in test_scarlett_prep are updated. On macOS, python -m unittest discover -s tests -q gives the same result as main (75fdeba): two existing errors, in test_shader_inventory and test_prep_jobs_defaults_and_bounds, and 70 Linux-only skips. With sys.platform forced to linux, test_runtime_shader_links, test_shader_prep, test_chase_warmup, test_scarlett_prep, test_runtime_shader_workers and test_dxil_store pass 43 of 44, and the one error (sched_getaffinity in the worker test that counts jobs) also happens on main. I have not run this on Linux or against recorded ProjectScarlett requests.

🤖 Generated with Claude Code

**@⁠absceptual** on GitHub · 2026-11-25 00:38 UTC · [original](https://github.com/brcly/TuxBox/pull/129) `absceptual:scarlett/cached-refusal-reasons` → `main` · +138 −17 · 9 files · 1 commits · merged 2026-11-25 00:39 UTC An `.unsupported` marker holds only the request key. Once a refusal is cached, every later preparation reports it as `cached_reason_unavailable`, so a warm run cannot rank its refusals. In #39, the 3,966 preparation refusals in a tester's log could not be ranked for this reason, and the tester was asked to run a separate emitter pass with `tools/triage_scarlett_shaders.py` instead. This change keeps the reason with the marker: - When xshader refuses a request (exit 65), `compile_request` writes the emitter's last stderr line to `<key>.reason`, capped at 512 bytes, and then publishes the marker. xshader prints the refusal as that last line. - On a cached refusal, `compile_request` reads `<key>.reason` without following links and raises `ShaderRefused(reason, cached=True, remembered=True)`. `refusal_bucket` and the top-ten reason list in preparation use it like a fresh refusal. - The `.unsupported` marker still contains exactly the key, so the D3D12 provider's `cached_refusal` check is unchanged. - A marker without a usable reason file (one written by an older build, one over 512 bytes, or a symlink) is still reported as `cached_reason_unavailable`. - The preparation summary now reads "N with a reason, M cached before reasons were kept" instead of "N new, M cached (reason unavailable)", because cached refusals can now have reasons. - `normalize_refusal` and `refusal_detail` each had a copy of the code that strips the `xshader failed (65):` prefix and takes the last line. Both now call `refusal_line` in `shader_diagnostics`, which the new code also uses. The reason file stays in the local cache. The aggregate line still prints only fixed bucket labels, and the top-ten list prints normalized reasons as it already did for fresh refusals. docs/PROJECTSCARLETT.md is updated to match. Tests: `tests/test_refusal_reasons.py` checks that a warm refusal keeps the same bucket as the fresh one without running xshader again, that the marker still holds only the key, that a missing, oversized or symlinked reason file falls back to `cached_reason_unavailable`, and that a long reason is capped. The expected bucket in `test_runtime_shader_links` and the summary text in `test_scarlett_prep` are updated. On macOS, `python -m unittest discover -s tests -q` gives the same result as `main` (75fdeba): two existing errors, in `test_shader_inventory` and `test_prep_jobs_defaults_and_bounds`, and 70 Linux-only skips. With `sys.platform` forced to `linux`, `test_runtime_shader_links`, `test_shader_prep`, `test_chase_warmup`, `test_scarlett_prep`, `test_runtime_shader_workers` and `test_dxil_store` pass 43 of 44, and the one error (`sched_getaffinity` in the worker test that counts jobs) also happens on `main`. I have not run this on Linux or against recorded ProjectScarlett requests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
An .unsupported marker holds only the request key, so every warm run
reported its refusals as cached_reason_unavailable and they could not be
ranked without a separate triage pass.

Write the emitter's one-line reason to <key>.reason before the marker and
read it back on a cached refusal, so warm and cold runs give the same
bucket. The marker format the D3D12 provider reads is unchanged, and
markers without a reason file are still reported as unavailable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:33:09 +00:00
github manually merged commit 5d2b59dd67 into gh-pr/129/base 2026-11-26 06:33:10 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.