[PR #3902] [MERGED] fix: make connection reference cleanup atomic #6149

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

📋 Pull Request Information

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

Base: staging ← Head: fix/atomic-connection-reference-cleanup


📝 Commits (2)

  • 6cfa9c4 fix: make connection reference cleanup atomic
  • 25a136a Handle lowercase connection references

📊 Changes

2 files changed (+32 additions, -52 deletions)

View changed files

📝 packages/server/src/services/storage/connection-reference-cleanup.ts (+28 -49)
📝 packages/server/src/services/storage/connections.storage.ts (+4 -3)

📄 Description

Linked issue

Closes #3900

Why this change

  • Bulk connection deletion sends requests concurrently. Each deletion previously removed its connection and then rewrote stale whole-JSON cleanup snapshots outside a transaction, allowing one sweep to restore another deleted connection ID.
  • A cleanup failure could also leave the connection deleted with only part of its references cleared.

What changed

  • Run connection deletion and the complete dangling-reference sweep inside one file-store transaction.
  • Replace bespoke parse-and-copy recursion with a private JSON reviver helper while preserving malformed JSON, non-object roots, legacy object-shaped values, nested arrays, and __proto__ properties.
  • Propagate genuine serialization and reviver failures so the transaction rolls back; suppress only malformed-input SyntaxError.
  • Narrow internal cleanup symbols that have no external consumers while retaining cleanup counts and logging.

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 on the final rebased commit.
  • An isolated actual file-store probe confirmed concurrent deletion of connections A and B clears both references.
  • Focused probes confirmed transaction rollback after injected cleanup failure and deep valid-JSON processing failure.
  • Focused compatibility controls covered direct and nested references, malformed JSON, root arrays, nonmatching IDs, legacy raw objects, and nested __proto__.
  • No browser or container verification was performed; this is an internal server storage change.
  • Atomicity is scoped to in-process writer serialization and error rollback. Crash durability and general read isolation are unchanged.

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 metadata changes are expected for this internal storage correction.

UI evidence (if applicable)

Not applicable; no UI changed.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cleanup of references when a connection is deleted.
    • Connection deletions and related reference cleanup now occur together, reducing the risk of inconsistent data.
    • Invalid or unsupported stored JSON is preserved instead of being unintentionally modified.
    • Direct connection references in chats, agent configurations, and embedding settings are cleared reliably.

🔄 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/3902 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 7/21/2026 **Status:** ✅ Merged **Merged:** 7/21/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/atomic-connection-reference-cleanup` --- ### 📝 Commits (2) - [`6cfa9c4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6cfa9c4c1dd852e302e5f9d9ef4647442224dc0a) fix: make connection reference cleanup atomic - [`25a136a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/25a136aaff0211664e4428ff37245f1d1f783fba) Handle lowercase connection references ### 📊 Changes **2 files changed** (+32 additions, -52 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/storage/connection-reference-cleanup.ts` (+28 -49) 📝 `packages/server/src/services/storage/connections.storage.ts` (+4 -3) </details> ### 📄 Description ## Linked issue Closes #3900 ## Why this change - Bulk connection deletion sends requests concurrently. Each deletion previously removed its connection and then rewrote stale whole-JSON cleanup snapshots outside a transaction, allowing one sweep to restore another deleted connection ID. - A cleanup failure could also leave the connection deleted with only part of its references cleared. ## What changed - Run connection deletion and the complete dangling-reference sweep inside one file-store transaction. - Replace bespoke parse-and-copy recursion with a private JSON reviver helper while preserving malformed JSON, non-object roots, legacy object-shaped values, nested arrays, and `__proto__` properties. - Propagate genuine serialization and reviver failures so the transaction rolls back; suppress only malformed-input `SyntaxError`. - Narrow internal cleanup symbols that have no external consumers while retaining cleanup counts and logging. ## Validation - [x] `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) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - `pnpm check` passed on the final rebased commit. - An isolated actual file-store probe confirmed concurrent deletion of connections A and B clears both references. - Focused probes confirmed transaction rollback after injected cleanup failure and deep valid-JSON processing failure. - Focused compatibility controls covered direct and nested references, malformed JSON, root arrays, nonmatching IDs, legacy raw objects, and nested `__proto__`. - No browser or container verification was performed; this is an internal server storage change. - Atomicity is scoped to in-process writer serialization and error rollback. Crash durability and general read isolation are unchanged. ## 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 metadata changes are expected for this internal storage correction. ## UI evidence (if applicable) Not applicable; no UI changed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved cleanup of references when a connection is deleted. * Connection deletions and related reference cleanup now occur together, reducing the risk of inconsistent data. * Invalid or unsupported stored JSON is preserved instead of being unintentionally modified. * Direct connection references in chats, agent configurations, and embedding settings are cleared reliably. <!-- 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:33 +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#6149
No description provided.