[GH-ISSUE #4026] [Issue]: In GM mode, many hardcoded max_tokens values are too low #2171

Closed
opened 2026-10-21 05:45:57 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @Aculeasis on GitHub (Jul 24, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4026

Originally assigned to: @SpicyMarinara on GitHub.

Summary

In GM mode, many requests use hardcoded max_tokens values that can be too low. As a result, the LLM can consume the entire token budget without being able to return valid output.

Expected behavior

  • Honor the "Max Output Tokens" value from the connection settings instead of overriding it with a smaller hardcoded value.
  • Alternatively, if different max_tokens values are intentional for different request types, expose a max_tokens setting for each request type in the GM creation wizard.
  • Provide a clearer error message.

Actual behavior

When generating a medium-size map (16places), the model consumed the entire token budget, the response was exactly 10000 tokens. Generation was truncated at location 3 out of 16, meaning a significantly larger budget is needed for this request type :)

Other request types also appear to have hardcoded max_tokens (and possibly other hardcoded parameters), so they may fail the same way.

Additionally:

  1. The error message is unclear: it says "The AI could not create a valid map draft," without specifying whether the response was invalid JSON, had the wrong structure, or was empty. (In my case, the JSON was truncated and therefore invalid.)
  2. The error message states that I can build one later from Chat Settings, but I could not find where to do this.

Steps to reproduce

  1. Start a new GM game with a "Hierarchical world map" (medium size), using a model that tends to "think" a lot.
  2. Observe an incomplete/invalid response after the full token budget is consumed.

Environment

  • Marinara Engine version: 2.3.4
  • Install type: docker
  • OS + version: Ubuntu 24
  • Browser or app shell: Firefox 152.0.6

Logs, screenshots, or video

Request for "Hierarchical world map" generation, with hardcoded max_tokens:

{
  "model": "nanogpt/zai-org/glm-5.2:thinking",
  "messages": [
    {
      "role": "system",
      "content": "You design practical hierarchical world maps for an AI game engine....."
    },
    {
      "role": "user",
      "content": "Owner mode: game\n\nRequested size: medium\n\nReusable creator guidance..."
    }
  ],
  "stream": false,
  "max_tokens": 10000,
  "temperature": 0.55
}

Popup error:

The game was created, but its map draft failed: The AI could not create a valid map draft. Try again, add clearer instructions, or choose a smaller size.. You can build one later from Chat Settings.

I also have the full response, but it is just had a large, truncated JSON.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Aculeasis on GitHub (Jul 24, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/4026 Originally assigned to: @SpicyMarinara on GitHub. ## Summary In GM mode, many requests use hardcoded `max_tokens` values that can be too low. As a result, the LLM can consume the entire token budget without being able to return valid output. ## Expected behavior - Honor the "Max Output Tokens" value from the connection settings instead of overriding it with a smaller hardcoded value. - Alternatively, if different `max_tokens` values are intentional for different request types, expose a `max_tokens` setting for each request type in the GM creation wizard. - Provide a clearer error message. ## Actual behavior When generating a medium-size map (16places), the model consumed the entire token budget, the response was exactly 10000 tokens. Generation was truncated at location 3 out of 16, meaning a significantly larger budget is needed for this request type :) Other request types also appear to have hardcoded `max_tokens` (and possibly other hardcoded parameters), so they may fail the same way. Additionally: 1. The error message is unclear: it says "The AI could not create a valid map draft," without specifying whether the response was invalid JSON, had the wrong structure, or was empty. (In my case, the JSON was truncated and therefore invalid.) 2. The error message states that I can build one later from Chat Settings, but I could not find where to do this. ## Steps to reproduce 1. Start a new GM game with a "Hierarchical world map" (medium size), using a model that tends to "think" a lot. 2. Observe an incomplete/invalid response after the full token budget is consumed. ## Environment - Marinara Engine version: 2.3.4 - Install type: docker - OS + version: Ubuntu 24 - Browser or app shell: Firefox 152.0.6 ## Logs, screenshots, or video Request for "Hierarchical world map" generation, with hardcoded `max_tokens`: ```json { "model": "nanogpt/zai-org/glm-5.2:thinking", "messages": [ { "role": "system", "content": "You design practical hierarchical world maps for an AI game engine....." }, { "role": "user", "content": "Owner mode: game\n\nRequested size: medium\n\nReusable creator guidance..." } ], "stream": false, "max_tokens": 10000, "temperature": 0.55 } ``` Popup error: ``` The game was created, but its map draft failed: The AI could not create a valid map draft. Try again, add clearer instructions, or choose a smaller size.. You can build one later from Chat Settings. ``` I also have the full response, but it is just had a large, truncated JSON. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:45:57 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@SpicyMarinara commented on GitHub (Jul 24, 2026):

Hm, seems like the issue is only with Hierarchical Maps, the Game mode itself respects connection overwrites.

<!-- gh-comment-id:5066761563 --> @SpicyMarinara commented on GitHub (Jul 24, 2026): Hm, seems like the issue is only with Hierarchical Maps, the Game mode itself respects connection overwrites.
Author
Owner

@Aculeasis commented on GitHub (Jul 24, 2026):

Hm, seems like the issue is only with Hierarchical Maps, the Game mode itself respects connection overwrites.

Well, I enabled and set max_token 16000, Temperature 0.9, Top P 0.95:

{
  "model": "nanogpt/zai-org/glm-5.2:thinking",
  "messages": [
    {
      "role": "system",
      "content": "You are Marinara's Game Mode Storyboard Illustrator...."
    },
    {
      "role": "user",
      "content": "<game_context>\nMode: exploration\n...."
    }
  ],
  "stream": false,
  "max_tokens": 2200,
  "temperature": 0.9,
  "top_p": 0.95,
  "response_format": {
    "type": "json_object"
  }
}

{
  "model": "nanogpt/zai-org/glm-5.2:thinking",
  "messages": [
    {
      "role": "system",
      "content": "Generate a map for the current area in the RPG game.\n\nLocation type: current location\nContext: Location..."
    },
    {
      "role": "user",
      "content": "Generate the map."
    }
  ],
  "stream": false,
  "max_tokens": 8192,
  "temperature": 0.6,
  "top_p": 1,
  "verbosity": "high",
  "reasoning_effort": "high"
}

{
  "model": "nanogpt/zai-org/glm-5.2:thinking",
  "messages": [
    {
      "role": "system",
      "content": "<role>\nYou are an excellent Game Master for the user...."
    },
    {
      "role": "user",
      "content": "<current_state>\nState: exploration | Session #1\n</current_state>\n\n<output_format>..."
    }
  ],
  "stream": true,
  "max_tokens": 16384,
  "stream_options": {
    "include_usage": true
  },
  "temperature": 1,
  "top_p": 1
}

<!-- gh-comment-id:5066814612 --> @Aculeasis commented on GitHub (Jul 24, 2026): > Hm, seems like the issue is only with Hierarchical Maps, the Game mode itself respects connection overwrites. Well, I enabled and set max_token 16000, Temperature 0.9, Top P 0.95: ``` { "model": "nanogpt/zai-org/glm-5.2:thinking", "messages": [ { "role": "system", "content": "You are Marinara's Game Mode Storyboard Illustrator...." }, { "role": "user", "content": "<game_context>\nMode: exploration\n...." } ], "stream": false, "max_tokens": 2200, "temperature": 0.9, "top_p": 0.95, "response_format": { "type": "json_object" } } { "model": "nanogpt/zai-org/glm-5.2:thinking", "messages": [ { "role": "system", "content": "Generate a map for the current area in the RPG game.\n\nLocation type: current location\nContext: Location..." }, { "role": "user", "content": "Generate the map." } ], "stream": false, "max_tokens": 8192, "temperature": 0.6, "top_p": 1, "verbosity": "high", "reasoning_effort": "high" } { "model": "nanogpt/zai-org/glm-5.2:thinking", "messages": [ { "role": "system", "content": "<role>\nYou are an excellent Game Master for the user...." }, { "role": "user", "content": "<current_state>\nState: exploration | Session #1\n</current_state>\n\n<output_format>..." } ], "stream": true, "max_tokens": 16384, "stream_options": { "include_usage": true }, "temperature": 1, "top_p": 1 } ```
Author
Owner

@SpicyMarinara commented on GitHub (Jul 24, 2026):

Triaged this. The Game mode itself does honor the connection's Max Output Tokens (as you noted) — the problem is isolated to the Hierarchical Maps capability, and that's the catch: the map-draft generation, its hardcoded max_tokens, and the "could not create a valid map draft" error all live inside the vendored, pre-built capability bundle (packages/server/data/capability-packages/versions/hierarchical-maps/*/server.mjs), not in the Marinara-Engine source tree.

Those .mjs files are minified build artifacts downloaded/installed by the capability package manager; their source is in the separate capability-package repo. So this can't be fixed from the Marinara-Engine repo without hand-editing a minified bundle (which the next package update would overwrite).

Where the fix belongs (capability package source):

  1. Make the hierarchical world-map draft request honor the connection's Max Output Tokens instead of the hardcoded value (the issue shows max_tokens: 10000 truncating a 16-place medium map), or expose a per-request token setting in the GM wizard.
  2. Distinguish the failure modes in the error (truncated/invalid JSON vs. wrong structure vs. empty) instead of the generic "could not create a valid map draft."
  3. Fix the misleading "You can build one later from Chat Settings" hint (the reporter couldn't find that entry point).

Flagging for whoever maintains the hierarchical-maps capability package. Happy to open a PR there if you point me at the source repo.

<!-- gh-comment-id:5067686916 --> @SpicyMarinara commented on GitHub (Jul 24, 2026): Triaged this. The Game mode itself does honor the connection's Max Output Tokens (as you noted) — the problem is isolated to the **Hierarchical Maps** capability, and that's the catch: the map-draft generation, its hardcoded `max_tokens`, and the "could not create a valid map draft" error all live inside the **vendored, pre-built capability bundle** (`packages/server/data/capability-packages/versions/hierarchical-maps/*/server.mjs`), not in the Marinara-Engine source tree. Those `.mjs` files are minified build artifacts downloaded/installed by the capability package manager; their source is in the separate capability-package repo. So this can't be fixed from the Marinara-Engine repo without hand-editing a minified bundle (which the next package update would overwrite). **Where the fix belongs (capability package source):** 1. Make the hierarchical world-map draft request honor the connection's Max Output Tokens instead of the hardcoded value (the issue shows `max_tokens: 10000` truncating a 16-place medium map), or expose a per-request token setting in the GM wizard. 2. Distinguish the failure modes in the error (truncated/invalid JSON vs. wrong structure vs. empty) instead of the generic "could not create a valid map draft." 3. Fix the misleading "You can build one later from Chat Settings" hint (the reporter couldn't find that entry point). Flagging for whoever maintains the hierarchical-maps capability package. Happy to open a PR there if you point me at the source repo.
Author
Owner

@Aculeasis commented on GitHub (Jul 24, 2026):

@SpicyMarinara Alright, this agent is part of https://github.com/Pasta-Devs/Marinara-Agents (https://github.com/Pasta-Devs/Marinara-Agents/tree/main/packages/hierarchical-maps).

the problem is isolated to the Hierarchical Maps capability

Not quite, please take a look at my previous post. Different requests are using different hardcoded parameters.

<!-- gh-comment-id:5067853219 --> @Aculeasis commented on GitHub (Jul 24, 2026): @SpicyMarinara Alright, this agent is part of https://github.com/Pasta-Devs/Marinara-Agents (https://github.com/Pasta-Devs/Marinara-Agents/tree/main/packages/hierarchical-maps). > the problem is isolated to the Hierarchical Maps capability Not quite, please take a look at my previous post. Different requests are using different hardcoded parameters.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 24, 2026):

Fixed in the capability package: Marinara-Agents PR #99 (hierarchical-maps 1.1.8), owned by @SpicyMarinara.

Root cause: the Engine only uses a connection's Max Output Tokens to cap the map-draft request (min(request, override)), never to raise it — and the capability requested small hardcoded per-size budgets (medium 10k), which reasoning models burn on hidden thinking before finishing the JSON. That's why setting 16000 didn't help.

The capability can't read the connection's Max Output Tokens (the host abstraction only exposes chatComplete), so the fix raises the per-size request budgets (small 12k / medium 24k / large 40k). The Engine still caps to the connection's setting, so a higher value now actually takes effect while a lower one is respected. Map-draft errors are also now specific (empty / truncated-JSON with an actionable hint / structure mismatch) instead of the generic message.

Note: the "You can build one later from Chat Settings" wrapper in the popup is Engine-side (game-creation flow), so that discoverability wording is out of scope for the capability PR.

<!-- gh-comment-id:5068215680 --> @SpicyMarinara commented on GitHub (Jul 24, 2026): Fixed in the capability package: **Marinara-Agents PR [#99](https://github.com/Pasta-Devs/Marinara-Agents/pull/99)** (hierarchical-maps 1.1.8), owned by @SpicyMarinara. Root cause: the Engine only uses a connection's Max Output Tokens to *cap* the map-draft request (`min(request, override)`), never to raise it — and the capability requested small hardcoded per-size budgets (medium 10k), which reasoning models burn on hidden thinking before finishing the JSON. That's why setting 16000 didn't help. The capability can't read the connection's Max Output Tokens (the host abstraction only exposes `chatComplete`), so the fix raises the per-size request budgets (small 12k / medium 24k / large 40k). The Engine still caps to the connection's setting, so a higher value now actually takes effect while a lower one is respected. Map-draft errors are also now specific (empty / truncated-JSON with an actionable hint / structure mismatch) instead of the generic message. Note: the "You can build one later from **Chat Settings**" wrapper in the popup is Engine-side (game-creation flow), so that discoverability wording is out of scope for the capability PR.
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#2171
No description provided.