mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #3044] [Issue]: Activating a non-existent/stale persona id deactivates ALL personas and still returns success, leaving no active persona #1613
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#1613
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?
Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3044
Originally assigned to: @SpicyMarinara on GitHub.
What's wrong
The "set active persona" path first clears the active flag on EVERY persona (an UPDATE with no WHERE), then sets it true only on the row matching the given id. There is no existence check in either the route or the storage method. If the id doesn't exist — a persona deleted in another tab, a stale client cache, a typo, or any direct API caller — the first UPDATE deactivates all personas and the second matches zero rows, leaving the system with NO active persona. The route still returns HTTP 200
{ success: true }. Every server path that falls back to the globally-active persona (personas.find(p => p.isActive === "true")) then silently gets undefined and drops the user's persona from the prompt until a valid persona is manually re-activated. (Chats that pin an explicitchat.personaIdare unaffected, which is why severity is bounded.)How to reproduce (try it yourself)
chat.personaId.You'll see: the response is 200
{ success: true }, but no persona hasisActive === "true", and the global-active fallback resolves to undefined so the user's persona is omitted from the prompt.Expected: a non-existent id returns 404 and leaves the existing active persona untouched.
Where it is
packages/server/src/services/storage/characters.storage.ts:428-433—setActivePersonadoesdb.update(personas).set({ isActive: "false" })(no WHERE), then.set({ isActive: "true", ... }).where(eq(personas.id, id)). No existence guard.packages/server/src/routes/characters.routes.ts:925-928— PUT /personas/:id/activate callsstorage.setActivePersona(req.params.id)and returns{ success: true }unconditionally. This is the only caller ofsetActivePersona.packages/server/src/routes/chats.routes.ts:386-394(buildPersonaSnapshotForChatreturns null when nothing is active). The sameisActive === "true"fallback appears in ~15 sites (generate/prompts/scene/encounter routes, awareness.service.ts, etc.).What's happening
The deactivate-all UPDATE runs before validating the target exists, and the activate UPDATE is a no-op when the id is absent. On the default file-native backend, an UPDATE with no condition matches every row (
evaluateCondition(undefined)returns true), andeq(id, badId)matches zero — identical to the SQLite path. The sibling DELETE and gallery routes for personas already dogetPersona+ 404, so the missing guard here is an inconsistency, not intent.Suggested fix
Guard the route before any rows are touched, mirroring the existing DELETE /personas/:id route exactly (reply param, path-segment guard, getPersona + 404). Keep
setActivePersonaunchanged:This ensures the unconditional deactivate-all is never reached for a non-existent id, so the table can never be left with zero active personas while the route reports success. Regression notes: the valid-id happy path is unchanged. The client hook
useActivatePersona(use-characters.ts:649-655) has noonError; on a 404 it simply skips its cache invalidation instead of refetching into a corrupted state — strictly better than the previous false 200.setActivePersonahas exactly one caller, so the route-level guard fully closes the hole with no storage change or transaction needed. Equivalently, the guard could live insetActivePersona(returning false, with the route honoring it via 404), mirroringchat-presets.storage.ts/themes.storage.tssetActive; the load-bearing part is checking existence before clearing any flag.AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.
@SpicyMarinara commented on GitHub (Jun 29, 2026):
Claiming this for the current staging sweep in draft PR #3053 (branch
codex/issue-sweep-3033-3052).@SpicyMarinara commented on GitHub (Jun 29, 2026):
Fixed in PR #3053 on branch
codex/issue-sweep-3033-3052(commitbfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.