[GH-ISSUE #3858] [Issue]: Partial character PATCH silently overwrites nested extensions and lorebook data #2085

Closed
opened 2026-10-21 05:45:15 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @Xelvanis on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3858

Originally assigned to: @SpicyMarinara on GitHub.

Summary

A partial PATCH /api/characters/:id can silently erase nested character data. The update schema is only shallow-partial: when extensions or character_book is supplied incompletely, their nested schemas materialize defaults, and the route/storage path persists those generated values as replacements.

Expected behavior

A PATCH request should either:

  • update only the nested fields explicitly supplied and preserve omitted data; or
  • reject incomplete nested objects when those objects are defined as complete replacements.

It should not silently turn omitted fields into defaults and persist them over existing data.

Actual behavior

updateCharacterSchema uses characterDataSchema.partial(), which makes only the immediate data properties optional. The nested schemas retain their defaults.

For example, this request:

{ "data": { "extensions": { "fav": true } } }

is parsed into an extensions object that also contains default talkativeness, world, depth_prompt, backstory, and appearance values. The general character PATCH route passes mergeExtensions: false, so storage replaces the existing extensions object and drops omitted passthrough or third-party fields.

Similarly:

{ "data": { "character_book": { "name": "Renamed" } } }

is accepted and default-filled with entries: [], empty extensions, and default scanning settings. Storage's top-level merge then replaces the existing character book, including its entries.

Steps to reproduce

  1. Create or import a character containing non-default extension fields and an embedded character_book with entries.
  2. Send PATCH /api/characters/:id with { "data": { "extensions": { "fav": true } } }.
  3. Fetch or export the character and observe that omitted extension fields were reset or removed.
  4. As a separate variant, PATCH only character_book.name and observe that omitted book fields, including entries, are replaced by defaults.

Environment

  • Marinara Engine version: 2.3.3 staging
  • Install type: source
  • OS + version: Environment-independent server code path; verified from a Windows source checkout
  • Browser or app shell: Not applicable; direct HTTP contract. Not live-reproduced end-to-end.

Logs, screenshots, or video

A direct schema parse produced:

{"data":{"extensions":{"talkativeness":0.5,"fav":true,"world":"","depth_prompt":{"prompt":"","depth":4,"role":"system"},"backstory":"","appearance":""}}}
{"data":{"character_book":{"name":"Renamed","description":"","scan_depth":2,"token_budget":512,"recursive_scanning":false,"extensions":{},"entries":[]}}}

Relevant code:

  • packages/shared/src/schemas/character.schema.ts: shallow characterDataSchema.partial() plus nested defaults.
  • packages/server/src/routes/characters.routes.ts: the general PATCH route sets mergeExtensions: false.
  • packages/server/src/services/storage/characters.storage.ts: shallow top-level merge and optional extension replacement.

Additional context

The built-in character editor generally sends the complete character, so its normal save path is less exposed. Version snapshots also usually provide recovery, although the route accepts skipVersionSnapshot: true from callers.

This needs an explicit compatibility decision. A true partial-update design requires both a deep-partial update schema and nested merge semantics; changing only the schema is insufficient. If the editor needs full replacement semantics so deleted keys stay deleted, consider a separate explicit replacement operation (for example PUT or a dedicated mode) while keeping PATCH merge-based. The alternative is to require and validate complete nested replacements instead of accepting partial objects.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Xelvanis on GitHub (Jul 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3858 Originally assigned to: @SpicyMarinara on GitHub. ## Summary A partial `PATCH /api/characters/:id` can silently erase nested character data. The update schema is only shallow-partial: when `extensions` or `character_book` is supplied incompletely, their nested schemas materialize defaults, and the route/storage path persists those generated values as replacements. ## Expected behavior A PATCH request should either: - update only the nested fields explicitly supplied and preserve omitted data; or - reject incomplete nested objects when those objects are defined as complete replacements. It should not silently turn omitted fields into defaults and persist them over existing data. ## Actual behavior `updateCharacterSchema` uses `characterDataSchema.partial()`, which makes only the immediate `data` properties optional. The nested schemas retain their defaults. For example, this request: ```json { "data": { "extensions": { "fav": true } } } ``` is parsed into an `extensions` object that also contains default `talkativeness`, `world`, `depth_prompt`, `backstory`, and `appearance` values. The general character PATCH route passes `mergeExtensions: false`, so storage replaces the existing extensions object and drops omitted passthrough or third-party fields. Similarly: ```json { "data": { "character_book": { "name": "Renamed" } } } ``` is accepted and default-filled with `entries: []`, empty extensions, and default scanning settings. Storage's top-level merge then replaces the existing character book, including its entries. ## Steps to reproduce 1. Create or import a character containing non-default extension fields and an embedded `character_book` with entries. 2. Send `PATCH /api/characters/:id` with `{ "data": { "extensions": { "fav": true } } }`. 3. Fetch or export the character and observe that omitted extension fields were reset or removed. 4. As a separate variant, PATCH only `character_book.name` and observe that omitted book fields, including `entries`, are replaced by defaults. ## Environment - Marinara Engine version: 2.3.3 staging - Install type: source - OS + version: Environment-independent server code path; verified from a Windows source checkout - Browser or app shell: Not applicable; direct HTTP contract. Not live-reproduced end-to-end. ## Logs, screenshots, or video A direct schema parse produced: ```json {"data":{"extensions":{"talkativeness":0.5,"fav":true,"world":"","depth_prompt":{"prompt":"","depth":4,"role":"system"},"backstory":"","appearance":""}}} {"data":{"character_book":{"name":"Renamed","description":"","scan_depth":2,"token_budget":512,"recursive_scanning":false,"extensions":{},"entries":[]}}} ``` Relevant code: - `packages/shared/src/schemas/character.schema.ts`: shallow `characterDataSchema.partial()` plus nested defaults. - `packages/server/src/routes/characters.routes.ts`: the general PATCH route sets `mergeExtensions: false`. - `packages/server/src/services/storage/characters.storage.ts`: shallow top-level merge and optional extension replacement. ## Additional context The built-in character editor generally sends the complete character, so its normal save path is less exposed. Version snapshots also usually provide recovery, although the route accepts `skipVersionSnapshot: true` from callers. This needs an explicit compatibility decision. A true partial-update design requires both a deep-partial update schema and nested merge semantics; changing only the schema is insufficient. If the editor needs full replacement semantics so deleted keys stay deleted, consider a separate explicit replacement operation (for example PUT or a dedicated mode) while keeping PATCH merge-based. The alternative is to require and validate complete nested replacements instead of accepting partial objects. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:45:15 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 20, 2026):

SpicyMarinara is taking this issue in the current assigned-issue sweep. I’m tracing the reported boundary, adding focused regression coverage, and will link the draft PR here as soon as the proof commit is pushed.

<!-- gh-comment-id:5022367869 --> @SpicyMarinara commented on GitHub (Jul 20, 2026): SpicyMarinara is taking this issue in the current assigned-issue sweep. I’m tracing the reported boundary, adding focused regression coverage, and will link the draft PR here as soon as the proof commit is pushed.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 20, 2026):

Implementation is now tracked in draft PR #3862 against staging.

<!-- gh-comment-id:5022407950 --> @SpicyMarinara commented on GitHub (Jul 20, 2026): Implementation is now tracked in draft PR #3862 against `staging`.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 20, 2026):

Addressed in #3862 and merged to staging as ca6d0c15be.

<!-- gh-comment-id:5022914483 --> @SpicyMarinara commented on GitHub (Jul 20, 2026): Addressed in #3862 and merged to staging as ca6d0c15bee712686203483621028050ed0239a9.
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#2085
No description provided.