WIP: fix(control): a game the sandbox confined serves its pipe in its AppContainer's namespace, and the client finds it #2742

Closed
ChloeNow wants to merge 1453 commits from ChloeNow/Longshot:fix/control-pipe-appcontainer into mod-api
Member

A stopgap. The control connection is to go through the broker, once longshot-builder brokers between the game and the system: the game will then serve no pipe of its own, and this goes. Until then it keeps sandboxed test runs on Windows (dev.py game-tests, any longshot_bridge session) working: without it they end "the game did not start" even when their tests pass.

Summary

On Windows the control bridge never served a game the sandbox confined (the default since #2434): a process in an
AppContainer may make named pipes only in its own namespace, so the game's CreateNamedPipe of \\.\pipe\<HOS_CONTROL>
was refused with error 5, and the log said control: off. dev.py game-tests (and any longshot_bridge session)
then never saw the game ready: a sandboxed test run ended "the game did not start: game exited 0 before ready=present",
exit 2, even when its tests passed and wrote results.json. #544 let the container connect to the pipe; nothing let
it make one.

  • host/control.c: in an AppContainer (pipe_security already reads its SID), the pipe is made as
    \\.\pipe\LOCAL\<name>, and the log names the path a client outside opens:
    \\.\pipe\Sessions\<n>\AppContainerNamedObjects\<the container's SID>\<name>. A name already in a namespace
    (LOCAL\, Sessions\) is taken as it is. Outside a container nothing changes.
  • scripts/longshot_bridge.py: a pipe its plain name does not find is tried at that path, for the sandbox's
    container, Longshot.Game (its SID derived as host/sandbox_windows.c derives it; this session's number).
  • docs/dev/reference/control-bridge.md: the Security section says so.

On mod-api, to see it: Windows, dev.py game-tests <a mod with an in-game test> (sandboxed, the default): the
game's log says control: \\.\pipe\longshot-control-...: 5 and control: off, and game-tests says the game did not
start. A sandboxed start with a profile also needs #2726 to reach play at all.

Read first: host/control.c transport_open, scripts/longshot_bridge.py Bridge.__init__ and container_pipe.

Testing

Tested: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24.

  • tests/test_control_appcontainer.py (new, Windows only): tests/control_test.c (the bridge over a fake game, as
    tests/test_control.py builds it) serving inside a real Longshot.Game AppContainer with no capabilities, as the
    sandbox starts the game, and longshot_bridge.Bridge outside asking status and quit. On mod-api: the confined
    bridge exits 3, its pipe not made. Here: passes. With the client half undone: "no client reached the confined
    bridge in 30 s ... cannot find the file specified", so both halves are needed.
  • tests/test_control.py and tests/test_control_pipe_security.py pass (Windows, clang).
  • In the game: dev.py game-tests of a mod with an in-game test, sandboxed with its profile, on this branch merged with #2726 (which
    a sandboxed profile start needs to reach play; a local merge, not pushed). The game's log: control: in an AppContainer: served as \\.\pipe\LOCAL\longshot-control-..., which a client outside opens as \\.\pipe\Sessions\1\AppContainerNamedObjects\S-1-15-2-...\longshot-control-..., control: listening on ...,
    control: state boot -> intro, intro -> menu. game-tests: ok - test/main.test.ts: ..., "1 passed, 0 failed,
    4 skipped (in the game)", exit 0. On #2726 alone the same run's game log says control: off, and game-tests "the game
    did not start: game exited 0 before ready=present", exit 2.

Still to test:

  • Linux: nothing changes there (a Unix socket, no AppContainer); tests/test_control.py in CI.
  • Windows, a longshot_ctl.py session (shot, press, teleport) against a sandboxed game (by hand).

Measurements

Nothing to measure: the pipe's name and a client's second try, at connect only.

Risks

  • The client's second name is the sandbox's own container's namespace only (Longshot.Game's SID, this session): no
    other app's pipes are tried.
  • An AppContainer-hosted game with a HOS_CONTROL already of a namespace keeps it as it is.
  • A revert is enough.

Checklist

Ready for review

  • One topic, on current mod-api; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • Docs updated.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

