[GH-ISSUE #2987] [Issue]: Expression/Spotify agent set to the Pre-Generation phase has its result silently dropped (never finalized or applied) #1560

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

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

Originally assigned to: @SpicyMarinara on GitHub.

What's wrong
The expression sprite_change and Spotify events are always deferred until a finalize step re-emits them, but that finalize step only runs over post-generation results. The agent editor lets you move the built-in Expression (or Music DJ) agent to the Pre-Generation phase. When you do, the agent runs in phase 1, its result is deferred, and because pre-generation results are never finalized or applied, the result is silently dropped. The agent burns an LLM call every eligible turn but no sprite/playback ever reaches the client — a silent no-op.

How to reproduce (try it yourself)

  1. In a roleplay/visual_novel chat, enable the Expression Engine agent.
  2. Open the agent editor and change its Pipeline Phase from Post-Processing to Pre-Generation (the UI allows this for built-ins).
  3. Send a message.

You'll see: the agent executes (visible in agent-debug / token usage), but no expression/sprite event reaches the client and no sprite is applied. Same for the Music DJ (spotify) agent moved to pre_generation.
Expected: the phase change is either honored or not offered; the agent should not silently no-op.

Where it is
packages/server/src/services/generation/agent-event-dispatcher.ts:5-7,31-36 (defer, phase-agnostic); packages/server/src/services/generation/spotify-agent-runtime.ts:160-162 (spotify defer); packages/shared/src/types/agent.ts:25-32 (normalizeAgentPhaseForType only hard-locks prose-guardian/continuity); packages/client/src/components/agents/AgentEditor.tsx:1644-1646 (phase selector rendered for all agents). Finalize/apply gap at packages/server/src/routes/generate.routes.ts:7786-7791 (finalize loop iterates only postResults) and postResults construction at :7665-7673.

What's happening
The defer/finalize protocol assumes deferred expression/spotify events are always produced by post-processing agents whose results land in postResults. shouldDeferExpressionAgentEvent/shouldDeferSpotifyAgentEvent defer regardless of phase, and there is no finalize path for these result types in the pre-generation phase. Because the phase selector is editable for these built-ins, a deferred event can be created that is never finalized or applied.

Suggested fix
Hard-lock expression and spotify to post_processing in normalizeAgentPhaseForType (packages/shared/src/types/agent.ts:30), the single normalization chokepoint:

  if (agentType === "prose-guardian" || agentType === "continuity" || agentType === "expression" || agentType === "spotify") return "post_processing";

Because every layer routes through this function, the one edit makes the AgentEditor phase buttons no-ops for these built-ins, coerces any already-persisted pre_generation/parallel config back to post_processing on read (agents.storage.ts:51), and keeps BUILT_IN_AGENTS consistent. No dispatcher or finalize-loop changes are needed. Do NOT thread phase into the dispatcher or duplicate the finalize/apply loops over pre-gen results — both are larger and touch the high-risk apply path, and the manifests already declare these post_processing-only. Note: this also forecloses the parallel phase for these two, which is correct — parallel runs before mainResponse exists, and both agents need the assistant reply, so parallel was already a broken configuration.


AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.

Originally created by @kolacheee on GitHub (Jun 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2987 Originally assigned to: @SpicyMarinara on GitHub. **What's wrong** The expression sprite_change and Spotify events are always deferred until a finalize step re-emits them, but that finalize step only runs over post-generation results. The agent editor lets you move the built-in Expression (or Music DJ) agent to the Pre-Generation phase. When you do, the agent runs in phase 1, its result is deferred, and because pre-generation results are never finalized or applied, the result is silently dropped. The agent burns an LLM call every eligible turn but no sprite/playback ever reaches the client — a silent no-op. **How to reproduce (try it yourself)** 1. In a roleplay/visual_novel chat, enable the Expression Engine agent. 2. Open the agent editor and change its Pipeline Phase from Post-Processing to Pre-Generation (the UI allows this for built-ins). 3. Send a message. You'll see: the agent executes (visible in agent-debug / token usage), but no expression/sprite event reaches the client and no sprite is applied. Same for the Music DJ (spotify) agent moved to pre_generation. Expected: the phase change is either honored or not offered; the agent should not silently no-op. **Where it is** `packages/server/src/services/generation/agent-event-dispatcher.ts:5-7,31-36` (defer, phase-agnostic); `packages/server/src/services/generation/spotify-agent-runtime.ts:160-162` (spotify defer); `packages/shared/src/types/agent.ts:25-32` (`normalizeAgentPhaseForType` only hard-locks prose-guardian/continuity); `packages/client/src/components/agents/AgentEditor.tsx:1644-1646` (phase selector rendered for all agents). Finalize/apply gap at `packages/server/src/routes/generate.routes.ts:7786-7791` (finalize loop iterates only postResults) and postResults construction at `:7665-7673`. **What's happening** The defer/finalize protocol assumes deferred expression/spotify events are always produced by post-processing agents whose results land in `postResults`. `shouldDeferExpressionAgentEvent`/`shouldDeferSpotifyAgentEvent` defer regardless of phase, and there is no finalize path for these result types in the pre-generation phase. Because the phase selector is editable for these built-ins, a deferred event can be created that is never finalized or applied. **Suggested fix** Hard-lock expression and spotify to `post_processing` in `normalizeAgentPhaseForType` (packages/shared/src/types/agent.ts:30), the single normalization chokepoint: ```ts if (agentType === "prose-guardian" || agentType === "continuity" || agentType === "expression" || agentType === "spotify") return "post_processing"; ``` Because every layer routes through this function, the one edit makes the AgentEditor phase buttons no-ops for these built-ins, coerces any already-persisted pre_generation/parallel config back to post_processing on read (agents.storage.ts:51), and keeps BUILT_IN_AGENTS consistent. No dispatcher or finalize-loop changes are needed. Do NOT thread phase into the dispatcher or duplicate the finalize/apply loops over pre-gen results — both are larger and touch the high-risk apply path, and the manifests already declare these post_processing-only. Note: this also forecloses the `parallel` phase for these two, which is correct — `parallel` runs before mainResponse exists, and both agents need the assistant reply, so `parallel` was already a broken configuration. --- *AI-investigated against v2.0.6; cited lines read and confirmed. Please verify before fixing.*
Author
Owner

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

Fixed in merged staging PR #3004.

<!-- gh-comment-id:4832279372 --> @SpicyMarinara commented on GitHub (Jun 29, 2026): Fixed in merged staging PR #3004.
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#1560
No description provided.