Skip to content

gta6rt: the offline WinHTTP stub passes a handle's context value to its children - #3682

Open
shdann wants to merge 2 commits into
ItsNotRexed:mainfrom
shdann:winhttp-context-inherit
Open

shdann wants to merge 2 commits into
ItsNotRexed:mainfrom
shdann:winhttp-context-inherit

Conversation

@shdann

@shdann shdann commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claim: #3574 (comment) (a new RT item, no ID yet)

What and why

make_handle in runtime/shims/winhttp_offline.cpp copies the parent's status callback and notification mask to a new handle and leaves its context at 0. The host's winhttp.dll passes WINHTTP_OPTION_CONTEXT_VALUE on as well. This copies the parent's context in the same place: one line, under the parent's mutex that is already held there.

The stub stays what it is: nothing is resolved, connected or sent.

What this does not show: that the game depends on it. docs/runtime_imports.md says the package's DLLs give the context to WinHttpSendRequest, which already worked and is unchanged. This makes the stub answer as the host does for code that sets the context on the session or the connection instead.

Measured on the host

With the host's winhttp.dll, an asynchronous session, a loopback address and no request sent (handles are only created, queried and closed):

Step Host Stub before Stub now
context 7 set on the session, then WinHttpQueryOption on a new connection and a new request 7, 7 0, 0 7, 7
HANDLE_CREATED for the connection and the request carry 7 carry 0 carry 7
context 9 set on the request request 9, connection 7 request 9, connection 0 request 9, connection 7
context 11 set on the session afterwards existing connection 7, request 9; a new connection 11 0 / 9 / 0 as the host
a request under a connection whose own context is 13 13 0 the connection's
HANDLE_CLOSING each handle's own context 0 for inherited ones each handle's own

So the value is the parent's at the moment the child is made, and it does not follow a later change.

Reproduction (no game files)

The new block in runtime/test/winhttp_offline_test.cpp goes through those steps against the stub, on a synchronous session so every callback runs on the test's thread. On main f847748:

FAIL a connection and a request start with the session's context
FAIL and their HANDLE_CREATED callbacks carry it
FAIL a context set on the request replaces the inherited one for that request only
FAIL a context set on the session later does not change handles that exist
FAIL a connection made after that starts with the new one
FAIL a request starts with its connection's context, not the session's
FAIL HANDLE_CLOSING carries each handle's own context
49 check(s), 7 failure(s)

With the fix: 49 check(s), 0 failure(s). The block also checks that the context given to WinHttpSendRequest replaces the inherited one.

Tests run

Windows 11, Visual Studio 18 (MSVC 14.51), Windows SDK 10.0.26100.8249, CMake 4.4.3 + Ninja, RelWithDebInfo, Vulkan headers from -DLEONIDA_VULKAN_HEADERS_FETCH=ON; no glslangValidator, llvm-mc or SDL3, so the tests that need them were not built.

  • winhttp_offline_test: 49 checks, 0 failures, six runs in a row. (The known intermittent failure of this test on main, TEST-721, is in the asynchronous blocks and did not show up in these runs; this change does not touch them.)
  • ctest -C RelWithDebInfo --output-on-failure: 122 tests, 120 passed, 2 failed (d3d12_present, xbox_present), 8 skipped, 1 disabled. Those two fail on this machine on unchanged main as well, on a swapchain-extent check, and vary from run to run; the machine runs a tiling window manager that resizes new windows, which is the likely cause, not confirmed. Neither touches WinHTTP.
  • python -I tests/test_docs_links.py: OK.

No GPU is used by the change or its test. The full ctest run used an NVIDIA GeForce RTX 4090, driver 32.0.16.2101.

Other open pull requests

#3542 (TEST-721) changes runtime/test/winhttp_offline_test.cpp in three other places (after ms_since, and in the two asynchronous blocks). The new block here is a separate one before the WinHttpCrackUrl block, and the added #include <vector> is at the top, so the two should merge in either order. No open pull request changes winhttp_offline.cpp.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…ts children

make_handle copied the parent's status callback and notification mask to
a new handle and left its context at 0. The host's winhttp.dll also
passes WINHTTP_OPTION_CONTEXT_VALUE on: a connection and a request start
with the context their parent has when they are made, WinHttpQueryOption
returns it and their HANDLE_CREATED and HANDLE_CLOSING callbacks carry
it. A context set on the handle itself, or given to WinHttpSendRequest,
still replaces it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 21:20

Copilot AI 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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

6 open issues
What changed in this PR

