tools/startup: add redacted 1-run telemetry summarizer (triage_run.py) #1457

Merged
tedin7 merged 4 commits from upstream-pr/1464 into main 2026-11-24 12:49:00 +00:00
tedin7 commented 2026-11-24 11:58:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:58:20Z.


Add tools/startup/triage_run.py, a zero-dependency Python 3 CLI tool that summarizes a startup log directory (and optional --shader-cache DIR) into a path-redacted, address-redacted, title-neutral Markdown report for issue triage.

What it summarizes

  • Device::slot70 memory SRV refusals grouped by (reason, dim, fmt, view_dim, view_fmt, layout, flags) (stripping raw guest addresses and pointers)
  • Unhandled/stubbed x2w-d3d12 / x2w-trap / x2w-noop calls and x2w-d3d12-debug messages
  • x2w-dstorage failure outcomes, entry/OpenFile/zlib failures, and StatusArray::GetHResult / EnqueueSignal HRESULT counts
  • x2w-runtime / x2w-api failing methods and HRESULTs
  • X2W_SHADER_CACHE .fail Unsupported(...) / fxc reasons when --shader-cache is supplied

Strict redaction

Redacts Windows drive/UNC paths, POSIX local paths, *.exe filenames, and 64-bit hex addresses (0x[0-9a-fA-F]{9,}).

