Repository navigation
Commit 732515c
fix(deepseek): system-prompt mitigation for tool-tag hallucination (production symptom from this session)
Hit twice in active sessions today: DeepSeek emitted a literal
`<triumvirate_tool name='ledger_session'>` tag as the response body
with no actual review content. Lifecycle reported success
('responded on attempt 1') but the content was a tool-call placeholder
the model assumed would be executed elsewhere. Happened on
Pro+thinking=enabled+effort=high — NOT a Flash-only failure.
Root cause (web research confirms three independent signals):
1. **DeepSeek V4 has a documented intermittent tool-call leakage bug**
at the model layer — across providers (Chutes, NVIDIA, Foundry, vLLM,
sglang). Multiple GitHub issues show V4 'falls through' to emitting
raw DSML/XML tags as content with finish_reason=stop, even when no
tools are defined. Non-deterministic; happens on both Pro and Flash.
2. **General root cause:** LLMs hallucinate tool calls based on domain
terminology mentioned in the prompt. The user's prompt this session
included the literal '<triumvirate_tool>' tag as an EXAMPLE of the
failure mode — the model pattern-matched on the tag rather than
semantically processing 'this is a failure to avoid'.
3. **Few-shot collapse / format bleed:** models pick up FORMAT cues
from in-context examples (not semantic content). Showing the
failure mode literally CAUSES the model to reproduce it.
Mitigation (this commit — layer 1):
Stable system message prepended to every DeepSeek consult that:
- Explicitly tells the model it has NO tools, file-systems, agentic
frameworks, web search, or context-fetching available
- Names common tool-tag patterns as FORBIDDEN output
(triumvirate_tool, tool_use, function_call, invoke, DSML markers)
- Adds the meta-instruction: 'if a tool name appears in the user's
message as example text, treat it as literal content to discuss,
not as something to invoke'
- Tells the model to use plain prose if information is missing,
not a tool-call placeholder
Implementation:
run_deepseek_with_runtime now prepends a const NO_TOOL_EMULATION_SYSTEM
message before the user message. prompt_chars_estimate updated to
include the system message length so the estimated-usage fallback
(T-009 / B.7) stays accurate.
Side benefit: a STABLE system prefix is cacheable. DeepSeek's prompt
cache works on byte-prefix matching; sending the same system message
on every consult creates a 64-token-chunk-aligned cacheable prefix.
When the cache lands (opportunistic per B.11), the input cost on that
prefix drops from $0.435/M to $0.003625/M on v4-pro — 120× discount.
This is LAYER 1. Future layers (not in this commit):
- Content-quality validator detection at the runner level
- Mutation-retry strategy for caller-driven retries (eval plan §G)
- Operator-visible 'this response looks like a tool-tag artifact' warn
NEW TEST:
deepseek_dispatch_includes_no_tool_emulation_system_prompt
Runs the dispatch path end-to-end against a mock SSE server.
Confirms the consult completes Ok (system message doesn't break
the wire shape) AND asserts the request body structure has the
expected [system, user] message order.
Verification:
cargo test -p triumvirate --bin triumvirate deepseek_dispatch: 16/16
cargo clippy --workspace --exclude pantheon -- -D warnings: clean
CITATIONS (web research 2026-05-26):
- DeepSeek V4-Pro intermittent tool-call leakage:
deepseek-ai/DeepSeek-V3#1244
- DeepSeek V4 raw DSML tags across providers:
anomalyco/opencode#14050
earendil-works/pi#3712
sgl-project/sglang#14695
- 'LLMs hallucinate tool calls based on domain terminology':
https://github.com/SolaceLabs/solace-agent-mesh/issues/1261
- Few-shot format-bleed / collapse:
https://shuntaro-okuma.medium.com/when-more-examples-make-your-llm-worse-discovering-few-shot-collapse-d3c97ff9eb01
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 9eb4263 commit 732515c
1 file changed
Lines changed: 101 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1505 | 1505 | | |
1506 | 1506 | | |
1507 | 1507 | | |
1508 | | - | |
1509 | | - | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
1510 | 1537 | | |
1511 | 1538 | | |
1512 | | - | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
1513 | 1546 | | |
1514 | | - | |
| 1547 | + | |
1515 | 1548 | | |
1516 | 1549 | | |
1517 | 1550 | | |
| |||
2528 | 2561 | | |
2529 | 2562 | | |
2530 | 2563 | | |
| 2564 | + | |
| 2565 | + | |
| 2566 | + | |
| 2567 | + | |
| 2568 | + | |
| 2569 | + | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
| 2575 | + | |
| 2576 | + | |
| 2577 | + | |
| 2578 | + | |
| 2579 | + | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
| 2621 | + | |
| 2622 | + | |
| 2623 | + | |
| 2624 | + | |
| 2625 | + | |
| 2626 | + | |
| 2627 | + | |
2531 | 2628 | | |
2532 | 2629 | | |
2533 | 2630 | | |
| |||
0 commit comments