[GH-ISSUE #2736] [Issue]: Post-merge (#2730) low-severity regressions & robustness gaps — agent tool-loop deadline, chat_history depth-0, conclude dedup, /game/setup streaming, lorebook group cap #1376

Closed
opened 2026-10-21 05:32:37 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2736

Originally assigned to: @SpicyMarinara on GitHub.

Summary

A post-merge verification sweep of #2730 found several low-severity robustness gaps and minor regressions in v2.0.0. None is independently game-breaking (each is recoverable, config-gated, or has an uncommon precondition), but they're grouped here so they aren't lost. Each was adversarially verified against the merged staging tree.


1. Per-agent timeout is per-call, not cumulative (regression, hang-ish)

agentCallSignal() creates a fresh AbortSignal.timeout(5min) on every call (agent-executor.ts:239). executeAgentWithTools loops up to maxToolRounds (default 100) and passes a new agentCallSignal() each round (:536), so a tool-using agent (Spotify, lorebook-writer) has no cumulative deadline — worst case ~100×5min. Not a true infinite hang (each call bounded; loop bounded; client disconnect aborts), but the #2730 timeout fix (commit 99827f92) bounds each call, not the agent's lifetime.

Fix: capture one AbortSignal.timeout (or elapsed-time budget) once before the loop and share it across rounds.


2. chat_history at injectionDepth: 0 flattened into depth-injection (regression, history-order corruption)

#2730 commit 90ac85b6 changed the depth-routing predicate at assembler.ts:356 from injectionDepth > 0 to >= 0 with no isChatHistory guard. A chat_history section configured injectionPosition='depth', injectionDepth=0 now routes to depthSections, gets flattened into individual depth entries, loses contextKind:'history', and is re-injected at prompt end as contextKind:'injection'; findHistoryBounds then returns null so depth-0 lorebook/character entries mis-anchor too. Non-default config (shipped preset keeps Chat History "ordered"); depth>=1 was already mishandled pre-sweep.

Fix: exclude isChatHistory sections from depth routing regardless of depth: if (!resolved.isChatHistory && section.injectionPosition === 'depth' && section.injectionDepth >= 0).


3. Concurrent /game/session/conclude dedup leaks undefined to the duplicate caller (regression, broken-flow)

The conclude handler dedups by chatId (game.routes.ts:4393-4394). If the in-flight request hits a JSON-parse failure it calls sendJsonRepairError(reply#1, …) then return; (:4540), so the shared promise resolves to undefined. The second (duplicate-click) caller gets undefined and never sent its own reply → the repair modal never opens for the duplicate (and on Fastify 5 may hang the duplicate). The apply-json sibling (:4644-4792) is structurally identical. Dedup Map added by #2730 commit 09bdc806. Only the redundant duplicate click misbehaves.

Fix: have the inner function return a serializable result ({jsonRepair|error} / {summary}) instead of reply.send + return undefined, and have the second caller re-derive/re-run when the shared promise resolved undefined.


4. /game/setup streams world-gen JSON with no buffered-empty retry (broken-flow on some provider stacks)

setupSchema.streaming defaults true (game.routes.ts:564); the handler builds setupOptions with stream: streaming (:3845) and the two-attempt parse/validate retry re-invokes with the same streamed options both times (:3878-3925). /game/scene-wrap deliberately forces stream:false + a streamed-collection retry because some GPT-5.5/OpenAI-compatible stacks return empty content when chatComplete streams this JSON route. /game/setup has neither, so an empty streamed response → responseText='' → parse throws on both attempts → 422 repair despite a world the model would produce fine buffered. Recoverable (repair modal); not a #2730 regression (streaming default predates it).

Fix: mirror scene-wrap — send the world-setup completion stream:false, or add a buffered-then-streamed cross-fallback when responseText is empty before declaring a parse failure.


5. Inclusion-group one-of cap not enforced across recursive scan passes (wrong-output)

applyGroupSelection (keyword-scanner.ts:349-372, invoked at :573) picks one weighted member per group but only within the current pass and carries no cross-pass state; the budgeting layer has no group awareness. In the recursion loop (index.ts:710-748) a group sibling dropped on pass 0 survives into remaining and the next pass's applyGroupSelection sees it as a singleton and lets it in — so a one-of group can inject 2+ members (A on pass 0, sibling B later), wasting context and presenting contradictory mutually-exclusive lore. Inherent design gap, not a #2730 regression.

Fix: track already-selected group keys across recursion passes and exclude entries whose group is already represented from each pass's remaining, or run group selection once over the final union.


Template checklist

  • pnpm check passes (TypeScript + ESLint)
  • Manually verify a long tool-loop agent (Spotify/lorebook-writer) is bounded by a single overall deadline
  • Manually verify a chat_history section set to depth-0 still renders inline in order
  • Manually verify a duplicate /game/session/conclude click opens the repair modal (not a blank 200)
  • Manually verify /game/setup recovers when the provider returns empty streamed content
  • Manually verify a one-of inclusion group injects at most one member across recursion passes

Found by a post-merge verification sweep of #2730 against the merged staging tree; each item adversarially verified. Boxes left unchecked for human verification.

Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2736 Originally assigned to: @SpicyMarinara on GitHub. ## Summary A post-merge verification sweep of #2730 found several **low-severity** robustness gaps and minor regressions in v2.0.0. None is independently game-breaking (each is recoverable, config-gated, or has an uncommon precondition), but they're grouped here so they aren't lost. Each was adversarially verified against the merged `staging` tree. --- ### 1. Per-agent timeout is per-call, not cumulative (regression, hang-ish) `agentCallSignal()` creates a **fresh** `AbortSignal.timeout(5min)` on every call (`agent-executor.ts:239`). `executeAgentWithTools` loops up to `maxToolRounds` (default 100) and passes a new `agentCallSignal()` each round (`:536`), so a tool-using agent (Spotify, lorebook-writer) has no cumulative deadline — worst case ~100×5min. Not a true infinite hang (each call bounded; loop bounded; client disconnect aborts), but the #2730 timeout fix (commit `99827f92`) bounds each call, not the agent's lifetime. **Fix:** capture one `AbortSignal.timeout` (or elapsed-time budget) once before the loop and share it across rounds. --- ### 2. `chat_history` at `injectionDepth: 0` flattened into depth-injection (regression, history-order corruption) #2730 commit `90ac85b6` changed the depth-routing predicate at `assembler.ts:356` from `injectionDepth > 0` to `>= 0` with no `isChatHistory` guard. A `chat_history` section configured `injectionPosition='depth'`, `injectionDepth=0` now routes to `depthSections`, gets flattened into individual depth entries, loses `contextKind:'history'`, and is re-injected at prompt end as `contextKind:'injection'`; `findHistoryBounds` then returns null so depth-0 lorebook/character entries mis-anchor too. Non-default config (shipped preset keeps Chat History "ordered"); `depth>=1` was already mishandled pre-sweep. **Fix:** exclude `isChatHistory` sections from depth routing regardless of depth: `if (!resolved.isChatHistory && section.injectionPosition === 'depth' && section.injectionDepth >= 0)`. --- ### 3. Concurrent `/game/session/conclude` dedup leaks `undefined` to the duplicate caller (regression, broken-flow) The conclude handler dedups by `chatId` (`game.routes.ts:4393-4394`). If the in-flight request hits a JSON-parse failure it calls `sendJsonRepairError(reply#1, …)` then `return;` (`:4540`), so the **shared promise resolves to `undefined`**. The second (duplicate-click) caller gets `undefined` and never sent its own reply → the repair modal never opens for the duplicate (and on Fastify 5 may hang the duplicate). The `apply-json` sibling (`:4644-4792`) is structurally identical. Dedup Map added by #2730 commit `09bdc806`. Only the redundant duplicate click misbehaves. **Fix:** have the inner function return a serializable result (`{jsonRepair|error}` / `{summary}`) instead of `reply.send + return undefined`, and have the second caller re-derive/re-run when the shared promise resolved `undefined`. --- ### 4. `/game/setup` streams world-gen JSON with no buffered-empty retry (broken-flow on some provider stacks) `setupSchema.streaming` defaults `true` (`game.routes.ts:564`); the handler builds `setupOptions` with `stream: streaming` (`:3845`) and the two-attempt parse/validate retry re-invokes with the **same streamed options** both times (`:3878-3925`). `/game/scene-wrap` deliberately forces `stream:false` + a streamed-collection retry because some GPT-5.5/OpenAI-compatible stacks return empty content when `chatComplete` streams this JSON route. `/game/setup` has neither, so an empty streamed response → `responseText=''` → parse throws on both attempts → 422 repair despite a world the model would produce fine buffered. Recoverable (repair modal); not a #2730 regression (streaming default predates it). **Fix:** mirror scene-wrap — send the world-setup completion `stream:false`, or add a buffered-then-streamed cross-fallback when `responseText` is empty before declaring a parse failure. --- ### 5. Inclusion-group one-of cap not enforced across recursive scan passes (wrong-output) `applyGroupSelection` (`keyword-scanner.ts:349-372`, invoked at `:573`) picks one weighted member per group but only within the current pass and carries no cross-pass state; the budgeting layer has no group awareness. In the recursion loop (`index.ts:710-748`) a group sibling dropped on pass 0 survives into `remaining` and the next pass's `applyGroupSelection` sees it as a singleton and lets it in — so a one-of group can inject 2+ members (A on pass 0, sibling B later), wasting context and presenting contradictory mutually-exclusive lore. Inherent design gap, not a #2730 regression. **Fix:** track already-selected group keys across recursion passes and exclude entries whose group is already represented from each pass's `remaining`, or run group selection once over the final union. --- ## Template checklist - [ ] `pnpm check` passes (TypeScript + ESLint) - [ ] Manually verify a long tool-loop agent (Spotify/lorebook-writer) is bounded by a single overall deadline - [ ] Manually verify a `chat_history` section set to depth-0 still renders inline in order - [ ] Manually verify a duplicate `/game/session/conclude` click opens the repair modal (not a blank 200) - [ ] Manually verify `/game/setup` recovers when the provider returns empty streamed content - [ ] Manually verify a one-of inclusion group injects at most one member across recursion passes --- _Found by a post-merge verification sweep of #2730 against the merged `staging` tree; each item adversarially verified. Boxes left unchecked for human verification._
bsakaguchi 2026-10-21 05:32:37 +07:00
  • closed this issue
  • added the
    in-pr
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Addressed in PR #2747.

<!-- gh-comment-id:4763115573 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Addressed in PR #2747.
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#1376
No description provided.