[GH-ISSUE #5135] Game-surface Experiences need one host-run structured generation call (world briefs), like #5102 gave them state #2840

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

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

Originally assigned to: @kolacheee on GitHub.

The gap

A game-surface Experience can now store timeline-anchored state (#5102), but it has no way to run the ONE structured LLM call its content pipeline needs at game creation — for example, turning the player's wizard preferences into a compact "world brief" that a deterministic generator then compiles into a tile world. Packages are client-only by design here; the capability language-model host exists but is reachable only from privileged server entrypoints (capability-language-model.service.ts), which game-surface packages deliberately don't have, and package-registered routes are privileged-only (unusable off loopback — the same reason #5102 went host-owned).

So today an Experience wanting LLM-decided content has to abuse a visible chat turn and parse the GM's narration, which pollutes the story and breaks on the first formatting whim.

Suggested fix

One host-owned route in the #5102 mold, modeled on /game/scene-wrap (the existing client-triggered one-shot JSON-mode call, game.routes.ts:10548), not on /game/setup:

  • POST /api/game/:chatId/experience-generation — body: instructions (the package's guidance/schema text, bounded), optional schema (JSON schema forwarded as responseFormat where the provider supports it — OpenAI-compatible and Google do; Anthropic and the local sidecar ignore it, so the tolerant parser stays the real contract), optional userContent, optional connectionId override, bounded maxTokens.
  • Same gate as the experience-state routes: game-mode chat with a validly-stamped gameExperienceId (404 missing chat / 409 otherwise) — only the chat's own Experience can spend tokens, and only on its own chat.
  • Composes the existing stack: resolveConnection → createGameMainProvider → stored-parameter resolution + output-token clamp → abort/watchdog (runGameChatComplete) → thinking-block strip → parseGameJsonish, with the truncation case surfaced as the existing "increase max output tokens" 422. On a parse failure, one repair round-trip (the bad output appended as an assistant turn plus a corrective user turn — the illustrator's pattern, which converges better than a blind re-run) before giving up with the raw text so the package can degrade to defaults.
  • Cost guards: a dedicated rate-limit rule (one-shot LLM call per player action — the agent-suite-rewrite 20/min class, not the 600/min default) plus the per-chat generation lock so one chat can't hold two calls in flight, and a small route bodyLimit.

Driving case: the pixel-RPG Experience's preference-driven world generation ("the LLM decides what exists, the algorithm decides where every tile goes"). Verified against current staging.

Originally created by @kolacheee on GitHub (Aug 16, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5135 Originally assigned to: @kolacheee on GitHub. ### The gap A game-surface Experience can now store timeline-anchored state (#5102), but it has no way to run the ONE structured LLM call its content pipeline needs at game creation — for example, turning the player's wizard preferences into a compact "world brief" that a deterministic generator then compiles into a tile world. Packages are client-only by design here; the capability language-model host exists but is reachable only from privileged server entrypoints (`capability-language-model.service.ts`), which game-surface packages deliberately don't have, and package-registered routes are privileged-only (unusable off loopback — the same reason #5102 went host-owned). So today an Experience wanting LLM-decided content has to abuse a visible chat turn and parse the GM's narration, which pollutes the story and breaks on the first formatting whim. ### Suggested fix One host-owned route in the #5102 mold, modeled on `/game/scene-wrap` (the existing client-triggered one-shot JSON-mode call, `game.routes.ts:10548`), not on `/game/setup`: - `POST /api/game/:chatId/experience-generation` — body: `instructions` (the package's guidance/schema text, bounded), optional `schema` (JSON schema forwarded as `responseFormat` where the provider supports it — OpenAI-compatible and Google do; Anthropic and the local sidecar ignore it, so the tolerant parser stays the real contract), optional `userContent`, optional `connectionId` override, bounded `maxTokens`. - Same gate as the experience-state routes: game-mode chat with a validly-stamped `gameExperienceId` (404 missing chat / 409 otherwise) — only the chat's own Experience can spend tokens, and only on its own chat. - Composes the existing stack: `resolveConnection` → `createGameMainProvider` → stored-parameter resolution + output-token clamp → abort/watchdog (`runGameChatComplete`) → thinking-block strip → `parseGameJsonish`, with the truncation case surfaced as the existing "increase max output tokens" 422. On a parse failure, one repair round-trip (the bad output appended as an assistant turn plus a corrective user turn — the illustrator's pattern, which converges better than a blind re-run) before giving up with the raw text so the package can degrade to defaults. - Cost guards: a dedicated rate-limit rule (one-shot LLM call per player action — the `agent-suite-rewrite` 20/min class, not the 600/min default) plus the per-chat generation lock so one chat can't hold two calls in flight, and a small route bodyLimit. Driving case: the pixel-RPG Experience's preference-driven world generation ("the LLM decides what exists, the algorithm decides where every tile goes"). Verified against current `staging`.
bsakaguchi 2026-10-21 05:56:39 +07:00
Author
Owner

@kolacheee commented on GitHub (Aug 16, 2026):

Taking this one (agent working from kolacheee's fork) — draft PR up shortly.

<!-- gh-comment-id:5307159894 --> @kolacheee commented on GitHub (Aug 16, 2026): Taking this one (agent working from kolacheee's fork) — draft PR up shortly.
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#2840
No description provided.