> **A stopgap.** The control connection is to go through the broker, once longshot-builder brokers between the game and the system: the game will then serve no pipe of its own, and this goes. Until then it keeps sandboxed test runs on Windows (`dev.py game-tests`, any `longshot_bridge` session) working: without it they end "the game did not start" even when their tests pass. ## Summary On Windows the control bridge never served a game the sandbox confined (the default since #2434): a process in an AppContainer may make named pipes only in its own namespace, so the game's `CreateNamedPipe` of `\\.\pipe\<HOS_CONTROL>` was refused with error 5, and the log said `control: off`. `dev.py game-tests` (and any `longshot_bridge` session) then never saw the game ready: a sandboxed test run ended "the game did not start: game exited 0 before ready=present", exit 2, even when its tests passed and wrote `results.json`. #544 let the container *connect* to the pipe; nothing let it *make* one. - **`host/control.c`**: in an AppContainer (`pipe_security` already reads its SID), the pipe is made as `\\.\pipe\LOCAL\<name>`, and the log names the path a client outside opens: `\\.\pipe\Sessions\<n>\AppContainerNamedObjects\<the container's SID>\<name>`. A name already in a namespace (`LOCAL\`, `Sessions\`) is taken as it is. Outside a container nothing changes. - **`scripts/longshot_bridge.py`**: a pipe its plain name does not find is tried at that path, for the sandbox's container, `Longshot.Game` (its SID derived as `host/sandbox_windows.c` derives it; this session's number). - **`docs/dev/reference/control-bridge.md`**: the Security section says so. **On mod-api, to see it:** Windows, `dev.py game-tests <a mod with an in-game test>` (sandboxed, the default): the game's log says `control: \\.\pipe\longshot-control-...: 5` and `control: off`, and game-tests says the game did not start. A sandboxed start with a profile also needs #2726 to reach play at all. Read first: `host/control.c` `transport_open`, `scripts/longshot_bridge.py` `Bridge.__init__` and `container_pipe`. ## Testing **Tested:** Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24. - `tests/test_control_appcontainer.py` (new, Windows only): `tests/control_test.c` (the bridge over a fake game, as `tests/test_control.py` builds it) serving inside a real `Longshot.Game` AppContainer with no capabilities, as the sandbox starts the game, and `longshot_bridge.Bridge` outside asking `status` and `quit`. On mod-api: the confined bridge exits 3, its pipe not made. Here: passes. With the client half undone: "no client reached the confined bridge in 30 s ... cannot find the file specified", so both halves are needed. - `tests/test_control.py` and `tests/test_control_pipe_security.py` pass (Windows, clang). - In the game: `dev.py game-tests` of a mod with an in-game test, sandboxed with its profile, on this branch merged with #2726 (which a sandboxed profile start needs to reach play; a local merge, not pushed). The game's log: `control: in an AppContainer: served as \\.\pipe\LOCAL\longshot-control-..., which a client outside opens as \\.\pipe\Sessions\1\AppContainerNamedObjects\S-1-15-2-...\longshot-control-...`, `control: listening on ...`, `control: state boot -> intro`, `intro -> menu`. game-tests: `ok - test/main.test.ts: ...`, "1 passed, 0 failed, 4 skipped (in the game)", exit 0. On #2726 alone the same run's game log says `control: off`, and game-tests "the game did not start: game exited 0 before ready=present", exit 2. **Still to test:** - Linux: nothing changes there (a Unix socket, no AppContainer); `tests/test_control.py` in CI. - Windows, a `longshot_ctl.py` session (shot, press, teleport) against a sandboxed game (by hand). ## Measurements Nothing to measure: the pipe's name and a client's second try, at connect only. ## Risks - The client's second name is the sandbox's own container's namespace only (`Longshot.Game`'s SID, this session): no other app's pipes are tried. - An AppContainer-hosted game with a `HOS_CONTROL` already of a namespace keeps it as it is. - A revert is enough. ## Checklist ### Ready for review - [x] One topic, on current `mod-api`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). <!-- Windows: the control checks; Linux: CI --> - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. <!-- Windows built; Linux: CI --> - [x] Docs updated. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tests/control_test.c (host/control.c over a fake game) is started serving inside the game's own AppContainer, with no
capabilities, as host/sandbox_windows.c starts the game, by a launcher built here; its folder given to the container to
read and run. scripts/longshot_bridge.py's Bridge, outside, opens the pipe by HOS_CONTROL's name, asks status, and quits
it. Fails on mod-api: the confined bridge cannot make \.\pipe\<name> (an AppContainer makes pipes only under its own
LOCAL\ namespace) and exits 3, so dev.py game-tests never sees a sandboxed game ready.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(control): a game the sandbox confined serves its pipe in its AppContainer's namespace, and the client finds it
All checks were successful
PR description / Title and description (pull_request_target) Successful in 6s
7ffc7313a0
A process in an AppContainer makes named pipes only in its own namespace: the confined game's CreateNamedPipe of
\.\pipe\<HOS_CONTROL> was refused (error 5, "control: off"), so the bridge never served a sandboxed game and dev.py
game-tests said "the game did not start" even of a run whose tests passed. #544 let the container connect to the pipe;
it could not make it.

