[PR #1771] [MERGED] fix(gacha-forge): story memory recall like the Engine's advanced recall (1.25.0) #1960

Closed
opened 2026-11-07 16:38:19 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Agents/pull/1771
Author: @SpicyMarinara
Created: 10/27/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/gacha-forge-recall-quality


📝 Commits (3)

  • 6734c85 feat(gacha-forge): semantic, relevance-gated and private story memory recall
  • d0d1803 Merge remote-tracking branch 'origin/staging' into fix/gacha-forge-recall-quality
  • e229ed6 fix(gacha-forge): close recall review findings and release 1.25.0

📊 Changes

25 files changed (+1756 additions, -317 deletions)

View changed files

📝 .github/workflows/pull-request-checks.yml (+1 -0)
➕ artifacts/gacha-forge-1.25.0.zip (+0 -0)
📝 catalog/catalog.json (+10 -10)
📝 catalog/notes.json (+6 -6)
📝 catalog/v2/catalog.json (+10 -10)
📝 catalog/v2/notes.json (+6 -6)
📝 catalog/v3/catalog.json (+10 -10)
📝 catalog/v3/notes.json (+6 -6)
📝 packages/gacha-forge/CHANGELOG.md (+6 -0)
📝 packages/gacha-forge/README.md (+13 -1)
📝 packages/gacha-forge/bundle-patches.json (+92 -0)
📝 packages/gacha-forge/client.js (+2 -2)
📝 packages/gacha-forge/manifest.json (+7 -7)
📝 packages/gacha-forge/server.mjs (+460 -116)
📝 packages/gacha-forge/src/player-choices-server.mjs (+3 -1)
📝 packages/gacha-forge/src/proactive-messages-adapter.mjs (+6 -3)
📝 packages/gacha-forge/src/seasonal-events-adapter.mjs (+14 -3)
📝 packages/gacha-forge/src/story-memory-integration.mjs (+88 -16)
📝 packages/gacha-forge/src/story-memory.mjs (+333 -77)
📝 tests/gacha-forge-chapter-regeneration-package.regression.mjs (+2 -0)

...and 5 more files

📄 Description

Pull request

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch to main.

Linked issue

Fixes #1765

Why this change

The maintainer asked for Gacha Forge story memory to recall the way the Engine's advanced memory recall does, without losing anything. The 1.24.x recall had four gaps:

  • it matched words only, with no embeddings;
  • it searched with the chapter plan text, not with what was just played or said;
  • it had no relevance floor, so weak matches filled the slots, and side memories had no cap;
  • private chats were folded into the overview every prompt shares, so any unit could know another unit's conversations.

The maintainer also asked that characters know only what they could know in the story, and nothing outside it.

What changed

Package gacha-forge 1.25.0.

  • Engine recall scoring (src/story-memory.mjs), ported from advanced-memory-ranking.ts and advanced-memory.ts:
    • terms: NFKC, CJK pairs, stop words;
    • names weighted ×8, except the speakers' own names;
    • binary BM25;
    • an earlier, broader query loses 1.5× its excess, so it cannot outrank the latest cue;
    • word-overlap window;
    • vector similarity counts as sim − 0.25 above 0.45;
    • relevance floor 0.12.
  • Caps and budget. At most three chapter recalls and three side memories (Character Stories, events and chats together). They fit in a tenth of the context, plus 2,000 tokens, minus the overview and the recent canon.
  • Embeddings through runtime.resolveEmbeddings():
    • vectors are written in the background after summaries, 32 per batch, as base64 Float32;
    • when a batch fails, records are retried one at a time, shortest first;
    • a new embedding model re-embeds;
    • a query is embedded only when records have vectors in that model's space, waits at most 1.5 s, and falls back to the latest cue alone.
  • Queries come from what was just played or said:
    • the end of the current chapter so far, with the choice label unwrapped;
    • the last fight's outcome;
    • in a chat, the player's messages since the companion last spoke;
    • plan text is only the weakest cue.
  • Who may know what:
    • Chats leave the shared overview. A unit's chats are recalled in its own chats, its Character Story planning, scenes and events it is in (by cast), and main chapter planning, never in fights or other units' chats.
    • Another unit's Character Story reaches a chat only through the overview. Its decisions are not listed there, and neither is its text when memory is not ready and the legacy history stands in.
    • The seasonal event planner lists only its cast's conversations.
    • An overview saved before 1.25.0 that holds chats is not sent to restricted readers until the background rebuild.
  • No duplicates. Conversations a writer already lists among its newest are not recalled again, so they don't take side slots. A chat's own list now shows each conversation's verbatim line.
  • Knowledge boundary. One line in the chapter planner, narrator, Character Story planner, fight guide and every chat: a character knows only what they saw, took part in or learned in the story, never another character's private conversations unless told, and nothing outside the fiction.
  • Cancel and reset now stop memory upkeep: the story's signal reaches maintain.
  • Release: in-game What's new (1.24.10 pinned), CHANGELOG, README, manifest, artifact and catalog. New CI regression: tests/gacha-forge-story-memory-audience.regression.mjs.

Package and security impact

  • Affected package IDs: gacha-forge
  • Engine compatibility impact: uses the existing runtime.resolveEmbeddings() / runtime.embeddings capability when present; without it, recall uses words only.
  • New or changed permissions/entrypoints: none.
  • Restart, storage, update, or uninstall impact:
    • Memory records gain optional embedding and embeddingSpaceId fields.
    • The first background run after the update rebuilds the overview without chats and embeds existing records. No migration step is needed, and no data is removed.

Validation

  • node scripts/validate-catalog.mjs passes locally
  • git diff --check passes locally
  • Rebuilt every affected manifest, payload, artifact, and catalog entry
  • Installed or updated the affected package through Marinara Engine
  • Checked supported modes, restart behavior, and uninstall cleanup
  • Read and followed CONTRIBUTING.md

Manual verification notes

Agent-side checks:

  • All 69 tests/gacha-forge-*.regression.mjs files pass locally (539 tests).
  • prettier, eslint and node --check on the bundle are clean.
  • validate-catalog could not run locally (sparse worktree without artifacts/).
  • New and changed regressions:
    • Core:
      • Engine scoring, floor, name and speaker weighting, the diffuse plan penalty, the budget and the vector threshold;
      • query vectors are skipped without saved vectors, time out at 1.5 s and fall back to the latest cue;
      • vector upkeep in batches, a refused text first, a new model, and Cancel mid-upkeep;
      • chat and Character Story audience by reader and cast;
      • a pre-1.25.0 overview with chats is held back from restricted readers.
    • Integration: played-text queries, reader and cast pass-through, audiences on sources, the chat query, and the story signal reaching maintain.
    • Bundle (story-memory-audience, fails on the pre-fix bundle):
      • no other unit's Character Story in a chat, in the legacy or ready path;
      • no other unit's decisions;
      • a listed conversation appears once, with its line;
      • the event planner lists cast-only conversations.
    • Package:
      • a scene without the Keeper does not recall the Keeper's chat, and one with the Keeper does;
      • the knowledge boundary reaches the planner, narrator and a real chat prompt.
  • An adversarial review workflow ran: five reviewers, each with a refuting verifier. Its six confirmed findings are fixed in the second commit. One unconfirmed finding was rejected: on a replay, required recent canon can use up the recall budget. That is the Engine's own budget rule, and a replay of an already played beat returns stored text before recall runs.

To verify by hand:

  • Manually verify that with an embedding model set in the Engine, Continuity reaches Ready after a chapter and recall still answers quickly.
  • Manually verify that in Arden's chat, asking about something said only in Bryn's chat gets no knowledge of it, while Bryn's chat remembers it.
  • Manually verify that a scene featuring a unit can reference that unit's earlier chat, and a scene without them does not.
  • Manually verify that characters do not mention the player, the game or prompts.

🤖 Generated with Claude Code


🔄 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-Agents/pull/1771 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/27/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/gacha-forge-recall-quality` --- ### 📝 Commits (3) - [`6734c85`](https://github.com/Pasta-Devs/Marinara-Agents/commit/6734c8552d7c9343265351c739f60e78fbe7b789) feat(gacha-forge): semantic, relevance-gated and private story memory recall - [`d0d1803`](https://github.com/Pasta-Devs/Marinara-Agents/commit/d0d18030a174f3a6aacd0af57c93ec29bb4b35ef) Merge remote-tracking branch 'origin/staging' into fix/gacha-forge-recall-quality - [`e229ed6`](https://github.com/Pasta-Devs/Marinara-Agents/commit/e229ed60c7a8a0635954c507af2ea9ec2bd64a71) fix(gacha-forge): close recall review findings and release 1.25.0 ### 📊 Changes **25 files changed** (+1756 additions, -317 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/pull-request-checks.yml` (+1 -0) ➕ `artifacts/gacha-forge-1.25.0.zip` (+0 -0) 📝 `catalog/catalog.json` (+10 -10) 📝 `catalog/notes.json` (+6 -6) 📝 `catalog/v2/catalog.json` (+10 -10) 📝 `catalog/v2/notes.json` (+6 -6) 📝 `catalog/v3/catalog.json` (+10 -10) 📝 `catalog/v3/notes.json` (+6 -6) 📝 `packages/gacha-forge/CHANGELOG.md` (+6 -0) 📝 `packages/gacha-forge/README.md` (+13 -1) 📝 `packages/gacha-forge/bundle-patches.json` (+92 -0) 📝 `packages/gacha-forge/client.js` (+2 -2) 📝 `packages/gacha-forge/manifest.json` (+7 -7) 📝 `packages/gacha-forge/server.mjs` (+460 -116) 📝 `packages/gacha-forge/src/player-choices-server.mjs` (+3 -1) 📝 `packages/gacha-forge/src/proactive-messages-adapter.mjs` (+6 -3) 📝 `packages/gacha-forge/src/seasonal-events-adapter.mjs` (+14 -3) 📝 `packages/gacha-forge/src/story-memory-integration.mjs` (+88 -16) 📝 `packages/gacha-forge/src/story-memory.mjs` (+333 -77) 📝 `tests/gacha-forge-chapter-regeneration-package.regression.mjs` (+2 -0) _...and 5 more files_ </details> ### 📄 Description # Pull request > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch to `main`. ## Linked issue Fixes #1765 ## Why this change The maintainer asked for Gacha Forge story memory to recall the way the Engine's advanced memory recall does, without losing anything. The 1.24.x recall had four gaps: - it matched words only, with no embeddings; - it searched with the chapter plan text, not with what was just played or said; - it had no relevance floor, so weak matches filled the slots, and side memories had no cap; - private chats were folded into the overview every prompt shares, so any unit could know another unit's conversations. The maintainer also asked that characters know only what they could know in the story, and nothing outside it. ## What changed Package `gacha-forge` 1.25.0. - **Engine recall scoring** (`src/story-memory.mjs`), ported from `advanced-memory-ranking.ts` and `advanced-memory.ts`: - terms: NFKC, CJK pairs, stop words; - names weighted ×8, except the speakers' own names; - binary BM25; - an earlier, broader query loses 1.5× its excess, so it cannot outrank the latest cue; - word-overlap window; - vector similarity counts as `sim − 0.25` above 0.45; - relevance floor 0.12. - **Caps and budget.** At most three chapter recalls and three side memories (Character Stories, events and chats together). They fit in a tenth of the context, plus 2,000 tokens, minus the overview and the recent canon. - **Embeddings** through `runtime.resolveEmbeddings()`: - vectors are written in the background after summaries, 32 per batch, as base64 Float32; - when a batch fails, records are retried one at a time, shortest first; - a new embedding model re-embeds; - a query is embedded only when records have vectors in that model's space, waits at most 1.5 s, and falls back to the latest cue alone. - **Queries** come from what was just played or said: - the end of the current chapter so far, with the choice label unwrapped; - the last fight's outcome; - in a chat, the player's messages since the companion last spoke; - plan text is only the weakest cue. - **Who may know what:** - Chats leave the shared overview. A unit's chats are recalled in its own chats, its Character Story planning, scenes and events it is in (by cast), and main chapter planning, never in fights or other units' chats. - Another unit's Character Story reaches a chat only through the overview. Its decisions are not listed there, and neither is its text when memory is not ready and the legacy history stands in. - The seasonal event planner lists only its cast's conversations. - An overview saved before 1.25.0 that holds chats is not sent to restricted readers until the background rebuild. - **No duplicates.** Conversations a writer already lists among its newest are not recalled again, so they don't take side slots. A chat's own list now shows each conversation's verbatim line. - **Knowledge boundary.** One line in the chapter planner, narrator, Character Story planner, fight guide and every chat: a character knows only what they saw, took part in or learned in the story, never another character's private conversations unless told, and nothing outside the fiction. - **Cancel and reset** now stop memory upkeep: the story's signal reaches `maintain`. - **Release:** in-game What's new (1.24.10 pinned), CHANGELOG, README, manifest, artifact and catalog. New CI regression: `tests/gacha-forge-story-memory-audience.regression.mjs`. ## Package and security impact - Affected package IDs: `gacha-forge` - Engine compatibility impact: uses the existing `runtime.resolveEmbeddings()` / `runtime.embeddings` capability when present; without it, recall uses words only. - New or changed permissions/entrypoints: none. - Restart, storage, update, or uninstall impact: - Memory records gain optional `embedding` and `embeddingSpaceId` fields. - The first background run after the update rebuilds the overview without chats and embeds existing records. No migration step is needed, and no data is removed. ## Validation - [ ] `node scripts/validate-catalog.mjs` passes locally - [ ] `git diff --check` passes locally - [ ] Rebuilt every affected manifest, payload, artifact, and catalog entry - [ ] Installed or updated the affected package through Marinara Engine - [ ] Checked supported modes, restart behavior, and uninstall cleanup - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Agent-side checks: - All 69 `tests/gacha-forge-*.regression.mjs` files pass locally (539 tests). - `prettier`, `eslint` and `node --check` on the bundle are clean. - `validate-catalog` could not run locally (sparse worktree without `artifacts/`). - New and changed regressions: - **Core:** - Engine scoring, floor, name and speaker weighting, the diffuse plan penalty, the budget and the vector threshold; - query vectors are skipped without saved vectors, time out at 1.5 s and fall back to the latest cue; - vector upkeep in batches, a refused text first, a new model, and Cancel mid-upkeep; - chat and Character Story audience by reader and cast; - a pre-1.25.0 overview with chats is held back from restricted readers. - **Integration:** played-text queries, reader and cast pass-through, audiences on sources, the chat query, and the story signal reaching `maintain`. - **Bundle** (`story-memory-audience`, fails on the pre-fix bundle): - no other unit's Character Story in a chat, in the legacy or ready path; - no other unit's decisions; - a listed conversation appears once, with its line; - the event planner lists cast-only conversations. - **Package:** - a scene without the Keeper does not recall the Keeper's chat, and one with the Keeper does; - the knowledge boundary reaches the planner, narrator and a real chat prompt. - An adversarial review workflow ran: five reviewers, each with a refuting verifier. Its six confirmed findings are fixed in the second commit. One unconfirmed finding was rejected: on a replay, required recent canon can use up the recall budget. That is the Engine's own budget rule, and a replay of an already played beat returns stored text before recall runs. To verify by hand: - Manually verify that with an embedding model set in the Engine, Continuity reaches Ready after a chapter and recall still answers quickly. - Manually verify that in Arden's chat, asking about something said only in Bryn's chat gets no knowledge of it, while Bryn's chat remembers it. - Manually verify that a scene featuring a unit can reference that unit's earlier chat, and a scene without them does not. - Manually verify that characters do not mention the player, the game or prompts. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:38:19 +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-Agents#1960
No description provided.