Verification

  • Linux: python3 -B tests/startup_triage_run_check.py (0 failed), python3 -B tests/docs_links_check.py, python3 -B tests/bidi_controls_check.py, git diff --check origin/main..HEAD
  • CTest (startup_triage_run) and .github/workflows/windows.yml Python checks wired; Win2025 verification pending.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6581236248 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:58:20Z. --- Add `tools/startup/triage_run.py`, a zero-dependency Python 3 CLI tool that summarizes a startup log directory (and optional `--shader-cache DIR`) into a path-redacted, address-redacted, title-neutral Markdown report for issue triage. ### What it summarizes - `Device::slot70` memory SRV refusals grouped by `(reason, dim, fmt, view_dim, view_fmt, layout, flags)` (stripping raw guest addresses and pointers) - Unhandled/stubbed `x2w-d3d12` / `x2w-trap` / `x2w-noop` calls and `x2w-d3d12-debug` messages - `x2w-dstorage` failure outcomes, entry/OpenFile/zlib failures, and `StatusArray::GetHResult` / `EnqueueSignal` HRESULT counts - `x2w-runtime` / `x2w-api` failing methods and HRESULTs - `X2W_SHADER_CACHE` `.fail` `Unsupported(...)` / `fxc` reasons when `--shader-cache` is supplied ### Strict redaction Redacts Windows drive/UNC paths, POSIX local paths, `*.exe` filenames, and 64-bit hex addresses (`0x[0-9a-fA-F]{9,}`). ### Verification - Linux: `python3 -B tests/startup_triage_run_check.py` (`0 failed`), `python3 -B tests/docs_links_check.py`, `python3 -B tests/bidi_controls_check.py`, `git diff --check origin/main..HEAD` - CTest (`startup_triage_run`) and `.github/workflows/windows.yml` Python checks wired; Win2025 verification pending. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 12:03:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:02:50Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit c44bd0ad785cc4a01110bd05360710fdf3a498f0:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev -- -j 6): 103.03s (configure 1.70s)
    • Test (ctest --preset dev -R '^startup_triage_run$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.23s: startup_triage_run 0.16s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release -- -j 6): 125.84s (configure 1.74s)
    • Test (ctest --preset release -R '^startup_triage_run$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.24s: startup_triage_run 0.16s)
  • sccache: 550/860 hits; wall 238.4s
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7130887558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#issuecomment-7130887558). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:02:50Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `c44bd0ad785cc4a01110bd05360710fdf3a498f0`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev -- -j 6`): `103.03s` (configure `1.70s`) - Test (`ctest --preset dev -R '^startup_triage_run$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.23s`: `startup_triage_run` `0.16s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release -- -j 6`): `125.84s` (configure `1.74s`) - Test (`ctest --preset release -R '^startup_triage_run$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.24s`: `startup_triage_run` `0.16s`) - `sccache`: 550/860 hits; wall `238.4s`
upstream-sync closed this pull request 2026-11-24 13:00:38 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 13:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:10:21Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c44bd0ad78

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6038940957 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#pullrequestreview-6038940957). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T12:10:21Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `c44bd0ad78` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-24 13:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:16:29Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039030472 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#pullrequestreview-6039030472). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:16:29Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 13:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:16:33Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039031229 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#pullrequestreview-6039031229). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:16:33Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-24 13:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:16:37Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039032029 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#pullrequestreview-6039032029). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:16:37Z. **Review:** COMMENTED --- _No description provided._
R0Y00 commented 2026-11-24 13:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:17:34Z.

Review: CHANGES_REQUESTED


The summary is described as ready for a public issue, but it still emits arbitrary debug text, shader failure lines and several untyped field values. Regex redaction cannot establish that those strings contain only public evidence. Please make the default report allowlist structured values such as known reasons, numeric format categories, counts, diagnostic IDs and status codes, grouping unknown text without copying it. Add a synthetic control with a bare private module name, an unprefixed address, an opaque object name and a Markdown link. Keep raw snippets local.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039044348 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#pullrequestreview-6039044348). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T12:17:34Z. **Review:** CHANGES_REQUESTED --- The summary is described as ready for a public issue, but it still emits arbitrary debug text, shader failure lines and several untyped field values. Regex redaction cannot establish that those strings contain only public evidence. Please make the default report allowlist structured values such as known reasons, numeric format categories, counts, diagnostic IDs and status codes, grouping unknown text without copying it. Add a synthetic control with a bare private module name, an unprefixed address, an opaque object name and a Markdown link. Keep raw snippets local.
R0Y00 commented 2026-11-24 13:00:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T12:43:52Z.

Review: APPROVED


The allowlist export passes the synthetic privacy tests. I added controls for a long numeral in a slot field and an address-shaped value in a status field. Both are omitted. Short and correctly sign-extended HRESULTs still combine. The triage, docs links, and bidi checks passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6039395896 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#pullrequestreview-6039395896). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T12:43:52Z. **Review:** APPROVED --- The allowlist export passes the synthetic privacy tests. I added controls for a long numeral in a slot field and an address-shaped value in a status field. Both are omitted. Short and correctly sign-extended HRESULTs still combine. The triage, docs links, and bidi checks passed.
chatgpt-codex-connector[bot commented 2026-11-24 13:00:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:10:26Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T12:10:24.652915Z c44bd0a Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131068383 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#issuecomment-7131068383). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T12:10:26Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"c44bd0ad785cc4a01110bd05360710fdf3a498f0","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T12:10:24.652915Z">2026-11-24T12:10:24.652915Z</relative-time> | `c44bd0a` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
tedin7 commented 2026-11-24 13:00:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:26:13Z.


Fixed in 71ec5842ed: the report is now allowlist-only. It copies just known slot70 reasons and dstorage outcomes, decimal IDs and counts, hex HRESULT/format/flag codes, slot numbers, trap tags, and shader-failure categories (for mnemonics only the family prefix, e.g. v_*). Debug messages are reduced to severity/ID counts, with no context or message text. View-skipped, device-removed, entry-failed, OpenFile and runtime rows no longer carry free text, module names or object prefixes. Anything unrecognised is grouped as other (text omitted). The default redaction regexes are removed, and the docs now describe the allowlist contract.

New synthetic control in tests/startup_triage_run_check.py covers a bare private module name, an unprefixed address, an opaque object name, a Markdown link, and free-form debug/dstorage/shader text; none of it appears in the output.

Local: startup_triage_run_check, docs_links_check, bidi_controls_check, git diff --check and preflight pass. Windows Server 2025: Debug and Release /O2 startup_triage_run 1/1 passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7131436657 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#issuecomment-7131436657). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:26:13Z. --- Fixed in 71ec5842ed23644e8ddabdd88ca7175645a66e20: the report is now allowlist-only. It copies just known slot70 reasons and dstorage outcomes, decimal IDs and counts, hex HRESULT/format/flag codes, slot numbers, trap tags, and shader-failure categories (for mnemonics only the family prefix, e.g. `v_*`). Debug messages are reduced to severity/ID counts, with no context or message text. View-skipped, device-removed, entry-failed, OpenFile and runtime rows no longer carry free text, module names or object prefixes. Anything unrecognised is grouped as `other (text omitted)`. The default redaction regexes are removed, and the docs now describe the allowlist contract. New synthetic control in `tests/startup_triage_run_check.py` covers a bare private module name, an unprefixed address, an opaque object name, a Markdown link, and free-form debug/dstorage/shader text; none of it appears in the output. Local: startup_triage_run_check, docs_links_check, bidi_controls_check, `git diff --check` and preflight pass. Windows Server 2025: Debug and Release /O2 `startup_triage_run` 1/1 passed.
chatgpt-codex-connector[bot commented 2026-11-24 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:10:21Z.

Code review location: tools/startup/triage_run.py; line 34

@@ -0,0 +1,497 @@
+#!/usr/bin/env python3
+"""Summarize a startup log directory (and optional shader cache) into redacted Markdown.
+
+Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a
+title-neutral, path-redacted, address-redacted Markdown summary suitable for a
+GitHub issue. Uses only the Python 3 standard library.
+"""
+
+from __future__ import annotations
+
+import argparse
+from collections import Counter
+from pathlib import Path
+import re
+import sys
+from typing import Iterable
+
+
+LOG_EXTENSIONS = {".txt", ".log", ".out"}
+
+DSTORAGE_OK_OUTCOMES = {
+    "done",
+    "empty",
+    "inflated",
+    "inflated (larger/short)",
+    "inflated (chunked stream piece 0)",
+    "inflated (slice from stream cache)",
+    "bcpack decoded",
+    "inflated + bcpack decoded",
+}
+
+# Redaction patterns (applied in order from most specific/broadest path to tokens).
+RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"')
+RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)')

P1 Badge Redact complete diagnostic paths containing spaces

For a shader .fail line such as fxc ps: C:\Users\Alice Smith\PrivateTitle\shader.hlsl(1,1): error X3000, this regex stops at the first space, leaving <path> Smith\PrivateTitle\shader.hlsl(1,1): error X3000 in the report. gfx2hlsl.translate_to() writes compiler stderr verbatim into these files, so a cache path containing spaces can expose personal and title-specific directories in the supposedly path-redacted, title-neutral report intended for public issues. Redact the whole diagnostic path rather than only its first whitespace-delimited fragment.

AGENTS.md reference: AGENTS.md:L23-L24

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679774263 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#discussion_r4679774263). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T12:10:21Z. **Code review location:** `tools/startup/triage_run.py`; line 34 ~~~~diff @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""Summarize a startup log directory (and optional shader cache) into redacted Markdown. + +Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a +title-neutral, path-redacted, address-redacted Markdown summary suitable for a +GitHub issue. Uses only the Python 3 standard library. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys +from typing import Iterable + + +LOG_EXTENSIONS = {".txt", ".log", ".out"} + +DSTORAGE_OK_OUTCOMES = { + "done", + "empty", + "inflated", + "inflated (larger/short)", + "inflated (chunked stream piece 0)", + "inflated (slice from stream cache)", + "bcpack decoded", + "inflated + bcpack decoded", +} + +# Redaction patterns (applied in order from most specific/broadest path to tokens). +RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"') +RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)') ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Redact complete diagnostic paths containing spaces** For a shader `.fail` line such as `fxc ps: C:\Users\Alice Smith\PrivateTitle\shader.hlsl(1,1): error X3000`, this regex stops at the first space, leaving `<path> Smith\PrivateTitle\shader.hlsl(1,1): error X3000` in the report. `gfx2hlsl.translate_to()` writes compiler stderr verbatim into these files, so a cache path containing spaces can expose personal and title-specific directories in the supposedly path-redacted, title-neutral report intended for public issues. Redact the whole diagnostic path rather than only its first whitespace-delimited fragment. AGENTS.md reference: [AGENTS.md:L23-L24](https://github.com/R0Y00/Xbox2Windows/blob/c44bd0ad785cc4a01110bd05360710fdf3a498f0/AGENTS.md#L23-L24) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:10:21Z.

Code review location: tools/startup/triage_run.py; line 459

@@ -0,0 +1,497 @@
+#!/usr/bin/env python3
+"""Summarize a startup log directory (and optional shader cache) into redacted Markdown.
+
+Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a
+title-neutral, path-redacted, address-redacted Markdown summary suitable for a
+GitHub issue. Uses only the Python 3 standard library.
+"""
+
+from __future__ import annotations
+
+import argparse
+from collections import Counter
+from pathlib import Path
+import re
+import sys
+from typing import Iterable
+
+
+LOG_EXTENSIONS = {".txt", ".log", ".out"}
+
+DSTORAGE_OK_OUTCOMES = {
+    "done",
+    "empty",
+    "inflated",
+    "inflated (larger/short)",
+    "inflated (chunked stream piece 0)",
+    "inflated (slice from stream cache)",
+    "bcpack decoded",
+    "inflated + bcpack decoded",
+}
+
+# Redaction patterns (applied in order from most specific/broadest path to tokens).
+RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"')
+RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)')
+RE_QUOTED_POSIX_PATH = re.compile(
+    r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"'
+)
+RE_POSIX_PATH = re.compile(
+    r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+'
+)
+RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE)
+RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b')
+
+# Log line patterns matching src/startup_stubs/*.
+RE_SLOT70 = re.compile(
+    r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}'
+)
+RE_KV = re.compile(r'(\w+)=([^\s}]+)')
+
+RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)')
+RE_D3D12_PIPELINE_TRAP = re.compile(
+    r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)'
+)
+RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:')
+RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$')
+RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b')
+RE_D3D12_REMOVED = re.compile(
+    r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$'
+)
+RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$')
+
+RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$')
+RE_DSTORAGE_ENTRY_FAIL = re.compile(
+    r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$'
+)
+RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$')
+RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$')
+RE_DSTORAGE_HRESULT = re.compile(
+    r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_DSTORAGE_SIGNAL = re.compile(
+    r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)'
+)
+
+RE_RUNTIME_CALL = re.compile(
+    r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_STORAGE = re.compile(
+    r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_GAMESAVE = re.compile(
+    r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)'
+)
+
+
+def redact(text: str) -> str:
+    """Strip local paths, executable names, and 64-bit addresses from a log snippet."""
+    out = RE_QUOTED_WIN_PATH.sub('"<path>"', text)
+    out = RE_WIN_PATH.sub("<path>", out)
+    out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out)
+    out = RE_POSIX_PATH.sub("<path>", out)
+    out = RE_EXE_NAME.sub("<exe>", out)
+    out = RE_ADDR64.sub("0x<addr>", out)
+    return out
+
+
+def _md_cell(value: object) -> str:
+    return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ")
+
+
+def _parse_kv_block(block: str) -> dict[str, str]:
+    if block.strip() == "unreadable":
+        return {"_unreadable": "1"}
+    return dict(RE_KV.findall(block))
+
+
+def _is_failed_hresult(hex_text: str) -> tuple[bool, str]:
+    val = int(hex_text, 16) & 0xFFFFFFFF
+    return (val & 0x80000000) != 0, f"0x{val:08x}"
+
+
+def iter_log_files(log_target: Path) -> list[Path]:
+    """Return sorted log files under log_target (or [log_target] if it is a file)."""
+    if not log_target.exists():
+        return []
+    if log_target.is_file():
+        return [log_target]
+    if not log_target.is_dir():
+        return []
+    files = [
+        p
+        for p in log_target.rglob("*")
+        if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS
+    ]
+    files.sort()
+    return files
+
+
+def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]:
+    """Aggregate startup telemetry counters from an iterable of log lines."""
+    slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter()
+    d3d12_unhandled: Counter[str] = Counter()
+    d3d12_debug: Counter[tuple[str, str, str, str]] = Counter()
+    dstorage_failures: Counter[str] = Counter()
+    dstorage_hresults: Counter[str] = Counter()
+    runtime_failures: Counter[tuple[str, str]] = Counter()
+
+    for raw_line in lines:
+        line = raw_line.strip()
+        if not line:
+            continue
+
+        # 1. slot70 memory SRV refusals
+        m = RE_SLOT70.search(line)
+        if m:
+            reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3)
+            res = _parse_kv_block(res_raw)
+            view = _parse_kv_block(view_raw)
+            if "_unreadable" in res:
+                dim = fmt = layout = flags = "unreadable"
+            else:
+                dim = res.get("dim", "?")
+                fmt = res.get("fmt", "?")
+                layout = res.get("layout", "?")
+                flags = res.get("flags", "?")
+            if "_unreadable" in view:
+                view_dim = view_fmt = "unreadable"
+            else:
+                view_dim = view.get("dim", "?")
+                view_fmt = view.get("fmt", "?")
+            slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1
+            continue
+
+        # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail
+        m = RE_TRAP_TAG.match(line)
+        if m:
+            tag, target = m.group(1), redact(m.group(2))
+            d3d12_unhandled[f"{tag} {target}"] += 1
+            continue
+
+        # 3. x2w-d3d12-debug
+        m = RE_D3D12_DEBUG.search(line)
+        if m:
+            ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4))
+            if len(msg) > 120:
+                msg = msg[:117] + "..."
+            d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1
+            continue
+
+        # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed
+        if "x2w-d3d12" in line:
+            m = RE_D3D12_REMOVED.search(line)
+            if m:
+                d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_PIPELINE_TRAP.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1
+                continue
+            m = RE_D3D12_IID_PASS.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1
+                continue
+            m = RE_D3D12_VIEW_SKIPPED.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_SLOT_CALL.search(line)
+            if m:
+                d3d12_unhandled[m.group(1)] += 1
+                continue
+
+        # 5. x2w-dstorage failures & status HRESULTs
+        if "x2w-dstorage" in line:
+            m = RE_DSTORAGE_OUTCOME.search(line)
+            if m:
+                outcome = m.group(1).strip()
+                if outcome not in DSTORAGE_OK_OUTCOMES:
+                    dstorage_failures[redact(outcome)] += 1
+                continue
+            m = RE_DSTORAGE_ENTRY_FAIL.search(line)
+            if m:
+                dstorage_failures[f"entry failed: {redact(m.group(1))}"] += 1
+                continue
+            m = RE_DSTORAGE_ZLIB_FAIL.search(line)
+            if m:
+                dstorage_failures["zlib failure"] += 1
+                continue
+            m = RE_DSTORAGE_OPENFILE_FAIL.search(line)
+            if m:
+                dstorage_failures[f"OpenFile: {redact(m.group(1))}"] += 1
+                continue
+            m = RE_DSTORAGE_HRESULT.search(line)
+            if m:
+                _, norm_hr = _is_failed_hresult(m.group(1))
+                dstorage_hresults[norm_hr] += 1
+                continue
+            m = RE_DSTORAGE_SIGNAL.search(line)
+            if m:
+                failed, norm_hr = _is_failed_hresult(m.group(1))
+                if failed:
+                    dstorage_hresults[norm_hr] += 1
+                continue
+
+        # 6. x2w-runtime / x2w-api failing methods / HRESULTs
+        if "x2w-runtime" in line or "x2w-api" in line:
+            m = RE_RUNTIME_CALL.search(line)
+            if m:
+                failed, norm_hr = _is_failed_hresult(m.group(2))
+                if failed:
+                    runtime_failures[(m.group(1), norm_hr)] += 1
+                continue
+            m = RE_RUNTIME_STORAGE.search(line)
+            if m:
+                _, norm_hr = _is_failed_hresult(m.group(1))
+                runtime_failures[("persistent_local_storage", norm_hr)] += 1
+                continue
+            m = RE_RUNTIME_GAMESAVE.search(line)
+            if m:
+                runtime_failures[("game_save_update", f"status {m.group(1)}")] += 1
+                continue
+
+    return {
+        "slot70_refusals": slot70_refusals,
+        "d3d12_unhandled": d3d12_unhandled,
+        "d3d12_debug": d3d12_debug,
+        "dstorage_failures": dstorage_failures,
+        "dstorage_hresults": dstorage_hresults,
+        "runtime_failures": runtime_failures,
+    }
+
+
+def summarize_shader_cache(cache_dir: Path | None) -> Counter[str]:
+    """Count .fail Unsupported(...) / fxc reasons in X2W_SHADER_CACHE."""
+    reasons: Counter[str] = Counter()
+    if cache_dir is None or not cache_dir.is_dir():
+        return reasons
+    for fail_path in sorted(cache_dir.glob("*.fail")):
+        try:
+            text = fail_path.read_text(encoding="utf-8", errors="replace")
+        except OSError:
+            continue
+        first_line = ""
+        for line in text.splitlines():
+            stripped = line.strip()
+            if stripped:
+                first_line = stripped
+                break
+        if not first_line:
+            first_line = "(empty .fail)"
+        cleaned = redact(first_line)
+        if len(cleaned) > 120:
+            cleaned = cleaned[:117] + "..."
+        reasons[cleaned] += 1
+    return reasons
+
+
+def _format_table(
+    headers: list[str],
+    rows: list[list[object]],
+    total_unique: int,
+    total_events: int,
+    max_items: int,
+) -> list[str]:
+    if not rows:
+        return ["_None observed._", ""]
+    lines = [
+        "| " + " | ".join(headers) + " |",
+        "| " + " | ".join(["---"] * len(headers)) + " |",
+    ]
+    for row in rows[:max_items]:
+        lines.append("| " + " | ".join(_md_cell(c) for c in row) + " |")
+    if total_unique > max_items:
+        lines.append(
+            f"_Showing top {max_items} of {total_unique} unique entries ({total_events} total events)._"
+        )
+    lines.append("")
+    return lines
+
+
+def format_markdown(
+    summary: dict[str, Counter],
+    shader_failures: Counter[str],
+    files_scanned: int,
+    shader_cache_provided: bool,
+    max_items: int,
+) -> str:
+    """Render aggregated counters as clean-room Markdown."""
+    out: list[str] = [
+        "## Startup Run Triage Summary",
+        "",
+        f"- Log files scanned: `{files_scanned}`",
+        f"- `slot70` memory SRV refusals: `{sum(summary['slot70_refusals'].values())}` "
+        f"({len(summary['slot70_refusals'])} unique)",
+        f"- `x2w-d3d12` / trap slot events: `{sum(summary['d3d12_unhandled'].values())}` "
+        f"({len(summary['d3d12_unhandled'])} unique)",
+        f"- `x2w-d3d12-debug` messages: `{sum(summary['d3d12_debug'].values())}` "
+        f"({len(summary['d3d12_debug'])} unique)",
+        f"- `x2w-dstorage` failures: `{sum(summary['dstorage_failures'].values())}` "
+        f"({len(summary['dstorage_failures'])} unique)",
+        f"- `x2w-runtime` failing calls: `{sum(summary['runtime_failures'].values())}` "
+        f"({len(summary['runtime_failures'])} unique)",
+    ]
+    if shader_cache_provided:
+        out.append(
+            f"- `X2W_SHADER_CACHE` `.fail` shaders: `{sum(shader_failures.values())}` "
+            f"({len(shader_failures)} unique reasons)"
+        )
+    out.append("")
+
+    # 1. slot70 refusals
+    out.extend(["### `Device::slot70` Memory SRV Refusals", ""])
+    s70 = summary["slot70_refusals"]
+    s70_rows = [
+        [count, reason, dim, fmt, vdim, vfmt, layout, flags]
+        for (reason, dim, fmt, vdim, vfmt, layout, flags), count in s70.most_common()
+    ]
+    out.extend(
+        _format_table(
+            ["Count", "Reason", "Res Dim", "Res Fmt", "View Dim", "View Fmt", "Layout", "Flags"],
+            s70_rows,
+            len(s70),
+            sum(s70.values()),
+            max_items,
+        )
+    )
+
+    # 2. x2w-d3d12 unhandled/stubbed calls & traps
+    out.extend(["### Unhandled / Stubbed `x2w-d3d12` & Trap Calls", ""])
+    d3d = summary["d3d12_unhandled"]
+    d3d_rows = [[count, f"`{call}`"] for call, count in d3d.most_common()]
+    out.extend(
+        _format_table(
+            ["Count", "Call / Slot"],
+            d3d_rows,
+            len(d3d),
+            sum(d3d.values()),
+            max_items,
+        )
+    )
+
+    # 3. x2w-d3d12-debug
+    dbg = summary["d3d12_debug"]
+    if dbg:
+        out.extend(["### `x2w-d3d12-debug` Messages", ""])
+        dbg_rows = [
+            [count, ctx, sev, msg_id, msg]
+            for (ctx, sev, msg_id, msg), count in dbg.most_common()
+        ]
+        out.extend(
+            _format_table(
+                ["Count", "Context", "Sev", "ID", "Message (redacted)"],
+                dbg_rows,
+                len(dbg),
+                sum(dbg.values()),
+                max_items,
+            )
+        )
+
+    # 4. x2w-dstorage failures & HRESULTs
+    out.extend(["### `x2w-dstorage` Failures & Status HRESULTs", ""])
+    ds_fail = summary["dstorage_failures"]
+    ds_rows = [[count, reason] for reason, count in ds_fail.most_common()]
+    out.extend(
+        _format_table(
+            ["Count", "Failure Reason"],
+            ds_rows,
+            len(ds_fail),
+            sum(ds_fail.values()),
+            max_items,
+        )
+    )
+    ds_hr = summary["dstorage_hresults"]
+    if ds_hr:
+        hr_rows = [[count, f"`{hr}`"] for hr, count in ds_hr.most_common()]
+        out.extend(
+            _format_table(
+                ["Count", "Status HRESULT"],
+                hr_rows,
+                len(ds_hr),
+                sum(ds_hr.values()),
+                max_items,
+            )
+        )
+
+    # 5. x2w-runtime failing methods / HRESULTs
+    out.extend(["### `x2w-runtime` Failing Methods", ""])
+    rt = summary["runtime_failures"]
+    rt_rows = [[count, f"`{method}`", f"`{hr}`"] for (method, hr), count in rt.most_common()]
+    out.extend(
+        _format_table(
+            ["Count", "Method", "HRESULT / Status"],
+            rt_rows,
+            len(rt),
+            sum(rt.values()),
+            max_items,
+        )
+    )
+
+    # 6. X2W_SHADER_CACHE .fail reasons
+    if shader_cache_provided:
+        out.extend(["### `X2W_SHADER_CACHE` `.fail` Reasons", ""])
+        sh_rows = [[count, f"`{reason}`"] for reason, count in shader_failures.most_common()]
+        out.extend(
+            _format_table(
+                ["Count", "Reason"],
+                sh_rows,
+                len(shader_failures),
+                sum(shader_failures.values()),
+                max_items,
+            )
+        )
+
+    return "\n".join(out)
+
+
+def triage_run(
+    logdir: Path,
+    shader_cache: Path | None = None,
+    max_items: int = 16,
+) -> str:
+    """Scan logdir (and optional shader_cache) and return a redacted Markdown summary."""
+    log_files = iter_log_files(logdir)
+
+    def _line_stream() -> Iterable[str]:
+        for path in log_files:
+            try:
+                with path.open("r", encoding="utf-8", errors="replace") as handle:
+                    yield from handle

