[PR #6994] [MERGED] fix(launcher): repair a damaged server build and unblock installer updates #7422

Closed
opened 2026-10-23 04:19:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6994
Author: @SpicyMarinara
Created: 10/3/2026
Status: ✅ Merged
Merged: 10/3/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/damaged-server-build-6984


📝 Commits (9)

  • dd70013 fix(launcher): repair a damaged server build and unblock installer updates
  • 6180562 fix(launcher): keep type-error builds startable and prove the build checks
  • bf01d09 Merge remote-tracking branch 'origin/staging' into HEAD
  • b5dbe39 Merge remote-tracking branch 'origin/staging' into fix/damaged-server-build-6984
  • 0a23059 fix(launcher): let a stop end the repair build and its tsc
  • dada4d8 Merge remote-tracking branch 'origin/staging' into fix/damaged-server-build-6984
  • 732dfba test(launcher): let the stop regression exit as soon as it is done
  • 7f1096b docs(changelog): split the damaged-build entry into one step per sentence
  • 2954d6c Merge branch 'staging' into fix/damaged-server-build-6984

📊 Changes

8 files changed (+300 additions, -32 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 package.json (+1 -1)
📝 packages/server/scripts/build.mjs (+17 -15)
📝 packages/server/scripts/write-build-meta.mjs (+50 -9)
📝 scripts/check-windows-installer-layout.mjs (+13 -0)
➕ scripts/regressions/launcher/server-build.regression.mjs (+170 -0)
📝 scripts/run-server.mjs (+46 -7)
📝 win/installer/installer.nsi (+2 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6984

Why this change

A Windows user's built server file packages/server/dist/services/generation/conversation-command-runtime.js ended up containing if(, raw) { }. After that, the server would not start, restarting the PC did not help, and only a clean install fixed it. The latest .exe installer also refused to update the install. Two problems are behind this, and both are on staging, so today's release would ship them:

  1. The Windows installer's in-place update always fails. After git checkout, win/installer/installer.nsi reads git rev-parse HEAD with nsExec::ExecToStack and compares it with the release commit. NSIS keeps git's trailing newline in stack mode and only the release commit is trimmed, so the check fails after every successful checkout: "Repository update did not land on the expected commit". This started with f35f8a475 and d7179e7a7 (2026-05-04), and v2.4.6 shipped it. The fresh-clone path already trims, so only updates over an existing install are affected.
  2. A damaged built server file bricks the install until a reinstall. The launchers rebuild only when the version or commit in build-meta.json changes, so a damaged file with matching metadata is started every time. The rebuilds run by the installer and the in-app updater are incremental tsc runs, which were a 1.9 s no-op that left the damaged line in place.

What wrote the bad line is not proven. tsc cannot emit it. The only in-app writer that can reach packages/server/dist is Professor Mari's workspace tools; a separate PR stops her from writing build output.

What changed

  • packages/server/scripts/write-build-meta.mjs records a SHA-256 for every built code file (.js, .mjs, .cjs, .json; 658 on the real server) in dist/config/build-meta.json. It also exports findChangedBuildFile(), which returns the first missing or changed file.
  • scripts/run-server.mjs, which start.bat, start.sh, start-termux.sh, start-local.bat and pnpm start all use, checks the build before each start in about 25 ms. When a file is missing or changed, it names the file, rebuilds the server, and starts. If the rebuild fails it prints a clear error; a Ctrl+C during the rebuild is not reported as a failure. A stop sent to the launcher reaches the rebuild the same way it reaches the server, and build.mjs passes it on to tsc, so stopping during a rebuild ends the whole build at once and the server does not start. Private builds (dist-*) and runs from src are not checked.
  • packages/server/scripts/build.mjs deletes tsconfig.tsbuildinfo before the incremental tsc run when dist does not match its recorded hashes, or has none. tsc then rewrites every file, so the installer's and the in-app updater's rebuilds repair a damaged build. A build that fails type-checking still records the files it wrote, with commit null, so the launchers rebuild it as before instead of starting it.
  • win/installer/installer.nsi trims the post-checkout git rev-parse HEAD output before the comparison, and scripts/check-windows-installer-layout.mjs now requires every commit the installer reads to be trimmed. That check fails on current staging and passes here.
  • New scripts/regressions/launcher/server-build.regression.mjs, added to regression:launcher-update. It runs the real run-server, build and metadata scripts on a one-module package and covers:
    • repair at start for a damaged file and for a deleted one;
    • repair by an incremental build;
    • a type-error build that stays startable and rebuilds;
    • a stop sent only to the launcher during a rebuild ends the build and its tsc at once, and the server does not start (macOS and Linux);
    • negative controls: a private build is left alone, and an older build without hashes is not checked at start but is rewritten by its next build.
  • CHANGELOG entry.

Release compatibility (how a 2.4.6 install reaches this code):

  • The new .exe over an old install: the update check now passes. The installer's build sees no hashes and does a full rebuild, which records them.
  • In-app update or launcher update from 2.4.6: the next build likewise does a full rebuild and records hashes. Until then, a build without hashes is simply not checked.
  • Docker and Dockerfile.lite overwrite build-meta.json and start dist/index.js directly, so the check is inert there.
  • Termux rebuilds through its existing low-memory esbuild path.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Run by the agent:

  • pnpm check, pnpm regression:launcher-update (including the new regression), restart-supervisor and server-signal-shutdown pass.
  • The new regression fails without each part: the original run-server, the build pre-check, the private-build gate, missing-file detection, the type-error handling, and either half of the stop handling (the old launcher waits for the build; the old build.mjs leaves tsc running).
  • On the real server, line 8 of the built conversation-command-runtime.js was replaced with if(, raw) { }. That gives exactly the reported SyntaxError. Through the fixed launcher it prints a warning naming the file, rebuilds, and /api/health answers.
  • An adversarial review found two minor gaps and two nits. All four were reproduced and fixed.
  • GitHub CodeRabbit asked for the repair build to stay stoppable; fixed in 0a2305994. Local CodeRabbit on that fix found one minor item, a guard timer in the new regression that kept Node running 10 s after the launcher exited; fixed in 732dfba2d.
  • A separate check upgraded real v2.4.6 installs to this branch: the in-app updater and the launcher auto-update both rebuilt every server file and recorded its hash, a damaged file was repaired at start, and a fresh install, pnpm version:check, the Docker image and the Termux esbuild path were all fine.
  • The NSIS change compiles with makensis 3.11. The installer .exe itself was not run on Windows.

Still to verify by hand:

  • On Windows, run the new installer .exe over an existing install: it updates without "Repository update did not land on the expected commit".
  • On Windows, damage a built file (append if(, raw) { } to packages/server/dist/services/generation/conversation-command-runtime.js) and run start.bat: it names the file, rebuilds and starts. Press Ctrl+C during the rebuild and check no "reinstall" error appears.
  • On Windows, after a server build that failed type-checking, start.bat reports a build commit mismatch and builds again rather than starting it.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG updated. No user docs describe the build check.

Summary by CodeRabbit

  • Bug Fixes
    • The server launcher now repairs missing or damaged build files before starting the server.
    • Server files are repaired during updates through the Windows installer or in-app updater.
    • Windows installer updates for existing installations now correctly compare release versions.
    • Interrupted server builds stop cleanly without launching the server.
  • Tests
    • Added regression checks for server build repair, installer layout validation, and build interruption handling. These checks cover damaged or missing files and ensure interrupted repairs do not start the server.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6994 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/3/2026 **Status:** ✅ Merged **Merged:** 10/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/damaged-server-build-6984` --- ### 📝 Commits (9) - [`dd70013`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dd700138cb0b38d8eb43b3aabcb496e2f1834e11) fix(launcher): repair a damaged server build and unblock installer updates - [`6180562`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6180562cd93229f3b6a7806dc6622a1f2042f1f0) fix(launcher): keep type-error builds startable and prove the build checks - [`bf01d09`](https://github.com/Pasta-Devs/Marinara-Engine/commit/bf01d093c45506af5e331e03159431aeb5f01f0a) Merge remote-tracking branch 'origin/staging' into HEAD - [`b5dbe39`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b5dbe3949b675e4e12978f0addefcf27be44a59c) Merge remote-tracking branch 'origin/staging' into fix/damaged-server-build-6984 - [`0a23059`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0a23059943248076029840a368e1ca0fb6302722) fix(launcher): let a stop end the repair build and its tsc - [`dada4d8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dada4d8e04e4e724913afce3911fa6c85ecab474) Merge remote-tracking branch 'origin/staging' into fix/damaged-server-build-6984 - [`732dfba`](https://github.com/Pasta-Devs/Marinara-Engine/commit/732dfba2d61d799cf1cae59c3d9639134fbe2e4e) test(launcher): let the stop regression exit as soon as it is done - [`7f1096b`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7f1096bb636d3489a44c87f3053e0f37b5378890) docs(changelog): split the damaged-build entry into one step per sentence - [`2954d6c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2954d6c8bfa41c1d0b8ab957f5c32a58ab8821c8) Merge branch 'staging' into fix/damaged-server-build-6984 ### 📊 Changes **8 files changed** (+300 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `package.json` (+1 -1) 📝 `packages/server/scripts/build.mjs` (+17 -15) 📝 `packages/server/scripts/write-build-meta.mjs` (+50 -9) 📝 `scripts/check-windows-installer-layout.mjs` (+13 -0) ➕ `scripts/regressions/launcher/server-build.regression.mjs` (+170 -0) 📝 `scripts/run-server.mjs` (+46 -7) 📝 `win/installer/installer.nsi` (+2 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6984 ## Why this change A Windows user's built server file `packages/server/dist/services/generation/conversation-command-runtime.js` ended up containing `if(, raw) { }`. After that, the server would not start, restarting the PC did not help, and only a clean install fixed it. The latest `.exe` installer also refused to update the install. Two problems are behind this, and both are on staging, so today's release would ship them: 1. **The Windows installer's in-place update always fails.** After `git checkout`, `win/installer/installer.nsi` reads `git rev-parse HEAD` with `nsExec::ExecToStack` and compares it with the release commit. NSIS keeps git's trailing newline in stack mode and only the release commit is trimmed, so the check fails after every successful checkout: "Repository update did not land on the expected commit". This started with f35f8a475 and d7179e7a7 (2026-05-04), and v2.4.6 shipped it. The fresh-clone path already trims, so only updates over an existing install are affected. 2. **A damaged built server file bricks the install until a reinstall.** The launchers rebuild only when the version or commit in `build-meta.json` changes, so a damaged file with matching metadata is started every time. The rebuilds run by the installer and the in-app updater are incremental `tsc` runs, which were a 1.9 s no-op that left the damaged line in place. What wrote the bad line is not proven. `tsc` cannot emit it. The only in-app writer that can reach `packages/server/dist` is Professor Mari's workspace tools; a separate PR stops her from writing build output. ## What changed - `packages/server/scripts/write-build-meta.mjs` records a SHA-256 for every built code file (`.js`, `.mjs`, `.cjs`, `.json`; 658 on the real server) in `dist/config/build-meta.json`. It also exports `findChangedBuildFile()`, which returns the first missing or changed file. - `scripts/run-server.mjs`, which start.bat, start.sh, start-termux.sh, start-local.bat and `pnpm start` all use, checks the build before each start in about 25 ms. When a file is missing or changed, it names the file, rebuilds the server, and starts. If the rebuild fails it prints a clear error; a Ctrl+C during the rebuild is not reported as a failure. A stop sent to the launcher reaches the rebuild the same way it reaches the server, and `build.mjs` passes it on to `tsc`, so stopping during a rebuild ends the whole build at once and the server does not start. Private builds (`dist-*`) and runs from `src` are not checked. - `packages/server/scripts/build.mjs` deletes `tsconfig.tsbuildinfo` before the incremental `tsc` run when dist does not match its recorded hashes, or has none. `tsc` then rewrites every file, so the installer's and the in-app updater's rebuilds repair a damaged build. A build that fails type-checking still records the files it wrote, with commit `null`, so the launchers rebuild it as before instead of starting it. - `win/installer/installer.nsi` trims the post-checkout `git rev-parse HEAD` output before the comparison, and `scripts/check-windows-installer-layout.mjs` now requires every commit the installer reads to be trimmed. That check fails on current staging and passes here. - New `scripts/regressions/launcher/server-build.regression.mjs`, added to `regression:launcher-update`. It runs the real run-server, build and metadata scripts on a one-module package and covers: - repair at start for a damaged file and for a deleted one; - repair by an incremental build; - a type-error build that stays startable and rebuilds; - a stop sent only to the launcher during a rebuild ends the build and its `tsc` at once, and the server does not start (macOS and Linux); - negative controls: a private build is left alone, and an older build without hashes is not checked at start but is rewritten by its next build. - CHANGELOG entry. Release compatibility (how a 2.4.6 install reaches this code): - **The new `.exe` over an old install:** the update check now passes. The installer's build sees no hashes and does a full rebuild, which records them. - **In-app update or launcher update from 2.4.6:** the next build likewise does a full rebuild and records hashes. Until then, a build without hashes is simply not checked. - **Docker and Dockerfile.lite** overwrite `build-meta.json` and start `dist/index.js` directly, so the check is inert there. - **Termux** rebuilds through its existing low-memory esbuild path. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Run by the agent: - `pnpm check`, `pnpm regression:launcher-update` (including the new regression), `restart-supervisor` and `server-signal-shutdown` pass. - The new regression fails without each part: the original run-server, the build pre-check, the private-build gate, missing-file detection, the type-error handling, and either half of the stop handling (the old launcher waits for the build; the old `build.mjs` leaves `tsc` running). - On the real server, line 8 of the built `conversation-command-runtime.js` was replaced with `if(, raw) { }`. That gives exactly the reported `SyntaxError`. Through the fixed launcher it prints a warning naming the file, rebuilds, and `/api/health` answers. - An adversarial review found two minor gaps and two nits. All four were reproduced and fixed. - GitHub CodeRabbit asked for the repair build to stay stoppable; fixed in 0a2305994. Local CodeRabbit on that fix found one minor item, a guard timer in the new regression that kept Node running 10 s after the launcher exited; fixed in 732dfba2d. - A separate check upgraded real v2.4.6 installs to this branch: the in-app updater and the launcher auto-update both rebuilt every server file and recorded its hash, a damaged file was repaired at start, and a fresh install, `pnpm version:check`, the Docker image and the Termux esbuild path were all fine. - The NSIS change compiles with makensis 3.11. The installer `.exe` itself was not run on Windows. Still to verify by hand: - On Windows, run the new installer `.exe` over an existing install: it updates without "Repository update did not land on the expected commit". - On Windows, damage a built file (append `if(, raw) { }` to `packages/server/dist/services/generation/conversation-command-runtime.js`) and run start.bat: it names the file, rebuilds and starts. Press Ctrl+C during the rebuild and check no "reinstall" error appears. - On Windows, after a server build that failed type-checking, start.bat reports a build commit mismatch and builds again rather than starting it. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG updated. No user docs describe the build check. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * The server launcher now repairs missing or damaged build files before starting the server. * Server files are repaired during updates through the Windows installer or in-app updater. * Windows installer updates for existing installations now correctly compare release versions. * Interrupted server builds stop cleanly without launching the server. * **Tests** * Added regression checks for server build repair, installer layout validation, and build interruption handling. These checks cover damaged or missing files and ensure interrupted repairs do not start the server. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:19:37 +07:00
Sign in to join this conversation.
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
Pasta-Devs/Marinara-Engine#7422
No description provided.