Aligns the offline WinHTTP shim with host winhttp.dll behavior by inheriting WINHTTP_OPTION_CONTEXT_VALUE from parent handles at creation time, and adds a regression test to verify correct inheritance and callback context propagation.

Changes:

  • Copy parent handle context into newly created child handles in make_handle.
  • Add a new test block validating context inheritance semantics and callback HANDLE_CREATED/HANDLE_CLOSING context values.
  • Update runtime imports documentation to reflect the inherited context behavior.
File Description
runtime/​shims/​winhttp_offline.cpp Makes child handles inherit the parent’s context value at creation time.
runtime/​test/​winhttp_offline_test.cpp Adds coverage for context inheritance and callback context behavior.
docs/​runtime_imports.md Documents that context is inherited from the parent at child creation time.

Review effort: Lite

DWORD status;
DWORD_PTR context;
};
static std::vector<Event> events; // a synchronous session: every callback runs on this thread

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b1d2a06. The block calls events.clear() before it records. The list stays static because the callback is a lambda without captures and must reach it. This is a test-only change. winhttp_offline_test: 49 checks, 0 failures, six runs.

AI-assisted reply.

Comment thread runtime/test/winhttp_offline_test.cpp Outdated
Comment on lines +293 to +295
DWORD_PTR value = ~DWORD_PTR{0};
DWORD size = sizeof(value);
return query_option(handle, WINHTTP_OPTION_CONTEXT_VALUE, &value, &size) ? value : ~DWORD_PTR{0};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b1d2a06. The block now has kSessionContext (7), kRequestContext (9), kLaterSessionContext (11), kSendContext (0x51) and kNoContext (~DWORD_PTR{0}). The values and the checks are the same. winhttp_offline_test: 49 checks, 0 failures, six runs.

AI-assisted reply.