P2 Badge Avoid counting mirrored log messages twice

For directories produced by run.ps1/debug_launch.py, stderr.txt and trap.log contain the same telemetry: the launcher sets X2W_TRAP_LOG while capturing stderr, and the shared and component loggers write each message to both destinations. Concatenating every discovered file therefore doubles the event counts; a synthetic run with one failed DirectStorage request mirrored in those two standard files reports two failures. Select a canonical stream per run or reconcile the mirrored sources while preserving genuine repeated calls.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679774276 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#discussion_r4679774276). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T12:10:21Z. **Code review location:** `tools/startup/triage_run.py`; line 459 ~~~~diff @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""Summarize a startup log directory (and optional shader cache) into redacted Markdown. + +Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a +title-neutral, path-redacted, address-redacted Markdown summary suitable for a +GitHub issue. Uses only the Python 3 standard library. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys +from typing import Iterable + + +LOG_EXTENSIONS = {".txt", ".log", ".out"} + +DSTORAGE_OK_OUTCOMES = { + "done", + "empty", + "inflated", + "inflated (larger/short)", + "inflated (chunked stream piece 0)", + "inflated (slice from stream cache)", + "bcpack decoded", + "inflated + bcpack decoded", +} + +# Redaction patterns (applied in order from most specific/broadest path to tokens). +RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"') +RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)') +RE_QUOTED_POSIX_PATH = re.compile( + r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"' +) +RE_POSIX_PATH = re.compile( + r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+' +) +RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE) +RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b') + +# Log line patterns matching src/startup_stubs/*. +RE_SLOT70 = re.compile( + r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}' +) +RE_KV = re.compile(r'(\w+)=([^\s}]+)') + +RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)') +RE_D3D12_PIPELINE_TRAP = re.compile( + r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)' +) +RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:') +RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$') +RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b') +RE_D3D12_REMOVED = re.compile( + r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$' +) +RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$') + +RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$') +RE_DSTORAGE_ENTRY_FAIL = re.compile( + r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$' +) +RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$') +RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$') +RE_DSTORAGE_HRESULT = re.compile( + r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_DSTORAGE_SIGNAL = re.compile( + r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)' +) + +RE_RUNTIME_CALL = re.compile( + r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_STORAGE = re.compile( + r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_GAMESAVE = re.compile( + r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)' +) + + +def redact(text: str) -> str: + """Strip local paths, executable names, and 64-bit addresses from a log snippet.""" + out = RE_QUOTED_WIN_PATH.sub('"<path>"', text) + out = RE_WIN_PATH.sub("<path>", out) + out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out) + out = RE_POSIX_PATH.sub("<path>", out) + out = RE_EXE_NAME.sub("<exe>", out) + out = RE_ADDR64.sub("0x<addr>", out) + return out + + +def _md_cell(value: object) -> str: + return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ") + + +def _parse_kv_block(block: str) -> dict[str, str]: + if block.strip() == "unreadable": + return {"_unreadable": "1"} + return dict(RE_KV.findall(block)) + + +def _is_failed_hresult(hex_text: str) -> tuple[bool, str]: + val = int(hex_text, 16) & 0xFFFFFFFF + return (val & 0x80000000) != 0, f"0x{val:08x}" + + +def iter_log_files(log_target: Path) -> list[Path]: + """Return sorted log files under log_target (or [log_target] if it is a file).""" + if not log_target.exists(): + return [] + if log_target.is_file(): + return [log_target] + if not log_target.is_dir(): + return [] + files = [ + p + for p in log_target.rglob("*") + if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS + ] + files.sort() + return files + + +def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]: + """Aggregate startup telemetry counters from an iterable of log lines.""" + slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter() + d3d12_unhandled: Counter[str] = Counter() + d3d12_debug: Counter[tuple[str, str, str, str]] = Counter() + dstorage_failures: Counter[str] = Counter() + dstorage_hresults: Counter[str] = Counter() + runtime_failures: Counter[tuple[str, str]] = Counter() + + for raw_line in lines: + line = raw_line.strip() + if not line: + continue + + # 1. slot70 memory SRV refusals + m = RE_SLOT70.search(line) + if m: + reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3) + res = _parse_kv_block(res_raw) + view = _parse_kv_block(view_raw) + if "_unreadable" in res: + dim = fmt = layout = flags = "unreadable" + else: + dim = res.get("dim", "?") + fmt = res.get("fmt", "?") + layout = res.get("layout", "?") + flags = res.get("flags", "?") + if "_unreadable" in view: + view_dim = view_fmt = "unreadable" + else: + view_dim = view.get("dim", "?") + view_fmt = view.get("fmt", "?") + slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1 + continue + + # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail + m = RE_TRAP_TAG.match(line) + if m: + tag, target = m.group(1), redact(m.group(2)) + d3d12_unhandled[f"{tag} {target}"] += 1 + continue + + # 3. x2w-d3d12-debug + m = RE_D3D12_DEBUG.search(line) + if m: + ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4)) + if len(msg) > 120: + msg = msg[:117] + "..." + d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1 + continue + + # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed + if "x2w-d3d12" in line: + m = RE_D3D12_REMOVED.search(line) + if m: + d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_PIPELINE_TRAP.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1 + continue + m = RE_D3D12_IID_PASS.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1 + continue + m = RE_D3D12_VIEW_SKIPPED.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_SLOT_CALL.search(line) + if m: + d3d12_unhandled[m.group(1)] += 1 + continue + + # 5. x2w-dstorage failures & status HRESULTs + if "x2w-dstorage" in line: + m = RE_DSTORAGE_OUTCOME.search(line) + if m: + outcome = m.group(1).strip() + if outcome not in DSTORAGE_OK_OUTCOMES: + dstorage_failures[redact(outcome)] += 1 + continue + m = RE_DSTORAGE_ENTRY_FAIL.search(line) + if m: + dstorage_failures[f"entry failed: {redact(m.group(1))}"] += 1 + continue + m = RE_DSTORAGE_ZLIB_FAIL.search(line) + if m: + dstorage_failures["zlib failure"] += 1 + continue + m = RE_DSTORAGE_OPENFILE_FAIL.search(line) + if m: + dstorage_failures[f"OpenFile: {redact(m.group(1))}"] += 1 + continue + m = RE_DSTORAGE_HRESULT.search(line) + if m: + _, norm_hr = _is_failed_hresult(m.group(1)) + dstorage_hresults[norm_hr] += 1 + continue + m = RE_DSTORAGE_SIGNAL.search(line) + if m: + failed, norm_hr = _is_failed_hresult(m.group(1)) + if failed: + dstorage_hresults[norm_hr] += 1 + continue + + # 6. x2w-runtime / x2w-api failing methods / HRESULTs + if "x2w-runtime" in line or "x2w-api" in line: + m = RE_RUNTIME_CALL.search(line) + if m: + failed, norm_hr = _is_failed_hresult(m.group(2)) + if failed: + runtime_failures[(m.group(1), norm_hr)] += 1 + continue + m = RE_RUNTIME_STORAGE.search(line) + if m: + _, norm_hr = _is_failed_hresult(m.group(1)) + runtime_failures[("persistent_local_storage", norm_hr)] += 1 + continue + m = RE_RUNTIME_GAMESAVE.search(line) + if m: + runtime_failures[("game_save_update", f"status {m.group(1)}")] += 1 + continue + + return { + "slot70_refusals": slot70_refusals, + "d3d12_unhandled": d3d12_unhandled, + "d3d12_debug": d3d12_debug, + "dstorage_failures": dstorage_failures, + "dstorage_hresults": dstorage_hresults, + "runtime_failures": runtime_failures, + } + + +def summarize_shader_cache(cache_dir: Path | None) -> Counter[str]: + """Count .fail Unsupported(...) / fxc reasons in X2W_SHADER_CACHE.""" + reasons: Counter[str] = Counter() + if cache_dir is None or not cache_dir.is_dir(): + return reasons + for fail_path in sorted(cache_dir.glob("*.fail")): + try: + text = fail_path.read_text(encoding="utf-8", errors="replace") + except OSError: + continue + first_line = "" + for line in text.splitlines(): + stripped = line.strip() + if stripped: + first_line = stripped + break + if not first_line: + first_line = "(empty .fail)" + cleaned = redact(first_line) + if len(cleaned) > 120: + cleaned = cleaned[:117] + "..." + reasons[cleaned] += 1 + return reasons + + +def _format_table( + headers: list[str], + rows: list[list[object]], + total_unique: int, + total_events: int, + max_items: int, +) -> list[str]: + if not rows: + return ["_None observed._", ""] + lines = [ + "| " + " | ".join(headers) + " |", + "| " + " | ".join(["---"] * len(headers)) + " |", + ] + for row in rows[:max_items]: + lines.append("| " + " | ".join(_md_cell(c) for c in row) + " |") + if total_unique > max_items: + lines.append( + f"_Showing top {max_items} of {total_unique} unique entries ({total_events} total events)._" + ) + lines.append("") + return lines + + +def format_markdown( + summary: dict[str, Counter], + shader_failures: Counter[str], + files_scanned: int, + shader_cache_provided: bool, + max_items: int, +) -> str: + """Render aggregated counters as clean-room Markdown.""" + out: list[str] = [ + "## Startup Run Triage Summary", + "", + f"- Log files scanned: `{files_scanned}`", + f"- `slot70` memory SRV refusals: `{sum(summary['slot70_refusals'].values())}` " + f"({len(summary['slot70_refusals'])} unique)", + f"- `x2w-d3d12` / trap slot events: `{sum(summary['d3d12_unhandled'].values())}` " + f"({len(summary['d3d12_unhandled'])} unique)", + f"- `x2w-d3d12-debug` messages: `{sum(summary['d3d12_debug'].values())}` " + f"({len(summary['d3d12_debug'])} unique)", + f"- `x2w-dstorage` failures: `{sum(summary['dstorage_failures'].values())}` " + f"({len(summary['dstorage_failures'])} unique)", + f"- `x2w-runtime` failing calls: `{sum(summary['runtime_failures'].values())}` " + f"({len(summary['runtime_failures'])} unique)", + ] + if shader_cache_provided: + out.append( + f"- `X2W_SHADER_CACHE` `.fail` shaders: `{sum(shader_failures.values())}` " + f"({len(shader_failures)} unique reasons)" + ) + out.append("") + + # 1. slot70 refusals + out.extend(["### `Device::slot70` Memory SRV Refusals", ""]) + s70 = summary["slot70_refusals"] + s70_rows = [ + [count, reason, dim, fmt, vdim, vfmt, layout, flags] + for (reason, dim, fmt, vdim, vfmt, layout, flags), count in s70.most_common() + ] + out.extend( + _format_table( + ["Count", "Reason", "Res Dim", "Res Fmt", "View Dim", "View Fmt", "Layout", "Flags"], + s70_rows, + len(s70), + sum(s70.values()), + max_items, + ) + ) + + # 2. x2w-d3d12 unhandled/stubbed calls & traps + out.extend(["### Unhandled / Stubbed `x2w-d3d12` & Trap Calls", ""]) + d3d = summary["d3d12_unhandled"] + d3d_rows = [[count, f"`{call}`"] for call, count in d3d.most_common()] + out.extend( + _format_table( + ["Count", "Call / Slot"], + d3d_rows, + len(d3d), + sum(d3d.values()), + max_items, + ) + ) + + # 3. x2w-d3d12-debug + dbg = summary["d3d12_debug"] + if dbg: + out.extend(["### `x2w-d3d12-debug` Messages", ""]) + dbg_rows = [ + [count, ctx, sev, msg_id, msg] + for (ctx, sev, msg_id, msg), count in dbg.most_common() + ] + out.extend( + _format_table( + ["Count", "Context", "Sev", "ID", "Message (redacted)"], + dbg_rows, + len(dbg), + sum(dbg.values()), + max_items, + ) + ) + + # 4. x2w-dstorage failures & HRESULTs + out.extend(["### `x2w-dstorage` Failures & Status HRESULTs", ""]) + ds_fail = summary["dstorage_failures"] + ds_rows = [[count, reason] for reason, count in ds_fail.most_common()] + out.extend( + _format_table( + ["Count", "Failure Reason"], + ds_rows, + len(ds_fail), + sum(ds_fail.values()), + max_items, + ) + ) + ds_hr = summary["dstorage_hresults"] + if ds_hr: + hr_rows = [[count, f"`{hr}`"] for hr, count in ds_hr.most_common()] + out.extend( + _format_table( + ["Count", "Status HRESULT"], + hr_rows, + len(ds_hr), + sum(ds_hr.values()), + max_items, + ) + ) + + # 5. x2w-runtime failing methods / HRESULTs + out.extend(["### `x2w-runtime` Failing Methods", ""]) + rt = summary["runtime_failures"] + rt_rows = [[count, f"`{method}`", f"`{hr}`"] for (method, hr), count in rt.most_common()] + out.extend( + _format_table( + ["Count", "Method", "HRESULT / Status"], + rt_rows, + len(rt), + sum(rt.values()), + max_items, + ) + ) + + # 6. X2W_SHADER_CACHE .fail reasons + if shader_cache_provided: + out.extend(["### `X2W_SHADER_CACHE` `.fail` Reasons", ""]) + sh_rows = [[count, f"`{reason}`"] for reason, count in shader_failures.most_common()] + out.extend( + _format_table( + ["Count", "Reason"], + sh_rows, + len(shader_failures), + sum(shader_failures.values()), + max_items, + ) + ) + + return "\n".join(out) + + +def triage_run( + logdir: Path, + shader_cache: Path | None = None, + max_items: int = 16, +) -> str: + """Scan logdir (and optional shader_cache) and return a redacted Markdown summary.""" + log_files = iter_log_files(logdir) + + def _line_stream() -> Iterable[str]: + for path in log_files: + try: + with path.open("r", encoding="utf-8", errors="replace") as handle: + yield from handle ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Avoid counting mirrored log messages twice** For directories produced by `run.ps1`/`debug_launch.py`, `stderr.txt` and `trap.log` contain the same telemetry: the launcher sets `X2W_TRAP_LOG` while capturing stderr, and the shared and component loggers write each message to both destinations. Concatenating every discovered file therefore doubles the event counts; a synthetic run with one failed DirectStorage request mirrored in those two standard files reports two failures. Select a canonical stream per run or reconcile the mirrored sources while preserving genuine repeated calls. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-24 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T12:10:21Z.

