WIP: fix(sandbox): Windows: a confined start takes its profile's start slot: profile.json is read once the sandbox is in #2827

Draft
llun wants to merge 2 commits from llun/Longshot:fix/mod-api-win-profile-slot into mod-api
Member

Summary

For #2822 (into mod-api). On Windows, a confined start (the sandbox's default) ignores its profile's start slot. profile_start_slot (host/hos_main.c) reads the profile's profile.json and hands its start_slot on as HOS_START_SLOT. On Windows it ran right after longshot_env.txt, before hos_sandbox_start. Inside the AppContainer, profile.json can only be opened through the builder's file layer, which hos_sandbox_start puts in, so the open was refused. Every confined run then logged profile: <profile> (no profile.json: no start slot) and started on no slot, whatever the profile chose. This reads it at the end of the sandbox's block instead, still after longshot_env.txt (which may set HOS_START_SLOT, taken away first). Nothing reads HOS_START_SLOT before then: its only reader is game/crates/api/src/save_start.rs, at the game's start. Linux's start is unchanged, since the builder's Landlock is in before the exec.

To see it on mod-api: Windows, the sandbox on, LONGSHOT_PROFILE naming a profile whose profile.json has a start_slot. The log's profile: line says no profile.json. (On plain mod-api a confined start with a profile stops earlier, at the save folder: #2726's first two bugs. The runs below have #2726's save-folder fix and the same broker change applied locally, beneath this PR.)

Read first: the sandbox's block in the Windows main of host/hos_main.c.

Testing

Tested: Windows 11, RTX 5080, a confined start through longshot-builder game with a profile whose profile.json has "start_slot": "slot_00". Before: profile: …\profile (no profile.json: no start slot). After: profile: …\profile; its start slot slot_00 (HOS_START_SLOT=0), with sandbox: in the AppContainer, the builder reached … just before it, and Skip title screen started.

Checks: the new tests/test_sandbox_profile_slot.py cuts the Windows start (from load_longshot_env() through the sandbox's block) and profile_start_slot from host/hos_main.c and compiles them with stand-ins, where profile.json opens only outside the container or once the file layer is in. It fails on mod-api @ eaf4a48b (HOS_START_SLOT -, no profile.json: no start slot) and passes here, on Windows (llvm-mingw clang) and Linux (WSL Ubuntu 24.04, gcc). With the fix's lines undone it fails again, as does tests/test_game_start.py. That check's order rule is updated, not dropped: Linux reads the slot right after longshot_env.txt, Windows after it and after hos_sandbox_start. The 44 checks that read host/hos_main.c were run: the ones failing here fail the same way on mod-api on this PC (POSIX headers and calls in Linux-only checks, the MSVC host's cargo). mise run lint passes.

Still to test:

  • Windows, a profile with a save in its start slot: start confined, expecting Skip title screen to load that slot (by hand)
  • Linux: start with a profile's start_slot, expecting the same profile: line as before this PR (@Beanstalk: a Linux start with a profile's start slot)

Measurements

Verdict: fixed. A confined Windows start takes its profile's start slot.

Baseline: mod-api (#2822's head), the branch this PR goes into: the bug is there, not on main. The in-game runs are both on mod-api with #2726's save-folder fix and the broker change applied locally, beneath this PR.

Setup: Windows 11, RTX 5080, NVIDIA 621.40. The same profile ("start_slot": "slot_00"), started confined through longshot-builder game. Its log's profile: line, and the check.

Before: mod-api @ eaf4a48b After: this PR @ d455c5a0
The log's profile: line, confined (no profile.json: no start slot) its start slot slot_00 (HOS_START_SLOT=0)
tests/test_sandbox_profile_slot.py FAIL pass

Risks

The sandbox: no grant, root or right changes. profile.json is read through the builder's file layer, under the file-read grant the plan already gives it (sandbox: allowed file-read …\profile.json). Reading it after hos_sandbox_start is what keeps that read inside the confinement: before the sandbox was in, the confined game's open was refused.

Only Windows' start changes: the profile is read a few calls later, after the sandbox's start. A Windows start that HOS_SANDBOX=0 leaves unconfined reads it at the same place, where it opens as before. A revert is enough. A player notices that a profile's start slot now applies on Windows.

Checklist

Ready for review

  • One topic, on current mod-api (#2822's head); 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). (The checks this change reaches pass. mod-api's whole suite has failures on Windows that this PR doesn't change: #2825 and #2826 fix eight of them.)
  • 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. (It fails on mod-api, where the bug is.)
  • 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 and run; Linux: CI.)
  • 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

## Summary For [#2822](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2822) (into `mod-api`). On Windows, a confined start (the sandbox's default) ignores its profile's start slot. `profile_start_slot` (`host/hos_main.c`) reads the profile's `profile.json` and hands its `start_slot` on as `HOS_START_SLOT`. On Windows it ran right after `longshot_env.txt`, before `hos_sandbox_start`. Inside the AppContainer, `profile.json` can only be opened through the builder's file layer, which `hos_sandbox_start` puts in, so the open was refused. Every confined run then logged `profile: <profile> (no profile.json: no start slot)` and started on no slot, whatever the profile chose. This reads it at the end of the sandbox's block instead, still after `longshot_env.txt` (which may set `HOS_START_SLOT`, taken away first). Nothing reads `HOS_START_SLOT` before then: its only reader is `game/crates/api/src/save_start.rs`, at the game's start. Linux's start is unchanged, since the builder's Landlock is in before the exec. **To see it on `mod-api`:** Windows, the sandbox on, `LONGSHOT_PROFILE` naming a profile whose `profile.json` has a `start_slot`. The log's `profile:` line says `no profile.json`. (On plain `mod-api` a confined start with a profile stops earlier, at the save folder: [#2726](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2726)'s first two bugs. The runs below have #2726's save-folder fix and the same broker change applied locally, beneath this PR.) Read first: the sandbox's block in the Windows `main` of `host/hos_main.c`. ## Testing **Tested:** Windows 11, RTX 5080, a confined start through `longshot-builder game` with a profile whose `profile.json` has `"start_slot": "slot_00"`. Before: `profile: …\profile (no profile.json: no start slot)`. After: `profile: …\profile; its start slot slot_00 (HOS_START_SLOT=0)`, with `sandbox: in the AppContainer, the builder reached …` just before it, and Skip title screen started. Checks: the new `tests/test_sandbox_profile_slot.py` cuts the Windows start (from `load_longshot_env()` through the sandbox's block) and `profile_start_slot` from `host/hos_main.c` and compiles them with stand-ins, where `profile.json` opens only outside the container or once the file layer is in. It fails on `mod-api` @ eaf4a48b (`HOS_START_SLOT -`, `no profile.json: no start slot`) and passes here, on Windows (llvm-mingw clang) and Linux (WSL Ubuntu 24.04, gcc). With the fix's lines undone it fails again, as does `tests/test_game_start.py`. That check's order rule is updated, not dropped: Linux reads the slot right after `longshot_env.txt`, Windows after it and after `hos_sandbox_start`. The 44 checks that read `host/hos_main.c` were run: the ones failing here fail the same way on `mod-api` on this PC (POSIX headers and calls in Linux-only checks, the MSVC host's cargo). `mise run lint` passes. **Still to test:** - Windows, a profile with a save in its start slot: start confined, expecting Skip title screen to load that slot (by hand) - Linux: start with a profile's `start_slot`, expecting the same `profile:` line as before this PR (@Beanstalk: a Linux start with a profile's start slot) ## Measurements **Verdict:** fixed. A confined Windows start takes its profile's start slot. Baseline: `mod-api` (#2822's head), the branch this PR goes into: the bug is there, not on `main`. The in-game runs are both on `mod-api` with #2726's save-folder fix and the broker change applied locally, beneath this PR. Setup: Windows 11, RTX 5080, NVIDIA 621.40. The same profile (`"start_slot": "slot_00"`), started confined through `longshot-builder game`. Its log's `profile:` line, and the check. | | Before: mod-api @ eaf4a48b | After: this PR @ d455c5a0 | |---|---|---| | The log's `profile:` line, confined | `(no profile.json: no start slot)` | `its start slot slot_00 (HOS_START_SLOT=0)` | | `tests/test_sandbox_profile_slot.py` | FAIL | pass | ## Risks **The sandbox:** no grant, root or right changes. `profile.json` is read through the builder's file layer, under the file-read grant the plan already gives it (`sandbox: allowed file-read …\profile.json`). Reading it after `hos_sandbox_start` is what keeps that read inside the confinement: before the sandbox was in, the confined game's open was refused. Only Windows' start changes: the profile is read a few calls later, after the sandbox's start. A Windows start that HOS_SANDBOX=0 leaves unconfined reads it at the same place, where it opens as before. A revert is enough. A player notices that a profile's start slot now applies on Windows. ## Checklist ### Ready for review - [x] One topic, on current `mod-api` (#2822's head); 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). (The checks this change reaches pass. `mod-api`'s whole suite has failures on Windows that this PR doesn't change: [#2825](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2825) and [#2826](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2826) fix eight of them.) - [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. (It fails on `mod-api`, where the bug is.) - [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 and run; Linux: CI.) - [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)
feat(game)!: the game side and the whole mod API in Rust, with system mods and the sandbox on by default
Some checks failed
CI / Third-party parts and guide screenshots (pull_request) Successful in 28s
PR description / Title and description (pull_request_target) Successful in 47s
CI / What the change needs (pull_request) Successful in 2m21s
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Successful in 1m48s
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
9e6b9c5782
The game side (between the C host and the lifted game) and the mod API move from C to Rust (game/crates), every game
setting and feature becomes a system mod (game/mods, Rust or TypeScript), and longshot-builder becomes the game's only
entrypoint, its sandboxer (Landlock and seccomp on Linux, an AppContainer on Windows) and its broker over one framed
channel. Native C mods and wasm are removed. The Insert menu is the menu system mod. One squashed commit of the former
mod-api branch (#2434).

Co-authored-by: Chloe Christley <[email protected]>
Co-authored-by: Jer9 <[email protected]>
Co-authored-by: snaildev99 <[email protected]>
Co-authored-by: SqueezyLemonade <[email protected]>
Co-authored-by: flashman4 <[email protected]>
Co-authored-by: dyst <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
host/hos_main.c's Windows start, from load_longshot_env() through the sandbox's block, and profile_start_slot cut from
the source and compiled with stand-ins: profile.json opens outside the container, or inside it once hos_sandbox_start
has put the builder's file layer in. A profile whose start_slot is slot_03 must give HOS_START_SLOT=3 inside the
container and outside it. It fails on mod-api: the confined game reads profile.json before the sandbox is started, the
open is refused, and the start takes no slot ("profile: ... (no profile.json: no start slot)").

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
fix(sandbox): Windows: a confined start takes its profile's start slot: profile.json is read once the sandbox is in
All checks were successful
PR description / Title and description (pull_request_target) Successful in 58s
0fc794cc33
The Windows start read the profile's profile.json (profile_start_slot: its start_slot as HOS_START_SLOT) right after
longshot_env.txt, before hos_sandbox_start. Inside the AppContainer profile.json is the builder's to open, through the
file layer hos_sandbox_start puts in, so the open was refused: "profile: ... (no profile.json: no start slot)", and
every confined run started on no slot, whatever the profile chose. It is now read at the end of the sandbox's block,
still after longshot_env.txt (which may set HOS_START_SLOT, taken away first); nothing reads HOS_START_SLOT before it
(save_start.rs, at the game's start). Linux's start is unchanged: the builder's Landlock is in before the exec.
tests/test_game_start.py's order check follows: Linux right after longshot_env.txt, Windows after it and the sandbox.

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

Tested in the game: Windows 11, RTX 5080, NVIDIA 621.40, a confined start through longshot-builder game with a profile whose profile.json has "start_slot": "slot_00" (on mod-api with #2726's save-folder fix and the broker change applied locally, beneath this PR). Before: profile: ...\profile (no profile.json: no start slot). After: profile: ...\profile; its start slot slot_00 (HOS_START_SLOT=0), with sandbox: in the AppContainer, the builder reached ... before it, and Skip title screen started.

Tested in the game: Windows 11, RTX 5080, NVIDIA 621.40, a confined start through `longshot-builder game` with a profile whose `profile.json` has `"start_slot": "slot_00"` (on `mod-api` with #2726's save-folder fix and the broker change applied locally, beneath this PR). Before: `profile: ...\profile (no profile.json: no start slot)`. After: `profile: ...\profile; its start slot slot_00 (HOS_START_SLOT=0)`, with `sandbox: in the AppContainer, the builder reached ...` before it, and Skip title screen started.
llun force-pushed fix/mod-api-win-profile-slot from 0fc794cc33
All checks were successful
PR description / Title and description (pull_request_target) Successful in 58s
to 22f0dd2ce6
All checks were successful
PR description / Title and description (pull_request_target) Successful in 13s
2026-11-29 22:15:19 +00:00
Compare
Author
Member

Rebased onto mod-api's new squash eaf4a48b (the same tree as 9e6b9c57, which this branch was on): the diff is this PR's own commits again. The checks and runs above hold as they are (the tree under them is unchanged); the description's commits are the new ones.

Rebased onto mod-api's new squash eaf4a48b (the same tree as 9e6b9c57, which this branch was on): the diff is this PR's own commits again. The checks and runs above hold as they are (the tree under them is unchanged); the description's commits are the new ones.
Author
Member

Risks now says how this change stands with the sandbox (what it touches, and why the confined game reaches nothing more).

Risks now says how this change stands with the sandbox (what it touches, and why the confined game reaches nothing more).
llun force-pushed fix/mod-api-win-profile-slot from 22f0dd2ce6
All checks were successful
PR description / Title and description (pull_request_target) Successful in 13s
to 0bfefe8616
All checks were successful
PR description / Title and description (pull_request_target) Successful in 16s
2026-11-29 23:27:34 +00:00
Compare
Author
Member

Rebased onto mod-api's newest (4cc50ca1: main's newest merged in), with no conflict; this PR's own checks were run again on the rebased head and pass as before. The merge touched none of this PR's files (#2827: only a comment in host/hos_main.c, far from its change), so the measurements and runs above hold; the After commit is the rebased head.

Rebased onto mod-api's newest (4cc50ca1: main's newest merged in), with no conflict; this PR's own checks were run again on the rebased head and pass as before. The merge touched none of this PR's files (#2827: only a comment in host/hos_main.c, far from its change), so the measurements and runs above hold; the After commit is the rebased head.
llun force-pushed fix/mod-api-win-profile-slot from 0bfefe8616
All checks were successful
PR description / Title and description (pull_request_target) Successful in 16s
to 0b74d3d55a
All checks were successful
PR description / Title and description (pull_request_target) Successful in 14s
2026-11-29 23:58:26 +00:00
Compare
Author
Member

Rebased onto mod-api @ 816d2354 (#2837, headless shots of the mods' UI), now 0b74d3d5. No conflict, and the diff is the same as before (same git patch-id). #2837 touches none of this PR's files.

Rebased onto `mod-api` @ 816d2354 ([#2837](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2837), headless shots of the mods' UI), now 0b74d3d5. No conflict, and the diff is the same as before (same `git patch-id`). #2837 touches none of this PR's files.
llun force-pushed fix/mod-api-win-profile-slot from 0b74d3d55a
All checks were successful
PR description / Title and description (pull_request_target) Successful in 14s
to 58e5f83233
All checks were successful
PR description / Title and description (pull_request_target) Successful in 1m34s
2026-11-30 00:38:44 +00:00
Compare
llun force-pushed fix/mod-api-win-profile-slot from 58e5f83233
All checks were successful
PR description / Title and description (pull_request_target) Successful in 1m34s
to d455c5a046
All checks were successful
PR description / Title and description (pull_request_target) Successful in 18s
2026-11-30 00:43:03 +00:00
Compare
Author
Member

Rebased onto mod-api @ c5e5b676: it was re-squashed onto main @ 46291934 (#2833) twice today (cdbb8551, then c5e5b676), which made this PR show main's and the whole mod API's diff. Now d455c5a0, the same diff as before (same git patch-id), no conflict. The changes underneath touch none of this PR's files, so its checks still hold.

Rebased onto `mod-api` @ c5e5b676: it was re-squashed onto main @ 46291934 (#2833) twice today (cdbb8551, then c5e5b676), which made this PR show main's and the whole mod API's diff. Now d455c5a0, the same diff as before (same `git patch-id`), no conflict. The changes underneath touch none of this PR's files, so its checks still hold.
All checks were successful
PR description / Title and description (pull_request_target) Successful in 18s
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'fix/mod-api-win-profile-slot:llun-fix/mod-api-win-profile-slot'
git switch 'llun-fix/mod-api-win-profile-slot'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'mod-api'
git merge --no-ff 'llun-fix/mod-api-win-profile-slot'
git switch 'llun-fix/mod-api-win-profile-slot'
git rebase 'mod-api'
git switch 'mod-api'
git merge --ff-only 'llun-fix/mod-api-win-profile-slot'
git switch 'llun-fix/mod-api-win-profile-slot'
git rebase 'mod-api'
git switch 'mod-api'
git merge --no-ff 'llun-fix/mod-api-win-profile-slot'
git switch 'mod-api'
git merge --squash 'llun-fix/mod-api-win-profile-slot'
git switch 'mod-api'
git merge --ff-only 'llun-fix/mod-api-win-profile-slot'
git switch 'mod-api'
git merge 'llun-fix/mod-api-win-profile-slot'
git push origin 'mod-api'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
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!2827
No description provided.