- host/control.c: in an AppContainer (pipe_security reads its SID), the pipe is \.\pipe\LOCAL\<name>, and the log
  names the path a client outside opens, \.\pipe\Sessions\<n>\AppContainerNamedObjects\<the SID>\<name>. A name
  already in a namespace (LOCAL\, Sessions\) is taken as it is. Outside a container nothing changes.
- scripts/longshot_bridge.py: a pipe not found by its plain name is tried there for the sandbox's container,
  Longshot.Game (its SID derived as host/sandbox_windows.c derives it, this session's number).
- docs/dev/reference/control-bridge.md: the Security section says so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

Tested in game: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24: dev.py game-tests of a mod with an in-game test, sandboxed with its profile, on this branch merged locally with #2726. The game's log: 'control: in an AppContainer: served as .\pipe\LOCAL\longshot-control-...', 'control: listening on ...', its states boot, intro, menu followed; game-tests: '1 passed, 0 failed, 4 skipped (in the game)', exit 0. On #2726 alone: 'control: off' and 'the game did not start ... before ready=present', exit 2.

Tested in game: Windows 11, NVIDIA GeForce RTX 4060 Laptop GPU, driver 621.24: dev.py game-tests of a mod with an in-game test, sandboxed with its profile, on this branch merged locally with #2726. The game's log: 'control: in an AppContainer: served as \.\pipe\LOCAL\longshot-control-...', 'control: listening on ...', its states boot, intro, menu followed; game-tests: '1 passed, 0 failed, 4 skipped (in the game)', exit 0. On #2726 alone: 'control: off' and 'the game did not start ... before ready=present', exit 2.
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The sandboxed bridge works in the reported game run, but a client can connect to a different game when confined and unconfined games use the same pipe name. Explicit LOCAL names also remain unreachable through the client.

The change lets a sandboxed Windows game serve its control bridge and lets the Python client discover it. It fixes the reported game-tests failure, at the cost of introducing ambiguity between identically named pipes in different namespaces.

Blocking (1): must change before merging.

  1. L1 scripts/longshot_bridge.py:191: Trying the global pipe first can connect a session to the wrong game because the same name can now exist in both namespaces. (more on the line) Do: Carry the intended game's namespace or identity to the client and select or verify the pipe against that identity before sending commands. Add a test with both namespaces occupied.

Should fix (2): not blocking, but worth doing before merging.

  • L2 scripts/longshot_bridge.py:94: The client refuses to translate an explicit LOCAL pipe name, although the server accepts that name in the container. (more on the line) Do: Translate LOCAL-prefixed names to the container's external path after stripping LOCAL, and test an explicit LOCAL name end to end.
  • L3 tests/test_control_appcontainer.py:103: The new test ignores CC and can silently skip despite a configured Windows compiler. (more on the line) Do: Honor the configured compiler, including the test runner's compiler argument, and make a missing required compiler visible to the Windows test run.

@fix can do L1, L2 and L3.

More: does it help, other systems, switches, what was read

Does it help: Yes. On Windows 11, the author reports that the sandboxed in-game test changed from control being off and game-tests exiting 2 to one test passing and exit 0, with #2726 included on both sides.

Other systems: The changed transport and discovery paths are Windows-only; Linux continues to use Unix sockets. The reported Windows run used NVIDIA hardware. Explicit pipe names, simultaneous confined and unconfined games, and a manual longshot_ctl session need coverage.

Switches: No switches added, changed, or removed.

Reviewed: 7ffc7313a0 against 4266ba68cc: Read the diff, both commit messages, repository rules, PR template, the new test, changed transport and client code, and relevant callers and security tests. The large host/control.c and scripts/longshot_bridge.py outputs were truncated, so their unchanged portions were not read in full. The requested review checklist and adjacent Tooling AGENTS.md were absent. No generated files or recorded runs were changed.; nothing run (a code review).

Checked and fine:

  • Both commits record AI assistance in trailers.
  • The new game-free test exercises a real AppContainer and the reported run shows it fails when the client half is undone.
  • No game-derived files, generated files, or third-party files appear in the diff.

Testing: Read-only review; no code, scripts, builds, or tests were run. The PR remains WIP and reports a dependency on #2726 for sandboxed profile starts.

Overlaps and merge order: #2726 is needed for the reported sandboxed profile start; the reported game comparison includes it on both sides.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The sandboxed bridge works in the reported game run, but a client can connect to a different game when confined and unconfined games use the same pipe name. Explicit LOCAL names also remain unreachable through the client. The change lets a sandboxed Windows game serve its control bridge and lets the Python client discover it. It fixes the reported game-tests failure, at the cost of introducing ambiguity between identically named pipes in different namespaces. **Blocking (1)**: must change before merging. 1. **L1** `scripts/longshot_bridge.py:191`: Trying the global pipe first can connect a session to the wrong game because the same name can now exist in both namespaces. (more on the line) **Do:** Carry the intended game's namespace or identity to the client and select or verify the pipe against that identity before sending commands. Add a test with both namespaces occupied. **Should fix (2)**: not blocking, but worth doing before merging. - **L2** `scripts/longshot_bridge.py:94`: The client refuses to translate an explicit LOCAL pipe name, although the server accepts that name in the container. (more on the line) **Do:** Translate LOCAL-prefixed names to the container's external path after stripping LOCAL, and test an explicit LOCAL name end to end. - **L3** `tests/test_control_appcontainer.py:103`: The new test ignores CC and can silently skip despite a configured Windows compiler. (more on the line) **Do:** Honor the configured compiler, including the test runner's compiler argument, and make a missing required compiler visible to the Windows test run. `@fix` can do L1, L2 and L3. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Yes. On Windows 11, the author reports that the sandboxed in-game test changed from control being off and game-tests exiting 2 to one test passing and exit 0, with #2726 included on both sides. **Other systems:** The changed transport and discovery paths are Windows-only; Linux continues to use Unix sockets. The reported Windows run used NVIDIA hardware. Explicit pipe names, simultaneous confined and unconfined games, and a manual longshot_ctl session need coverage. **Switches:** No switches added, changed, or removed. **Reviewed:** 7ffc7313a0fc against 4266ba68cc0d: Read the diff, both commit messages, repository rules, PR template, the new test, changed transport and client code, and relevant callers and security tests. The large host/control.c and scripts/longshot_bridge.py outputs were truncated, so their unchanged portions were not read in full. The requested review checklist and adjacent Tooling AGENTS.md were absent. No generated files or recorded runs were changed.; nothing run (a code review). **Checked and fine:** - Both commits record AI assistance in trailers. - The new game-free test exercises a real AppContainer and the reported run shows it fails when the client half is undone. - No game-derived files, generated files, or third-party files appear in the diff. **Testing:** Read-only review; no code, scripts, builds, or tests were run. The PR remains WIP and reports a dependency on #2726 for sandboxed profile starts. **Overlaps and merge order:** #2726 is needed for the reported sandboxed profile start; the reported game comparison includes it on both sides. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -87,0 +91,4 @@
"""The path a client outside opens for the pipe a process in the AppContainer `sid` serves as \\\\.\\pipe\\LOCAL\\<leaf>
(host/control.c: a confined game's); None for a name already in some namespace (LOCAL\\, Sessions\\)"""
leaf = name[len("\\\\.\\pipe\\"):] if name.startswith("\\\\.\\pipe\\") else name
if not leaf or leaf.lower().startswith(("local\\", "sessions\\")):
Member

L2 (should fix): The client refuses to translate an explicit LOCAL pipe name, although the server accepts that name in the container.

When: With HOS_CONTROL set to LOCAL\foo, the confined server creates its container-local pipe, but an outside Bridge tries its own LOCAL namespace and then returns None instead of trying the container's external Sessions path. It therefore cannot reach the running game.

Do: Translate LOCAL-prefixed names to the container's external path after stripping LOCAL, and test an explicit LOCAL name end to end.

**L2** (should fix): The client refuses to translate an explicit LOCAL pipe name, although the server accepts that name in the container. *When:* With HOS_CONTROL set to LOCAL\foo, the confined server creates its container-local pipe, but an outside Bridge tries its own LOCAL namespace and then returns None instead of trying the container's external Sessions path. It therefore cannot reach the running game. **Do:** Translate LOCAL-prefixed names to the container's external path after stripping LOCAL, and test an explicit LOCAL name end to end.
@ -144,2 +189,3 @@
self.sock = None
self.pipe = open_windows_pipe(name, timeout)
try:
self.pipe = open_windows_pipe(name, timeout)
Member

L1 (blocking): Trying the global pipe first can connect a session to the wrong game because the same name can now exist in both namespaces.

When: If an unconfined game and a sandboxed game both use the same explicit HOS_CONTROL name, both pipes can be created. A client for the sandboxed game opens the unconfined pipe successfully and sends its commands there; a quit or write can affect the wrong game.

Do: Carry the intended game's namespace or identity to the client and select or verify the pipe against that identity before sending commands. Add a test with both namespaces occupied.

**L1** (blocking): Trying the global pipe first can connect a session to the wrong game because the same name can now exist in both namespaces. *When:* If an unconfined game and a sandboxed game both use the same explicit HOS_CONTROL name, both pipes can be created. A client for the sandboxed game opens the unconfined pipe successfully and sends its commands there; a quit or write can affect the wrong game. **Do:** Carry the intended game's namespace or identity to the client and select or verify the pipe against that identity before sending commands. Add a test with both namespaces occupied.
@ -0,0 +100,4 @@
print("SKIP: Windows only (AppContainers)")
return
mingw = os.environ.get("LONGSHOT_MINGW")
cc = a.cc or (str(Path(mingw, "bin", "clang.exe")) if mingw else shutil.which("clang"))
Member

L3 (should fix): The new test ignores CC and can silently skip despite a configured Windows compiler.

When: On a Windows test host with CC set to a suitable compiler but no clang on PATH and no LONGSHOT_MINGW, the test reports SKIP and exits successfully without exercising either half of the fix.

Do: Honor the configured compiler, including the test runner's compiler argument, and make a missing required compiler visible to the Windows test run.

**L3** (should fix): The new test ignores CC and can silently skip despite a configured Windows compiler. *When:* On a Windows test host with CC set to a suitable compiler but no clang on PATH and no LONGSHOT_MINGW, the test reports SKIP and exits successfully without exercising either half of the fix. **Do:** Honor the configured compiler, including the test runner's compiler argument, and make a missing required compiler visible to the Windows test run.
Author
Member

Marked as a stopgap: the plan is for the control connection to go through the builder's broker, and then the game serves no pipe of its own and this goes. Until that lands, it is what keeps sandboxed test runs working on Windows.

Marked as a stopgap: the plan is for the control connection to go through the builder's broker, and then the game serves no pipe of its own and this goes. Until that lands, it is what keeps sandboxed test runs working on Windows.
Author
Member

Superseded by the builder broker on mod-api (eaf4a48b9): the builder now listens on the control pipe and hands the confined game its clients, so the game serves no pipe of its own. Verified on Windows: a sandboxed dev.py game-tests run connected through the builder and passed. Closing.

Superseded by the builder broker on mod-api (eaf4a48b9): the builder now listens on the control pipe and hands the confined game its clients, so the game serves no pipe of its own. Verified on Windows: a sandboxed dev.py game-tests run connected through the builder and passed. Closing.
ChloeNow closed this pull request 2026-11-29 23:55:52 +00:00
All checks were successful
PR description / Title and description (pull_request_target) Successful in 6s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2742
No description provided.