[PR #1590] [MERGED] [codex] Optimize character summary avatar loading #5130

Closed
opened 2026-10-22 04:13:34 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1590
Author: @Xelvanis
Created: 5/29/2026
Status: ✅ Merged
Merged: 5/29/2026
Merged by: @Xelvanis

Base: refactor ← Head: codex/character-collection-performance


📝 Commits (4)

  • a36acfe Optimize character summary avatar loading
  • 135ddaf Fix summary fanout and lorebook filters
  • 96fc2a7 Fix character summary hook stability
  • b720ca4 Harden managed asset URL segments

📊 Changes

15 files changed (+336 additions, -89 deletions)

View changed files

📝 src-tauri/src/http_server.rs (+29 -1)
📝 src/app/shell/ChatSidebar.tsx (+35 -10)
📝 src/features/catalog/characters/components/CharacterAvatarImage.tsx (+11 -3)
📝 src/features/catalog/characters/hooks/use-characters.ts (+35 -15)
📝 src/features/catalog/characters/index.ts (+1 -0)
➕ src/features/catalog/characters/lib/character-avatar-url.ts (+12 -0)
📝 src/features/catalog/lorebooks/components/LorebookEditor.tsx (+30 -15)
📝 src/features/catalog/lorebooks/components/LorebooksPanel.tsx (+17 -3)
📝 src/features/modes/game/components/GameSetupWizard.tsx (+10 -9)
📝 src/features/modes/router/components/RecentChats.tsx (+11 -11)
📝 src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx (+11 -1)
📝 src/features/modes/shared/chat-ui/components/ChatSetupWizard.tsx (+23 -9)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts (+21 -8)
➕ src/shared/api/local-file-api.test.ts (+67 -0)
📝 src/shared/api/local-file-api.ts (+23 -4)

📄 Description

Linked issue

Closes #1582

Refs #1584, #1583, #1585

Why this change

Character summary consumers were still paying for embedded avatar payloads or broad character reads in places that only needed names, tags, metadata, and avatar file handles. That made startup/sidebar/lorebook surfaces expensive for large character libraries and kept remote-hosted avatar display tied to local absolute paths or inline data.

What changed

  • Trimmed character summary reads to id, display metadata, comment, avatarFilePath, and avatarFilename instead of embedded avatarPath data.
  • Added a shared character avatar URL helper and updated chat/sidebar/setup/lorebook consumers to resolve avatars from managed file metadata.
  • Changed ID-scoped summary reads to reuse the projected summary list cache instead of fanning out full storage_get reads per character.
  • Added a hostable /api/assets/avatar/... managed avatar route with filename sanitization.
  • Fixed lorebook entry character/tag filters so the Entries tab still has all projected character filter choices, while the linked-character picker loads lazily with a loading state.
  • Added focused tests for avatar URL resolution and the Rust avatar filename guard.

Refactor impact

Primary owner:

catalog characters, catalog lorebooks, app shell, shared mode UI, shared API, remote runtime/Rust storage asset serving

Impact areas reviewed:

  • Character summary hooks and React Query cache keys
  • Chat sidebar character lookup/search/unread avatar display
  • Recent chats, chat setup/settings, game setup, and chat surface character avatar display
  • Lorebook panel/editor linked character names and entry-level character/tag filters
  • Hostable runtime managed avatar asset route and local/remote avatar URL resolution

Boundary notes:

  • Feature/UI code continues to call shared API helpers instead of raw Tauri commands.
  • Engine code was not given UI/runtime dependencies.
  • Rust change is limited to the hostable managed asset route for avatar files.
  • Remote avatar URLs use managed filenames rather than exposing absolute paths.

Pressure points touched:

  • src/app/shell/ChatSidebar.tsx
  • src/features/modes/shared/chat-ui/*
  • src/features/catalog/lorebooks/*
  • src-tauri/src/http_server.rs

Validation

  • pnpm check passes locally
  • pnpm typecheck passes locally
  • pnpm build passes locally
  • pnpm check:architecture passes locally
  • pnpm check:docs passes locally
  • cargo check --manifest-path src-tauri/Cargo.toml --workspace passes locally
  • Rust clippy/tests were run for Rust behavior changes
  • Browser or Tauri app manual verification completed
  • Playwright, screenshot, or recording evidence added for UI changes
  • Remote runtime smoke checked when relevant

Manual verification notes

Automated/local checks run by Codex:

  • pnpm exec vitest run src/shared/api/local-file-api.test.ts src/features/catalog/characters/hooks/use-characters.test.ts passed
  • cargo test --manifest-path src-tauri/Cargo.toml avatar_asset_filename_rejects_parent_directory_tokens passed
  • pnpm typecheck passed
  • pnpm check:architecture passed
  • pnpm check:rust passed before the final Bunny follow-up fix
  • git diff --check origin/refactor...HEAD passed

Manual app verification not run in this pass. Remote runtime route has unit coverage for filename guarding but no end-to-end browser smoke.

Docs and release impact

  • No docs changes needed
  • Updated README.md
  • Updated CONTRIBUTING.md
  • Updated docs/developer/
  • Updated repo skills or AGENTS.md
  • Confirmed this PR does not restore old staging/package-workspace/release claims

No changelog file was found at the repo root; no docs changes were made because this is an internal performance/runtime-path fix with unchanged user-facing workflow.

UI evidence

No screenshots or recordings attached; UI behavior changes are data-loading/avatar-path changes rather than a visual redesign.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added loading indicator to character picker when fetching character data
  • Improvements

    • Enhanced avatar file management and resolution system for improved reliability
    • Optimized character summary data fetching for better performance when loading character information

Review Change Stack


🔄 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/1590 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/29/2026 **Status:** ✅ Merged **Merged:** 5/29/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `codex/character-collection-performance` --- ### 📝 Commits (4) - [`a36acfe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a36acfe48f17621b3e7ca5d43c075bbf0ea7b172) Optimize character summary avatar loading - [`135ddaf`](https://github.com/Pasta-Devs/Marinara-Engine/commit/135ddafa4a2ad3a157eb0bc7cae9d6123d1029b8) Fix summary fanout and lorebook filters - [`96fc2a7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96fc2a7314f3343bc5aa6866d08880b49d9f1eb6) Fix character summary hook stability - [`b720ca4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b720ca4c4842537a8e77a02d2aeb779b0350382c) Harden managed asset URL segments ### 📊 Changes **15 files changed** (+336 additions, -89 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/http_server.rs` (+29 -1) 📝 `src/app/shell/ChatSidebar.tsx` (+35 -10) 📝 `src/features/catalog/characters/components/CharacterAvatarImage.tsx` (+11 -3) 📝 `src/features/catalog/characters/hooks/use-characters.ts` (+35 -15) 📝 `src/features/catalog/characters/index.ts` (+1 -0) ➕ `src/features/catalog/characters/lib/character-avatar-url.ts` (+12 -0) 📝 `src/features/catalog/lorebooks/components/LorebookEditor.tsx` (+30 -15) 📝 `src/features/catalog/lorebooks/components/LorebooksPanel.tsx` (+17 -3) 📝 `src/features/modes/game/components/GameSetupWizard.tsx` (+10 -9) 📝 `src/features/modes/router/components/RecentChats.tsx` (+11 -11) 📝 `src/features/modes/shared/chat-ui/components/ChatSettingsDrawer.tsx` (+11 -1) 📝 `src/features/modes/shared/chat-ui/components/ChatSetupWizard.tsx` (+23 -9) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts` (+21 -8) ➕ `src/shared/api/local-file-api.test.ts` (+67 -0) 📝 `src/shared/api/local-file-api.ts` (+23 -4) </details> ### 📄 Description ## Linked issue Closes #1582 Refs #1584, #1583, #1585 ## Why this change Character summary consumers were still paying for embedded avatar payloads or broad character reads in places that only needed names, tags, metadata, and avatar file handles. That made startup/sidebar/lorebook surfaces expensive for large character libraries and kept remote-hosted avatar display tied to local absolute paths or inline data. ## What changed - Trimmed character summary reads to `id`, display metadata, comment, `avatarFilePath`, and `avatarFilename` instead of embedded `avatarPath` data. - Added a shared character avatar URL helper and updated chat/sidebar/setup/lorebook consumers to resolve avatars from managed file metadata. - Changed ID-scoped summary reads to reuse the projected summary list cache instead of fanning out full `storage_get` reads per character. - Added a hostable `/api/assets/avatar/...` managed avatar route with filename sanitization. - Fixed lorebook entry character/tag filters so the Entries tab still has all projected character filter choices, while the linked-character picker loads lazily with a loading state. - Added focused tests for avatar URL resolution and the Rust avatar filename guard. ## Refactor impact Primary owner: catalog characters, catalog lorebooks, app shell, shared mode UI, shared API, remote runtime/Rust storage asset serving Impact areas reviewed: - Character summary hooks and React Query cache keys - Chat sidebar character lookup/search/unread avatar display - Recent chats, chat setup/settings, game setup, and chat surface character avatar display - Lorebook panel/editor linked character names and entry-level character/tag filters - Hostable runtime managed avatar asset route and local/remote avatar URL resolution Boundary notes: - Feature/UI code continues to call shared API helpers instead of raw Tauri commands. - Engine code was not given UI/runtime dependencies. - Rust change is limited to the hostable managed asset route for avatar files. - Remote avatar URLs use managed filenames rather than exposing absolute paths. Pressure points touched: - `src/app/shell/ChatSidebar.tsx` - `src/features/modes/shared/chat-ui/*` - `src/features/catalog/lorebooks/*` - `src-tauri/src/http_server.rs` ## Validation - [x] `pnpm check` passes locally - [x] `pnpm typecheck` passes locally - [x] `pnpm build` passes locally - [x] `pnpm check:architecture` passes locally - [x] `pnpm check:docs` passes locally - [x] `cargo check --manifest-path src-tauri/Cargo.toml --workspace` passes locally - [ ] Rust clippy/tests were run for Rust behavior changes - [ ] Browser or Tauri app manual verification completed - [ ] Playwright, screenshot, or recording evidence added for UI changes - [ ] Remote runtime smoke checked when relevant ### Manual verification notes Automated/local checks run by Codex: - `pnpm exec vitest run src/shared/api/local-file-api.test.ts src/features/catalog/characters/hooks/use-characters.test.ts` passed - `cargo test --manifest-path src-tauri/Cargo.toml avatar_asset_filename_rejects_parent_directory_tokens` passed - `pnpm typecheck` passed - `pnpm check:architecture` passed - `pnpm check:rust` passed before the final Bunny follow-up fix - `git diff --check origin/refactor...HEAD` passed Manual app verification not run in this pass. Remote runtime route has unit coverage for filename guarding but no end-to-end browser smoke. ## Docs and release impact - [x] No docs changes needed - [ ] Updated `README.md` - [ ] Updated `CONTRIBUTING.md` - [ ] Updated `docs/developer/` - [ ] Updated repo skills or `AGENTS.md` - [x] Confirmed this PR does not restore old staging/package-workspace/release claims No changelog file was found at the repo root; no docs changes were made because this is an internal performance/runtime-path fix with unchanged user-facing workflow. ## UI evidence No screenshots or recordings attached; UI behavior changes are data-loading/avatar-path changes rather than a visual redesign. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit # Release Notes * **New Features** * Added loading indicator to character picker when fetching character data * **Improvements** * Enhanced avatar file management and resolution system for improved reliability * Optimized character summary data fetching for better performance when loading character information <!-- review_stack_entry_start --> [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/1590?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- 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-22 04:13:34 +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#5130
No description provided.