[PR #6256] [MERGED] Fix full-card token estimates in character catalog and panel #7107

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6256
Author: @minikkeuen
Created: 9/16/2026
Status: ✅ Merged
Merged: 9/16/2026
Merged by: @undefined

Base: staging ← Head: pr/character-library-token-estimates


📝 Commits (7)

  • 3073602 fix(character-library): restore full-card token estimates
  • 45adf70 fix(character-library): use catalog token estimates in panel
  • 0cde2f9 chore: format character token count import
  • 2da1a13 Merge remote-tracking branch 'origin/staging' into review/6256-token-estimates
  • 364ad49 docs: record full-card token estimate fix
  • 466bf24 Merge remote-tracking branch 'origin/staging' into review/6256-token-estimates
  • c73f75f test: prove each full-card token source is included

📊 Changes

8 files changed (+195 additions, -111 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/client/src/components/characters/CharacterLibraryView.tsx (+5 -2)
📝 packages/client/src/components/panels/CharactersPanel.tsx (+3 -3)
📝 packages/client/src/lib/character-token-count.ts (+2 -88)
📝 packages/server/src/services/storage/character-catalog.ts (+2 -18)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/utils/character-token-estimator.ts (+83 -0)
➕ scripts/regressions/character-library-token-estimate.regression.ts (+97 -0)

📄 Description

Linked issue

Closes #6255

Why this change

  • Character token estimates can be undercounted when they are calculated from the compact catalog representation instead of the full character card.
  • Some fields used by the character card token estimator are intentionally omitted from the compact catalog data, so recalculating from those fields can produce substantially lower values.
  • The Character Library and Characters panel should use a consistent estimate based on the full card without requiring full card JSON in catalog responses.

What changed

  • Moved the full character card token estimation helper to the shared package.
  • Calculate tokenEstimate from the full stored character data when building the server character catalog.
  • Use the catalog-provided estimate in the Character Library.
  • Use the catalog-provided estimate for both regular and folder character rows in the Characters panel instead of recalculating from compact parsed data.
  • Added regression coverage for full-card estimation and catalog/UI token estimate usage.

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

Manual verification notes

  • Ran Marinara from the updated source build and checked character token estimates in the UI.
  • Verified a reproduced character whose compact-data estimate was approximately 1,088 tokens.
  • Verified that the catalog API returned the full-card estimate of 1,769 tokens.
  • Confirmed that the Characters panel displays the catalog-provided 1,769-token estimate after the fix.
  • Confirmed that an embedded character book is included when it is present in the full character card data.

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)

UI evidence (if applicable)

Before: the Characters panel displayed approximately 1,088 tokens based on compact catalog fields.
스크린샷 2026-09-16 20 44 23

After: the same character displays approximately 1,769 tokens using the full-card estimate provided by the catalog.
스크린샷 2026-09-16 20 42 27

Summary by CodeRabbit

  • Bug Fixes

    • Character token estimates now account for complete card content, including example messages, alternate greetings, instructions, extensions, prompts, and character-book details.
    • Token estimates are now consistent across the Character Library and Characters panels.
    • Character views use stored estimates when available, reducing unnecessary recalculation and improving responsiveness.
  • Tests

    • Added regression coverage to verify accurate token estimates for full character cards and consistent results across character browsing experiences.

🔄 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/6256 **Author:** [@minikkeuen](https://github.com/minikkeuen) **Created:** 9/16/2026 **Status:** ✅ Merged **Merged:** 9/16/2026 **Merged by:** [@undefined](undefined) **Base:** `staging` ← **Head:** `pr/character-library-token-estimates` --- ### 📝 Commits (7) - [`3073602`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3073602558f815a001d859b86db47078844b28cc) fix(character-library): restore full-card token estimates - [`45adf70`](https://github.com/Pasta-Devs/Marinara-Engine/commit/45adf7033b02791542a238ebb5c7fe4e60d27d4f) fix(character-library): use catalog token estimates in panel - [`0cde2f9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0cde2f98af991d53e720d2a33ab0223d8cc3f749) chore: format character token count import - [`2da1a13`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2da1a139b041f268bc67ffec304f62ba7c1fb5a8) Merge remote-tracking branch 'origin/staging' into review/6256-token-estimates - [`364ad49`](https://github.com/Pasta-Devs/Marinara-Engine/commit/364ad4994748c812e4b90572c6c42b89749cf944) docs: record full-card token estimate fix - [`466bf24`](https://github.com/Pasta-Devs/Marinara-Engine/commit/466bf249037f925550cefc9c0b18d0a01dc55735) Merge remote-tracking branch 'origin/staging' into review/6256-token-estimates - [`c73f75f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c73f75f188991ef1a47671e81a80c001c3a5c639) test: prove each full-card token source is included ### 📊 Changes **8 files changed** (+195 additions, -111 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/client/src/components/characters/CharacterLibraryView.tsx` (+5 -2) 📝 `packages/client/src/components/panels/CharactersPanel.tsx` (+3 -3) 📝 `packages/client/src/lib/character-token-count.ts` (+2 -88) 📝 `packages/server/src/services/storage/character-catalog.ts` (+2 -18) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/utils/character-token-estimator.ts` (+83 -0) ➕ `scripts/regressions/character-library-token-estimate.regression.ts` (+97 -0) </details> ### 📄 Description ## Linked issue Closes #6255 ## Why this change - Character token estimates can be undercounted when they are calculated from the compact catalog representation instead of the full character card. - Some fields used by the character card token estimator are intentionally omitted from the compact catalog data, so recalculating from those fields can produce substantially lower values. - The Character Library and Characters panel should use a consistent estimate based on the full card without requiring full card JSON in catalog responses. ## What changed - Moved the full character card token estimation helper to the shared package. - Calculate `tokenEstimate` from the full stored character data when building the server character catalog. - Use the catalog-provided estimate in the Character Library. - Use the catalog-provided estimate for both regular and folder character rows in the Characters panel instead of recalculating from compact parsed data. - Added regression coverage for full-card estimation and catalog/UI token estimate usage. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] 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` ### Manual verification notes - Ran Marinara from the updated source build and checked character token estimates in the UI. - Verified a reproduced character whose compact-data estimate was approximately 1,088 tokens. - Verified that the catalog API returned the full-card estimate of 1,769 tokens. - Confirmed that the Characters panel displays the catalog-provided 1,769-token estimate after the fix. - Confirmed that an embedded character book is included when it is present in the full character card data. ## Docs and release impact - [x] 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) ## UI evidence (if applicable) Before: the Characters panel displayed approximately 1,088 tokens based on compact catalog fields. <img width="193" height="61" alt="스크린샷 2026-09-16 20 44 23" src="https://github.com/user-attachments/assets/17eff6c0-a6b6-4e0c-8f49-6e583ddc3c68" /> After: the same character displays approximately 1,769 tokens using the full-card estimate provided by the catalog. <img width="178" height="57" alt="스크린샷 2026-09-16 20 42 27" src="https://github.com/user-attachments/assets/3414ff6a-2b03-455a-87c1-086a6e9aaae9" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Character token estimates now account for complete card content, including example messages, alternate greetings, instructions, extensions, prompts, and character-book details. - Token estimates are now consistent across the Character Library and Characters panels. - Character views use stored estimates when available, reducing unnecessary recalculation and improving responsiveness. - **Tests** - Added regression coverage to verify accurate token estimates for full character cards and consistent results across character browsing experiences. <!-- 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:16:36 +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#7107
No description provided.