mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2689] [Issue]: Re-importing a built-in agent wipes its connectionId, settings, and OAuth tokens (create→update reroute) #1333
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#1333
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 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2689
Originally assigned to: @SpicyMarinara on GitHub.
Summary
Re-importing (or re-creating) a built-in agent silently wipes its stored
connectionId, settings (including Spotify/YouTube OAuth tokens), andpromptTemplate.create()detects an existing built-in type and reroutes toupdate()with a full schema-default payload, which wholesale-overwrites the stored row — so the agent loses its per-agent connection (falling back to the wrong provider/model) and any auth tokens stored in settings.Expected behavior
Re-importing or re-saving a built-in agent should not clobber fields the caller didn't intend to change — especially the per-agent
connectionIdand OAuth tokens stored in settings. Import should be idempotent or merge, mirroring the OAuth-field preservation the agent editor already does.Actual behavior
create()detects a built-in type and, if a config of that type exists, returnsthis.update(existing.id, input). The POST/agentsroute parses the body withcreateAgentConfigSchema, which (zod) applies all defaults — so the parsedinputalways containsconnectionId:null,settings:{}(or imported, token-stripped settings),promptTemplate:"", etc.update()then runs everyif (data.X !== undefined)branch:connectionIdis present (null) → overwrites the stored connection with null;settingsis present →JSON.stringify({ ...data.settings })wholesale-replaces stored settings (no merge);promptTemplateoverwrites. Agent export hardcodesconnectionId:nulland strips Spotify/YouTube tokens, so the import payload carries exactly those clobbering defaults.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/services/storage/agents.storage.ts:187-191—create()built-in reroute toupdate(existing.id, input).packages/server/src/routes/agents.routes.ts:221— parses withcreateAgentConfigSchema(applies defaults).agents.storage.ts:219-239—update()if (data.X !== undefined)branches:connectionIdoverwritten to null (:226);settingswholesale-replaced viaJSON.stringify({ ...data.settings })(:230-233);promptTemplateoverwritten.AgentsPanel.serializeAgentConfig/AgentEditorhardcodeconnectionId:null;agent-transfer.ts:2-6stripsspotifyAccessToken/spotifyRefreshToken/youtubeApiKey; import loop POSTs each entry (AgentsPanel.tsx:490-499). The editor's ownhandleSaveworks around the wholesale replace by re-injectingpreservedSpotifyFields(AgentEditor.tsx:877-892) — but the import/create-reroute path has no such preservation.Steps to reproduce
/agents→create()sees the existing built-in →update(existing.id, importedInput)withconnectionId:nulland token-stripped settings.connection_idNULL and settings without the per-agent connection / Spotify tokens → the agent resolves to the default/main connection and (Spotify) loses auth.Suggested fix
Do not run
create()'s update-reroute with a fullcreateAgentConfigSchemapayload carrying schema defaults. Either (a) forward only fields the caller actually supplied (omitconnectionId/settings/promptTemplatewhen they equal unintended defaults), (b) makeupdate()'s settings branch merge with stored settings and skip overwritingconnectionId/promptTemplatewhen not meaningfully provided, or (c) treat built-in re-import as an idempotent merge. Mirror the OAuth-field preservation the editor already does (spotifyAccessToken/spotifyRefreshToken/spotifyExpiresAt/spotifyScope/youtubeApiKey).Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of the agent subsystem. Causes data loss (per-agent connection + OAuth tokens) and silently moves the agent to the wrong connection on a routine export→import. Part of a set of agent-pipeline issues filed together.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@SpicyMarinara commented on GitHub (Jun 21, 2026):
Fixed in branch
codex/spicy-issue-sweep-2026-06-21.What changed:
Final repo checks will run after the full issue sweep.