mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #3866] [MERGED] Sweep dangling connection references when a connection is deleted #6134
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#6134
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3866
Author: @kh0p
Created: 7/20/2026
Status: ✅ Merged
Merged: 7/20/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/cleanup-dangling-connection-references📝 Commits (4)
23b335cSweep dangling connection references when a connection is deleted9d210c3Merge branch 'staging' into fix/cleanup-dangling-connection-references94dea0aAddress connection cleanup review feedback41a2dd4Merge branch 'staging' into fix/cleanup-dangling-connection-references📊 Changes
2 files changed (+184 additions, -0 deletions)
View changed files
➕
packages/server/src/services/storage/connection-reference-cleanup.ts(+170 -0)📝
packages/server/src/services/storage/connections.storage.ts(+14 -0)📄 Description
Linked issue
Closes #3865
Why this change
Deleting a connection leaves every stored reference to its id untouched —
chats.connectionId,agentConfigs.connectionId,connections.embeddingConnectionId, and 15+ distinct*ConnectionIdfields insidechats.metadata(illustratorPromptConnectionId,gameImageConnectionId,gameSceneConnectionId,sceneVideoConnectionId,imageGenConnectionId,agentOverrides.<type>.imageConnectionId, and more). #2683 / PR #2730 fixed the general per-agent connection resolution path to fail gracefully on a dangling id, but that fix didn't (and structurally couldn't, being a resolution-time guard) prevent the dangling reference from existing in the first place, and at least one other path (illustratorPromptConnectionIdread directly inagent-resolution.ts's illustrator special case and its near-duplicate inretry-agents-route.ts) doesn't fail gracefully at all — reproduced firsthand, a stale reference there silently misrouted a post-processing agent turn onto an unrelated, much larger model and turned a normal ~3 minute turn into over an hour.Rather than adding another one-off guard to that specific path (and every future path that reads one of these fields), this removes the dangling reference at the source: the moment a connection is deleted.
What changed
sweepDanglingConnectionReferences()(services/storage/connection-reference-cleanup.ts), called fromconnections.storage.ts'sremove().chats.connectionIdandagentConfigs.connectionIddirectly, andconnections.embeddingConnectionIdon any other connection.chats.metadataandagentConfigs.settingsrecursively: any JSON key matching/ConnectionId$/, at any nesting depth, is treated as a connection reference and nulled if it matches the deleted id.*ConnectionIdsettings get added without this file needing to track them.chatsUpdated/agentsUpdated/connectionsUpdated) when the sweep actually clears something, silent no-op otherwise.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
This is a backend-only, non-UI change, so the container/UI-mode checklist items above don't apply (left unticked rather than claimed). What I did verify directly:
tsc --noEmitand a fulltscbuild against a real, dependency-installed checkout — both pass with zero errors.chat.connectionId,metadata.illustratorPromptConnectionId,metadata.gameImageConnectionId, and the nestedmetadata.agentOverrides.custom-akistar-forge.imageConnectionId), deleted the connection via the API, then re-fetched the chat and confirmed all four references were nulled. Repeated with a fresh connection/chat pair to rule out a fluke.Docs and release impact
UI evidence (if applicable)
N/A — backend-only change, no UI surface.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.