Skip to content

xgameruntime: LEONIDA_TRACE_XGAMESAVE logs every XGameSave call - #2432

Merged
aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-xgamesave-trace
Nov 27, 2026
Merged

aslan2142 merged 1 commit into
ProjectLeonida:mainfrom
OreoFR:rt-xgamesave-trace

Conversation

@OreoFR

@OreoFR OreoFR commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-XGAMESAVE-TRACE

What and why

"Couldn't autosave" still shows sometimes, and the logs cannot say whether a save call failed: the offline save shim (runtime/shims/xgameruntime_gamesave.cpp) logs only when the provider opens. Reads, updates, writes and submits make no log line, so "no save call" and "a save call failed" look the same in a log.

LEONIDA_TRACE_XGAMESAVE=1 makes every XGameSave* and XGameSaveFiles* slot log one [rt] xgamesave: line on stderr. Each line has the call, its handles, container and blob names, sizes and HRESULT, after t=<ms since the process started>ms tid=<thread>. An async call also logs these lines:

  • schedule: when begin() calls XAsyncSchedule.
  • run: when its work starts on the queue, with waited= for the time it sat there.
  • complete: with its HRESULT and how long the work took.
  • the ...Result call: when the title collects the result.

All of these lines name the title's XAsyncBlock, so one job's lines can be matched up (XAsync hands the provider a copy of the block, so the shim keeps the title's block pointer). A job stuck behind a stalled queue, or a result the title never collects, then shows in the log. Blob contents are never logged: a read logs its blob names and sizes only. Enumerations log how many containers or blobs they returned.

It is off by default. The variable is read once, and when it is off each call costs one relaxed load. Names are only looked up while tracing. The slot behaviour does not change. Where a slot had early returns, its body moved into a helper so that the wrapper can log the result.

The row is in runtime/README.md's xgameruntime table, and there is a paragraph under XGameSaveImpl in docs/runtime_imports.md.

Tested

  • xgameruntime_gamesave_test: a new block turns the trace on through a test hook (xgameruntime_gamesave_trace_for_test, which sends the lines to a callback instead of stderr). It creates a container and an update, writes a 300-byte blob, then:

    • submits it with SubmitUpdateAsync/Result;
    • reads it with ReadBlobData, then with ReadBlobDataAsync/Result;
    • closes the handles and deletes the container, all in a temporary LEONIDA_SAVE_DIR.

    It checks the line format, the names, sizes and HRESULTs, and that the schedule, run, complete and Result lines come in that order and name the title's block. It also checks that the blob's contents appear in no line and that a call logs nothing once the trace is off. 91 checks, 0 failures.

  • ctest -R ^xgameruntime: 8/8 pass (xgameruntime, _user, _gamesave, _store, _offline, _offline_hdr, _user_gamertag, _user_gamertag_long). No new warnings in the shim at /W4.

  • The 13 tests/test_docs_*.py pass. scripts/check_no_game_data.py passes on the four changed files.

  • Not yet run on retail. The runs from a fixed copy of the save folder described in the claim come next, as a finding.

GPUs tested: n/a (no GPU code); built and tested on Windows 11, MSVC.

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: runtime only)

🤖 Generated with Claude Code

With LEONIDA_TRACE_XGAMESAVE=1 the offline XGameSaveImpl logs one
"[rt] xgamesave:" line per XGameSave* and XGameSaveFiles* call: the call,
its handles, container and blob names, sizes and HRESULT, with the
milliseconds since the process started and the thread id. An async call
also logs when begin() schedules its job, when the work runs (and how
long it waited on the queue), when it completes and when the title
collects the result, all naming the title's XAsyncBlock. Blob contents
are never logged. Off by default: a call then pays one relaxed load.

xgameruntime_gamesave_test turns it on through a test hook, writes and
reads a blob (sync and async) and checks the lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@tiguan26 tiguan26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving. Checked on 2bf19e6, which fast-forwards onto main.

Built xgameruntime_gamesave_test (clang-cl, cross-built) and ran it under Wine: passes with the trace off, and with LEONIDA_TRACE_XGAMESAVE=1 (exit 0, including "no trace line holds blob contents"). The docs validators (test_docs_env_vars.py and the other doc tests) pass. I read the stderr output of a traced run as well: the sync calls, the enumerations' counts and sizes, the too-small-buffer reads (read=(none) hr=0x80830007) and the async jobs' schedule/run/complete/Result lines all match up by async=, with the work on another tid and waited= filled in. No contents anywhere, only names and sizes.

Read the diff. The places that could have gone wrong look right to me: the Begin and DoWork lines copy what they need before XAsyncSchedule/XAsyncComplete can free the job, container_label and update_label take the recursive mutex so calling them under it in CloseContainer is fine, and every *count/*out dereference in a trace line is behind SUCCEEDED(hr) or a null check.

One small thing, not a blocker: for an async call the call's own line (XGameSave...Async async=... hr=) is logged after XAsyncBegin returns, so it always comes after the schedule line and sometimes after run (in the traced test run, schedule then the call line then run). The doc says the async call "logs four more lines", which is true, but a reader matching lines in a stalled run might expect the call line first. A word in the doc, or logging the call line before XAsyncBegin, would settle it.

@aslan2142

Copy link
Copy Markdown
Collaborator

Merging.

Thanks @OreoFR.

AI-assisted (Claude Code, Claude Opus 5.5 and Claude Fable 5.2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants