Skip to content

startup: trace declared provider outputs behind an opt-in switch - #1324

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
triggered02:tooling/api-trace
Nov 24, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
triggered02:tooling/api-trace

Conversation

@triggered02

Copy link
Copy Markdown
Contributor

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 reports out=? 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 unchanged 3,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, interface bf2346b2-39af-4658-b5ea-44713c7e83b3. That provider is the connectivity family in our stand-in (slot 15 is answered locally as a connectivity hint with level none, cost unknown, initialized set — 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 returns S_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_FALSE poll, but has not tied that call to the consuming condition inside the factory.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
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-24T08:08:56.055748Z dce4ce6 PR opened
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/startup_stubs/runtime_proxy.cpp Resolved
Comment thread src/startup_stubs/runtime_proxy.cpp Resolved
Comment thread src/startup_stubs/runtime_proxy.cpp Resolved
Comment thread src/startup_stubs/runtime_proxy.cpp Resolved

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at commit dce4ce6da0208bf65816bf1fbbbebb7f739d51b0.

Code Review & Findings

  • Bug (written sentinel for arg0): in forward(), 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; and if (written)). For {0x37e56907, 15, 0, no_second}, declared->first is 0 (arg0), so when args[0] changes, written stays 0 and out=unchanged is logged instead of out=arg0. Initializing int written = -1; and checking written < 0 / written >= 0 resolves 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 report out=unreadable (safe, just worth noting).
    • For two-output slots (15 and 20), only the first modified output is reported (out=arg3 even if arg4 also changed).
    • No unit test in tests/startup_stub_consumer.cpp exercises X2W_TRACE_API=1 yet.

Verification

Linux:

  • git diff --check origin/main...HEAD: clean
  • python -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.
@triggered02

Copy link
Copy Markdown
Contributor Author

All four findings and R0Y00's request are addressed in 8d6c5477.

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. readable was checking page accessibility, not the object's extent, which is exactly the hole you both identified.

written sentinel (R0Y00 + the fourth finding). Index 0 is a real output — the connectivity hint — so int written = 0 double-counted it as "nothing changed". It is now -1 with a separate notion of "any output was readable", so a changed hint reports arg0 instead of unchanged.

Slot contracts (first finding). XUserGetId is slot 11; slot 12 is XUserFindUserById. Both are declared, plus the duplicate-handle (3), local-id (9), find-for-device (40) slots that were missing for the same reason.

Secondary gamertag interface (second finding). Provider 0xcef4fac0 slot 3 now has its own row, so its buffer and used count are traced rather than reported as unknown.

Measured with X2W_TRACE_API=1 over a 60 s offline run (5,638 calls):

out=?        2893   (no declared contract)
out=arg0     2601   (connectivity hint, previously misreported as unchanged)
out=arg3       84   (gamertag buffer)
out=arg1       56
out=unchanged   4

The unchanged count collapsing from thousands to four is the width fix working: the constant hint is now compared over its real 16 bytes and correctly reported as written. startup_stubs passes; nothing changes unless the switch is set.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.
@triggered02

Copy link
Copy Markdown
Contributor Author

Second review addressed in 9731fae2, including the source-built controls.

Every changed output is reported. The loop no longer stops at the first: it prints changed:0 or changed:3,4.

The three outcomes are now distinguished, which is what the single word was conflating:

text meaning
same every declared output was compared and held the same value
same,partial one was compared and equal while another declared output could not be compared
unreadable no declared output could be compared

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 src/startup_stubs/api_trace.h with the contract table, so it is testable without a title. tests/api_trace_check.cpp (ctest api_trace) covers the four cases you asked for:

index 0 change is reported: ok                       -> changed:0, not "nothing changed"
both changed outputs are listed: ok                  -> changed:3,4
a byte past the width is not this output's change: ok -> one-byte output compared over one byte
a short caller buffer is compared over its capacity: ok
identical bytes are reported as same: ok
one comparable output is partial: ok                 -> same,partial
no comparable output is unreadable: ok
undeclared slot reports unknown: ok                  -> "?" and nothing read

It also asserts the table answers for XUserGetId (11), XUserFindUserById (12), the secondary gamertag interface (0xcef4fac0 slot 3) and the connectivity hint (0x37e56907 slot 15) - the four contracts the previous round added or corrected.

api_trace passes (13 cases) and startup_stubs passes; nothing changes unless X2W_TRACE_API is set.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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.

@R0Y00
R0Y00 merged commit eca20d6 into R0Y00:main Nov 24, 2026
5 checks passed
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