[PR #1651] [MERGED] [codex] Wire lorebook timing and skill check history #5183

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/lorebook-timing-skill-check-history


📝 Commits (3)

  • ffc62d3 Wire lorebook timing and skill check history
  • 7d32aec Guard skill check history rewrites by chat
  • f00636e Address lorebook timing review findings

📊 Changes

15 files changed (+788 additions, -12 deletions)

View changed files

📝 src-tauri/crates/storage/src/lib.rs (+38 -0)
📝 src-tauri/src/commands/storage/chats.rs (+68 -0)
📝 src-tauri/src/commands/storage/commands/chats.rs (+17 -0)
📝 src-tauri/src/http_dispatch.rs (+16 -0)
📝 src-tauri/src/lib.rs (+1 -0)
📝 src/engine/capabilities/storage.ts (+6 -0)
📝 src/engine/generation/prompt-assembly.test.ts (+114 -0)
📝 src/engine/generation/prompt-assembly.ts (+92 -1)
📝 src/engine/generation/start-generation.test.ts (+133 -1)
📝 src/engine/generation/start-generation.ts (+21 -0)
📝 src/features/modes/game/api/game-api.test.ts (+175 -0)
📝 src/features/modes/game/api/game-api.ts (+58 -10)
📝 src/shared/api/remote-runtime.ts (+1 -0)
📝 src/shared/api/storage-api.test.ts (+35 -0)
📝 src/shared/api/storage-api.ts (+13 -0)

📄 Description

Linked issue

No linked issue.

Why this change

  • Lorebook entry timing state and resolved game skill checks had engine/runtime helpers available, but the app paths were not carrying those results through persistence. That meant delayed/sticky lorebook timing could be lost between generated turns, and game skill-check history could keep unresolved tags instead of the resolved roll result.
  • Review found three follow-up risks: timing state advanced before the final chat-wide lorebook budget, direct input.messages generations did not persist lorebook timing after save, and skill-check history rewrites used a blind read-modify-write on message content.

What changed

  • Wires lorebook timing state through prompt assembly and generation persistence after successful assistant message saves.
  • Computes next lorebook timing state from the post-chat-budget included entries so budget-skipped lore does not burn cooldown/sticky/delay state.
  • Persists lorebook timing state in the direct request-message save path after a successful assistant message save.
  • Persists resolved game skill-check tags back into the source message history when a message id is provided.
  • Keeps already-resolved skill-check tags unchanged and treats history persistence as best-effort so roll results still return if storage update fails.
  • Guards skill-check history rewrites by chat id to avoid cross-chat message mutation.
  • Adds a focused conditional chat-message content update through the shared storage API, embedded Tauri command, and hostable HTTP dispatch so skill-check history rewrites can retry without clobbering concurrent content changes.

Refactor impact

Primary owner:

Engine generation, game mode API, shared storage API, and Rust storage command routing.

Impact areas reviewed:

  • Prompt assembly lorebook scan/timing path.
  • Generation assistant-message save flow, including direct request-message saves.
  • Game mode skill-check API and history mutation path.
  • Shared storage API wrapper and remote-runtime allowlist.
  • Embedded Tauri command registration and hostable HTTP dispatch.
  • Game hooks/surface callers, skill-check tag parser/serializer, segment edits, and storage API contracts.

Boundary notes:

  • Engine generation remains React-free and uses engine contracts/helpers only.
  • Feature game API continues to call focused shared storage API wrappers rather than raw Tauri or remote-runtime fetch.
  • The new conditional content update is owned by the storage API boundary and is explicitly routed through Tauri command registration, remote-runtime.ts, and http_dispatch.rs.
  • Rust storage keeps the atomic compare/update under the storage write lock; game-specific tag serialization remains in TypeScript game API code.

Pressure points touched:

  • Prompt assembly timing-state output.
  • startGeneration post-save metadata persistence in normal and direct-message branches.
  • Game API skill-check history persistence.
  • Shared storage API and Rust storage command routing.
  • GameSurface was reviewed as a dependent caller but not modified.

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

  • Rebased onto current origin/refactor before initial push.
  • Ran pnpm exec vitest run src/engine/generation/prompt-assembly.test.ts src/engine/generation/start-generation.test.ts src/features/modes/game/api/game-api.test.ts src/shared/api/storage-api.test.ts after review fixes: 4 files passed, 135 tests passed.
  • Ran cargo test --manifest-path src-tauri/Cargo.toml update_message_content_if_unchanged_updates_only_matching_content: passed.
  • Ran pnpm typecheck: passed.
  • Ran cargo check --manifest-path src-tauri/Cargo.toml --workspace: passed.
  • Ran pnpm check:architecture: passed.
  • Ran pnpm check:unused: passed.
  • Ran pnpm format:check: passed.
  • Ran pnpm build: passed with the existing Vite large-chunk warning.
  • Ran git diff --check: passed.
  • No native Tauri/manual game UI pass was run.

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 is present in this repo. No docs updates were made because this wires existing runtime/history behavior and adds a narrow storage command for that path rather than changing setup, architecture guidance, or user-facing documentation.

UI evidence

Not a visual UI change; no screenshots or recordings added.

Summary by CodeRabbit

New Features

  • Lorebook entries now maintain and persist timing states across conversation turns, properly tracking delays, cooldowns, and sticky effects.
  • Skill check results in game mode are now automatically recorded and saved in chat history for reference and persistence.

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/1651 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 5/30/2026 **Status:** ✅ Merged **Merged:** 5/30/2026 **Merged by:** [@Xelvanis](https://github.com/Xelvanis) **Base:** `refactor` ← **Head:** `fix/lorebook-timing-skill-check-history` --- ### 📝 Commits (3) - [`ffc62d3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ffc62d316cd66e2bc9361f5d0685334ed11f7e2c) Wire lorebook timing and skill check history - [`7d32aec`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7d32aecafd62b44e209db0d5bf2dfe35d60e9c47) Guard skill check history rewrites by chat - [`f00636e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f00636ecd1244485be77fa72e6e3214ce68c06a9) Address lorebook timing review findings ### 📊 Changes **15 files changed** (+788 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/crates/storage/src/lib.rs` (+38 -0) 📝 `src-tauri/src/commands/storage/chats.rs` (+68 -0) 📝 `src-tauri/src/commands/storage/commands/chats.rs` (+17 -0) 📝 `src-tauri/src/http_dispatch.rs` (+16 -0) 📝 `src-tauri/src/lib.rs` (+1 -0) 📝 `src/engine/capabilities/storage.ts` (+6 -0) 📝 `src/engine/generation/prompt-assembly.test.ts` (+114 -0) 📝 `src/engine/generation/prompt-assembly.ts` (+92 -1) 📝 `src/engine/generation/start-generation.test.ts` (+133 -1) 📝 `src/engine/generation/start-generation.ts` (+21 -0) 📝 `src/features/modes/game/api/game-api.test.ts` (+175 -0) 📝 `src/features/modes/game/api/game-api.ts` (+58 -10) 📝 `src/shared/api/remote-runtime.ts` (+1 -0) 📝 `src/shared/api/storage-api.test.ts` (+35 -0) 📝 `src/shared/api/storage-api.ts` (+13 -0) </details> ### 📄 Description ## Linked issue No linked issue. ## Why this change - Lorebook entry timing state and resolved game skill checks had engine/runtime helpers available, but the app paths were not carrying those results through persistence. That meant delayed/sticky lorebook timing could be lost between generated turns, and game skill-check history could keep unresolved tags instead of the resolved roll result. - Review found three follow-up risks: timing state advanced before the final chat-wide lorebook budget, direct `input.messages` generations did not persist lorebook timing after save, and skill-check history rewrites used a blind read-modify-write on message content. ## What changed - Wires lorebook timing state through prompt assembly and generation persistence after successful assistant message saves. - Computes next lorebook timing state from the post-chat-budget included entries so budget-skipped lore does not burn cooldown/sticky/delay state. - Persists lorebook timing state in the direct request-message save path after a successful assistant message save. - Persists resolved game skill-check tags back into the source message history when a message id is provided. - Keeps already-resolved skill-check tags unchanged and treats history persistence as best-effort so roll results still return if storage update fails. - Guards skill-check history rewrites by chat id to avoid cross-chat message mutation. - Adds a focused conditional chat-message content update through the shared storage API, embedded Tauri command, and hostable HTTP dispatch so skill-check history rewrites can retry without clobbering concurrent content changes. ## Refactor impact Primary owner: Engine generation, game mode API, shared storage API, and Rust storage command routing. Impact areas reviewed: - Prompt assembly lorebook scan/timing path. - Generation assistant-message save flow, including direct request-message saves. - Game mode skill-check API and history mutation path. - Shared storage API wrapper and remote-runtime allowlist. - Embedded Tauri command registration and hostable HTTP dispatch. - Game hooks/surface callers, skill-check tag parser/serializer, segment edits, and storage API contracts. Boundary notes: - Engine generation remains React-free and uses engine contracts/helpers only. - Feature game API continues to call focused shared storage API wrappers rather than raw Tauri or remote-runtime fetch. - The new conditional content update is owned by the storage API boundary and is explicitly routed through Tauri command registration, `remote-runtime.ts`, and `http_dispatch.rs`. - Rust storage keeps the atomic compare/update under the storage write lock; game-specific tag serialization remains in TypeScript game API code. Pressure points touched: - Prompt assembly timing-state output. - `startGeneration` post-save metadata persistence in normal and direct-message branches. - Game API skill-check history persistence. - Shared storage API and Rust storage command routing. - `GameSurface` was reviewed as a dependent caller but not modified. ## Validation <!-- Check only what you personally ran or manually verified. Treat unchecked items as explicit TODOs. --> - [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 - [ ] `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 - Rebased onto current `origin/refactor` before initial push. - Ran `pnpm exec vitest run src/engine/generation/prompt-assembly.test.ts src/engine/generation/start-generation.test.ts src/features/modes/game/api/game-api.test.ts src/shared/api/storage-api.test.ts` after review fixes: 4 files passed, 135 tests passed. - Ran `cargo test --manifest-path src-tauri/Cargo.toml update_message_content_if_unchanged_updates_only_matching_content`: passed. - Ran `pnpm typecheck`: passed. - Ran `cargo check --manifest-path src-tauri/Cargo.toml --workspace`: passed. - Ran `pnpm check:architecture`: passed. - Ran `pnpm check:unused`: passed. - Ran `pnpm format:check`: passed. - Ran `pnpm build`: passed with the existing Vite large-chunk warning. - Ran `git diff --check`: passed. - No native Tauri/manual game UI pass was run. ## 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 is present in this repo. No docs updates were made because this wires existing runtime/history behavior and adds a narrow storage command for that path rather than changing setup, architecture guidance, or user-facing documentation. ## UI evidence Not a visual UI change; no screenshots or recordings added. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## New Features * Lorebook entries now maintain and persist timing states across conversation turns, properly tracking delays, cooldowns, and sticky effects. * Skill check results in game mode are now automatically recorded and saved in chat history for reference and persistence. <!-- 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/1651?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:14:01 +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#5183
No description provided.