fix(mods): restart switching builds in a mod whose versions call no function, and follows jump tables in data #3216
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!3216
Loading…
Reference in a new issue
No description provided.
Delete branch "snaildev99/Longshot:mods/switch-parity"
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?
Summary
mainbuilds a code mod's ExeFS patches behind a switch, so the player can turn the mod off and on at a restartwithout a build (the re-implementation of #1036). Comparing it with #1036 found cases where a switched build could run
code that doesn't exist, and a few loose ends:
its last round, was lifted anyway; so was a version that calls into data. Now the mods involved are built in
(fixed in their profile state) and the build goes again; if the profile's own state goes where no code is (and the
game's own code doesn't), building it in would keep that, so the build stops first and names the mods and the
target (
unsafe_patch_switch).records the bytes it reads to recover a table, and a switch that writes them versions the reader.
image too.
patch is active at that start, and a table cut between two complete writes is refused (new tables carry their row
counts; older complete ones still read).
files built in without a switch.
How to see it on
main: the test commit (206fef104) has ten tests for the cases above (two of them whole builds throughthe driver of a switched mod whose patch calls into data, the mod on and off); each fails on
main.Read first:
builder/crates/lift/src/whole/switches.rs(discover_switched,fix_switches),builder/crates/build-driver/src/build.rs(the retry and its stop),builder/crates/cfg/src/table.rs, thengame/crates/longshot-game/src/switches.rsandgame/crates/api/src/loader/switch.rs.Testing
Tested: Windows 11 Pro, RTX 3090, NVIDIA 610.88, in the game, built by
longshot-builder play --profilewiththis PR and the other mod compatibility ports merged (and #3213, which a restart without a build needs), adult Link in
Kakariko. The profile's only mods are four patch-only test mods (IPS32, one instruction each in the HUD's per-frame
update: its entry returned at once, or one of three calls in it skipped). The build put all four in behind a switch:
Each start set them as the profile said (
local/patch-hud-call-a-off: its ExeFS patches are off at this start (built in behind a switch)); call A turned off and then on again, each a restart through the builder, needed no build(
fast check: up to date) and was set as asked; the save loads and plays each time.main's builder gives the samebuild and start lines for the same profile. These mods hit none of the cases this PR fixes (the game-free tests below
build each one): the run checks that switching that worked still does.
After the rebase onto
main@3a0f7d8f7and the review's fixes, the same profile again, built with this PR @efdae26b4and the other ports merged (929bf025a): the same two build lines, each mod set at the start as the profilesays, call A off and on again through two restarts (
fast check: up to date, 15.8 and 4.1 ms, set as asked eachtime), and the save loads and plays.
The Mods tab note this changes shows only on the page of an emulator-layout mod whose patches are built in, and this
base never builds those (it reads ExeFS from manifest mods alone), so there is no screenshot: the
apitest checks it.mise run test, run locally while CI's run waits for approval (Windows 11,tests/run_all.py --strict, 12 checks atonce), here @
efdae26b4and onmain@3a0f7d8f7: 838 passed, 21 failed, 52 skipped here; 845 passed, 14 failed, 52skipped on
main. 14 of the 21 also fail onmain: test_dlssg, test_fsr4_tune, test_lifter, test_no_game_title,test_no_map_reload, test_present_acquire_ahead, test_present_geometry_trace, test_present_held_image,
test_present_image_free, test_program_cache_store_record, test_rt_pin, test_sync_watch_event, test_turf_budget,
test_ui_renderer. The other seven hit their timeouts while other work ran on the PC: test_audio_voice_biquad,
test_audio_wave_buffer_release, test_check_third_party, test_quit_not_crash and test_settings_atomic pass here run
alone (
--exact); test_dev_update and test_native_zstd timed out again alone beside another suite, and time out thesame way on
main@3a0f7d8f7beside the same load. This PR touches none of the sources these seven read (scripts/,the host's zstd, the audio code).
Still to test:
main(measurement, the review'sL2)
Measurements
Verdict: It works: each of the ten tests fails on
mainand passes here, and in the game four switched patchmods build and switch at each start as on
main. Nothing per frame to measure: the change is in the build and in thestart's read of the switch table.
Setup:
cargo testofgame-files,lift,api,longshot-gameandbuild-driveron Windows 11; the before sideis the test commit (
206fef104), which ismain's code with the tests.3a0f7d8f7efdae26b4cargo test -p lift whole::tests::(missing call, call into data, ADR entry, table in data)cargo test -p game-files fixing_a_switch_keeps_the_profile_bytes_and_updates_both_listscargo test -p api(cut table, off mod's switched patch)cargo test -p longshot-game an_unreadable_table_keeps_the_all_on_image_and_dispatchcargo test -p build-driver --test driver switched(the mod on: stops; off: built in)Risks
(
unsafe_patch_switch, naming it) wheremainbuilt it. Built in without a switch (past the eight, or with a codemodule), the same patch still builds as on
main.main).is the unsafe one, the build stops and names it); one whose switching worked as before keeps it. No save or setting changes. A revert is enough.
Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). (run locally, Testing names them; CI's run waits for approval)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. (tests/test_dlss_nr_forwarder.pyreads build-driver'sbuild.rs(finished_files, unchanged here): it passes unchanged)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
Tested in game: Windows 11 Pro, RTX 3090, NVIDIA 610.88, adult Link in Kakariko: four patch-only test mods built in behind switches (15 more versions lifted); each start set them as the profile said, a restart with one turned off and on again needed no build (with #3213), and the save loads and plays each time; main's builder gives the same build and start lines.
mise run test, run locally while CI's run waits for approval: 824 passed, 21 failed, 51 skipped here @
a7198bbbc; 20 of the 21 also fail on main @f577a1aea(named in Testing), the other (test_mesh_args_cleanup) hit a fixture case's 10 s timeout under load and passes here run alone (--exact). test_dlss_nr_forwarder, which reads build-driver's build.rs, passes unchanged. Boxes ticked.WIP: fix(mods): restart switching builds in a mod whose versions call no function, and follows jump tables in datato fix(mods): restart switching builds in a mod whose versions call no function, and follows jump tables in dataRecommendation: Request changes. The retry can still produce a build whose selected mod state transfers control to a missing function. The added tests show several discovery fixes, but they stop before checking the full retry and resulting build.
The change detects unsafe switched versions, versions readers of patched jump tables, and keeps dispatch consistent when the switch table is unreadable. It can require another image build and discovery round, and its build-time cost has not been measured.
Blocking (2): must change before merging.
builder/crates/build-driver/src/build.rs:626: The retry loses the unresolved-transfer check when fixing the last switch, so an invalid transfer in the profile's selected state can still be built. (more on the line) Do: After fixing switches, validate the selected image's implicated transfers before accepting the lift, and return a player-facing error naming the mods and target if the selected state is still invalid. Add a full retry test for both selected states.@​fixor@​rebasetry first). (for the author)Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/lift/src/whole/mod.rs:403: The added all-off scan and possible repeated image builds and discovery rounds have no build-time measurement. (more on the line) Do: Compare clean and one-function-change build times and output sizes against the base, including a representative switched profile and a profile that triggers a retry. (@fixdoes its part first: Avoid repeating the full address scan or image work where its results can safely be reused.)@fixcan do L1 and L2.Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Partly shown: the PR reports eight game-free cases failing on the base and passing here, plus a Windows game run showing existing switching still works. The selected-state failure after a retry is not covered, and build-time cost is unmeasured.
Other systems: The builder and startup switch-table reader run on Windows and Linux. The reported game run is on Windows; the changed discovery can also affect builds with data-only mods and functions shared by several switches. The reported run does not exercise the newly fixed cases in game.
Switches: No environment variables or developer switches added, changed, or removed. Existing per-mod switches can become fixed at the profile state when discovery finds an unsafe version.
Reviewed:
a7198bbbcbagainstf577a1aeab: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the pull request template, commits and the complete diff. Read the switch planning, CFG entry and walk, patch classification, switch-table parser and startup switch files in full; inspected relevant retry, discovery, lift and stamp callers. The remaining changed code files and documentation were reviewed through their diffs and surrounding code, not read in full. No review checklist or adjacent Tooling checkout was present.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no tests or project code were run. The supplied CI checks are still running.
Overlaps and merge order: Not established; network access is closed. The reported restart test depends on #3213.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, as snaildev99 took it out of WIP. Nothing was run; a maintainer decides.
@ -623,0 +623,4 @@{r.log(format!("exefs: {detail}. Fixing those mods as selected for this build."));game_files::switches::fix(&mut patches.files, &mods);patches.update_lists(&game_files::nso::Nso::load(&p.work.exefs.join("main"))?);L1 (blocking): The retry loses the unresolved-transfer check when fixing the last switch, so an invalid transfer in the profile's selected state can still be built.
When: If the only switched mod is on and its patch calls into data, discovery returns PatchSwitch and this branch fixes the mod on. The next lift has an empty switch table, so discover_switched uses ordinary discovery without checking the transfer and the build proceeds with a missing destination instead of stopping and naming the mod and target.
Do: After fixing switches, validate the selected image's implicated transfers before accepting the lift, and return a player-facing error naming the mods and target if the selected state is still invalid. Add a full retry test for both selected states.
@ -401,3 +401,3 @@return Ok((discover(o, image)?, BTreeMap::new()));}let mut more = switches::entries(image, &o.switches);let mut more = switches::entries(image, &o.switches)L2 (should fix): The added all-off scan and possible repeated image builds and discovery rounds have no build-time measurement.
When: A build with switched code now scans address references on another image, and an unsafe switch can cause the image and lift discovery to run again. The reported tests and game run do not quantify the cost to players building such profiles.
Do: Compare clean and one-function-change build times and output sizes against the base, including a representative switched profile and a profile that triggers a retry.
a7198bbbcbefdae26b4cRebased onto main @
3a0f7d8f7for the base conflict; here @efdae26b4. Tested (the game again on this head),mise run test(against main @3a0f7d8f7: the failures main doesn't have are timeouts under load, each passing alone or timing out on main beside the same load) and Measurements are updated. Answers to the review below.L1 (the retry loses the unresolved-transfer check): fixed in
efdae26b4. The check is the profile's own state, donebefore the fix rather than after it: the lift already walked every state of each function it names, and all of a
function's switches are fixed together, so built in, the function is exactly the version of the profile's state. The
lift now reports, with the mods it names, each version's call or branch to a place with no code that the game's own
code (the function's switches all off) doesn't make, with which of the function's mods are on in that version
(
build_core::NoCode). When one of those versions is the profile's, the build stops withunsafe_patch_switch,naming the mods that are on and the target, before it makes the image again; otherwise it fixes the mods and goes on
as before. A version's call into code is no stop: built in, that call is a BL target and so an entry. Tests, whole
builds through
build::buildwith the real lift (build-driver/tests/driver.rs):a_switched_mod_on_whose_patch_calls_where_no_code_is_stops_the_build(the mod on: the build stops, naminglocal/strayand0x80000200; on the previous head it built) anda_switched_mod_off_whose_patch_calls_where_no_code_is_built_in_off(the mod off: fixed off, the image made againwith the game's own word, no switch table). Both fail on
main.builder.md,using-mods.mdand the code's row inbuild-events.mdsay so.L2 (build-time measurement): the measurement is still to run. Of the code part: with
L1's fix, a build whose selected state can't be built in stops before the image and the lift are made again. The
all-off address scan runs once per lift, not per discovery round, and is linear in the code; a retry's image and
discovery are made again because the bytes they read change. Nothing else here could be reused safely without
duplicating the scanner's window logic, so no further change.
L3 (conflicts with main): rebased onto
main@3a0f7d8f7. The one conflict was the warnings row of the codestable in
build-events.md, which main changed (#3137 droppedmod_needs_import) next to the row this PR adds: main'srow kept, this PR's
unsafe_patch_switchrow before it. The rest merged cleanly (#3137's ExeFS mods inread.rs,#3081's float middle path in
stages.rsand the lift's tests, #3192's load order).Still to test now lists the measurement the review asked for, which the answers above say is still to run.
Merge note for #3166 and #3216: each passes alone on
main, but whichever merges second needs a two-line test fix. #3216 giveswrite_imageinbuilder/crates/build-driver/tests/driver.rsa second argument (the writes), and #3166's two return tests call it with one:write_image(&d, &[]). With all the mod compatibility ports merged together, that is the only change it needed there.@review
Recommendation: Approve. The code is ready: only testing is left. The selected-state check now stops the build before retrying when a switched version introduces a transfer outside code. The build-time cost of the additional scan and retries remains unmeasured. Recommend approval; not approved on the forge.
The change fixes unsafe mod switching, versions readers of patched jump tables, and makes switch-table failures start consistently. It adds discovery work and can repeat image construction during a build.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/lift/src/whole/mod.rs:403: The added all-off scan and possible repeated image builds and discovery rounds have no build-time measurement. When: A build with switched code now scans address references on another image, and an unsafe switch can cause the image and lift discovery to run again. The reported tests and game run do not quantify the cost to players building such profiles. Do: Compare clean and one-function-change build times and output sizes against the base, including a representative switched profile and a profile that triggers a retry. (@fixdoes its part first: Avoid repeating the full address scan or image work where its results can safely be reused.)@fixcan do L2.Since the last review (on
a7198bbbcb)Resolved: L1 (The retry loses the unresolved-transfer check when fixing the last switch, so an invalid t…); L3 (It conflicts with its base branch: bring it up to date (
@​fixor@​rebasetry first).)Still open: L2 (The added all-off scan and possible repeated image builds and discovery rounds have no bui…)
Checks: Still running:
PR description / Title and description (pull_request_target).More: does it help, other systems, switches, what was read
Does it help: Yes for the covered fixes: the author reports ten game-free tests failing on main and passing here. An in-game Windows run confirms existing switching still works, but does not exercise the newly fixed cases.
Other systems: The builder changes affect Windows and Linux; the reported build and game runs are on Windows. Switch-table handling also runs at game startup. GPU-specific behavior is not implicated by the changed logic.
Switches: No player or developer switches added, changed, or removed. Mod patch switches retain their existing behavior, except unsafe ones are fixed to the profile state.
Reviewed:
efdae26b4cagainst3a0f7d8f7f: Read the repository's AGENTS.md, CONTRIBUTING.md and pull request template; the specified review checklist is absent. Examined the lift and build-driver diffs, the switch planning and retry paths, and game-files switch handling. Other changed files and their full contents were not read.; nothing run (a code review).Checked and fine:
Testing: No commands that build or run tests were executed. The author reports passing targeted tests and an in-game Windows switching run; the build-time comparison remains outstanding.
Overlaps and merge order: #3166 changes the same test helper; the author reports that whichever merges second needs its two calls updated.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@rebase
I rebased this pull request onto
main(6b1694a787): the new head is4b5bb09eae.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
efdae26b4c4b5bb09eaeRecommendation: Approve. The code is ready: only testing is left. The fix has game-free tests for the reported cases and an in-game check of existing switching, but its build-time cost remains unmeasured. Wait for the comparison against main. Recommend approval; not approved on the forge.
The change handles unsafe switched code, data-backed jump tables and incomplete switch tables, and corrects the Mods tab note. It can require another image build and discovery pass, adding build-time work whose cost is not yet known.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/lift/src/whole/mod.rs:403: The added all-off scan and possible repeated image builds and discovery rounds have no build-time measurement. When: A build with switched code now scans address references on another image, and an unsafe switch can cause the image and lift discovery to run again. The reported tests and game run do not quantify the cost to players building such profiles. Do: Compare clean and one-function-change build times and output sizes against the base, including a representative switched profile and a profile that triggers a retry. (@fixdoes its part first: Avoid repeating the full address scan or image work where its results can safely be reused.)@fixcan do L2.Since the last review (on
efdae26b4c)Still open: L2 (The added all-off scan and possible repeated image builds and discovery rounds have no bui…)
Checks: Still running: 11 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven for build-time cost. The description reports ten game-free tests failing on main and passing with the change, plus a Windows in-game switching run; it reports no build-time comparison.
Other systems: The builder and switch-table reader affect Windows and Linux. The recorded in-game run is on Windows; the game-free tests cover the reported failure cases, but no Linux run is reported.
Switches: No player-facing switches or environment variables added or changed. The patch switch table gains row counts, with support retained for complete version 1 tables.
Reviewed:
4b5bb09eaeagainst6b1694a787: Read AGENTS.md, CONTRIBUTING.md and builder/crates/game-files/src/switches.rs in full; inspected the changed diff for that file and docs/user/using-mods.md, the commit list, and references to discovery and retry. The remaining changed files and project standards were not read in full.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports ten targeted tests passing and an in-game Windows switching check; CI is still running.
Overlaps and merge order: The author reports that whichever of #3166 and #3216 merges second needs two test call sites updated for write_image's new argument.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.
@rebase
I rebased this pull request onto
main(e813a37f63): the new head is2e2a53d389.Conflicts resolved
Nothing was built or run: read the resolution before merging.
Automated rebase by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
4b5bb09eae2e2a53d389Recommendation: Approve. The code is ready: only testing is left. The fix has game-free test results and a Windows game run, but its added build-time cost has not been measured against main. Recommend approval; not approved on the forge.
The change builds unsafe switched patches into their selected state or stops an unsafe build, tracks jump-table data and off-state entries, and makes switch-table startup safer. It adds an address scan and can repeat image construction and discovery.
Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
builder/crates/lift/src/whole/mod.rs:403: The added all-off scan and possible repeated image builds and discovery rounds have no build-time measurement. When: A build with switched code now scans address references on another image, and an unsafe switch can cause the image and lift discovery to run again. The reported tests and game run do not quantify the cost to players building such profiles. Do: Compare clean and one-function-change build times and output sizes against the base, including a representative switched profile and a profile that triggers a retry. (@fixdoes its part first: Avoid repeating the full address scan or image work where its results can safely be reused.)@fixcan do L2.Since the last review (on
4b5bb09eae)Still open: L2 (The added all-off scan and possible repeated image builds and discovery rounds have no bui…)
Checks: they run again on this head; a failure shows on the pull request.
More: does it help, other systems, switches, what was read
Does it help: Yes for the covered correctness cases: the author reports ten tests failing on main and passing with the change, plus a Windows game run confirming existing switching still works. Build-time cost remains unmeasured.
Other systems: The builder and switch-table reader affect Windows and Linux; the reported game run is on Windows with NVIDIA hardware. The change also affects mod patch discovery and startup dispatch.
Switches: No player or developer switches added, changed, or removed; existing mod switches gain safer fallback behavior.
Reviewed:
2e2a53d389againste813a37f63: Read AGENTS.md, CONTRIBUTING.md, the pull request template, docs/dev/reference/mods.md, and the relevant discovery and build-retry sections; skimmed the relevant diff and supplied test reports. The remaining changed files and supporting code were not read in full.; nothing run (a code review).Checked and fine:
Testing: Await a comparable build-time measurement on a profile with switched patch mods, including a retry case. CI has not run on this head.
Overlaps and merge order: #3166 overlaps the driver test helper; whichever merges second needs the two reported call-site updates.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its rebase. Nothing was run; a maintainer decides.