[PR #4422] [MERGED] fix: clear stale untracked source files on channel switch (#4421) #6371

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4422
Author: @Gunterlie
Created: 8/1/2026
Status: ✅ Merged
Merged: 8/1/2026
Merged by: @Gunterlie

Base: staging ← Head: fix/4421-stale-source-cleanup


📝 Commits (3)

  • 5926532 fix: clear stale untracked source files on channel switch (#4421)
  • b5d7637 Merge branch 'staging' into fix/4421-stale-source-cleanup
  • 01b941d fix: cover manual apply and failed cleanup paths (#4421)

📊 Changes

4 files changed (+86 additions, -2 deletions)

View changed files

📝 packages/server/src/routes/updates.routes.ts (+28 -1)
📝 start-termux.sh (+19 -0)
📝 start.bat (+20 -1)
📝 start.sh (+19 -0)

📄 Description

Fixes #4421.

Why

A user switching from the stable channel to staging can end up with a checkout that never builds again. Files that exist on main but were deleted on staging can survive the switch as untracked leftovers — on Windows, git checkout can fail to delete an individual file (antivirus scanner or Windows Search indexer holding a brief lock) while still reporting the checkout as successful. tsc then picks the leftover up via include: ["src/**/*.ts"] and fails on types that no longer exist:

src/constants/chat-mode-capabilities.ts:149:3 - error TS2353:
  Object literal may only specify known properties, and 'visual_novel'
  does not exist in type 'Record<ChatMode, ChatModeCapabilities>'.

The launchers turned that from a transient glitch into a permanent one. git stash push -u captured the untracked leftover before every update and restore_stashed_changes put it back afterwards, so the broken tree survived every relaunch. There was no way out short of the user deleting the file by hand — and no message telling them which file to delete.

What changed

Untracked files under packages/{shared,server,client}/src are now removed:

  • after a channel-switch checkout, in checkoutOrCreateUpdateBranch (packages/server/src/routes/updates.routes.ts)
  • once per launch in start.bat, start.sh, and start-termux.sh

Placement notes, both deliberate:

  • Before git stash push -u, so the stale file can't be captured and restored again.
  • Above the SKIP_UPDATE / AUTO_UPDATE_DISABLED bails. Removing a file the checkout should have deleted is working-tree repair, not an update. Users with auto-update off previously jumped straight past any cleanup and stayed stuck indefinitely.

All three launchers shared the same stash-and-restore cycle, so all three are patched — the bug was not Windows-specific in mechanism, only in trigger.

Safety of the scope:

  • Pinned to the three source trees, so user data, .env, config, and node_modules are untouched.
  • No -x, so gitignored build output survives.
  • No -q, so git prints Removing <path> when it actually deletes — a stray file of your own leaves a trace in the console instead of vanishing silently.
  • The in-app clean is wrapped in try/catch and logs a warning. A still-locked file must not fail the whole update, since the launcher retries the same clean on the next start.

A full git clean -fd would have been too aggressive (it could take .env and data files); the ls-tree-diff alternative from the issue solves the same case with considerably more code.

Verified

  • pnpm check passes.
  • bash -n on both shell launchers.
  • Git semantics exercised in a scratch repo on Linux: the scoped clean removes an untracked stale file, keeps tracked files, keeps gitignored build output, leaves data/ and .env alone, and exits 0 when a pathspec doesn't exist. git clean -nd against this repo lists nothing, so the change is a no-op on a healthy tree.

Not verified — needs a human on Windows

None of this has been run on Windows, and the bug is Windows-triggered. start.bat has no automated test lane, so the ordering claim (clean runs before stash push -u) is read off the control flow rather than observed. Please confirm before merging.

Test plan

  • Fresh install of a release build on Windows (zipfile or NSIS installer).
  • Switch to the staging channel via the in-app updater; manually verify the build succeeds.
  • Reproduce the locked-file case (hold packages/shared/src/chat-mode-capabilities.ts open during the switch) and manually verify the next start.bat launch removes it and builds.
  • Manually verify start.bat prints Removing <path> when it deletes a leftover, and prints nothing on a clean tree.
  • Manually verify a launch with AUTO_UPDATE_ENABLED=false still clears a stale file.
  • Manually verify an untracked file under packages/*/src that a developer created is reported before deletion (expected behaviour change — flag if too aggressive).
  • Manually verify on Linux via start.sh that a normal launch and update are unaffected.
  • Manually verify on Termux via start-termux.sh.

Summary by CodeRabbit

  • Bug Fixes
    • Automatically removes untracked source files during startup and after switching update channels.
    • Cleanup runs whether automatic updates are enabled, skipped, or completed.
    • Cleanup failures no longer interrupt application updates or startup.
    • Applies only to Git-based installations; removal activity remains visible where supported.

🔄 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/4422 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 8/1/2026 **Status:** ✅ Merged **Merged:** 8/1/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `fix/4421-stale-source-cleanup` --- ### 📝 Commits (3) - [`5926532`](https://github.com/Pasta-Devs/Marinara-Engine/commit/592653275e7bc543576b4d12a38b3e5f5319501b) fix: clear stale untracked source files on channel switch (#4421) - [`b5d7637`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b5d763761bb267cfa2320304f27559b0cc8c5ed4) Merge branch 'staging' into fix/4421-stale-source-cleanup - [`01b941d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/01b941d39efd1b86e317e250fcbcbd025ba42c56) fix: cover manual apply and failed cleanup paths (#4421) ### 📊 Changes **4 files changed** (+86 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/updates.routes.ts` (+28 -1) 📝 `start-termux.sh` (+19 -0) 📝 `start.bat` (+20 -1) 📝 `start.sh` (+19 -0) </details> ### 📄 Description Fixes #4421. ## Why A user switching from the stable channel to staging can end up with a checkout that never builds again. Files that exist on `main` but were deleted on `staging` can survive the switch as untracked leftovers — on Windows, `git checkout` can fail to delete an individual file (antivirus scanner or Windows Search indexer holding a brief lock) while still reporting the checkout as successful. `tsc` then picks the leftover up via `include: ["src/**/*.ts"]` and fails on types that no longer exist: ``` src/constants/chat-mode-capabilities.ts:149:3 - error TS2353: Object literal may only specify known properties, and 'visual_novel' does not exist in type 'Record<ChatMode, ChatModeCapabilities>'. ``` The launchers turned that from a transient glitch into a permanent one. `git stash push -u` captured the untracked leftover before every update and `restore_stashed_changes` put it back afterwards, so the broken tree survived every relaunch. There was no way out short of the user deleting the file by hand — and no message telling them which file to delete. ## What changed Untracked files under `packages/{shared,server,client}/src` are now removed: - after a channel-switch checkout, in `checkoutOrCreateUpdateBranch` (`packages/server/src/routes/updates.routes.ts`) - once per launch in `start.bat`, `start.sh`, and `start-termux.sh` Placement notes, both deliberate: - **Before `git stash push -u`**, so the stale file can't be captured and restored again. - **Above the `SKIP_UPDATE` / `AUTO_UPDATE_DISABLED` bails.** Removing a file the checkout should have deleted is working-tree repair, not an update. Users with auto-update off previously jumped straight past any cleanup and stayed stuck indefinitely. All three launchers shared the same stash-and-restore cycle, so all three are patched — the bug was not Windows-specific in mechanism, only in trigger. Safety of the scope: - Pinned to the three source trees, so user data, `.env`, config, and `node_modules` are untouched. - No `-x`, so gitignored build output survives. - No `-q`, so git prints `Removing <path>` when it actually deletes — a stray file of your own leaves a trace in the console instead of vanishing silently. - The in-app clean is wrapped in try/catch and logs a warning. A still-locked file must not fail the whole update, since the launcher retries the same clean on the next start. A full `git clean -fd` would have been too aggressive (it could take `.env` and data files); the `ls-tree`-diff alternative from the issue solves the same case with considerably more code. ## Verified - `pnpm check` passes. - `bash -n` on both shell launchers. - Git semantics exercised in a scratch repo on Linux: the scoped clean removes an untracked stale file, keeps tracked files, keeps gitignored build output, leaves `data/` and `.env` alone, and exits 0 when a pathspec doesn't exist. `git clean -nd` against this repo lists nothing, so the change is a no-op on a healthy tree. ## Not verified — needs a human on Windows **None of this has been run on Windows, and the bug is Windows-triggered.** `start.bat` has no automated test lane, so the ordering claim (clean runs before `stash push -u`) is read off the control flow rather than observed. Please confirm before merging. ## Test plan - [ ] Fresh install of a release build on Windows (zipfile or NSIS installer). - [ ] Switch to the staging channel via the in-app updater; manually verify the build succeeds. - [ ] Reproduce the locked-file case (hold `packages/shared/src/chat-mode-capabilities.ts` open during the switch) and manually verify the next `start.bat` launch removes it and builds. - [ ] Manually verify `start.bat` prints `Removing <path>` when it deletes a leftover, and prints nothing on a clean tree. - [ ] Manually verify a launch with `AUTO_UPDATE_ENABLED=false` still clears a stale file. - [ ] Manually verify an untracked file under `packages/*/src` that a developer created is reported before deletion (expected behaviour change — flag if too aggressive). - [ ] Manually verify on Linux via `start.sh` that a normal launch and update are unaffected. - [ ] Manually verify on Termux via `start-termux.sh`. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Automatically removes untracked source files during startup and after switching update channels. * Cleanup runs whether automatic updates are enabled, skipped, or completed. * Cleanup failures no longer interrupt application updates or startup. * Applies only to Git-based installations; removal activity remains visible where supported. <!-- 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:09:46 +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#6371
No description provided.