[GH-ISSUE #4421] Channel switch (main → staging) can leave stale source files that break the build #2400

Closed
opened 2026-10-21 05:47:54 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @kolacheee on GitHub (Aug 1, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4421

Originally assigned to: @Gunterlie on GitHub.

When a user switches from the stable channel (main) to staging, files that exist on main but were deleted on staging can persist in the working tree as untracked files. The build then fails because tsc picks them up via include: ["src/**/*.ts"] and they reference types/enums that no longer exist on staging.

The immediate trigger is packages/shared/src/constants/chat-mode-capabilities.ts — present on main (where ChatMode includes visual_novel), deleted on staging via PR #4356. After a main→staging switch the file stays behind, and tsc errors on the stale visual_novel key:

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>'.

Why the file persists

On Windows, git checkout can fail to delete individual files (antivirus scanner, Windows Search indexer, or another process briefly locking the file). Git may still report the checkout as successful (HEAD moves to the target) while the locked file remains as an untracked leftover.

Once the file lingers, start.bat makes the problem self-perpetuating: its git stash push -u (line 190) captures the untracked file before every update, and restore_stashed_changes puts it back afterward — so the stale file survives every subsequent relaunch.

The in-app updater (updates.routes.ts) avoids this particular trap (its createUpdateStash uses --untracked-files=no), but neither update path runs any post-checkout cleanup to verify the working tree matches the target commit.

Try it yourself

  1. Fresh install of v2.3.4 (Windows zipfile/NSIS installer — creates a depth-1 clone at the tag).
  2. Switch to the staging channel (in-app updater or manual git checkout -b staging origin/staging).
  3. If the checkout silently fails to delete chat-mode-capabilities.ts (Windows file lock), the build fails with TS2353.
  4. Relaunch via start.bat — the file is stashed with -u, restored after the no-op update, and the build fails again.

Suggested fix

After a successful channel-switch checkout (both start.bat and checkoutOrCreateUpdateBranch in updates.routes.ts), run a targeted cleanup of source directories:

git clean -fd -- packages/shared/src packages/server/src packages/client/src

This removes untracked files in the source trees without touching user data, node_modules, or config files. A full git clean -fd would be too aggressive (could delete .env, data files, etc.), but scoping it to packages/*/src is safe — those directories should only contain tracked source.

An alternative (less targeted but more thorough): after any checkout that changes channels, compare git ls-tree -r --name-only HEAD against the working tree and remove files that exist locally but not in the target tree.

Originally created by @kolacheee on GitHub (Aug 1, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4421 Originally assigned to: @Gunterlie on GitHub. When a user switches from the stable channel (main) to staging, files that exist on main but were deleted on staging can persist in the working tree as untracked files. The build then fails because `tsc` picks them up via `include: ["src/**/*.ts"]` and they reference types/enums that no longer exist on staging. The immediate trigger is `packages/shared/src/constants/chat-mode-capabilities.ts` — present on main (where `ChatMode` includes `visual_novel`), deleted on staging via PR #4356. After a main→staging switch the file stays behind, and `tsc` errors on the stale `visual_novel` key: ``` 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>'. ``` ### Why the file persists On Windows, `git checkout` can fail to delete individual files (antivirus scanner, Windows Search indexer, or another process briefly locking the file). Git may still report the checkout as successful (HEAD moves to the target) while the locked file remains as an untracked leftover. Once the file lingers, `start.bat` makes the problem **self-perpetuating**: its `git stash push -u` (line 190) captures the untracked file before every update, and `restore_stashed_changes` puts it back afterward — so the stale file survives every subsequent relaunch. The in-app updater (`updates.routes.ts`) avoids this particular trap (its `createUpdateStash` uses `--untracked-files=no`), but neither update path runs any post-checkout cleanup to verify the working tree matches the target commit. ### Try it yourself 1. Fresh install of v2.3.4 (Windows zipfile/NSIS installer — creates a depth-1 clone at the tag). 2. Switch to the staging channel (in-app updater or manual `git checkout -b staging origin/staging`). 3. If the checkout silently fails to delete `chat-mode-capabilities.ts` (Windows file lock), the build fails with TS2353. 4. Relaunch via `start.bat` — the file is stashed with `-u`, restored after the no-op update, and the build fails again. ### Suggested fix After a successful channel-switch checkout (both `start.bat` and `checkoutOrCreateUpdateBranch` in `updates.routes.ts`), run a targeted cleanup of source directories: ```bash git clean -fd -- packages/shared/src packages/server/src packages/client/src ``` This removes untracked files in the source trees without touching user data, node_modules, or config files. A full `git clean -fd` would be too aggressive (could delete `.env`, data files, etc.), but scoping it to `packages/*/src` is safe — those directories should only contain tracked source. An alternative (less targeted but more thorough): after any checkout that changes channels, compare `git ls-tree -r --name-only HEAD` against the working tree and remove files that exist locally but not in the target tree.
bsakaguchi 2026-10-21 05:47:54 +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#2400
No description provided.