[PR #4901] [MERGED] fix: make Persona client writes race-safe #6534

Closed
opened 2026-10-23 04:11:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4901
Author: @Xelvanis
Created: 8/11/2026
Status: ✅ Merged
Merged: 8/11/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/persona-decoded-client-writes-pruned


📝 Commits (3)

  • 2dbc427 fix: make persona client writes race-safe
  • 2fcf42d fix: address Persona review feedback
  • a6450b3 Merge origin/staging into fix/persona-decoded-client-writes-pruned

📊 Changes

17 files changed (+1333 additions, -369 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 package.json (+3 -1)
➕ packages/client/.regression-fixtures/persona-mutation-types.ts (+37 -0)
📝 packages/client/src/components/bot-browser/BotBrowserView.tsx (+1 -1)
📝 packages/client/src/components/characters/CharacterEditor.tsx (+5 -7)
📝 packages/client/src/components/modals/ImportPersonaModal.tsx (+8 -45)
📝 packages/client/src/components/panels/PersonasPanel.tsx (+1 -1)
📝 packages/client/src/components/panels/settings/TrackerCardColorSettings.tsx (+4 -4)
📝 packages/client/src/components/personas/PersonaEditor.tsx (+588 -203)
➕ packages/client/src/components/personas/persona-editor-transitions.ts (+104 -0)
📝 packages/client/src/features/tracker-panel/hooks/use-persona-portrait-save.ts (+2 -2)
📝 packages/client/src/hooks/use-characters.ts (+90 -104)
📝 packages/client/src/lib/api-client.ts (+17 -0)
➕ packages/client/src/lib/persona-cache.ts (+50 -0)
📝 packages/client/src/localization/locales/en.json (+2 -0)
📝 scripts/regressions/avatar-crop-contract.regression.ts (+27 -1)
➕ scripts/regressions/persona-client-contract.regression.ts (+393 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Follow-up to #4646. That issue is already closed and cannot be reopened; PR #4857 completed its strict server/import/export boundary and explicitly left the built-in client write migration as a separate follow-up. This PR completes that client phase.

Why this change

Persona fields such as tags, stats, tracker configuration, conversation behavior, and avatar crops are structured values at the API boundary. First-party client callers still serialized some of them manually, and the editor treated saves as whole-form operations whose responses could race later edits or older reads.

Persona writes should use the shared decoded contract end to end. Successful server responses should become authoritative without allowing an older GET to overwrite them, and saving must not erase edits made while a request is still running or let incompatible avatar/Delete operations overlap.

What changed

  • Migrated first-party Persona create/update/import/conversion/tag/tracker callers to decoded shared request contracts.
  • Split generic Persona updates from tracker-card paint/portrait updates so each endpoint owns its payload and version policy.
  • Added one production cache reconciler that orders exact list/detail/active reads before seeding authoritative mutation responses, recovers unknown active identity from the server, and composes concurrent complete-list updates.
  • Made editor saves sparse against an authoritative baseline, preserving later same-field edits and reverts while adopting canonical server output.
  • Added one immediate editor operation mutex for save, avatar upload, gallery-avatar assignment, and Delete; retained text editing during saves.
  • Bound avatar crops to the image they frame, restored preview/crop state after failed replacement, and prevented stale editor sessions from mutating replacement state.
  • Kept local Back/Discard safe around dirty or in-flight writes and bound Delete confirmation to the initiating Persona id/session. External navigation intentionally remains current-base behavior.
  • Added exact empty-name and server field-path validation feedback.
  • Added focused production-backed Persona cache/editor/type regressions and wired the build-once client lane into regression:issues immediately after card-library search.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Automated and focused checks completed

On the rebased commit whose parent is freshly fetched origin/staging:

  • pnpm install --frozen-lockfile
  • pnpm regression:persona-client
  • pnpm regression:avatar-crop-contract
  • pnpm check
  • git diff --check origin/staging...HEAD
  • full client/server/shared lint and production builds through pnpm check
  • final Bunny review, Code Judo, ordinary simplification audit, cold finding triage, and independent originating-reviewer closure with no open finding
  • independent post-rebase integration reviews on both prepared bases: clean, with no actionable finding; the final 94445688... review confirmed all 16 non-changelog path patches stable and independently passed the focused Persona regression
  • final source-text simplification reduced the Persona regression from 373 to 353 lines; a retained decoded-import sentry failed under deliberate negative mutation, full readiness passed again, and the originating auditor closed the exact deletion with no finding

The final branch was rebased onto freshly fetched origin/staging at 94445688fed98b922a3d0ac9e6bc66aa83320718. The final rebase conflicted only in CHANGELOG.md; current staging's Feature-agent and Guide entries plus the Persona entry were preserved exactly once. Earlier package-script integration remained intact.

Manual verification notes

An isolated headed local-browser session covered the final reviewed production source immediately before the rebase. The rebase changed only changelog/script integration, and the later amendment removed only approved regression source-ledger assertions; no production behavior changed. Full post-amend validation above passed.

  1. Created Personas, changed multiple decoded fields, saved, closed/reopened, and confirmed authoritative persistence.
  2. Verified edit-then-revert returns to a clean disabled Save, then saved a later same-field value and reopened it successfully.
  3. Verified local Back warns, Keep Editing preserves the exact draft, and Discard & Close does not persist the draft or leave ghost dirty state.
  4. Verified whitespace-only names stay local and show exactly Persona name cannot be empty. Enter a name before saving.
  5. Simulated another client activating Persona B through the isolated public loopback API, then saved inactive A and confirmed the UI recovered active B rather than null or stale A.
  6. Verified Newest/search paginated Persona results refresh after an authoritative mutation.
  7. Seeded a synthetic gallery image through the isolated public API and assigned it as avatar through the UI; preview updated successfully.
  8. Exercised Delete cancel and local warning actions at desktop and 390×844. The browser reported zero console errors/warnings and no failed non-static local requests.
  9. Removed all synthetic Personas/gallery data and the exact wrapper-owned runtime.

Request-delay/edit-during-save, busy Back/Delete, stale-GET, and Delete-confirmation A→B timing remain permanent regression/source proof because the approved browser boundary forbids interception, eval, and storage manipulation. Gallery assignment preview passed, but a separate close/reopen crop-replacement observation was not completed.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG.md contains the user-facing entry. No docs/, translated documentation, installation/update guidance, or version-bearing files changed.

UI evidence (if applicable)

This changes editor behavior rather than visual styling. The isolated proof exercised desktop and mobile warning controls; screenshots were intentionally kept only inside the disposable owned browser runtime and removed with that runtime. No image asset is committed.

Summary by CodeRabbit

  • New Features

    • Persona saves support partial updates while preserving concurrent edits.
    • Avatar uploads, gallery assignments, deletions, and navigation are coordinated safely.
    • Persona imports and tracker-card settings support structured fields directly.
    • Validation errors identify affected fields, including missing persona names.
    • Persona lists and details stay synchronized after changes.
  • Bug Fixes

    • Prevented duplicate or stale persona data after updates.
    • Disabled relevant editing and discard controls during writes.
    • Improved avatar crop failure recovery and save reliability.
  • Tests

    • Added regression coverage for editing, imports, caching, validation, and avatar workflows.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/4901 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 8/11/2026 **Status:** ✅ Merged **Merged:** 8/11/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/persona-decoded-client-writes-pruned` --- ### 📝 Commits (3) - [`2dbc427`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2dbc427843d46088f93c472a042b381c50a36e49) fix: make persona client writes race-safe - [`2fcf42d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2fcf42d82ef61d735d48d3b99461de0188d9416e) fix: address Persona review feedback - [`a6450b3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a6450b36e7307faef818b4d759a572df42d5697d) Merge origin/staging into fix/persona-decoded-client-writes-pruned ### 📊 Changes **17 files changed** (+1333 additions, -369 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `package.json` (+3 -1) ➕ `packages/client/.regression-fixtures/persona-mutation-types.ts` (+37 -0) 📝 `packages/client/src/components/bot-browser/BotBrowserView.tsx` (+1 -1) 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+5 -7) 📝 `packages/client/src/components/modals/ImportPersonaModal.tsx` (+8 -45) 📝 `packages/client/src/components/panels/PersonasPanel.tsx` (+1 -1) 📝 `packages/client/src/components/panels/settings/TrackerCardColorSettings.tsx` (+4 -4) 📝 `packages/client/src/components/personas/PersonaEditor.tsx` (+588 -203) ➕ `packages/client/src/components/personas/persona-editor-transitions.ts` (+104 -0) 📝 `packages/client/src/features/tracker-panel/hooks/use-persona-portrait-save.ts` (+2 -2) 📝 `packages/client/src/hooks/use-characters.ts` (+90 -104) 📝 `packages/client/src/lib/api-client.ts` (+17 -0) ➕ `packages/client/src/lib/persona-cache.ts` (+50 -0) 📝 `packages/client/src/localization/locales/en.json` (+2 -0) 📝 `scripts/regressions/avatar-crop-contract.regression.ts` (+27 -1) ➕ `scripts/regressions/persona-client-contract.regression.ts` (+393 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. > <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Follow-up to #4646. That issue is already closed and cannot be reopened; PR #4857 completed its strict server/import/export boundary and explicitly left the built-in client write migration as a separate follow-up. This PR completes that client phase. ## Why this change Persona fields such as tags, stats, tracker configuration, conversation behavior, and avatar crops are structured values at the API boundary. First-party client callers still serialized some of them manually, and the editor treated saves as whole-form operations whose responses could race later edits or older reads. Persona writes should use the shared decoded contract end to end. Successful server responses should become authoritative without allowing an older GET to overwrite them, and saving must not erase edits made while a request is still running or let incompatible avatar/Delete operations overlap. ## What changed - Migrated first-party Persona create/update/import/conversion/tag/tracker callers to decoded shared request contracts. - Split generic Persona updates from tracker-card paint/portrait updates so each endpoint owns its payload and version policy. - Added one production cache reconciler that orders exact list/detail/active reads before seeding authoritative mutation responses, recovers unknown active identity from the server, and composes concurrent complete-list updates. - Made editor saves sparse against an authoritative baseline, preserving later same-field edits and reverts while adopting canonical server output. - Added one immediate editor operation mutex for save, avatar upload, gallery-avatar assignment, and Delete; retained text editing during saves. - Bound avatar crops to the image they frame, restored preview/crop state after failed replacement, and prevented stale editor sessions from mutating replacement state. - Kept local Back/Discard safe around dirty or in-flight writes and bound Delete confirmation to the initiating Persona id/session. External navigation intentionally remains current-base behavior. - Added exact empty-name and server field-path validation feedback. - Added focused production-backed Persona cache/editor/type regressions and wired the build-once client lane into `regression:issues` immediately after card-library search. ## Validation <!-- Checkboxes intentionally remain for the human submitter to confirm. --> - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Automated and focused checks completed On the rebased commit whose parent is freshly fetched `origin/staging`: - `pnpm install --frozen-lockfile` - `pnpm regression:persona-client` - `pnpm regression:avatar-crop-contract` - `pnpm check` - `git diff --check origin/staging...HEAD` - full client/server/shared lint and production builds through `pnpm check` - final Bunny review, Code Judo, ordinary simplification audit, cold finding triage, and independent originating-reviewer closure with no open finding - independent post-rebase integration reviews on both prepared bases: clean, with no actionable finding; the final `94445688...` review confirmed all 16 non-changelog path patches stable and independently passed the focused Persona regression - final source-text simplification reduced the Persona regression from 373 to 353 lines; a retained decoded-import sentry failed under deliberate negative mutation, full readiness passed again, and the originating auditor closed the exact deletion with no finding The final branch was rebased onto freshly fetched `origin/staging` at `94445688fed98b922a3d0ac9e6bc66aa83320718`. The final rebase conflicted only in `CHANGELOG.md`; current staging's Feature-agent and Guide entries plus the Persona entry were preserved exactly once. Earlier package-script integration remained intact. ### Manual verification notes An isolated headed local-browser session covered the final reviewed production source immediately before the rebase. The rebase changed only changelog/script integration, and the later amendment removed only approved regression source-ledger assertions; no production behavior changed. Full post-amend validation above passed. 1. Created Personas, changed multiple decoded fields, saved, closed/reopened, and confirmed authoritative persistence. 2. Verified edit-then-revert returns to a clean disabled Save, then saved a later same-field value and reopened it successfully. 3. Verified local Back warns, Keep Editing preserves the exact draft, and Discard & Close does not persist the draft or leave ghost dirty state. 4. Verified whitespace-only names stay local and show exactly `Persona name cannot be empty. Enter a name before saving.` 5. Simulated another client activating Persona B through the isolated public loopback API, then saved inactive A and confirmed the UI recovered active B rather than null or stale A. 6. Verified Newest/search paginated Persona results refresh after an authoritative mutation. 7. Seeded a synthetic gallery image through the isolated public API and assigned it as avatar through the UI; preview updated successfully. 8. Exercised Delete cancel and local warning actions at desktop and 390×844. The browser reported zero console errors/warnings and no failed non-static local requests. 9. Removed all synthetic Personas/gallery data and the exact wrapper-owned runtime. Request-delay/edit-during-save, busy Back/Delete, stale-GET, and Delete-confirmation A→B timing remain permanent regression/source proof because the approved browser boundary forbids interception, eval, and storage manipulation. Gallery assignment preview passed, but a separate close/reopen crop-replacement observation was not completed. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `CHANGELOG.md` contains the user-facing entry. No `docs/`, translated documentation, installation/update guidance, or version-bearing files changed. ## UI evidence (if applicable) This changes editor behavior rather than visual styling. The isolated proof exercised desktop and mobile warning controls; screenshots were intentionally kept only inside the disposable owned browser runtime and removed with that runtime. No image asset is committed. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Persona saves support partial updates while preserving concurrent edits. - Avatar uploads, gallery assignments, deletions, and navigation are coordinated safely. - Persona imports and tracker-card settings support structured fields directly. - Validation errors identify affected fields, including missing persona names. - Persona lists and details stay synchronized after changes. - **Bug Fixes** - Prevented duplicate or stale persona data after updates. - Disabled relevant editing and discard controls during writes. - Improved avatar crop failure recovery and save reliability. - **Tests** - Added regression coverage for editing, imports, caching, validation, and avatar workflows. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:11:20 +07:00
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#6534
No description provided.