Code review location: tools/startup/triage_run.py; line 200

@@ -0,0 +1,497 @@
+#!/usr/bin/env python3
+"""Summarize a startup log directory (and optional shader cache) into redacted Markdown.
+
+Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a
+title-neutral, path-redacted, address-redacted Markdown summary suitable for a
+GitHub issue. Uses only the Python 3 standard library.
+"""
+
+from __future__ import annotations
+
+import argparse
+from collections import Counter
+from pathlib import Path
+import re
+import sys
+from typing import Iterable
+
+
+LOG_EXTENSIONS = {".txt", ".log", ".out"}
+
+DSTORAGE_OK_OUTCOMES = {
+    "done",
+    "empty",
+    "inflated",
+    "inflated (larger/short)",
+    "inflated (chunked stream piece 0)",
+    "inflated (slice from stream cache)",
+    "bcpack decoded",
+    "inflated + bcpack decoded",
+}
+
+# Redaction patterns (applied in order from most specific/broadest path to tokens).
+RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"')
+RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)')
+RE_QUOTED_POSIX_PATH = re.compile(
+    r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"'
+)
+RE_POSIX_PATH = re.compile(
+    r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+'
+)
+RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE)
+RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b')
+
+# Log line patterns matching src/startup_stubs/*.
+RE_SLOT70 = re.compile(
+    r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}'
+)
+RE_KV = re.compile(r'(\w+)=([^\s}]+)')
+
+RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)')
+RE_D3D12_PIPELINE_TRAP = re.compile(
+    r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)'
+)
+RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:')
+RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$')
+RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b')
+RE_D3D12_REMOVED = re.compile(
+    r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$'
+)
+RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$')
+
+RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$')
+RE_DSTORAGE_ENTRY_FAIL = re.compile(
+    r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$'
+)
+RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$')
+RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$')
+RE_DSTORAGE_HRESULT = re.compile(
+    r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_DSTORAGE_SIGNAL = re.compile(
+    r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)'
+)
+
+RE_RUNTIME_CALL = re.compile(
+    r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_STORAGE = re.compile(
+    r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_GAMESAVE = re.compile(
+    r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)'
+)
+
+
+def redact(text: str) -> str:
+    """Strip local paths, executable names, and 64-bit addresses from a log snippet."""
+    out = RE_QUOTED_WIN_PATH.sub('"<path>"', text)
+    out = RE_WIN_PATH.sub("<path>", out)
+    out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out)
+    out = RE_POSIX_PATH.sub("<path>", out)
+    out = RE_EXE_NAME.sub("<exe>", out)
+    out = RE_ADDR64.sub("0x<addr>", out)
+    return out
+
+
+def _md_cell(value: object) -> str:
+    return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ")
+
+
+def _parse_kv_block(block: str) -> dict[str, str]:
+    if block.strip() == "unreadable":
+        return {"_unreadable": "1"}
+    return dict(RE_KV.findall(block))
+
+
+def _is_failed_hresult(hex_text: str) -> tuple[bool, str]:
+    val = int(hex_text, 16) & 0xFFFFFFFF
+    return (val & 0x80000000) != 0, f"0x{val:08x}"
+
+
+def iter_log_files(log_target: Path) -> list[Path]:
+    """Return sorted log files under log_target (or [log_target] if it is a file)."""
+    if not log_target.exists():
+        return []
+    if log_target.is_file():
+        return [log_target]
+    if not log_target.is_dir():
+        return []
+    files = [
+        p
+        for p in log_target.rglob("*")
+        if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS
+    ]
+    files.sort()
+    return files
+
+
+def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]:
+    """Aggregate startup telemetry counters from an iterable of log lines."""
+    slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter()
+    d3d12_unhandled: Counter[str] = Counter()
+    d3d12_debug: Counter[tuple[str, str, str, str]] = Counter()
+    dstorage_failures: Counter[str] = Counter()
+    dstorage_hresults: Counter[str] = Counter()
+    runtime_failures: Counter[tuple[str, str]] = Counter()
+
+    for raw_line in lines:
+        line = raw_line.strip()
+        if not line:
+            continue
+
+        # 1. slot70 memory SRV refusals
+        m = RE_SLOT70.search(line)
+        if m:
+            reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3)
+            res = _parse_kv_block(res_raw)
+            view = _parse_kv_block(view_raw)
+            if "_unreadable" in res:
+                dim = fmt = layout = flags = "unreadable"
+            else:
+                dim = res.get("dim", "?")
+                fmt = res.get("fmt", "?")
+                layout = res.get("layout", "?")
+                flags = res.get("flags", "?")
+            if "_unreadable" in view:
+                view_dim = view_fmt = "unreadable"
+            else:
+                view_dim = view.get("dim", "?")
+                view_fmt = view.get("fmt", "?")
+            slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1
+            continue
+
+        # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail
+        m = RE_TRAP_TAG.match(line)
+        if m:
+            tag, target = m.group(1), redact(m.group(2))
+            d3d12_unhandled[f"{tag} {target}"] += 1
+            continue
+
+        # 3. x2w-d3d12-debug
+        m = RE_D3D12_DEBUG.search(line)
+        if m:
+            ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4))
+            if len(msg) > 120:
+                msg = msg[:117] + "..."
+            d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1
+            continue
+
+        # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed
+        if "x2w-d3d12" in line:
+            m = RE_D3D12_REMOVED.search(line)
+            if m:
+                d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_PIPELINE_TRAP.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1
+                continue
+            m = RE_D3D12_IID_PASS.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1
+                continue
+            m = RE_D3D12_VIEW_SKIPPED.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_SLOT_CALL.search(line)
+            if m:
+                d3d12_unhandled[m.group(1)] += 1

P2 Badge Exclude successful forwarded slots from unhandled events