Comment thread runtime/test/winhttp_offline_test.cpp Outdated
const auto context_at = [&](HINTERNET handle, DWORD status) -> DWORD_PTR {
for (const Event& e : events)
if (e.handle == handle && e.status == status) return e.context;
return ~DWORD_PTR{0};

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b1d2a06: this line uses the named constants now. The reply on line 295 gives the names and the test result. AI-assisted reply.

Comment thread runtime/test/winhttp_offline_test.cpp Outdated

const HINTERNET session = open(L"test", WINHTTP_ACCESS_TYPE_NO_PROXY, nullptr, nullptr, 0);
set_callback(session, record, WINHTTP_CALLBACK_FLAG_HANDLES, 0);
check(set_context(session, 7), "WINHTTP_OPTION_CONTEXT_VALUE can be set on a session");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b1d2a06: this line uses the named constants now. The reply on line 295 gives the names and the test result. AI-assisted reply.

Comment thread runtime/test/winhttp_offline_test.cpp Outdated
Comment on lines +328 to +329
send(sent, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0x51);
check(context_of(sent) == 0x51, "the context WinHttpSendRequest is given replaces the inherited one");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b1d2a06: this line uses the named constants now. The reply on line 295 gives the names and the test result. AI-assisted reply.

Comment thread runtime/test/winhttp_offline_test.cpp Outdated
Comment on lines +297 to +339
const auto set_context = [&](HINTERNET handle, DWORD_PTR value) {
return set_option(handle, WINHTTP_OPTION_CONTEXT_VALUE, &value, sizeof(value)) != FALSE;
};
const auto context_at = [&](HINTERNET handle, DWORD status) -> DWORD_PTR {
for (const Event& e : events)
if (e.handle == handle && e.status == status) return e.context;
return ~DWORD_PTR{0};
};

const HINTERNET session = open(L"test", WINHTTP_ACCESS_TYPE_NO_PROXY, nullptr, nullptr, 0);
set_callback(session, record, WINHTTP_CALLBACK_FLAG_HANDLES, 0);
check(set_context(session, 7), "WINHTTP_OPTION_CONTEXT_VALUE can be set on a session");
const HINTERNET connection = connect(session, L"127.0.0.1", 1, 0);
const HINTERNET request = open_request(connection, L"GET", L"/", nullptr, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
check(context_of(connection) == 7 && context_of(request) == 7,
"a connection and a request start with the session's context");
check(context_at(connection, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED) == 7 &&
context_at(request, WINHTTP_CALLBACK_STATUS_HANDLE_CREATED) == 7,
"and their HANDLE_CREATED callbacks carry it");

check(set_context(request, 9) && context_of(request) == 9 && context_of(connection) == 7,
"a context set on the request replaces the inherited one for that request only");
check(set_context(session, 11) && context_of(connection) == 7 && context_of(request) == 9,
"a context set on the session later does not change handles that exist");
const HINTERNET late = connect(session, L"127.0.0.1", 1, 0);
check(context_of(late) == 11, "a connection made after that starts with the new one");

const HINTERNET sent = open_request(connection, L"GET", L"/", nullptr, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
check(context_of(sent) == 7, "a request starts with its connection's context, not the session's");
send(sent, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0x51);
check(context_of(sent) == 0x51, "the context WinHttpSendRequest is given replaces the inherited one");

close(sent);
close(request);
close(late);
close(connection);
close(session);
check(context_at(sent, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) == 0x51 &&
context_at(request, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) == 9 &&
context_at(late, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) == 11 &&
context_at(connection, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING) == 7,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in b1d2a06: this line uses the named constants now. The reply on line 295 gives the names and the test result. AI-assisted reply.

@itsonlysimbo

Copy link
Copy Markdown
Contributor

Tested 0f83451a on RTX 4070, NVIDIA 621.14, Windows 11 (10.0.26300), MSVC 19.44, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363: pass.

  • winhttp_offline passes, with file_system, loader and loader_tls.
  • ctest: 140/140; run_gpu_tests.py: 153/199 passed, 46 skipped, 0 failed, same as main f847748c.

AI-assisted (Claude Code).

@Maraco91

Copy link
Copy Markdown

Tested 0f83451 on Windows 11, MSVC 19.42 (VS 2022 Build Tools), Windows SDK 10.0.28000.0, NVIDIA RTX 3080 Ti, driver 616.56: pass

  • scripts\build_runtime.ps1: builds clean.
  • ctest -R winhttp: passes.
  • Full ctest: 132 of 132 pass (the same 8 skipped and 1 disabled as on main here).
  • Negative control: with runtime/shims/winhttp_offline.cpp restored to main and the test kept, winhttp_offline ends with "49 check(s), 7 failure(s)": the seven new inheritance checks, nothing else.

The host measurements in the description, repeated independently against this machine's winhttp.dll (10.0.26100.9949) from a small ctypes script, synchronous session, 127.0.0.1, handles only created, queried and closed:

Step Host here
context 7 set on the session; WinHttpQueryOption on a new connection and a new request 7, 7
context 9 set on the request request 9, connection still 7
context 11 set on the session afterwards connection still 7, request still 9
a connection made after that 11
a second request under the first connection 7 (its connection's, not the session's)

Every row agrees with what the new test asserts of the stub. I did not repeat the callback rows (HANDLE_CREATED / HANDLE_CLOSING carrying the value) or the WinHttpSendRequest context on the host, since the second would need a request to be sent.

No blocker found.

AI-assisted (Claude Code); no game files, and nothing was resolved, connected or sent.

@kacper-serewis kacper-serewis 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.

At 0f83451 all 49 synthetic Windows x64 checks passed. Creation copied the immediate parent's context, later mutations applied to future children, request overrides stayed local, and create/close callbacks reported inherited/final values respectively. Offline shim only. AI-assisted.

@kotorvr

kotorvr commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested 0f83451 on Windows 11 Home 26200, MSVC 19.44 (VS 2022), Ninja, RelWithDebInfo (the machine has an RTX 4090 on 621.14, which this CPU-side test does not use): pass.

The branch is on main f847748, built the same way for comparison.

winhttp_offline_test main f847748 0f83451
one run 40 checks, 0 failures 49 checks, 0 failures
ctest -R "^winhttp_offline$" --repeat until-fail:40, repeated failed on the 34th run of one batch (TEST-721: "notifications not asked for are not sent, and each handle still closes once") 0 failures in 200 runs (5 batches of 40)

About the second row: TEST-721's intermittent failure is on main and this PR does not claim to touch it. I did not see it in 200 runs here, but the machine was less loaded than during my main run, so I would not credit the PR with that; the point is only that the nine new context checks did not add a flaky one.

I did not compare against the host's winhttp.dll myself (the table in the PR body is the author's measurement). No game files, nothing sent on the network: the stub never connects. AI-assisted check (Claude Code).

@Parakeet-Wheat

Copy link
Copy Markdown
Contributor

Tested 0f83451 on Windows 11 26300, MSVC (VS 2022), Windows SDK 10.0.26100 (full ctest on an RTX 3070, 610.88): pass. My results agree with @itsonlysimbo and @Maraco91: winhttp_offline_test 49/0, ctest 140/140, and the negative control fails only the 7 new checks. What follows covers the rows @Maraco91 left out of their host check.

Host check: the callback rows, an asynchronous session, two more cases. I wrote a small C++ program against the system winhttp.dll, not part of the PR. It only creates, queries and closes handles: nothing is resolved, connected or sent. A synchronous and an asynchronous session give identical results, and every row matches your table and the new test:

  • HANDLE_CREATED for the connection and the request carries the session's 7.
  • HANDLE_CLOSING carries each handle's own context when it closes: 9 for the request, 11 for the late connection, and 13 for a request created under a connection set to 13.
  • A request created under a connection whose own context is 13 starts at 13, so the value comes from the immediate parent.
  • A session with no status callback still passes its context on: a connection under a session set to 21 reads 21. The new line copies context regardless of the callback, so the stub matches.

Loop: 30 runs of winhttp_offline_test with this PR gave 29 passes. The one failure was "notifications not asked for are not sent, and each handle still closes once", in the third asynchronous block. None of the new checks failed. That block comes right after the one #3542 (TEST-721) makes wait for its closings ("the connection and the session report HANDLE_CLOSING before the next block counts its own"). So a late closing from block 2 counted in block 3 would explain it, and #3542 probably covers it. It's unrelated to this change.

AI-assisted (Claude Code).

@requiemsnkrp

Copy link
Copy Markdown

Tested 0f83451a (merged onto main f847748c) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: pass.

  • winhttp_offline (with LEONIDA_VK_VALIDATION=1): Passed 0.06 sec, including PASS a connection and a request start with the session's context, PASS a context set on the request replaces the inherited one for that request only, PASS a context set on the session later does not change handles that exist, PASS a request starts with its connection's context, not the session's, PASS HANDLE_CLOSING carries each handle's own context.
  • Full ctest (-E "present|swapchain|frame_pacer"): 100% tests passed, 0 tests failed out of 127 (8 skipped/disabled, same set as main: shader_library_corpus, bink_decode, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).

AI-assisted (Claude). No game files.

@FaKL-Code

Copy link
Copy Markdown
Contributor

Tested 0f83451 (merged onto main f847748) on NVIDIA GeForce RTX 4060 Ti, driver 610.88 (32.0.16.1088), Windows 11 26200, MSVC 14.51.36231 (VS 2026), Vulkan SDK 1.4.363.0: pass

  • Merges cleanly; no new compiler warnings against main.
  • ctest: 131 of 131 pass (same 8 skips as main). Loader test passes; validation run: 52 tests clean (2 skipped, as on main).
  • winhttp_offline -V: "49 check(s), 0 failure(s)", including the new context checks (inherited by the connection and the request, a later session change not reaching existing handles, HANDLE_CREATED/HANDLE_CLOSING carrying each handle's own value).
  • This PR's winhttp_offline_test.cpp built against main's winhttp_offline.cpp: "49 check(s), 7 failure(s)", the 7 inheritance checks. The one already true on main ("the context WinHttpSendRequest is given replaces the inherited one") passes there too. That matches the table in the body.
  • Main has moved since (aa2988c); git merge-tree merges this head with it cleanly. I didn't rebuild on it.

AI-assisted (Claude).

…t of the inheritance block

Test only, no change of behaviour: the contexts 7, 9, 11 and 0x51 and the "no value" sentinel get constexpr names,
and the static event list is cleared before the block records into it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Summary of the review fixes. The new head is b1d2a06. The change is in the test only. winhttp_offline.cpp is the same as in the approved commit 0f83451.

  • events (Copilot, line 288): the block clears the list before it records.
  • Magic values (Copilot, lines 295, 303, 308, 329, 339): the contexts and the sentinel have constexpr names. The values and the checks are the same.

Tests on Windows 11, MSVC 14.51, Windows SDK 10.0.26100.8249, CMake 4.4.3 with Ninja, RelWithDebInfo:

  • winhttp_offline_test: 49 checks, 0 failures, six runs.
  • ctest -C RelWithDebInfo: 122 tests, 120 passed, 2 failed (d3d12_present, xbox_present). These two also fail on main on this machine. They do not use WinHTTP.
  • python -I tests/test_docs_links.py: OK.
  • GPU for the full run: NVIDIA GeForce RTX 4090, driver 621.01 (32.0.16.2101). The change uses no GPU.

AI-assisted (Claude Code).

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.

9 participants