[GH-ISSUE #2661] [Issue]: Assigning a preset races two endpoints → active preset can revert / next generation uses stale preset #1312

Closed
opened 2026-10-21 05:31:23 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Assigning a preset to a chat fires two endpoints concurrently with no sequencing; under latency the chat-metadata response can overwrite the chat detail cache with the stale promptPresetId, so the active-preset indicator reverts and the next generation may resolve the old preset.

Expected behavior

After selecting a preset for a chat, the chat's promptPresetId should reliably reflect the new preset in cache and for the next generation.

Actual behavior

selectPreset() calls updateMetadata.mutate({ id, presetChoices: {} }) and updateChat.mutate({ id, promptPresetId: newId }) back-to-back against two endpoints with no ordering. The metadata mutation's onSuccess writes the full chat row (which may still carry the old promptPresetId) into the detail cache via setQueryData. If the metadata response lands after the chat response, it clobbers the new promptPresetId.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • packages/client/src/components/panels/PresetsPanel.tsx:341–363 — the two mutations fire unordered against PATCH /chats/:id/metadata and PATCH /chats/:id.
  • useUpdateChatMetadata.onSuccess (packages/client/src/hooks/use-chats.ts) does qc.setQueryData(chatKeys.detail(id), data) with the full chat row returned by the metadata PATCH, whose getById read can still hold the old promptPresetId (the metadata write is unordered relative to the chat write).
  • ChatArea syncs useChat(activeChatId) into the Zustand store, so the stale value re-emits into the active-preset indicator (read ~PresetsPanel:289), and a generation started before refetch can resolve the stale preset.

Steps to reproduce

  1. Open a chat with preset A active.
  2. In the Presets panel, click "Use" on preset B.
  3. Under latency where the /metadata response lands slightly after /chats/:id, observe the active-preset checkmark snap back to A (or persist as A until a manual chat switch/refetch).

Suggested fix

Sequence the two mutations (only clear presetChoices after the promptPresetId change succeeds, or vice-versa), or have useUpdateChatMetadata.onSuccess merge only metadata fields into the cache rather than overwriting the whole chat row with setQueryData(detail, data).

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Identified via systematic source review on staging (refs @ b826f8f4). Directly affects which preset governs the next generation, so it can manifest as "I switched presets but the model still behaves like the old one." Filed alongside related pipeline issues.

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 @kolacheee on GitHub (Jun 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2661 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Assigning a preset to a chat fires two endpoints concurrently with no sequencing; under latency the chat-metadata response can overwrite the chat detail cache with the stale `promptPresetId`, so the active-preset indicator reverts and the next generation may resolve the old preset. ## Expected behavior After selecting a preset for a chat, the chat's `promptPresetId` should reliably reflect the new preset in cache and for the next generation. ## Actual behavior `selectPreset()` calls `updateMetadata.mutate({ id, presetChoices: {} })` and `updateChat.mutate({ id, promptPresetId: newId })` back-to-back against two endpoints with no ordering. The metadata mutation's `onSuccess` writes the full chat row (which may still carry the old `promptPresetId`) into the detail cache via `setQueryData`. If the metadata response lands after the chat response, it clobbers the new `promptPresetId`. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - `packages/client/src/components/panels/PresetsPanel.tsx:341–363` — the two mutations fire unordered against `PATCH /chats/:id/metadata` and `PATCH /chats/:id`. - `useUpdateChatMetadata.onSuccess` (`packages/client/src/hooks/use-chats.ts`) does `qc.setQueryData(chatKeys.detail(id), data)` with the full chat row returned by the metadata PATCH, whose `getById` read can still hold the old `promptPresetId` (the metadata write is unordered relative to the chat write). - `ChatArea` syncs `useChat(activeChatId)` into the Zustand store, so the stale value re-emits into the active-preset indicator (read ~`PresetsPanel:289`), and a generation started before refetch can resolve the stale preset. ## Steps to reproduce 1. Open a chat with preset A active. 2. In the Presets panel, click "Use" on preset B. 3. Under latency where the `/metadata` response lands slightly after `/chats/:id`, observe the active-preset checkmark snap back to A (or persist as A until a manual chat switch/refetch). ## Suggested fix Sequence the two mutations (only clear `presetChoices` after the `promptPresetId` change succeeds, or vice-versa), **or** have `useUpdateChatMetadata.onSuccess` merge only metadata fields into the cache rather than overwriting the whole chat row with `setQueryData(detail, data)`. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Identified via systematic source review on staging (refs @ `b826f8f4`). Directly affects which preset governs the next generation, so it can manifest as "I switched presets but the model still behaves like the old one." Filed alongside related pipeline issues. ## 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.
Author
Owner

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

Implemented on branch codex/spicymarinara-assigned-issues: metadata mutations now merge metadata into the cached chat detail instead of overwriting newer non-metadata fields like promptPresetId. Final validation will run after the full assigned sweep per maintainer request.

<!-- gh-comment-id:4760051969 --> @SpicyMarinara commented on GitHub (Jun 20, 2026): Implemented on branch codex/spicymarinara-assigned-issues: metadata mutations now merge metadata into the cached chat detail instead of overwriting newer non-metadata fields like promptPresetId. Final validation will run after the full assigned sweep per maintainer request.
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#1312
No description provided.