For a successful forwarded Device::slot13 (CheckFeatureSupport) call, the log emitted by forward_slot() still matches this fallback and increments d3d12_unhandled. The same happens for successful create_slot() calls. These methods are wired to real desktop implementations in src/startup_stubs/d3d12_xs_device.cpp, so normal implemented operations inflate the unhandled/stubbed report and can displace actual refusals in the limited table. Only add messages establishing unhandled or stubbed behavior here, or report ordinary slot telemetry separately.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679774285 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#discussion_r4679774285). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T12:10:21Z. **Code review location:** `tools/startup/triage_run.py`; line 200 ~~~~diff @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""Summarize a startup log directory (and optional shader cache) into redacted Markdown. + +Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a +title-neutral, path-redacted, address-redacted Markdown summary suitable for a +GitHub issue. Uses only the Python 3 standard library. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys +from typing import Iterable + + +LOG_EXTENSIONS = {".txt", ".log", ".out"} + +DSTORAGE_OK_OUTCOMES = { + "done", + "empty", + "inflated", + "inflated (larger/short)", + "inflated (chunked stream piece 0)", + "inflated (slice from stream cache)", + "bcpack decoded", + "inflated + bcpack decoded", +} + +# Redaction patterns (applied in order from most specific/broadest path to tokens). +RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"') +RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)') +RE_QUOTED_POSIX_PATH = re.compile( + r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"' +) +RE_POSIX_PATH = re.compile( + r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+' +) +RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE) +RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b') + +# Log line patterns matching src/startup_stubs/*. +RE_SLOT70 = re.compile( + r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}' +) +RE_KV = re.compile(r'(\w+)=([^\s}]+)') + +RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)') +RE_D3D12_PIPELINE_TRAP = re.compile( + r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)' +) +RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:') +RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$') +RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b') +RE_D3D12_REMOVED = re.compile( + r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$' +) +RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$') + +RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$') +RE_DSTORAGE_ENTRY_FAIL = re.compile( + r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$' +) +RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$') +RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$') +RE_DSTORAGE_HRESULT = re.compile( + r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_DSTORAGE_SIGNAL = re.compile( + r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)' +) + +RE_RUNTIME_CALL = re.compile( + r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_STORAGE = re.compile( + r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_GAMESAVE = re.compile( + r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)' +) + + +def redact(text: str) -> str: + """Strip local paths, executable names, and 64-bit addresses from a log snippet.""" + out = RE_QUOTED_WIN_PATH.sub('"<path>"', text) + out = RE_WIN_PATH.sub("<path>", out) + out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out) + out = RE_POSIX_PATH.sub("<path>", out) + out = RE_EXE_NAME.sub("<exe>", out) + out = RE_ADDR64.sub("0x<addr>", out) + return out + + +def _md_cell(value: object) -> str: + return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ") + + +def _parse_kv_block(block: str) -> dict[str, str]: + if block.strip() == "unreadable": + return {"_unreadable": "1"} + return dict(RE_KV.findall(block)) + + +def _is_failed_hresult(hex_text: str) -> tuple[bool, str]: + val = int(hex_text, 16) & 0xFFFFFFFF + return (val & 0x80000000) != 0, f"0x{val:08x}" + + +def iter_log_files(log_target: Path) -> list[Path]: + """Return sorted log files under log_target (or [log_target] if it is a file).""" + if not log_target.exists(): + return [] + if log_target.is_file(): + return [log_target] + if not log_target.is_dir(): + return [] + files = [ + p + for p in log_target.rglob("*") + if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS + ] + files.sort() + return files + + +def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]: + """Aggregate startup telemetry counters from an iterable of log lines.""" + slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter() + d3d12_unhandled: Counter[str] = Counter() + d3d12_debug: Counter[tuple[str, str, str, str]] = Counter() + dstorage_failures: Counter[str] = Counter() + dstorage_hresults: Counter[str] = Counter() + runtime_failures: Counter[tuple[str, str]] = Counter() + + for raw_line in lines: + line = raw_line.strip() + if not line: + continue + + # 1. slot70 memory SRV refusals + m = RE_SLOT70.search(line) + if m: + reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3) + res = _parse_kv_block(res_raw) + view = _parse_kv_block(view_raw) + if "_unreadable" in res: + dim = fmt = layout = flags = "unreadable" + else: + dim = res.get("dim", "?") + fmt = res.get("fmt", "?") + layout = res.get("layout", "?") + flags = res.get("flags", "?") + if "_unreadable" in view: + view_dim = view_fmt = "unreadable" + else: + view_dim = view.get("dim", "?") + view_fmt = view.get("fmt", "?") + slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1 + continue + + # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail + m = RE_TRAP_TAG.match(line) + if m: + tag, target = m.group(1), redact(m.group(2)) + d3d12_unhandled[f"{tag} {target}"] += 1 + continue + + # 3. x2w-d3d12-debug + m = RE_D3D12_DEBUG.search(line) + if m: + ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4)) + if len(msg) > 120: + msg = msg[:117] + "..." + d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1 + continue + + # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed + if "x2w-d3d12" in line: + m = RE_D3D12_REMOVED.search(line) + if m: + d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_PIPELINE_TRAP.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1 + continue + m = RE_D3D12_IID_PASS.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1 + continue + m = RE_D3D12_VIEW_SKIPPED.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_SLOT_CALL.search(line) + if m: + d3d12_unhandled[m.group(1)] += 1 ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Exclude successful forwarded slots from unhandled events** For a successful forwarded `Device::slot13` (`CheckFeatureSupport`) call, the log emitted by `forward_slot()` still matches this fallback and increments `d3d12_unhandled`. The same happens for successful `create_slot()` calls. These methods are wired to real desktop implementations in `src/startup_stubs/d3d12_xs_device.cpp`, so normal implemented operations inflate the unhandled/stubbed report and can displace actual refusals in the limited table. Only add messages establishing unhandled or stubbed behavior here, or report ordinary slot telemetry separately. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-24 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:16:29Z.

Code review location: tools/startup/triage_run.py; line 34

@@ -0,0 +1,497 @@
+#!/usr/bin/env python3
+"""Summarize a startup log directory (and optional shader cache) into redacted Markdown.
+
+Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a
+title-neutral, path-redacted, address-redacted Markdown summary suitable for a
+GitHub issue. Uses only the Python 3 standard library.
+"""
+
+from __future__ import annotations
+
+import argparse
+from collections import Counter
+from pathlib import Path
+import re
+import sys
+from typing import Iterable
+
+
+LOG_EXTENSIONS = {".txt", ".log", ".out"}
+
+DSTORAGE_OK_OUTCOMES = {
+    "done",
+    "empty",
+    "inflated",
+    "inflated (larger/short)",
+    "inflated (chunked stream piece 0)",
+    "inflated (slice from stream cache)",
+    "bcpack decoded",
+    "inflated + bcpack decoded",
+}
+
+# Redaction patterns (applied in order from most specific/broadest path to tokens).
+RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"')
+RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)')

Fixed in bf1b5b86: Unquoted diagnostic paths now redact whole directory components containing spaces (Windows and POSIX), so the full path is replaced; regression covers C:\Users\Alice Smith... and C:\Program Files\My App\shader.hlsl. Win2025 Debug and Release /O2: startup_triage_run 1/1 passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679846767 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#discussion_r4679846767). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:16:29Z. **Code review location:** `tools/startup/triage_run.py`; line 34 ~~~~diff @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""Summarize a startup log directory (and optional shader cache) into redacted Markdown. + +Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a +title-neutral, path-redacted, address-redacted Markdown summary suitable for a +GitHub issue. Uses only the Python 3 standard library. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys +from typing import Iterable + + +LOG_EXTENSIONS = {".txt", ".log", ".out"} + +DSTORAGE_OK_OUTCOMES = { + "done", + "empty", + "inflated", + "inflated (larger/short)", + "inflated (chunked stream piece 0)", + "inflated (slice from stream cache)", + "bcpack decoded", + "inflated + bcpack decoded", +} + +# Redaction patterns (applied in order from most specific/broadest path to tokens). +RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"') +RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)') ~~~~ --- Fixed in bf1b5b86: Unquoted diagnostic paths now redact whole directory components containing spaces (Windows and POSIX), so the full path is replaced; regression covers C:\Users\Alice Smith\... and C:\Program Files\My App\shader.hlsl. Win2025 Debug and Release /O2: startup_triage_run 1/1 passed.
tedin7 commented 2026-11-24 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:16:33Z.

Code review location: tools/startup/triage_run.py; line 459

@@ -0,0 +1,497 @@
+#!/usr/bin/env python3
+"""Summarize a startup log directory (and optional shader cache) into redacted Markdown.
+
+Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a
+title-neutral, path-redacted, address-redacted Markdown summary suitable for a
+GitHub issue. Uses only the Python 3 standard library.
+"""
+
+from __future__ import annotations
+
+import argparse
+from collections import Counter
+from pathlib import Path
+import re
+import sys
+from typing import Iterable
+
+
+LOG_EXTENSIONS = {".txt", ".log", ".out"}
+
+DSTORAGE_OK_OUTCOMES = {
+    "done",
+    "empty",
+    "inflated",
+    "inflated (larger/short)",
+    "inflated (chunked stream piece 0)",
+    "inflated (slice from stream cache)",
+    "bcpack decoded",
+    "inflated + bcpack decoded",
+}
+
+# Redaction patterns (applied in order from most specific/broadest path to tokens).
+RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"')
+RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)')
+RE_QUOTED_POSIX_PATH = re.compile(
+    r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"'
+)
+RE_POSIX_PATH = re.compile(
+    r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+'
+)
+RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE)
+RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b')
+
+# Log line patterns matching src/startup_stubs/*.
+RE_SLOT70 = re.compile(
+    r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}'
+)
+RE_KV = re.compile(r'(\w+)=([^\s}]+)')
+
+RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)')
+RE_D3D12_PIPELINE_TRAP = re.compile(
+    r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)'
+)
+RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:')
+RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$')
+RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b')
+RE_D3D12_REMOVED = re.compile(
+    r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$'
+)
+RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$')
+
+RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$')
+RE_DSTORAGE_ENTRY_FAIL = re.compile(
+    r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$'
+)
+RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$')
+RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$')
+RE_DSTORAGE_HRESULT = re.compile(
+    r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_DSTORAGE_SIGNAL = re.compile(
+    r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)'
+)
+
+RE_RUNTIME_CALL = re.compile(
+    r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_STORAGE = re.compile(
+    r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_GAMESAVE = re.compile(
+    r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)'
+)
+
+
+def redact(text: str) -> str:
+    """Strip local paths, executable names, and 64-bit addresses from a log snippet."""
+    out = RE_QUOTED_WIN_PATH.sub('"<path>"', text)
+    out = RE_WIN_PATH.sub("<path>", out)
+    out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out)
+    out = RE_POSIX_PATH.sub("<path>", out)
+    out = RE_EXE_NAME.sub("<exe>", out)
+    out = RE_ADDR64.sub("0x<addr>", out)
+    return out
+
+
+def _md_cell(value: object) -> str:
+    return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ")
+
+
+def _parse_kv_block(block: str) -> dict[str, str]:
+    if block.strip() == "unreadable":
+        return {"_unreadable": "1"}
+    return dict(RE_KV.findall(block))
+
+
+def _is_failed_hresult(hex_text: str) -> tuple[bool, str]:
+    val = int(hex_text, 16) & 0xFFFFFFFF
+    return (val & 0x80000000) != 0, f"0x{val:08x}"
+
+
+def iter_log_files(log_target: Path) -> list[Path]:
+    """Return sorted log files under log_target (or [log_target] if it is a file)."""
+    if not log_target.exists():
+        return []
+    if log_target.is_file():
+        return [log_target]
+    if not log_target.is_dir():
+        return []
+    files = [
+        p
+        for p in log_target.rglob("*")
+        if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS
+    ]
+    files.sort()
+    return files
+
+
+def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]:
+    """Aggregate startup telemetry counters from an iterable of log lines."""
+    slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter()
+    d3d12_unhandled: Counter[str] = Counter()
+    d3d12_debug: Counter[tuple[str, str, str, str]] = Counter()
+    dstorage_failures: Counter[str] = Counter()
+    dstorage_hresults: Counter[str] = Counter()
+    runtime_failures: Counter[tuple[str, str]] = Counter()
+
+    for raw_line in lines:
+        line = raw_line.strip()
+        if not line:
+            continue
+
+        # 1. slot70 memory SRV refusals
+        m = RE_SLOT70.search(line)
+        if m:
+            reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3)
+            res = _parse_kv_block(res_raw)
+            view = _parse_kv_block(view_raw)
+            if "_unreadable" in res:
+                dim = fmt = layout = flags = "unreadable"
+            else:
+                dim = res.get("dim", "?")
+                fmt = res.get("fmt", "?")
+                layout = res.get("layout", "?")
+                flags = res.get("flags", "?")
+            if "_unreadable" in view:
+                view_dim = view_fmt = "unreadable"
+            else:
+                view_dim = view.get("dim", "?")
+                view_fmt = view.get("fmt", "?")
+            slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1
+            continue
+
+        # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail
+        m = RE_TRAP_TAG.match(line)
+        if m:
+            tag, target = m.group(1), redact(m.group(2))
+            d3d12_unhandled[f"{tag} {target}"] += 1
+            continue
+
+        # 3. x2w-d3d12-debug
+        m = RE_D3D12_DEBUG.search(line)
+        if m:
+            ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4))
+            if len(msg) > 120:
+                msg = msg[:117] + "..."
+            d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1
+            continue
+
+        # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed
+        if "x2w-d3d12" in line:
+            m = RE_D3D12_REMOVED.search(line)
+            if m:
+                d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_PIPELINE_TRAP.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1
+                continue
+            m = RE_D3D12_IID_PASS.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1
+                continue
+            m = RE_D3D12_VIEW_SKIPPED.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_SLOT_CALL.search(line)
+            if m:
+                d3d12_unhandled[m.group(1)] += 1
+                continue
+
+        # 5. x2w-dstorage failures & status HRESULTs
+        if "x2w-dstorage" in line:
+            m = RE_DSTORAGE_OUTCOME.search(line)
+            if m:
+                outcome = m.group(1).strip()
+                if outcome not in DSTORAGE_OK_OUTCOMES:
+                    dstorage_failures[redact(outcome)] += 1
+                continue
+            m = RE_DSTORAGE_ENTRY_FAIL.search(line)
+            if m:
+                dstorage_failures[f"entry failed: {redact(m.group(1))}"] += 1
+                continue
+            m = RE_DSTORAGE_ZLIB_FAIL.search(line)
+            if m:
+                dstorage_failures["zlib failure"] += 1
+                continue
+            m = RE_DSTORAGE_OPENFILE_FAIL.search(line)
+            if m:
+                dstorage_failures[f"OpenFile: {redact(m.group(1))}"] += 1
+                continue
+            m = RE_DSTORAGE_HRESULT.search(line)
+            if m:
+                _, norm_hr = _is_failed_hresult(m.group(1))
+                dstorage_hresults[norm_hr] += 1
+                continue
+            m = RE_DSTORAGE_SIGNAL.search(line)
+            if m:
+                failed, norm_hr = _is_failed_hresult(m.group(1))
+                if failed:
+                    dstorage_hresults[norm_hr] += 1
+                continue
+
+        # 6. x2w-runtime / x2w-api failing methods / HRESULTs
+        if "x2w-runtime" in line or "x2w-api" in line:
+            m = RE_RUNTIME_CALL.search(line)
+            if m:
+                failed, norm_hr = _is_failed_hresult(m.group(2))
+                if failed:
+                    runtime_failures[(m.group(1), norm_hr)] += 1
+                continue
+            m = RE_RUNTIME_STORAGE.search(line)
+            if m:
+                _, norm_hr = _is_failed_hresult(m.group(1))
+                runtime_failures[("persistent_local_storage", norm_hr)] += 1
+                continue
+            m = RE_RUNTIME_GAMESAVE.search(line)
+            if m:
+                runtime_failures[("game_save_update", f"status {m.group(1)}")] += 1
+                continue
+
+    return {
+        "slot70_refusals": slot70_refusals,
+        "d3d12_unhandled": d3d12_unhandled,
+        "d3d12_debug": d3d12_debug,
+        "dstorage_failures": dstorage_failures,
+        "dstorage_hresults": dstorage_hresults,
+        "runtime_failures": runtime_failures,
+    }
+
+
+def summarize_shader_cache(cache_dir: Path | None) -> Counter[str]:
+    """Count .fail Unsupported(...) / fxc reasons in X2W_SHADER_CACHE."""
+    reasons: Counter[str] = Counter()
+    if cache_dir is None or not cache_dir.is_dir():
+        return reasons
+    for fail_path in sorted(cache_dir.glob("*.fail")):
+        try:
+            text = fail_path.read_text(encoding="utf-8", errors="replace")
+        except OSError:
+            continue
+        first_line = ""
+        for line in text.splitlines():
+            stripped = line.strip()
+            if stripped:
+                first_line = stripped
+                break
+        if not first_line:
+            first_line = "(empty .fail)"
+        cleaned = redact(first_line)
+        if len(cleaned) > 120:
+            cleaned = cleaned[:117] + "..."
+        reasons[cleaned] += 1
+    return reasons
+
+
+def _format_table(
+    headers: list[str],
+    rows: list[list[object]],
+    total_unique: int,
+    total_events: int,
+    max_items: int,
+) -> list[str]:
+    if not rows:
+        return ["_None observed._", ""]
+    lines = [
+        "| " + " | ".join(headers) + " |",
+        "| " + " | ".join(["---"] * len(headers)) + " |",
+    ]
+    for row in rows[:max_items]:
+        lines.append("| " + " | ".join(_md_cell(c) for c in row) + " |")
+    if total_unique > max_items:
+        lines.append(
+            f"_Showing top {max_items} of {total_unique} unique entries ({total_events} total events)._"
+        )
+    lines.append("")
+    return lines
+
+
+def format_markdown(
+    summary: dict[str, Counter],
+    shader_failures: Counter[str],
+    files_scanned: int,
+    shader_cache_provided: bool,
+    max_items: int,
+) -> str:
+    """Render aggregated counters as clean-room Markdown."""
+    out: list[str] = [
+        "## Startup Run Triage Summary",
+        "",
+        f"- Log files scanned: `{files_scanned}`",
+        f"- `slot70` memory SRV refusals: `{sum(summary['slot70_refusals'].values())}` "
+        f"({len(summary['slot70_refusals'])} unique)",
+        f"- `x2w-d3d12` / trap slot events: `{sum(summary['d3d12_unhandled'].values())}` "
+        f"({len(summary['d3d12_unhandled'])} unique)",
+        f"- `x2w-d3d12-debug` messages: `{sum(summary['d3d12_debug'].values())}` "
+        f"({len(summary['d3d12_debug'])} unique)",
+        f"- `x2w-dstorage` failures: `{sum(summary['dstorage_failures'].values())}` "
+        f"({len(summary['dstorage_failures'])} unique)",
+        f"- `x2w-runtime` failing calls: `{sum(summary['runtime_failures'].values())}` "
+        f"({len(summary['runtime_failures'])} unique)",
+    ]
+    if shader_cache_provided:
+        out.append(
+            f"- `X2W_SHADER_CACHE` `.fail` shaders: `{sum(shader_failures.values())}` "
+            f"({len(shader_failures)} unique reasons)"
+        )
+    out.append("")
+
+    # 1. slot70 refusals
+    out.extend(["### `Device::slot70` Memory SRV Refusals", ""])
+    s70 = summary["slot70_refusals"]
+    s70_rows = [
+        [count, reason, dim, fmt, vdim, vfmt, layout, flags]
+        for (reason, dim, fmt, vdim, vfmt, layout, flags), count in s70.most_common()
+    ]
+    out.extend(
+        _format_table(
+            ["Count", "Reason", "Res Dim", "Res Fmt", "View Dim", "View Fmt", "Layout", "Flags"],
+            s70_rows,
+            len(s70),
+            sum(s70.values()),
+            max_items,
+        )
+    )
+
+    # 2. x2w-d3d12 unhandled/stubbed calls & traps
+    out.extend(["### Unhandled / Stubbed `x2w-d3d12` & Trap Calls", ""])
+    d3d = summary["d3d12_unhandled"]
+    d3d_rows = [[count, f"`{call}`"] for call, count in d3d.most_common()]
+    out.extend(
+        _format_table(
+            ["Count", "Call / Slot"],
+            d3d_rows,
+            len(d3d),
+            sum(d3d.values()),
+            max_items,
+        )
+    )
+
+    # 3. x2w-d3d12-debug
+    dbg = summary["d3d12_debug"]
+    if dbg:
+        out.extend(["### `x2w-d3d12-debug` Messages", ""])
+        dbg_rows = [
+            [count, ctx, sev, msg_id, msg]
+            for (ctx, sev, msg_id, msg), count in dbg.most_common()
+        ]
+        out.extend(
+            _format_table(
+                ["Count", "Context", "Sev", "ID", "Message (redacted)"],
+                dbg_rows,
+                len(dbg),
+                sum(dbg.values()),
+                max_items,
+            )
+        )
+
+    # 4. x2w-dstorage failures & HRESULTs
+    out.extend(["### `x2w-dstorage` Failures & Status HRESULTs", ""])
+    ds_fail = summary["dstorage_failures"]
+    ds_rows = [[count, reason] for reason, count in ds_fail.most_common()]
+    out.extend(
+        _format_table(
+            ["Count", "Failure Reason"],
+            ds_rows,
+            len(ds_fail),
+            sum(ds_fail.values()),
+            max_items,
+        )
+    )
+    ds_hr = summary["dstorage_hresults"]
+    if ds_hr:
+        hr_rows = [[count, f"`{hr}`"] for hr, count in ds_hr.most_common()]
+        out.extend(
+            _format_table(
+                ["Count", "Status HRESULT"],
+                hr_rows,
+                len(ds_hr),
+                sum(ds_hr.values()),
+                max_items,
+            )
+        )
+
+    # 5. x2w-runtime failing methods / HRESULTs
+    out.extend(["### `x2w-runtime` Failing Methods", ""])
+    rt = summary["runtime_failures"]
+    rt_rows = [[count, f"`{method}`", f"`{hr}`"] for (method, hr), count in rt.most_common()]
+    out.extend(
+        _format_table(
+            ["Count", "Method", "HRESULT / Status"],
+            rt_rows,
+            len(rt),
+            sum(rt.values()),
+            max_items,
+        )
+    )
+
+    # 6. X2W_SHADER_CACHE .fail reasons
+    if shader_cache_provided:
+        out.extend(["### `X2W_SHADER_CACHE` `.fail` Reasons", ""])
+        sh_rows = [[count, f"`{reason}`"] for reason, count in shader_failures.most_common()]
+        out.extend(
+            _format_table(
+                ["Count", "Reason"],
+                sh_rows,
+                len(shader_failures),
+                sum(shader_failures.values()),
+                max_items,
+            )
+        )
+
+    return "\n".join(out)
+
+
+def triage_run(
+    logdir: Path,
+    shader_cache: Path | None = None,
+    max_items: int = 16,
+) -> str:
+    """Scan logdir (and optional shader_cache) and return a redacted Markdown summary."""
+    log_files = iter_log_files(logdir)
+
+    def _line_stream() -> Iterable[str]:
+        for path in log_files:
+            try:
+                with path.open("r", encoding="utf-8", errors="replace") as handle:
+                    yield from handle

Fixed in bf1b5b86: trap.log lines already present in the sibling stderr.txt are now skipped once each; genuine repeats beyond stderr.txt still count. Regression: one mirrored failure reports 1, a repeated one reports 2. Win2025 Debug and Release /O2: startup_triage_run 1/1 passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679847361 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#discussion_r4679847361). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:16:33Z. **Code review location:** `tools/startup/triage_run.py`; line 459 ~~~~diff @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""Summarize a startup log directory (and optional shader cache) into redacted Markdown. + +Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a +title-neutral, path-redacted, address-redacted Markdown summary suitable for a +GitHub issue. Uses only the Python 3 standard library. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys +from typing import Iterable + + +LOG_EXTENSIONS = {".txt", ".log", ".out"} + +DSTORAGE_OK_OUTCOMES = { + "done", + "empty", + "inflated", + "inflated (larger/short)", + "inflated (chunked stream piece 0)", + "inflated (slice from stream cache)", + "bcpack decoded", + "inflated + bcpack decoded", +} + +# Redaction patterns (applied in order from most specific/broadest path to tokens). +RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"') +RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)') +RE_QUOTED_POSIX_PATH = re.compile( + r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"' +) +RE_POSIX_PATH = re.compile( + r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+' +) +RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE) +RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b') + +# Log line patterns matching src/startup_stubs/*. +RE_SLOT70 = re.compile( + r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}' +) +RE_KV = re.compile(r'(\w+)=([^\s}]+)') + +RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)') +RE_D3D12_PIPELINE_TRAP = re.compile( + r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)' +) +RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:') +RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$') +RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b') +RE_D3D12_REMOVED = re.compile( + r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$' +) +RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$') + +RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$') +RE_DSTORAGE_ENTRY_FAIL = re.compile( + r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$' +) +RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$') +RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$') +RE_DSTORAGE_HRESULT = re.compile( + r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_DSTORAGE_SIGNAL = re.compile( + r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)' +) + +RE_RUNTIME_CALL = re.compile( + r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_STORAGE = re.compile( + r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_GAMESAVE = re.compile( + r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)' +) + + +def redact(text: str) -> str: + """Strip local paths, executable names, and 64-bit addresses from a log snippet.""" + out = RE_QUOTED_WIN_PATH.sub('"<path>"', text) + out = RE_WIN_PATH.sub("<path>", out) + out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out) + out = RE_POSIX_PATH.sub("<path>", out) + out = RE_EXE_NAME.sub("<exe>", out) + out = RE_ADDR64.sub("0x<addr>", out) + return out + + +def _md_cell(value: object) -> str: + return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ") + + +def _parse_kv_block(block: str) -> dict[str, str]: + if block.strip() == "unreadable": + return {"_unreadable": "1"} + return dict(RE_KV.findall(block)) + + +def _is_failed_hresult(hex_text: str) -> tuple[bool, str]: + val = int(hex_text, 16) & 0xFFFFFFFF + return (val & 0x80000000) != 0, f"0x{val:08x}" + + +def iter_log_files(log_target: Path) -> list[Path]: + """Return sorted log files under log_target (or [log_target] if it is a file).""" + if not log_target.exists(): + return [] + if log_target.is_file(): + return [log_target] + if not log_target.is_dir(): + return [] + files = [ + p + for p in log_target.rglob("*") + if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS + ] + files.sort() + return files + + +def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]: + """Aggregate startup telemetry counters from an iterable of log lines.""" + slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter() + d3d12_unhandled: Counter[str] = Counter() + d3d12_debug: Counter[tuple[str, str, str, str]] = Counter() + dstorage_failures: Counter[str] = Counter() + dstorage_hresults: Counter[str] = Counter() + runtime_failures: Counter[tuple[str, str]] = Counter() + + for raw_line in lines: + line = raw_line.strip() + if not line: + continue + + # 1. slot70 memory SRV refusals + m = RE_SLOT70.search(line) + if m: + reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3) + res = _parse_kv_block(res_raw) + view = _parse_kv_block(view_raw) + if "_unreadable" in res: + dim = fmt = layout = flags = "unreadable" + else: + dim = res.get("dim", "?") + fmt = res.get("fmt", "?") + layout = res.get("layout", "?") + flags = res.get("flags", "?") + if "_unreadable" in view: + view_dim = view_fmt = "unreadable" + else: + view_dim = view.get("dim", "?") + view_fmt = view.get("fmt", "?") + slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1 + continue + + # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail + m = RE_TRAP_TAG.match(line) + if m: + tag, target = m.group(1), redact(m.group(2)) + d3d12_unhandled[f"{tag} {target}"] += 1 + continue + + # 3. x2w-d3d12-debug + m = RE_D3D12_DEBUG.search(line) + if m: + ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4)) + if len(msg) > 120: + msg = msg[:117] + "..." + d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1 + continue + + # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed + if "x2w-d3d12" in line: + m = RE_D3D12_REMOVED.search(line) + if m: + d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_PIPELINE_TRAP.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1 + continue + m = RE_D3D12_IID_PASS.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1 + continue + m = RE_D3D12_VIEW_SKIPPED.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_SLOT_CALL.search(line) + if m: + d3d12_unhandled[m.group(1)] += 1 + continue + + # 5. x2w-dstorage failures & status HRESULTs + if "x2w-dstorage" in line: + m = RE_DSTORAGE_OUTCOME.search(line) + if m: + outcome = m.group(1).strip() + if outcome not in DSTORAGE_OK_OUTCOMES: + dstorage_failures[redact(outcome)] += 1 + continue + m = RE_DSTORAGE_ENTRY_FAIL.search(line) + if m: + dstorage_failures[f"entry failed: {redact(m.group(1))}"] += 1 + continue + m = RE_DSTORAGE_ZLIB_FAIL.search(line) + if m: + dstorage_failures["zlib failure"] += 1 + continue + m = RE_DSTORAGE_OPENFILE_FAIL.search(line) + if m: + dstorage_failures[f"OpenFile: {redact(m.group(1))}"] += 1 + continue + m = RE_DSTORAGE_HRESULT.search(line) + if m: + _, norm_hr = _is_failed_hresult(m.group(1)) + dstorage_hresults[norm_hr] += 1 + continue + m = RE_DSTORAGE_SIGNAL.search(line) + if m: + failed, norm_hr = _is_failed_hresult(m.group(1)) + if failed: + dstorage_hresults[norm_hr] += 1 + continue + + # 6. x2w-runtime / x2w-api failing methods / HRESULTs + if "x2w-runtime" in line or "x2w-api" in line: + m = RE_RUNTIME_CALL.search(line) + if m: + failed, norm_hr = _is_failed_hresult(m.group(2)) + if failed: + runtime_failures[(m.group(1), norm_hr)] += 1 + continue + m = RE_RUNTIME_STORAGE.search(line) + if m: + _, norm_hr = _is_failed_hresult(m.group(1)) + runtime_failures[("persistent_local_storage", norm_hr)] += 1 + continue + m = RE_RUNTIME_GAMESAVE.search(line) + if m: + runtime_failures[("game_save_update", f"status {m.group(1)}")] += 1 + continue + + return { + "slot70_refusals": slot70_refusals, + "d3d12_unhandled": d3d12_unhandled, + "d3d12_debug": d3d12_debug, + "dstorage_failures": dstorage_failures, + "dstorage_hresults": dstorage_hresults, + "runtime_failures": runtime_failures, + } + + +def summarize_shader_cache(cache_dir: Path | None) -> Counter[str]: + """Count .fail Unsupported(...) / fxc reasons in X2W_SHADER_CACHE.""" + reasons: Counter[str] = Counter() + if cache_dir is None or not cache_dir.is_dir(): + return reasons + for fail_path in sorted(cache_dir.glob("*.fail")): + try: + text = fail_path.read_text(encoding="utf-8", errors="replace") + except OSError: + continue + first_line = "" + for line in text.splitlines(): + stripped = line.strip() + if stripped: + first_line = stripped + break + if not first_line: + first_line = "(empty .fail)" + cleaned = redact(first_line) + if len(cleaned) > 120: + cleaned = cleaned[:117] + "..." + reasons[cleaned] += 1 + return reasons + + +def _format_table( + headers: list[str], + rows: list[list[object]], + total_unique: int, + total_events: int, + max_items: int, +) -> list[str]: + if not rows: + return ["_None observed._", ""] + lines = [ + "| " + " | ".join(headers) + " |", + "| " + " | ".join(["---"] * len(headers)) + " |", + ] + for row in rows[:max_items]: + lines.append("| " + " | ".join(_md_cell(c) for c in row) + " |") + if total_unique > max_items: + lines.append( + f"_Showing top {max_items} of {total_unique} unique entries ({total_events} total events)._" + ) + lines.append("") + return lines + + +def format_markdown( + summary: dict[str, Counter], + shader_failures: Counter[str], + files_scanned: int, + shader_cache_provided: bool, + max_items: int, +) -> str: + """Render aggregated counters as clean-room Markdown.""" + out: list[str] = [ + "## Startup Run Triage Summary", + "", + f"- Log files scanned: `{files_scanned}`", + f"- `slot70` memory SRV refusals: `{sum(summary['slot70_refusals'].values())}` " + f"({len(summary['slot70_refusals'])} unique)", + f"- `x2w-d3d12` / trap slot events: `{sum(summary['d3d12_unhandled'].values())}` " + f"({len(summary['d3d12_unhandled'])} unique)", + f"- `x2w-d3d12-debug` messages: `{sum(summary['d3d12_debug'].values())}` " + f"({len(summary['d3d12_debug'])} unique)", + f"- `x2w-dstorage` failures: `{sum(summary['dstorage_failures'].values())}` " + f"({len(summary['dstorage_failures'])} unique)", + f"- `x2w-runtime` failing calls: `{sum(summary['runtime_failures'].values())}` " + f"({len(summary['runtime_failures'])} unique)", + ] + if shader_cache_provided: + out.append( + f"- `X2W_SHADER_CACHE` `.fail` shaders: `{sum(shader_failures.values())}` " + f"({len(shader_failures)} unique reasons)" + ) + out.append("") + + # 1. slot70 refusals + out.extend(["### `Device::slot70` Memory SRV Refusals", ""]) + s70 = summary["slot70_refusals"] + s70_rows = [ + [count, reason, dim, fmt, vdim, vfmt, layout, flags] + for (reason, dim, fmt, vdim, vfmt, layout, flags), count in s70.most_common() + ] + out.extend( + _format_table( + ["Count", "Reason", "Res Dim", "Res Fmt", "View Dim", "View Fmt", "Layout", "Flags"], + s70_rows, + len(s70), + sum(s70.values()), + max_items, + ) + ) + + # 2. x2w-d3d12 unhandled/stubbed calls & traps + out.extend(["### Unhandled / Stubbed `x2w-d3d12` & Trap Calls", ""]) + d3d = summary["d3d12_unhandled"] + d3d_rows = [[count, f"`{call}`"] for call, count in d3d.most_common()] + out.extend( + _format_table( + ["Count", "Call / Slot"], + d3d_rows, + len(d3d), + sum(d3d.values()), + max_items, + ) + ) + + # 3. x2w-d3d12-debug + dbg = summary["d3d12_debug"] + if dbg: + out.extend(["### `x2w-d3d12-debug` Messages", ""]) + dbg_rows = [ + [count, ctx, sev, msg_id, msg] + for (ctx, sev, msg_id, msg), count in dbg.most_common() + ] + out.extend( + _format_table( + ["Count", "Context", "Sev", "ID", "Message (redacted)"], + dbg_rows, + len(dbg), + sum(dbg.values()), + max_items, + ) + ) + + # 4. x2w-dstorage failures & HRESULTs + out.extend(["### `x2w-dstorage` Failures & Status HRESULTs", ""]) + ds_fail = summary["dstorage_failures"] + ds_rows = [[count, reason] for reason, count in ds_fail.most_common()] + out.extend( + _format_table( + ["Count", "Failure Reason"], + ds_rows, + len(ds_fail), + sum(ds_fail.values()), + max_items, + ) + ) + ds_hr = summary["dstorage_hresults"] + if ds_hr: + hr_rows = [[count, f"`{hr}`"] for hr, count in ds_hr.most_common()] + out.extend( + _format_table( + ["Count", "Status HRESULT"], + hr_rows, + len(ds_hr), + sum(ds_hr.values()), + max_items, + ) + ) + + # 5. x2w-runtime failing methods / HRESULTs + out.extend(["### `x2w-runtime` Failing Methods", ""]) + rt = summary["runtime_failures"] + rt_rows = [[count, f"`{method}`", f"`{hr}`"] for (method, hr), count in rt.most_common()] + out.extend( + _format_table( + ["Count", "Method", "HRESULT / Status"], + rt_rows, + len(rt), + sum(rt.values()), + max_items, + ) + ) + + # 6. X2W_SHADER_CACHE .fail reasons + if shader_cache_provided: + out.extend(["### `X2W_SHADER_CACHE` `.fail` Reasons", ""]) + sh_rows = [[count, f"`{reason}`"] for reason, count in shader_failures.most_common()] + out.extend( + _format_table( + ["Count", "Reason"], + sh_rows, + len(shader_failures), + sum(shader_failures.values()), + max_items, + ) + ) + + return "\n".join(out) + + +def triage_run( + logdir: Path, + shader_cache: Path | None = None, + max_items: int = 16, +) -> str: + """Scan logdir (and optional shader_cache) and return a redacted Markdown summary.""" + log_files = iter_log_files(logdir) + + def _line_stream() -> Iterable[str]: + for path in log_files: + try: + with path.open("r", encoding="utf-8", errors="replace") as handle: + yield from handle ~~~~ --- Fixed in bf1b5b86: trap.log lines already present in the sibling stderr.txt are now skipped once each; genuine repeats beyond stderr.txt still count. Regression: one mirrored failure reports 1, a repeated one reports 2. Win2025 Debug and Release /O2: startup_triage_run 1/1 passed.
tedin7 commented 2026-11-24 13:00:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T12:16:37Z.

Code review location: tools/startup/triage_run.py; line 200

