startup: count failed DirectStorage requests by cause in the heartbeat #1781
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!1781
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1781/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@MasterDomino on GitHub · 2026-11-24 18:33 UTC · original
MasterDomino:startup/storage-failure-counters→main· +463 −9 · 4 files · 2 commits · merged 2026-11-24 18:45 UTCWhat / why
Refs #1198 (scope approved in #1198). Refs #1758, which collects the first-failure evidence. This PR only adds whole-run totals; it does not show which failure came first.
The DirectStorage heartbeat has only reported one
failed=total. That total does not show whether failures come from reads at or past EOF, reads crossing EOF, short destinations or decoding. This PR adds a second heartbeat line that splits the same total by cause. Behavior does not change: request statuses, queue ordering, the existing totals line and every per-request log text (includingread failed) stay the same.Change
src/startup_stubs/xcrdapi.cpp:enum class StorageFailure, oneLONGper cause) are added.count_failure(cause)increments the cause andrequests_failedtogether, so the causes always add up tofailed=. It replaces every existingInterlockedIncrement(&requests_failed): inexecute_request, the unreadable page array inrun_entry,fail_entryandfail_unstarted. The worker path allocates nothing new.execute_requestrecords its cause next to the unchangedoutcometext:read failedgets a read cause, and the other sites map aszlib failed→ zlib,bcpack failed→ bcpack,destination capacity exceeded→ destination-capacity anddestination not writable→ destination-not-writable. Everything else goes toother: unknown option bits, insufficient page grants, missing page tokens, page writes, a page array unreadable at run, an entry that threw and an entry never started.GetFileSizeExon the File object's handle. The call is made only on the failure path. At or past EOF isoffset >= size, and crossing EOF iscount > size - offset, checked only whenoffset < size. No end offset is computed, so neither an offset nor a count near 2^64 can wrap. If the size is unknown (closed or non-file object,GetFileSizeExfails), or the range fits in the file (a shortReadFile), the read is counted as other read.x2w-dstorage heartbeat <n> s: failed requests by cause read-at-or-past-eof=N read-crossing-eof=N read-other=N destination-capacity=N destination-not-writable=N zlib=N bcpack=N other=NThe existing line is byte-for-byte unchanged. The new line is safe for the existing parsers:
inflated=,options=,Factory::OpenFile,EnqueueRequest,Queue::EnqueueStatusorcommit peak=text.tools/startup/live_view.pyreaches itsheartbeatbranch, whereheartbeat: (\d+) frames presenteddoes not match, so it prints nothing.x2w-dstorageline regexes intools/startup/triage_run.pymatch it.tests/startup_heartbeat_check.pyneedscommit peak=on the same line, which this line does not have.tests/startup_storage_failure_counts.cpp(new sibling ofstartup_storage_refusal_order, registered next to it) andCMakeLists.txt.docs/startup-runtime.md: a new Findings entry "DirectStorage failure causes", plus one sentence in "Startup memory accounting", where the heartbeat is described.How the test reads the counts (no new public knob)
The heartbeat runs every 10 s. Waiting for it, or adding an environment variable or a DLL export only for the test, was avoided. The fixture compiles
src/startup_stubs/xcrdapi.cppinto itself, asstartup_storage_worker_startalready does. It reads the counters directly and formats the heartbeat line through the stand-in's ownformat_failure_causes, which the heartbeat also uses.xcrdapi.defand the DLL's export surface do not change.Tests
Fixture: one Submit of 13 requests, each followed by its status entry, closed by a fence. The file is generated by the test (patterned bytes, one valid stored-deflate zlib stream, the same stream with a wrong Adler-32).
0x98cabbecat offset 0; raw 16-byte read 8 bytes before EOFPAGE_READONLYpageThe test checks:
requests_failed(11);read failed;count = 2^64 − 1at offset 1 andsize = 2^64 − 1with offset2^64 − 2, count 2, where a naiveoffset + countwraps to 0.Environment: Windows 11 (10.0.26300), MSVC x64,
devpreset. Branchstartup/storage-failure-countersfromupstream/main787f284f.2/2 passed (
startup_storage_failure_counts,startup_storage_failure_counts_one_bucket_control). The passing run prints:x2w-dstorage heartbeat 20 s: failed requests by cause read-at-or-past-eof=2 read-crossing-eof=3 read-other=1 destination-capacity=1 destination-not-writable=1 zlib=1 bcpack=1 other=113/13 passed. This includes
startup_storage_refusal_order,startup_storage_worker_start,startup_storage_alloc_failure,startup_dstorage_destination,startup_dstorage_file_read,startup_storage_directory_batchandcpu_native_dstorage.207 tests: 203 passed, 0 failed, 4 capability skips (
startup_view_heap_hardware,startup_view_heap_warp,startup_logical_view_hardware,startup_logical_view_warp).startup_heartbeat_commit, which parses the live heartbeat from the DLL, passed with the new line present. So didstartup_triage_run.A live check loaded the built
XCRDAPI.dll, calledDStorageGetFactoryand waited for the heartbeat. The log showed the unchanged totals line, followed byx2w-dstorage heartbeat 10 s: failed requests by cause read-at-or-past-eof=0 ... other=0.Negative controls
startup_storage_failure_counts_one_bucket_control(--mutate one-bucket,WILL_FAIL) holds the expectations of a counter that books every failure under one cause. It fails as required:count_failurewas changed to always incrementother, then reverted. The real test fails:read_failure_cause, then reverted. The test fails:offset + count > sizein place ofcount > size - offset), then reverted. The test fails:Not covered
otheris not split further (page grants, page writes, an unreadable page array, a thrown entry, an entry never started, unknown option bits). The fixture covers only its unknown-option case.ReadFileinside the file's range is counted asread-other. The fixture reaches that bucket through a closed File object, not through a real I/O error.🤖 Generated with Claude Code
After its totals line, the DirectStorage stand-in's heartbeat prints a second line with failed requests split by cause: read at or past EOF, read crossing EOF, other read failure, destination capacity, non-writable destination, zlib, BCPack and other. The causes add up to the existing failed total. The EOF split compares the request range with the file size without forming an end offset, so it cannot wrap. The totals line, request statuses, ordering and per-request log text ("read failed" and the rest) are unchanged. The counters are fixed named slots; the worker path allocates nothing new. The startup_storage_failure_counts fixture compiles the stand-in into itself (like startup_storage_worker_start) and submits valid, at/past EOF, crossing EOF, closed-file, short-destination, read-only destination, invalid-zlib, BCPack and unknown-option requests. It asserts the exact count of each cause, the heartbeat line text, the "read failed" text and edge ranges near 2^64. The one-bucket control expects every failure under one cause and must fail. Refs #1198 Refs #1758 Co-Authored-By: Claude Opus 5.5 <[email protected]>@R0Y00 on GitHub · 2026-11-24 18:41 UTC · original
The two heartbeat lines now share a single sample of the failure buckets, so a worker reporting another failure between the lines cannot make the printed total disagree with their sum. The fixture publishes a new count after taking the sample and checks that the formatted breakdown still matches the recorded values. Windows Release refusal-order, exact counts, and the one-bucket control passed 3/3.