[GH-ISSUE #299] DeepSeek-V4.1 prompt format loses tool associations and later system instructions #110

Closed
opened 2026-10-29 21:20:59 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Gazelle221B on GitHub (Oct 20, 2026).
Original GitHub issue: https://github.com/mw00/project-maya/issues/299

Maya v1.1.17 (8d9a9b5d705049a87da853717cdc59440252de30, current main when checked) does not fully match DeepSeek-V4.1-Flash-1017's reference prompt format. This is an offline rendering/parsing result, independent of model weights or generation quality.

Reference: DeepSeek's encoder and five paired fixtures, pinned at 1bae0e1088993b9b82de08f59de5be5a34e42170 (MIT).

To reproduce the failure offline, use an unmodified checkout at the Maya commit above. Copy the pinned upstream encoding/tests/test_input_{1..5}.json and test_output_{1..5}.txt into fixtures/ (the accompanying branch also includes those unchanged files under serve/fixtures/deepseek_v41). Install Maya's Python test dependencies, then run from that baseline checkout:

python - <<'PY'
import json
from pathlib import Path
from serve.frontend import ChatTemplate, openai_to_messages
template = ChatTemplate(Path('tools/ds4/chat_template.jinja'))
for n in (3, 4):
    raw = json.loads(Path(f'fixtures/test_input_{n}.json').read_text())
    req = {'messages': raw, 'chat_template_kwargs': {'enable_thinking': False}}
    messages, tools, kwargs = openai_to_messages(req)
    actual = template.render(messages, tools=tools, **kwargs).encode('utf-8')
    expected = Path(f'fixtures/test_output_{n}.txt').read_bytes()
    offset = next((i for i, (a, b) in enumerate(zip(expected, actual)) if a != b), min(len(expected), len(actual)))
    print(n, 'reference/Maya bytes:', len(expected), len(actual), 'first differing byte:', offset)
PY

Expected output: test 3 has 2481/608 bytes and first differs at byte 100; test 4 has 574/506 bytes and first differs at byte 145. On the accompanying fix branch, run the full offline regression suite instead:

python -m unittest serve.test_ds41_conformance -v

The regression tests send the original message metadata through Maya's API adapter and renderer, request the fixture's thinking mode (the reference defaults unspecified modes to chat), and compare UTF-8 bytes against the supplied TXT outputs. Neither reproduction needs a server, network or GPU once the fixture files and dependencies are present. The pre-fix audit gave:

Fixture Result Reference / Maya UTF-8 bytes
1 identical 2476 / 2476
2 identical 294 / 294
3 differs 2481 / 608
4 differs 574 / 506
5 identical 408 / 408

Fixture 3 first differs at character 56 / UTF-8 byte 100, after 该助手为DeepSeek,由深度求索公司创造。:

Reference: <|latest_reminder|>2026-02-21,星期六,广州,App,中文<|System|>CITATION FORMAT:
Maya:      <|User|>CITATION FORMAT:

The reminder, later system role and that message's tool declarations disappear. Fixture 4 first differs at character 79 / UTF-8 byte 145, after 今天是2025年10月17日,星期五。:

Reference: <|latest_reminder|>2024-11-15,上海市,App,中文<|User|>热海大滚锅
Maya:      <|User|>热海大滚锅

Fixture 4 also loses the later <|action|> marker. Reminder, task and message-local tools are reference extensions; ordinary OpenAI requests need not contain them.

Separate ordinary API probes show why this matters to agents:

  • Parallel calls A/B followed by tool results B/A render results in receipt order because the adapter drops call/result IDs. The reference restores call order, needed because rendered result blocks carry no IDs.
  • Later system/developer messages become user messages.
  • Integer reasoning budgets 1–100 are rejected; existing medium/xhigh compatibility aliases work.
  • DSML string="true" arguments such as 123 become JSON numbers without a schema; schema heuristics can also override string="false".
  • Content-leading newlines and separators between adjacent text blocks are lost. Namespaced tool declarations/calls also differ.

All 48 comparisons of the official fixtures' completed assistant messages passed the existing parser. The parser failures above require targeted examples beyond those fixtures. These findings do not establish a measured generation-quality regression.

Expected: preserve DeepSeek's documented roles, metadata, tool associations, argument types and text while retaining Maya's compatibility aliases and keeping other model families unchanged.

Originally created by @Gazelle221B on GitHub (Oct 20, 2026). Original GitHub issue: https://github.com/mw00/project-maya/issues/299 Maya v1.1.17 (`8d9a9b5d705049a87da853717cdc59440252de30`, current `main` when checked) does not fully match DeepSeek-V4.1-Flash-1017's reference prompt format. This is an offline rendering/parsing result, independent of model weights or generation quality. Reference: DeepSeek's [encoder and five paired fixtures](https://huggingface.co/deepseek-ai/DeepSeek-V4.1-Flash-1017/tree/1bae0e1088993b9b82de08f59de5be5a34e42170/encoding), pinned at `1bae0e1088993b9b82de08f59de5be5a34e42170` (MIT). To reproduce the failure offline, use an unmodified checkout at the Maya commit above. Copy the pinned upstream `encoding/tests/test_input_{1..5}.json` and `test_output_{1..5}.txt` into `fixtures/` (the accompanying branch also includes those unchanged files under `serve/fixtures/deepseek_v41`). Install Maya's Python test dependencies, then run from that baseline checkout: ```sh python - <<'PY' import json from pathlib import Path from serve.frontend import ChatTemplate, openai_to_messages template = ChatTemplate(Path('tools/ds4/chat_template.jinja')) for n in (3, 4): raw = json.loads(Path(f'fixtures/test_input_{n}.json').read_text()) req = {'messages': raw, 'chat_template_kwargs': {'enable_thinking': False}} messages, tools, kwargs = openai_to_messages(req) actual = template.render(messages, tools=tools, **kwargs).encode('utf-8') expected = Path(f'fixtures/test_output_{n}.txt').read_bytes() offset = next((i for i, (a, b) in enumerate(zip(expected, actual)) if a != b), min(len(expected), len(actual))) print(n, 'reference/Maya bytes:', len(expected), len(actual), 'first differing byte:', offset) PY ``` Expected output: test 3 has 2481/608 bytes and first differs at byte 100; test 4 has 574/506 bytes and first differs at byte 145. On the accompanying fix branch, run the full offline regression suite instead: ```sh python -m unittest serve.test_ds41_conformance -v ``` The regression tests send the original message metadata through Maya's API adapter and renderer, request the fixture's thinking mode (the reference defaults unspecified modes to chat), and compare UTF-8 bytes against the supplied TXT outputs. Neither reproduction needs a server, network or GPU once the fixture files and dependencies are present. The pre-fix audit gave: | Fixture | Result | Reference / Maya UTF-8 bytes | | --- | --- | ---: | | 1 | identical | 2476 / 2476 | | 2 | identical | 294 / 294 | | 3 | differs | 2481 / 608 | | 4 | differs | 574 / 506 | | 5 | identical | 408 / 408 | Fixture 3 first differs at character 56 / UTF-8 byte 100, after `该助手为DeepSeek,由深度求索公司创造。`: ```text Reference: <|latest_reminder|>2026-02-21,星期六,广州,App,中文<|System|>CITATION FORMAT: Maya: <|User|>CITATION FORMAT: ``` The reminder, later system role and that message's tool declarations disappear. Fixture 4 first differs at character 79 / UTF-8 byte 145, after `今天是2025年10月17日,星期五。`: ```text Reference: <|latest_reminder|>2024-11-15,上海市,App,中文<|User|>热海大滚锅 Maya: <|User|>热海大滚锅 ``` Fixture 4 also loses the later `<|action|>` marker. Reminder, task and message-local tools are reference extensions; ordinary OpenAI requests need not contain them. Separate ordinary API probes show why this matters to agents: - Parallel calls A/B followed by tool results B/A render results in receipt order because the adapter drops call/result IDs. The reference restores call order, needed because rendered result blocks carry no IDs. - Later system/developer messages become user messages. - Integer reasoning budgets 1–100 are rejected; existing `medium`/`xhigh` compatibility aliases work. - DSML `string="true"` arguments such as `123` become JSON numbers without a schema; schema heuristics can also override `string="false"`. - Content-leading newlines and separators between adjacent text blocks are lost. Namespaced tool declarations/calls also differ. All 48 comparisons of the official fixtures' completed assistant messages passed the existing parser. The parser failures above require targeted examples beyond those fixtures. These findings do not establish a measured generation-quality regression. Expected: preserve DeepSeek's documented roles, metadata, tool associations, argument types and text while retaining Maya's compatibility aliases and keeping other model families unchanged.
Author
Owner

@mw00 commented on GitHub (Oct 20, 2026):

Fixed in v1.1.19 by #300: DeepSeek prompts are now rendered with DeepSeek's reference encoder, so later system messages, message-local tools and parallel tool results with their call ids are kept. Thanks, @Gazelle221B!

<!-- gh-comment-id:6298930774 --> @mw00 commented on GitHub (Oct 20, 2026): Fixed in [v1.1.19](https://github.com/mw00/project-maya/releases/tag/v1.1.19) by #300: DeepSeek prompts are now rendered with DeepSeek's reference encoder, so later system messages, message-local tools and parallel tool results with their call ids are kept. Thanks, @Gazelle221B!
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#110
No description provided.