[GH-ISSUE #3049] [Issue]: Character group avatar can never be set — the PATCH route's Zod schema strips avatarPath, making the storage write branch dead #1618

Closed
opened 2026-10-21 05:40:53 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @kolacheee on GitHub (Jun 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3049

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
characterGroups has an avatarPath column and the UI renders a group avatar from it, but a character group's avatar can never actually be set through any reachable path, so it always falls back to the placeholder. The only write path, PATCH /characters/groups/:id, validates the body with updateGroupSchema.parse(...). updateGroupSchema = createGroupSchema.partial(), and createGroupSchema only defines name/description/characterIds and is not .passthrough(), so Zod silently strips avatarPath out of the parsed input before it ever reaches storage. The storage layer's avatarPath write branch is therefore dead code, and the displayed group-avatar feature is effectively non-functional.

How to reproduce (try it yourself)

  1. PATCH /api/characters/groups/:id with body { avatarPath: "/api/avatars/file/x.png" }.
  2. GET /api/characters/groups/:id and open the group avatar in the chat settings group picker.

You'll see: avatarPath is still null; the value was dropped by updateGroupSchema.parse before reaching storage, and the group avatar renders the first-letter placeholder.
Expected: the avatar persists and the group picker shows the stored image.

Where it is

  • packages/server/src/routes/characters.routes.ts:1154-1157 — PATCH handler: const input = updateGroupSchema.parse(req.body); return storage.updateGroup(req.params.id, input);.
  • packages/shared/src/schemas/character.schema.ts:106-112 — createGroupSchema (no avatarPath, not passthrough) and updateGroupSchema = createGroupSchema.partial().
  • packages/server/src/services/storage/characters.storage.ts:638 — the unreachable ...(updates.avatarPath !== undefined && { avatarPath: updates.avatarPath }) branch.
  • Column: packages/server/src/db/schema/characters.ts:96 (avatarPath: text("avatar_path"), nullable).
  • UI render: packages/client/src/components/chat/ChatSettingsDrawer.tsx:3894-3905.

What's happening
Zod's default object parsing discards unknown keys, and updateGroupSchema inherits createGroupSchema, which omits avatarPath and isn't passthrough. So avatarPath never survives validation to reach updateGroup. The storage and DB column support it; only the route contract doesn't. There is no group-avatar upload route either (the backup/marinara importers only touch prompt groups).

Suggested fix
Add avatarPath to createGroupSchema (which updateGroupSchema inherits) as a nullable+optional string so the avatar can be both set AND cleared:

export const createGroupSchema = z.object({
  name: z.string().min(1),
  description: z.string().default(""),
  avatarPath: z.string().nullable().optional(),
  characterIds: z.array(z.string()).default([]),
});

This lets avatarPath survive validation in the PATCH handler and reach the existing storage write branch (which writes the nullable column), so the UI shows the stored avatar. .nullable().optional() (vs a plain .string().optional()) is preferred because the column is nullable and the storage guard already passes null through to .set({ avatarPath: null }), so a client can clear a previously-set group avatar back to the placeholder. Regression notes: the only consumers are POST /groups (which destructures only name/description/characterIds, ignoring the extra field harmlessly) and PATCH /groups/:id (which guards every field with !== undefined, so name-only/description-only/characterIds-only updates are unchanged). Adding an optional field is backward-compatible; the unrelated prompt-preset createGroup/updateGroup use a different schema and are untouched.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3049 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** `characterGroups` has an `avatarPath` column and the UI renders a group avatar from it, but a character group's avatar can never actually be set through any reachable path, so it always falls back to the placeholder. The only write path, PATCH /characters/groups/:id, validates the body with `updateGroupSchema.parse(...)`. `updateGroupSchema = createGroupSchema.partial()`, and `createGroupSchema` only defines name/description/characterIds and is not `.passthrough()`, so Zod silently strips `avatarPath` out of the parsed input before it ever reaches storage. The storage layer's `avatarPath` write branch is therefore dead code, and the displayed group-avatar feature is effectively non-functional. **How to reproduce (try it yourself)** 1. PATCH /api/characters/groups/:id with body `{ avatarPath: "/api/avatars/file/x.png" }`. 2. GET /api/characters/groups/:id and open the group avatar in the chat settings group picker. You'll see: `avatarPath` is still null; the value was dropped by `updateGroupSchema.parse` before reaching storage, and the group avatar renders the first-letter placeholder. Expected: the avatar persists and the group picker shows the stored image. **Where it is** - `packages/server/src/routes/characters.routes.ts:1154-1157` — PATCH handler: `const input = updateGroupSchema.parse(req.body); return storage.updateGroup(req.params.id, input);`. - `packages/shared/src/schemas/character.schema.ts:106-112` — `createGroupSchema` (no avatarPath, not passthrough) and `updateGroupSchema = createGroupSchema.partial()`. - `packages/server/src/services/storage/characters.storage.ts:638` — the unreachable `...(updates.avatarPath !== undefined && { avatarPath: updates.avatarPath })` branch. - Column: `packages/server/src/db/schema/characters.ts:96` (`avatarPath: text("avatar_path")`, nullable). - UI render: `packages/client/src/components/chat/ChatSettingsDrawer.tsx:3894-3905`. **What's happening** Zod's default object parsing discards unknown keys, and `updateGroupSchema` inherits `createGroupSchema`, which omits `avatarPath` and isn't passthrough. So `avatarPath` never survives validation to reach `updateGroup`. The storage and DB column support it; only the route contract doesn't. There is no group-avatar upload route either (the backup/marinara importers only touch prompt groups). **Suggested fix** Add `avatarPath` to `createGroupSchema` (which `updateGroupSchema` inherits) as a nullable+optional string so the avatar can be both set AND cleared: ```ts export const createGroupSchema = z.object({ name: z.string().min(1), description: z.string().default(""), avatarPath: z.string().nullable().optional(), characterIds: z.array(z.string()).default([]), }); ``` This lets `avatarPath` survive validation in the PATCH handler and reach the existing storage write branch (which writes the nullable column), so the UI shows the stored avatar. `.nullable().optional()` (vs a plain `.string().optional()`) is preferred because the column is nullable and the storage guard already passes null through to `.set({ avatarPath: null })`, so a client can clear a previously-set group avatar back to the placeholder. Regression notes: the only consumers are POST /groups (which destructures only name/description/characterIds, ignoring the extra field harmlessly) and PATCH /groups/:id (which guards every field with `!== undefined`, so name-only/description-only/characterIds-only updates are unchanged). Adding an optional field is backward-compatible; the unrelated prompt-preset `createGroup`/`updateGroup` use a different schema and are untouched. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Claiming this for the current staging sweep in draft PR #3053 (branch codex/issue-sweep-3033-3052).

<!-- gh-comment-id:4834990664 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Claiming this for the current staging sweep in draft PR #3053 (branch `codex/issue-sweep-3033-3052`).
Author
Owner

@SpicyMarinara commented on GitHub (Jun 29, 2026):

Fixed in PR #3053 on branch codex/issue-sweep-3033-3052 (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.

<!-- gh-comment-id:4835090770 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in PR #3053 on branch `codex/issue-sweep-3033-3052` (commit bfb1bc76). Closing this issue as addressed; the PR remains open for staging review/merge.
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#1618
No description provided.