[PR #3788] [MERGED] Fix browser update serialization and stash recovery #6101

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3788
Author: @Xelvanis
Created: 7/18/2026
Status: ✅ Merged
Merged: 7/18/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/serialize-browser-updates


📝 Commits (3)

  • f67d109 fix: serialize browser update application
  • e38973e Merge branch 'staging' into fix/serialize-browser-updates
  • b2fd0a1 fix(updates): accept variable-length git object ids

📊 Changes

1 file changed (+163 additions, -81 deletions)

View changed files

📝 packages/server/src/routes/updates.routes.ts (+163 -81)

📄 Description

Linked issue

Closes #3787

Why this change

  • Browser-applied updates could overlap across tabs or API clients and race Git state, the stash stack, dependency installation, and builds.
  • Stash creation/restoration failures were suppressed, allowing installation to continue from an ambiguous or conflicted checkout.

What changed

  • Added a process-local update mutex that returns 409 to competing callers and remains latched through successful scheduled shutdown.
  • Fetches, confirms, and moves to an immutable target commit instead of relying on a remote-tracking ref that can move mid-update.
  • Gives the updater stash a unique marker, records its immutable OID, restores only that stash, and preserves it when restoration conflicts.
  • Rolls movement failures back to the original branch or detached commit, verifies the restored HEAD, and stops before installation when recovery fails.
  • Keeps update-check branch discovery permissive while making update application fail safely when branch state cannot be read.

Residual boundary: serialization is intentionally process-local and does not cover manual Git activity or another server process sharing the checkout.

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

  • pnpm check passed: Impeccable context guard, all workspace lint/type checks, and production server/client builds.
  • Focused server TypeScript lint and git diff --check passed.
  • Disposable Git fixtures exercised exact stash selection/drop with an intervening stash, named and detached rollback, and restoration to the original commit.
  • A browser simulation intercepted all updater requests and verified the available-update UI, immutable target payload, pending state, success response, 409 contention response, recovery failure response, and rapid duplicate POST behavior without touching the real checkout.
  • The real self-update endpoint was not executed; injected internal command and unusual filesystem/permission failures remain manual validation gaps.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

No documentation or release-file changes are needed because configuration and user-facing update instructions are unchanged.

UI evidence (if applicable)

Not applicable: no UI code or visual behavior changed.

Summary by CodeRabbit

  • Bug Fixes
    • Prevented multiple updates from being applied at the same time.
    • Improved update reliability by preserving local changes and restoring the previous state when an update fails.
    • Added validation to ensure updates reach the expected version before completion.
    • Improved handling of unavailable Git information and non-Git installations.
    • Ensured update processes do not incorrectly reset during a planned shutdown.

🔄 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/3788 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 7/18/2026 **Status:** ✅ Merged **Merged:** 7/18/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/serialize-browser-updates` --- ### 📝 Commits (3) - [`f67d109`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f67d10915435adbecd44a56d142e2d282bc4daba) fix: serialize browser update application - [`e38973e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e38973e3c82ddd37b3c3f88b3573f2bab60f346d) Merge branch 'staging' into fix/serialize-browser-updates - [`b2fd0a1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b2fd0a15b9eb40488010370754fd4cf7120284a6) fix(updates): accept variable-length git object ids ### 📊 Changes **1 file changed** (+163 additions, -81 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/updates.routes.ts` (+163 -81) </details> ### 📄 Description ## Linked issue Closes #3787 ## Why this change - Browser-applied updates could overlap across tabs or API clients and race Git state, the stash stack, dependency installation, and builds. - Stash creation/restoration failures were suppressed, allowing installation to continue from an ambiguous or conflicted checkout. ## What changed - Added a process-local update mutex that returns `409` to competing callers and remains latched through successful scheduled shutdown. - Fetches, confirms, and moves to an immutable target commit instead of relying on a remote-tracking ref that can move mid-update. - Gives the updater stash a unique marker, records its immutable OID, restores only that stash, and preserves it when restoration conflicts. - Rolls movement failures back to the original branch or detached commit, verifies the restored HEAD, and stops before installation when recovery fails. - Keeps update-check branch discovery permissive while making update application fail safely when branch state cannot be read. Residual boundary: serialization is intentionally process-local and does not cover manual Git activity or another server process sharing the checkout. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passed: Impeccable context guard, all workspace lint/type checks, and production server/client builds. - Focused server TypeScript lint and `git diff --check` passed. - Disposable Git fixtures exercised exact stash selection/drop with an intervening stash, named and detached rollback, and restoration to the original commit. - A browser simulation intercepted all updater requests and verified the available-update UI, immutable target payload, pending state, success response, `409` contention response, recovery failure response, and rapid duplicate POST behavior without touching the real checkout. - The real self-update endpoint was not executed; injected internal command and unusual filesystem/permission failures remain manual validation gaps. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) No documentation or release-file changes are needed because configuration and user-facing update instructions are unchanged. ## UI evidence (if applicable) Not applicable: no UI code or visual behavior changed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Prevented multiple updates from being applied at the same time. * Improved update reliability by preserving local changes and restoring the previous state when an update fails. * Added validation to ensure updates reach the expected version before completion. * Improved handling of unavailable Git information and non-Git installations. * Ensured update processes do not incorrectly reset during a planned shutdown. <!-- 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:07:05 +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#6101
No description provided.