Skip to content

Prevent stop marker from mutating OpenAI-compatible prompts - #842

Open
jxnding wants to merge 1 commit into
mindcraft-bots:developfrom
jxnding:agent/fix-openai-prompt-mutation
Open

Prevent stop marker from mutating OpenAI-compatible prompts#842
jxnding wants to merge 1 commit into
mindcraft-bots:developfrom
jxnding:agent/fix-openai-prompt-mutation

Conversation

@jxnding

@jxnding jxnding commented Aug 18, 2026

Copy link
Copy Markdown

Summary

  • avoid mutating caller-owned chat turns while formatting GPT requests
  • apply stop-marker prompt shaping only to the OpenAI Responses API path
  • add regression coverage for custom OpenAI-compatible and Responses requests

Root cause

sendRequest previously ran strictFormat(turns) and appended stop_seq before choosing an API path. Both operations mutate the message objects. When a custom URL selected chat.completions, that branch reused the same turns, so the stop marker was sent inside the prompt as well as in the stop request option.

Some OpenAI-compatible servers can interpret a stop marker already present in the prompt as an immediate stop and return an empty completion. The mutation also leaked back into Mindcraft's conversation history and could accumulate across retries.

Fix

Clone messages before passing them to strictFormat, and append the prompt stop marker only in the Responses API branch. Custom endpoints continue to receive the existing stop option, while their message content remains clean.

Validation

  • npm test on Node 18.20.8, 20.20.2, and 22.23.2
  • two regression tests covering custom endpoint payloads, caller immutability, Responses prompt shaping, and output truncation
  • manually reproduced the empty response with a llama.cpp OpenAI-compatible endpoint before the fix and confirmed a non-empty response afterward

@jxnding
jxnding marked this pull request as ready for review August 18, 2026 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant