Repository navigation
startup: trace declared provider outputs behind an opt-in switch - #1324
Conversation
Adds X2W_TRACE_API=1, one line per provider call with the return code, whether the answer came from the stand-in or the real runtime, and which declared output argument was written. Only declared outputs are read. The previous revision of this trace probed every argument that looked like a readable pointer, which cannot distinguish an out-argument from a handle or size that happens to look like an address, and reports "none" for calls whose outputs sit outside the probed slots. The contracts are now a small table (user add result, id, guest flag, state, gamertag buffer and used count, age group, privilege result and deny reason, connectivity hint); a slot with no declared contract reports out=? and nothing is read. Nothing changes unless the switch is set. Measured with the switch on over a 70 s offline run (7,250 provider calls): x2w-api 37e56907::slot15 -> 0x00000000 local out=unchanged x2w-api 37e56907::slot2 -> 0x00000001 real out=? Outcomes: 3,833 undeclared (out=?), 3,400 unchanged, 15 arg3, 2 arg1. The 3,400 "unchanged" are the connectivity hint, whose four words are constant, so a repeat call leaves the same bytes — which is why "unchanged" is not by itself evidence that an output was skipped, and the log now says so per call instead of leaving it to be inferred.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dce4ce6da0
ℹ️ 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".
R0Y00
left a comment
There was a problem hiding this comment.
The opt-in trace still takes eight bytes from every output, even when the declared output is a flag, DWORD or a shorter caller buffer. A readable page does not establish the object's size. Please store the actual size/type in the contract, bound the snapshot by the declared buffer capacity, and report every changed output. The current written sentinel also treats index 0 (connectivity) as unchanged. A source-built control should cover index 0, two changed outputs, exact-width and short buffers, and a same-value write (which should remain reported as no observed change). Unknown slots should remain opaque. Please link #1160 in the PR body.
tedin7
left a comment
There was a problem hiding this comment.
Reviewed at commit dce4ce6da0208bf65816bf1fbbbebb7f739d51b0.
Code Review & Findings
- Bug (
writtensentinel forarg0): inforward(),int written = 0;is used both as the "no output changed" sentinel and as the index of the changed argument (if (now != before[i] && !written) written = index;andif (written)). For{0x37e56907, 15, 0, no_second},declared->firstis0(arg0), so whenargs[0]changes,writtenstays0andout=unchangedis logged instead ofout=arg0. Initializingint written = -1;and checkingwritten < 0/written >= 0resolves this. - Minor:
x2w_local::readable(..., 8)safely avoids probing arbitrary non-pointer arguments, though a 4-byte output sitting in the final 4 bytes of a page will reportout=unreadable(safe, just worth noting).- For two-output slots (
15and20), only the first modified output is reported (out=arg3even ifarg4also changed). - No unit test in
tests/startup_stub_consumer.cppexercisesX2W_TRACE_API=1yet.
Verification
Linux:
git diff --check origin/main...HEAD: cleanpython -B tests/docs_links_check.py: passed (16 Markdown files, 286 links)python -B tests/bidi_controls_check.py: passed (1076 files)
Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP):
- Debug (
--preset dev):cmake --build --preset dev --target startup_stub_gameinput startup_stub_consumer -- -j 6(4.95s) +ctest --preset dev -R '^startup_stubs$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.67s) - Release
/O2(--preset release):cmake --build --preset release --target startup_stub_gameinput startup_stub_consumer -- -j 6(2.94s) +ctest --preset release -R '^startup_stubs$' --parallel 4 --no-tests=error --output-on-failure: 1/1 passed (0.44s)
Addresses the review of R0Y00#1324. The trace took eight bytes from every output. A readable page does not establish the object's extent, so a one-byte flag or a DWORD could be read past its end or be classified unreadable when it straddles a page. The contract now carries each output's width: 1 for the guest flag, 4 for the state, age group and deny reason, 8 for handles, ids and used counts, 16 for the connectivity hint, and a caller-sized buffer for the gamertag, where the capacity comes from the size argument and the snapshot is bounded by it (and by a small cap). Also from the review: - Argument index 0 is a real output (the connectivity hint), so index 0 can no longer double as "no output changed". The trace uses a separate changed flag; before this, a changed hint was logged as `out=unchanged`. - XUserGetId is slot 11, not 12; slot 12 is XUserFindUserById. Both are declared, along with the duplicate-handle, local-id and find-for-device slots. - The dedicated gamertag interface (provider 0xcef4fac0, slot 3) has its own declaration, so its buffer and used count are no longer logged as unknown. Measured with X2W_TRACE_API=1 over a 60 s offline run (5,638 calls): 2,893 undeclared, 2,601 arg0 (the connectivity hint now correctly reported), 84 arg3 (gamertag buffer), 56 arg1, 4 unchanged. Because the widths are now correct, "unchanged" drops from thousands to four - the constant hint is compared over its real 16 bytes and reported as written. Nothing changes unless the switch is set; `startup_stubs` passes.
|
All four findings and R0Y00's request are addressed in Widths (R0Y00 + the third finding). The contract now carries each output's real width instead of taking eight bytes everywhere: 1 for the guest flag, 4 for the state, age group and deny reason, 8 for handles/ids/used counts, 16 for the connectivity hint, and for the gamertag a caller-sized buffer whose capacity comes from the size argument, bounded by it and by a small cap.
Slot contracts (first finding). Secondary gamertag interface (second finding). Provider Measured with The |
R0Y00
left a comment
There was a problem hiding this comment.
The declared widths and arg0 handling are improved. The revised loop stops after the first changed output and still has no source-built trace control. Please log both changed output indices where applicable, and distinguish “at least one compared and unchanged” from a partial comparison when another declared output was unreadable. Keep the text about observed byte changes precise: a provider can write the same value. Please add the index 0, two-output, exact/short-buffer and same-value controls from the previous review before requesting another pass.
…ontrol Addresses the second review of R0Y00#1324. The trace no longer stops at the first changed output: it reports every declared output that differs ("changed:0", "changed:3,4"), and it distinguishes three outcomes that were previously collapsed into one word: - "same" - every declared output was compared and held the same value; - "same,partial" - at least one output was compared and held the same value while another declared output could not be compared; - "unreadable" - no declared output could be compared at all. The wording is now about what was observed, not about what the provider did: a provider may legitimately write the value that was already there, so "same" never means "did not write". The decision is moved into src/startup_stubs/api_trace.h with the contract table, so it can be checked without a running title, and tests/api_trace_check.cpp covers the four cases the review asked for plus the surrounding ones: - argument index 0 changed is reported as "changed:0" (index 0 cannot double as "nothing changed"); - two changed outputs are both listed ("changed:3,4"); - a one-byte output is compared over one byte, and a byte past the declared width is not its change; - a caller buffer shorter than the declared width is compared over the caller's capacity only; - identical bytes report "same"; - one comparable output beside an uncomparable one reports "same,partial"; - no comparable output reports "unreadable", and an undeclared slot reports "?" and reads nothing; - the table answers for XUserGetId (11), XUserFindUserById (12), the secondary gamertag interface (0xcef4fac0 slot 3) and the connectivity hint (0x37e56907 slot 15). api_trace passes (13 cases) and startup_stubs passes; nothing changes unless X2W_TRACE_API is set.
|
Second review addressed in Every changed output is reported. The loop no longer stops at the first: it prints The three outcomes are now distinguished, which is what the single word was conflating:
Wording about providers. All text about observed bytes now says "same value", never "not written": a provider can write the value that was already there, so identical bytes are not evidence of a skipped write. Source-built controls. The decision now lives in It also asserts the table answers for
|
R0Y00
left a comment
There was a problem hiding this comment.
Retested the new trace and startup stand-ins on Windows Release (2/2). The declared width/capacity, arg0, two changes, same-value and partial cases now match the requested scope. The provider result stays unchanged.
The optional logging PR you welcomed is up: #1301,
X2W_TRACE_API=1, one line per provider call with the return code, whether the answer came from the stand-in or the real runtime, and which declared output argument was written. It reads only the outputs in a small contract table (user add result, id, guest flag, state, gamertag buffer and used count, age group, privilege result and deny reason, connectivity hint); a slot with no declared contract reportsout=?and nothing is read. The real provider result is left intact — nothing overrides or rewrites it.While writing it I also found that my previous "5,555 successes with no sampled argument changed" figure was too strong and should be withdrawn: with declared outputs, the connectivity hint reports
unchanged3,400 times simply because its four words are constant, so a repeat call leaves identical bytes. "Unchanged" therefore is not evidence that an output was skipped, and the earlier number cannot be read as "an S_OK with an untouched out-pointer". The new line says which case it is per call instead of leaving it to be inferred.Interface identification, since you asked for the contract: the poll pair is provider
37e56907-2f10-41e8-b72f-36edb185331a, interfacebf2346b2-39af-4658-b5ea-44713c7e83b3. That provider is the connectivity family in our stand-in (slot 15 is answered locally as a connectivity hint with levelnone, cost unknown,initializedset — the "stack initialized, no connectivity" answer already in the code), and slot 2 is not covered by the stand-in at all, so it passes through to the real runtime and returnsS_FALSE(0x00000001) there, 5,587 times in the last run, immediately before the assertion.So the typed poll you asked for is the next step and I have what it needs: a fixture that asks that interface for connectivity and distinguishes ready-with-item / empty-not-ready / failure, and records which of the three the real runtime gives for slot 2 versus what our hint says for slot 15. The contract I still cannot state from the code is what slot 2 is supposed to mean — if you can name the interface method, I will pin the documented return and output values into the fixture instead of inferring them.
Keeping the factory diagnosis open, as instructed: the trace ties the last call before the assertion to a
S_FALSEpoll, but has not tied that call to the consuming condition inside the factory.