@@ -0,0 +1,497 @@
+#!/usr/bin/env python3
+"""Summarize a startup log directory (and optional shader cache) into redacted Markdown.
+
+Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a
+title-neutral, path-redacted, address-redacted Markdown summary suitable for a
+GitHub issue. Uses only the Python 3 standard library.
+"""
+
+from __future__ import annotations
+
+import argparse
+from collections import Counter
+from pathlib import Path
+import re
+import sys
+from typing import Iterable
+
+
+LOG_EXTENSIONS = {".txt", ".log", ".out"}
+
+DSTORAGE_OK_OUTCOMES = {
+    "done",
+    "empty",
+    "inflated",
+    "inflated (larger/short)",
+    "inflated (chunked stream piece 0)",
+    "inflated (slice from stream cache)",
+    "bcpack decoded",
+    "inflated + bcpack decoded",
+}
+
+# Redaction patterns (applied in order from most specific/broadest path to tokens).
+RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"')
+RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)')
+RE_QUOTED_POSIX_PATH = re.compile(
+    r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"'
+)
+RE_POSIX_PATH = re.compile(
+    r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+'
+)
+RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE)
+RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b')
+
+# Log line patterns matching src/startup_stubs/*.
+RE_SLOT70 = re.compile(
+    r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}'
+)
+RE_KV = re.compile(r'(\w+)=([^\s}]+)')
+
+RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)')
+RE_D3D12_PIPELINE_TRAP = re.compile(
+    r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)'
+)
+RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:')
+RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$')
+RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b')
+RE_D3D12_REMOVED = re.compile(
+    r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$'
+)
+RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$')
+
+RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$')
+RE_DSTORAGE_ENTRY_FAIL = re.compile(
+    r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$'
+)
+RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$')
+RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$')
+RE_DSTORAGE_HRESULT = re.compile(
+    r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_DSTORAGE_SIGNAL = re.compile(
+    r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)'
+)
+
+RE_RUNTIME_CALL = re.compile(
+    r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_STORAGE = re.compile(
+    r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)'
+)
+RE_RUNTIME_GAMESAVE = re.compile(
+    r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)'
+)
+
+
+def redact(text: str) -> str:
+    """Strip local paths, executable names, and 64-bit addresses from a log snippet."""
+    out = RE_QUOTED_WIN_PATH.sub('"<path>"', text)
+    out = RE_WIN_PATH.sub("<path>", out)
+    out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out)
+    out = RE_POSIX_PATH.sub("<path>", out)
+    out = RE_EXE_NAME.sub("<exe>", out)
+    out = RE_ADDR64.sub("0x<addr>", out)
+    return out
+
+
+def _md_cell(value: object) -> str:
+    return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ")
+
+
+def _parse_kv_block(block: str) -> dict[str, str]:
+    if block.strip() == "unreadable":
+        return {"_unreadable": "1"}
+    return dict(RE_KV.findall(block))
+
+
+def _is_failed_hresult(hex_text: str) -> tuple[bool, str]:
+    val = int(hex_text, 16) & 0xFFFFFFFF
+    return (val & 0x80000000) != 0, f"0x{val:08x}"
+
+
+def iter_log_files(log_target: Path) -> list[Path]:
+    """Return sorted log files under log_target (or [log_target] if it is a file)."""
+    if not log_target.exists():
+        return []
+    if log_target.is_file():
+        return [log_target]
+    if not log_target.is_dir():
+        return []
+    files = [
+        p
+        for p in log_target.rglob("*")
+        if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS
+    ]
+    files.sort()
+    return files
+
+
+def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]:
+    """Aggregate startup telemetry counters from an iterable of log lines."""
+    slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter()
+    d3d12_unhandled: Counter[str] = Counter()
+    d3d12_debug: Counter[tuple[str, str, str, str]] = Counter()
+    dstorage_failures: Counter[str] = Counter()
+    dstorage_hresults: Counter[str] = Counter()
+    runtime_failures: Counter[tuple[str, str]] = Counter()
+
+    for raw_line in lines:
+        line = raw_line.strip()
+        if not line:
+            continue
+
+        # 1. slot70 memory SRV refusals
+        m = RE_SLOT70.search(line)
+        if m:
+            reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3)
+            res = _parse_kv_block(res_raw)
+            view = _parse_kv_block(view_raw)
+            if "_unreadable" in res:
+                dim = fmt = layout = flags = "unreadable"
+            else:
+                dim = res.get("dim", "?")
+                fmt = res.get("fmt", "?")
+                layout = res.get("layout", "?")
+                flags = res.get("flags", "?")
+            if "_unreadable" in view:
+                view_dim = view_fmt = "unreadable"
+            else:
+                view_dim = view.get("dim", "?")
+                view_fmt = view.get("fmt", "?")
+            slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1
+            continue
+
+        # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail
+        m = RE_TRAP_TAG.match(line)
+        if m:
+            tag, target = m.group(1), redact(m.group(2))
+            d3d12_unhandled[f"{tag} {target}"] += 1
+            continue
+
+        # 3. x2w-d3d12-debug
+        m = RE_D3D12_DEBUG.search(line)
+        if m:
+            ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4))
+            if len(msg) > 120:
+                msg = msg[:117] + "..."
+            d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1
+            continue
+
+        # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed
+        if "x2w-d3d12" in line:
+            m = RE_D3D12_REMOVED.search(line)
+            if m:
+                d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_PIPELINE_TRAP.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1
+                continue
+            m = RE_D3D12_IID_PASS.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1
+                continue
+            m = RE_D3D12_VIEW_SKIPPED.search(line)
+            if m:
+                d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1
+                continue
+            m = RE_D3D12_SLOT_CALL.search(line)
+            if m:
+                d3d12_unhandled[m.group(1)] += 1

Fixed in bf1b5b86: Forwarded/created slot lines ending in a successful result are no longer added to the unhandled table; failed results and untraced slot calls still are. Regression covers success, failure and untraced lines. Win2025 Debug and Release /O2: startup_triage_run 1/1 passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4679848011 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1464#discussion_r4679848011). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T12:16:37Z. **Code review location:** `tools/startup/triage_run.py`; line 200 ~~~~diff @@ -0,0 +1,497 @@ +#!/usr/bin/env python3 +"""Summarize a startup log directory (and optional shader cache) into redacted Markdown. + +Reads raw logs produced by tools/startup/run.ps1 / debug_launch.py and emits a +title-neutral, path-redacted, address-redacted Markdown summary suitable for a +GitHub issue. Uses only the Python 3 standard library. +""" + +from __future__ import annotations + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys +from typing import Iterable + + +LOG_EXTENSIONS = {".txt", ".log", ".out"} + +DSTORAGE_OK_OUTCOMES = { + "done", + "empty", + "inflated", + "inflated (larger/short)", + "inflated (chunked stream piece 0)", + "inflated (slice from stream cache)", + "bcpack decoded", + "inflated + bcpack decoded", +} + +# Redaction patterns (applied in order from most specific/broadest path to tokens). +RE_QUOTED_WIN_PATH = re.compile(r'"([A-Za-z]:\\[^"\r\n]+|[A-Za-z]:/[^"\r\n]+|\\\\[^\\"\r\n]+\\[^"\r\n]+)"') +RE_WIN_PATH = re.compile(r'(?:[A-Za-z]:\\[^\s"\'<>|]+|[A-Za-z]:/[^\s"\'<>|]+|\\\\[^\s"\'<>|\\]+\\[^\s"\'<>|]+)') +RE_QUOTED_POSIX_PATH = re.compile( + r'"(/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)/[^"\r\n]+)"' +) +RE_POSIX_PATH = re.compile( + r'/(?:home|Users|mnt|tmp|var|opt|root|srv|private|Volumes)(?:/[^\s"\'<>|]+)+' +) +RE_EXE_NAME = re.compile(r'\b[A-Za-z0-9_.\-]+\.exe\b', re.IGNORECASE) +RE_ADDR64 = re.compile(r'\b0x[0-9a-fA-F]{9,}\b') + +# Log line patterns matching src/startup_stubs/*. +RE_SLOT70 = re.compile( + r'x2w-d3d12\s+Device::slot70\b.*?\breason=(\S+)\s+res\{([^}]*)\}\s+view\{([^}]*)\}' +) +RE_KV = re.compile(r'(\w+)=([^\s}]+)') + +RE_TRAP_TAG = re.compile(r'^(x2w-(?:trap|noop|continue|fail))\s+(\S+)') +RE_D3D12_PIPELINE_TRAP = re.compile( + r'x2w-d3d12\s+Device::slot(\d+)\((Create(?:Graphics|Compute)PipelineState)\)' +) +RE_D3D12_IID_PASS = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+passes an IID:') +RE_D3D12_VIEW_SKIPPED = re.compile(r'x2w-d3d12\s+Device::slot(\d+)\s+view skipped:\s+(.+)$') +RE_D3D12_SLOT_CALL = re.compile(r'x2w-d3d12\s+([A-Za-z0-9_]+::slot\d+)\b') +RE_D3D12_REMOVED = re.compile( + r'x2w-d3d12\s+DEVICE REMOVED,\s+reason\s+(0x[0-9a-fA-F]+),\s+first noticed after\s+(.+)$' +) +RE_D3D12_DEBUG = re.compile(r'x2w-d3d12-debug\s+\[([^\]]+)\]\s+sev=(\d+)\s+id=(\d+)\s+(.+)$') + +RE_DSTORAGE_OUTCOME = re.compile(r'x2w-dstorage\s+options=0x[0-9a-fA-F]+.*?->\s+(.+)$') +RE_DSTORAGE_ENTRY_FAIL = re.compile( + r'x2w-dstorage\s+entry type\s+\d+\s+failed:\s+(.+?)(?:\s+\(options=0x[0-9a-fA-F]+\))?$' +) +RE_DSTORAGE_ZLIB_FAIL = re.compile(r'x2w-dstorage\s+zlib failure:\s+(.+)$') +RE_DSTORAGE_OPENFILE_FAIL = re.compile(r'x2w-dstorage\s+Factory::OpenFile\s+.*?->\s+(fail\b.*)$') +RE_DSTORAGE_HRESULT = re.compile( + r'x2w-dstorage\s+StatusArray::GetHResult\s+index=\d+\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_DSTORAGE_SIGNAL = re.compile( + r'x2w-dstorage\s+Queue::EnqueueSignal\s+.*?->\s+(0x[0-9a-fA-F]+)' +) + +RE_RUNTIME_CALL = re.compile( + r'x2w-(?:runtime|api)\s+([0-9a-fA-F]+::slot\d+)(?:\([^)]*\))?\s+->\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_STORAGE = re.compile( + r'x2w-runtime\s+persistent local storage:\s+local object instead of\s+(0x[0-9a-fA-F]+)' +) +RE_RUNTIME_GAMESAVE = re.compile( + r'x2w-runtime\s+game save:\s+update refused\s+\(status\s+(-?\d+)\)' +) + + +def redact(text: str) -> str: + """Strip local paths, executable names, and 64-bit addresses from a log snippet.""" + out = RE_QUOTED_WIN_PATH.sub('"<path>"', text) + out = RE_WIN_PATH.sub("<path>", out) + out = RE_QUOTED_POSIX_PATH.sub('"<path>"', out) + out = RE_POSIX_PATH.sub("<path>", out) + out = RE_EXE_NAME.sub("<exe>", out) + out = RE_ADDR64.sub("0x<addr>", out) + return out + + +def _md_cell(value: object) -> str: + return str(value).replace("|", "\\|").replace("\r", " ").replace("\n", " ") + + +def _parse_kv_block(block: str) -> dict[str, str]: + if block.strip() == "unreadable": + return {"_unreadable": "1"} + return dict(RE_KV.findall(block)) + + +def _is_failed_hresult(hex_text: str) -> tuple[bool, str]: + val = int(hex_text, 16) & 0xFFFFFFFF + return (val & 0x80000000) != 0, f"0x{val:08x}" + + +def iter_log_files(log_target: Path) -> list[Path]: + """Return sorted log files under log_target (or [log_target] if it is a file).""" + if not log_target.exists(): + return [] + if log_target.is_file(): + return [log_target] + if not log_target.is_dir(): + return [] + files = [ + p + for p in log_target.rglob("*") + if p.is_file() and p.suffix.lower() in LOG_EXTENSIONS + ] + files.sort() + return files + + +def summarize_lines(lines: Iterable[str]) -> dict[str, Counter]: + """Aggregate startup telemetry counters from an iterable of log lines.""" + slot70_refusals: Counter[tuple[str, str, str, str, str, str, str]] = Counter() + d3d12_unhandled: Counter[str] = Counter() + d3d12_debug: Counter[tuple[str, str, str, str]] = Counter() + dstorage_failures: Counter[str] = Counter() + dstorage_hresults: Counter[str] = Counter() + runtime_failures: Counter[tuple[str, str]] = Counter() + + for raw_line in lines: + line = raw_line.strip() + if not line: + continue + + # 1. slot70 memory SRV refusals + m = RE_SLOT70.search(line) + if m: + reason, res_raw, view_raw = m.group(1), m.group(2), m.group(3) + res = _parse_kv_block(res_raw) + view = _parse_kv_block(view_raw) + if "_unreadable" in res: + dim = fmt = layout = flags = "unreadable" + else: + dim = res.get("dim", "?") + fmt = res.get("fmt", "?") + layout = res.get("layout", "?") + flags = res.get("flags", "?") + if "_unreadable" in view: + view_dim = view_fmt = "unreadable" + else: + view_dim = view.get("dim", "?") + view_fmt = view.get("fmt", "?") + slot70_refusals[(reason, dim, fmt, view_dim, view_fmt, layout, flags)] += 1 + continue + + # 2. x2w-trap / x2w-noop / x2w-continue / x2w-fail + m = RE_TRAP_TAG.match(line) + if m: + tag, target = m.group(1), redact(m.group(2)) + d3d12_unhandled[f"{tag} {target}"] += 1 + continue + + # 3. x2w-d3d12-debug + m = RE_D3D12_DEBUG.search(line) + if m: + ctx, sev, msg_id, msg = m.group(1), m.group(2), m.group(3), redact(m.group(4)) + if len(msg) > 120: + msg = msg[:117] + "..." + d3d12_debug[(redact(ctx), sev, msg_id, msg)] += 1 + continue + + # 4. x2w-d3d12 unhandled/trapped/skipped slots & device removed + if "x2w-d3d12" in line: + m = RE_D3D12_REMOVED.search(line) + if m: + d3d12_unhandled[f"DEVICE REMOVED {m.group(1)} after {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_PIPELINE_TRAP.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)}({m.group(2)})"] += 1 + continue + m = RE_D3D12_IID_PASS.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} (passes IID)"] += 1 + continue + m = RE_D3D12_VIEW_SKIPPED.search(line) + if m: + d3d12_unhandled[f"Device::slot{m.group(1)} view skipped: {redact(m.group(2))}"] += 1 + continue + m = RE_D3D12_SLOT_CALL.search(line) + if m: + d3d12_unhandled[m.group(1)] += 1 ~~~~ --- Fixed in bf1b5b86: Forwarded/created slot lines ending in a successful result are no longer added to the unhandled table; failed results and untraced slot calls still are. Regression covers success, failure and untraced lines. Win2025 Debug and Release /O2: startup_triage_run 1/1 passed.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!1457
No description provided.