WIP: feat(sandbox)!: the builder is the game: only entrypoint, sandbox and broker #2898
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2898
Loading…
Reference in a new issue
No description provided.
Delete branch "bitg/builder-is-the-game"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Title: feat(builder)!: the builder is the game: the game process runs, draws and plays sound; everything else that touches the player's PC is the builder's
Summary
The game process now does three things: it runs the game, draws and plays sound. Everything else that touches the player's PC is the builder's: the player's files, the environment, restarts, crash records, logs and bug reports, mod watching, the control bridge and the Steam Deck's sensors. The sandbox then says the same thing on both systems and every kernel: system files read-only, the program's own files, the GPU and sound devices, the display and sound servers' sockets, and the few folders the system's libraries open themselves. No sandbox rule names a folder of the player's. Plan:
builder-is-the-game-plan.md(team notes), one commit per step, so the history reads step by step.restart {build}replacesrestart_to_apply; the window's close and the bridge'srelaunchask once, then exit. Gone:relaunch()on both systems (execve,CreateProcessW, the kept environment),host/hos_relaunch.h, the C channel client (bc_open...bc_restart_to_apply).host/hos_relaunch.cishost/hos_close.c. A restart drops Safe start and--set.build_core::game_env): the real environment, thenHOS_ENV_FILE's file, else the profile'slongshot_env.txt, else the game folder's, checked againstgpu/vk/switches.def(parsed in build-core'sbuild.rs: an unknown name warns, a removed one says its row, a bad value is left out). The game reads no file of switches (load_longshot_env,host/env_own.hgone); the builder's four other readers of the file are one. The file is the builder's too: its lines answer the builder's own switches (build_driver::env). Windows compares names case-blind;LD_*andLONGSHOT_GAME_MODULEare refused from any file.LONGSHOT_CONTROL_BY_BUILDERgo.3b. One command set for the bridge: the builder's
Longshot.exe mod(21 commands, one list,COMMANDSinmodtool);scripts/longshot_ctl.pykeeps the run harness and forwards every bridge command to it;longshot_bridge.Bridgeis the raw client.mod shotstages in the game'stemp/(a confined game cannot write the socket's folder: a bug).ReadDirectoryChangesWout ofhost/mod_watch.c, 747 lines to 123): the builder tells it, or it walks.build_core::crash_block): Linux, the handler stops itself, the builder reads the stopped child (/proc/<pid>/maps,process_vm_readv; a bounded stack copy in the block where Yama forbids the read) and resumes it; Windows, the builder walks the stack through its process handle (StackWalk64) and writes the minidump.host/hos_crash_record.c929 lines to about 170;LONGSHOT_CRASH_BY_BUILDER,LONGSHOT_CRASH_DUMP,LONGSHOT_LOG_PATHgone; seccomp refusesprocess_vm_readv/writev.bug_reportop;MKWVK_API_VERSION82). Gone:host/log_redact.{c,h},longshot_redact.h,build_driver::redact, most ofvk_bug_report.cpp. Logs are read without following links. Alsofix(dev):dev.py vknamed the renderer by the host, not the target.files_rules), deciding on an ask that names no system, with a Windows front (today's code) and a POSIX one. No behaviour change.build_core::files_linuxserves the player's files beneath held folder descriptors (openat2RESOLVE_BENEATH);host/hos_file_linux.cwraps the game's file calls at both links (--wrap, which covers Rust's std in the same link) and asks the builder only when the kernel refuses..hosnewstand-in beside each file written in place replaceshos_atomic_file.h's write-in-place fallback. One list of roots for both systems. Review fixes here:<game>/userwas served as a written root, which let the game write the launcher's files (older than this stack); the builder's shader cache was a root on neither system.build_core::deck_imu) and reach the game in the pads' snapshot: the game opens nohidrawnode, and the last device rule for one goes.host/options_path.cto about 40 lines; fiveLONGSHOT_SANDBOX_*variables gone). A hello without it ends the start.sandbox.mdaround the end state (one table of roots, what the fence still grants, the kernel table cut),build.md's slots and ops,control-bridge.md,switches.md,tools.md. Proposed text for the Modding API Spec's 12.2.1 and 12.7 is in the first comment.After review (the user's answers): the builder serves the pads to every game it starts, confined or not, so the Steam Deck's own sensors work with
HOS_SANDBOX=0too (the game's own SDL reads controllers only when the builder serves none);longshot-builder gameruns keep a crash record like play's (no window: a line on stderr naming it; none under--wait-for-debugger); the Switch 2 Pro Controller over USB and its NFC reader (Windows) moved into the builder's pads, so they work whatever the confinement. Its NFC commands are answered off the pads' thread (frame type 15, read-only reader commands only), so a tag scan never stalls the pads; the driver starts only when the builder's SDL can give its virtual pad.Read first:
builder/crates/build-core/src/game_env.rs,files_rules.rs,files_linux.rs,sandbox_linux.rs(rules,served_roots),crash_block.rs,host/hos_file_linux.c,game/crates/modtool/src/cmd/live.rs.Testing
Tested: Linux (CachyOS, kernel 7.3, Landlock ABI 9 in use, RTX 3090, NVIDIA driver), the stack's tip, built through the job queue (pack and runtime on the shared base):
longshot_ctl.py(Skip title on, the kokiri-start save): the game confined by the builder (sandbox: files and folders confined by the builder (Landlock ABI 9)), reached play, the Insert menu opened (thesystem/menupage), thenrelaunch:restart: the builder starts the game again, back in play (frame 527).files: 198 served by the builder, 7 refused (the first frame in play); after the restart 129 and 6.tests/run_all.py, through the queue) passes at the tip, as it does on mod-api@origin; on the way,test_program_hooks,test_lifter,test_fs_save_commitandtest_display_startup_failurewere brought up to date with the change. The host's C compiles for Linux (clang) and Windows (llvm-mingw), every file (onlyhost/dav1d_av1.candhost/nn_video.cfail on Windows here, for the dav1d and FFmpeg headers this PC lacks, as on mod-api); the renderer compiles and links for Windows (RX_TARGET=windows dev.py vk); clippy-D warningson the touched crates on Linux and Windows (gnullvm);tests/test_builder_files_wine.pyunder Wine (27 checks); the builder's Windows tests of the control pipe and the file service under Wine. Each step had its own cold review, and the whole stack one; their findings are fixed in the commits (two security ones:<game>/userserved as a written root let the game write the launcher's files, older than this PR; a hostile crash block could make the builder panic).Still to test:
HOS_CRASH_TEST(a record, the crash window, a minidump withHOS_CRASH_MINIDUMP), saves, settings, a screenshot, the shader store and NFC folder as roots, the.hosnewrename of the settings file, a second start compiling nothing,Longshot.exe mod status/shotthrough the pipe, expecting each to work as on main (@Beanstalk Windows NVIDIA and AMD: "confined play: restart, bug report, crash test, saves, settings, screenshot, second start")HOS_SANDBOX=0: the same gyro aiming, expecting the Deck's sensors through the builder too (@Beanstalk Steam Deck, or by hand)HOS_SANDBOX=0, expecting them as on main (by hand: the farm has none)HOS_SANDBOX=0: controllers through the builder's pads pipe, expecting them as confined (@Beanstalk Windows)longshot-builder gamewithHOS_CRASH_TEST, expecting a record in the game folder'sbug-reports/pending/and a stderr line naming it (by hand)user/in the game folder: a start moves it to~/.local/share/longshotonce (or keeps it while it cannot), the saves there (by hand)Measurements
Verdict: no change in play; a confined start reaches play about 1 s later (one warm sample a side), with about 110 files opened through the builder before the first frame in play and a handful more in play.
Setup: Linux (CachyOS, kernel 7.3), RTX 3090, NVIDIA driver; Hyrule Field (child), the A/B's pinned options (cap off, Render resolution 67 %), 1080p, no upscaler;
dev.py abwith each side's own runtime (--a-runtime), two interleaved 60 s runs each, timing mode; the start-up marks are the log'sstart: timelineline, the files counter the log'sfiles:lines.12f42db5b78ca2bc, which adds onlylongshot_ctl.py)play=)Not measured yet: the lab PC (HDD) and Windows (its file service was already in use; steps 5, 6 and 9 change it), and the heaviest mod profile's start.
Risks
sandbox.md. The served-files counter (files: N served by the builder) says how many in the log.restart_to_applyisrestart;mod stopismod quit,mod restart --manifestismod relaunch,mod waittakes<EVENT> --frames/--state; the channel is version 2. The mod API is unshipped; nothing in LongshotLauncher calls a renamed command.longshot_env.txtlines the builder leaves out are named in the log.MKWVK_API_VERSIONgoes to 82 here (step 6'sbuilder_bug_reportinMkwVkHost), as it does in #2877, #2880 and #2882: whichever merges later takes the next number.Checklist
Ready for review
mod-api; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here.tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged).Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8Wuc
The Insert menu's Restart now and the control bridge's relaunch ask the builder over the game's channel (restart, args.build) and exit; play starts the game again through the fast check, built first when asked (at most 3 builds in a row), and longshot-builder game starts it again as it is (a build asked is answered build: false). restart_to_apply goes. Removed: relaunch() on both systems (execve of /proc/self/exe, CreateProcessW with the kept environment and standard handles), host/hos_relaunch.h, hos_relaunch_keep_env, the confined-restart special case, the C channel client (bc_open, bc_send, bc_request, bc_read_message, bc_close, bc_restart_to_apply, bc_has_channel and the C copy of the frame format), host_sys::builder::{restart_to_apply, has_channel, sandboxed}, hos_romfs_nup_passed, sbxw_handle_text, HOS_RESTART_OF (now GONE), and longshot_bridge.py's relaunch following (follow_relaunch, Adopted, relaunched_game): the run's process is the builder, the same before and after. host/hos_relaunch.c is host/hos_close.c. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8WucThe game logs raw: every start of the game (play, --prepare-shaders, longshot-builder game, with a log file or without) goes through build_core::game_log::StderrTee, which redacts each line (crash::redact, now with the home folder's own and short names); a line cut across two writes is held for its end, a very long one keeps an overlap. The next-start redaction pass goes on both sides, and the builder opens the game's logs without following a link. host/log_redact.{c,h}, gpu/vk/compat/longshot_redact.h and build_driver::redact (with its example and test) go. The new channel op bug_report takes what only the game knows (version, GPU line, settings changed) and the picture as a file of its own; the builder writes bug-reports/<date>_<time>/ (build_driver::bug_report: this PC, the place from the log, the switches from the resolved environment, both logs) and opens it. The game no longer writes bug-reports/ on either system. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016o1k1SQVyAWsujjFVd8WucPossibly related, for context:
Windows host compile (llvm-mingw, with tools.lock's FFmpeg 9.0.2 headers): every host unit compiles at this head; box ticked.
Pushed
17a3fa3b(wasb78ca2bc), 7 commits on top: the builder serves pads (and the Deck's sensors) to unconfined games too; longshot-builder game runs keep a crash record; the Windows Switch 2 Pro USB driver and its NFC reader moved into the builder; review fixes. Full suite passes (bitg-f4 + bitg-f5).@Beanstalk please test this PR's head (
17a3fa3b) against its base, mod-api:HOS_CRASH_TESTset: a crash record and minidump are written.HOS_SANDBOX=0: controllers still work (they now come through the builder's pads pipe).HOS_SANDBOX=0: gyro aiming works in both.Beanstalk test farm
Commit
96d5bc7· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.17a3fa3b6196d5bc78fcRebased onto mod-api
75bcd270(#2881), no conflicts: was17a3fa3b, now96d5bc78. Host compiles on Linux and Windows (llvm-mingw with tools.lock's FFmpeg/dav1d headers), dev.py pack passes, run_all 806 passed / 1 failed: test_lifter's game-sites stress test (retire::tests::many_site_readers...), which this PR doesn't touch and which passed on a rerun before; test_builder_files_wine 27/27.Landed on mod-api as
716735d8(one commit), after its review fixes and one batched build + game run of all six cleanup areas together. mod-api work now goes straight onto the branch once self-reviewed.Pull request closed