Skip to content

Studio: keep a local model's built-in system prompt when the date setting is on - #12382

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:date-prompt-keeps-system-prompt
Oct 1, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
NilayYadav:date-prompt-keeps-system-prompt

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

With "Tell the model today's date" on (the default) and no system prompt, local chats sent a system turn holding only the date. Chat templates skip their own default system prompt when a system turn exists, so Qwen2.5, Mistral Small, Magistral, Granite and similar models silently lost it. Qwen2.5 stopped knowing it was Qwen, and Magistral lost its reasoning format instruction.

Now, when there is no system prompt, the date leads the chat's first message as "[Current date: YYYY-MM-DD]", the note Studio already adds when a chat crosses midnight. The template's default renders again, the model still knows the date, and later turns keep reusing the prompt cache. Chats with a system prompt, API key callers and external providers are unchanged.

Studio UI regression check

Base 6f70f901e vs head da53ab434. Functional: NO_REGRESSION, UI coverage 64%, 10 visual change(s), 6 text-only change(s). Only steps whose screenshots differ are shown.

The settings and load pairs differ only in the context meter on an empty chat: base priced the date-only system turn (4 / 2.0k), head shows - / 2.0k, as Studio already does with the date setting off. The compaction chat pairs differ in the model's reply text.

inference_settings/load_2048: | reproduced on confirm (VISUAL_DIFF)
inference_settings/load_2048

inference_settings/open_settings: | reproduced on confirm (VISUAL_DIFF)
inference_settings/open_settings

inference_settings/reapply_4096: | reproduced on confirm (VISUAL_DIFF)
inference_settings/reapply_4096

inference_settings/custom_sampling: | reproduced on confirm (VISUAL_DIFF)
inference_settings/custom_sampling

inference_settings/save_preset: | reproduced on confirm (VISUAL_DIFF)
inference_settings/save_preset

parallel/load_parallel: | reproduced on confirm (VISUAL_DIFF)
parallel/load_parallel

compaction/load_2048: | reproduced on confirm (VISUAL_DIFF)
compaction/load_2048

compaction/ui_settings: | reproduced on confirm (VISUAL_DIFF)
compaction/ui_settings

compaction/ui_compacted: masks cover 281% of the shot | reproduced on confirm (VISUAL_DIFF)
compaction/ui_compacted

compaction/ui_answer_after: masks cover 282% of the shot | reproduced on confirm (VISUAL_DIFF)
Facts: mentions_flappy: {'before': False, 'after': True}
compaction/ui_answer_after

Step Text / structure change
compaction/seed_history {'removed': ['28 / 2.0k', '#ctrl button:Context usage: 28 of 2.0k tokens'], 'added': ['- / 2.0k', '#ctrl button:Context window: 2.0k tokens, usage not counted y
compaction/api_compacts {'removed': ['28 / 2.0k', '#ctrl button:Context usage: 28 of 2.0k tokens'], 'added': ['- / 2.0k', '#ctrl button:Context window: 2.0k tokens, usage not counted y
compaction/over_window_compacts {'removed': ['28 / 2.0k', '#ctrl button:Context usage: 28 of 2.0k tokens'], 'added': ['- / 2.0k', '#ctrl button:Context window: 2.0k tokens, usage not counted y
compaction/api_refuses_when_off {'removed': ['28 / 2.0k', '#ctrl button:Context usage: 28 of 2.0k tokens'], 'added': ['- / 2.0k', '#ctrl button:Context window: 2.0k tokens, usage not counted y
compaction/api_short_not_compacted {'removed': ['28 / 2.0k', '#ctrl button:Context usage: 28 of 2.0k tokens'], 'added': ['- / 2.0k', '#ctrl button:Context window: 2.0k tokens, usage not counted y
crawl/r_projects

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review coverage

Mirror: NilayYadav#247 (base = merge base 6f70f901, head = this PR).

Reviewed commit: 47e355e3cbd73da2db83d1fec6611de60686c9d9 (the PR as submitted). One round, one item.

# Item Verdict
1 P2 studio/backend/routes/inference.py:6385 "Refresh stale date notes instead of accepting them": a first user message that already starts with [Current date: ...] is left as is False positive. The note is added server side per request and is never stored or sent back by the Studio client, and API key callers are gated before this point, so a stale note only reaches this line if a user types one by hand at the start of their own message.

Not covered by this round:

  • The follow-up commit 03773846ba pushed during review (keeps the date note when context compaction evicts the first turn). It was verified by hand on Modal and with the backend tests, but has not had its own Codex pass yet.
  • Runtime behaviour in general: the round is a static read of the diff. The by-hand reproduction (Qwen2.5 GGUF on Modal, main vs PR) is in the evidence comment.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review + reproduction evidence

Pinned review: 03773846ba (PR head 47e355e3 plus one fix pushed during review: keep the date note when context compaction evicts the first turn).

I reproduced the default chat (no system prompt, "Tell the model today's date" on) on fresh upstream main with Qwen2.5-0.5B-Instruct GGUF Q4_K_M, Studio installed with install.sh --local on Modal (Linux, CPU), Chromium 1440x900, Temperature 0 in Run settings:

  • main e477badf: "Who created you?" -> "I am a computer program created by Microsoft." The date-only system turn replaces Qwen's built-in "You are Qwen, created by Alibaba Cloud" prompt. Context meter 80 / 4.1k.
  • PR on main (e477badf + this branch): "I am a text-based AI created by Alibaba Cloud, and I was created by Alibaba Cloud." The model still answers today's date (2026-10-01). Context meter 106 / 4.1k.

PR 12382 before/after

Same flow through the API the web app calls (temperature 0, seed 0):

case main PR
no system prompt, "Who created you?" Microsoft, 38 prompt tokens Qwen / Alibaba Cloud, 54
no system prompt, "today's date?" 2026-09-30 2026-09-30
count_tokens vs completion prompt 38 / 38 54 / 54
system prompt set Microsoft, 44 identical, 44
date setting off Qwen, 38, date 2023-04-01 identical
sk-unsloth API key Qwen, 38, date 2023-04-01 identical

Fix pushed during review (03773846ba): the date now rides on the first user turn, which context compaction evicts first. On the PR as submitted, a 1024-token GGUF chat with context_overflow: truncate_oldest (what the web app sends) answered "2023-01-01" to "What is today's date?" after 12 long turns on the same day; main answered "2026-09-30". With the fix the note moves to the oldest kept user turn and the same flow answers "2026-09-30" (long and short first message both checked). Regression test: test_an_evicted_first_turn_hands_its_date_note_to_the_oldest_kept_turn.

  • Midnight: a thread started at 23:42 UTC and continued at 00:01 UTC answered 2026-10-01; the first message of an older empty thread got exactly one date note (64 tokens, same as a fresh chat).
  • Backend tests on Modal: the PR's four new or changed tests fail on main and pass on the branch (DISCRIMINATING); 1499 other tests unchanged.
  • Not on a hot path: one extra regex match per request, no change to prompt cache reuse between turns of a thread.

Conclusion: the bug is real on main and fixed by this PR; with the compaction fix above I found no remaining blocking issue. Not run here: Windows and macOS by hand, MLX, and templates whose default system prompt carries its own clock date (Mistral Small 3.x, Granite 3.x), which will now show both that date and the Studio note.

@NilayYadav NilayYadav left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex review coverage, round 2

Mirror: NilayYadav#247. Reviewed commit: 03773846ba (the compaction fix).

# Item Verdict
1 P2 studio/backend/core/inference/llama_cpp.py:417 "Recount after transferring the date note": the note was added after the fit measured the prompt, so prompt_tokens_after was stale and a tight fit could end up over target Genuine, fixed in edf23f8c9c: the fit is recounted after the note moves, prompt_tokens_after is updated, and the note is put back if it would push the prompt past the target. Tests: test_an_evicted_first_turn_hands_its_date_note_to_the_oldest_kept_turn, test_a_date_note_that_would_overflow_the_fit_is_not_moved.

Not covered: edf23f8c9c itself has not had a Codex pass (single round requested). ce291e35 is the pre-commit formatting commit only.

@danielhanchen

Copy link
Copy Markdown
Member

Review record for #12382, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#276.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror dee3fb6bc (this PR's da53ab434)

chatgpt-codex-connector[bot] on studio/backend/routes/inference.py (on the mirror)

@@ -6426,6 +6439,9 @@ def _apply_current_date_prompt(
     Kept ahead of the user's own text so a system prompt that ends in an instruction still reads
     as the last word to the model.
     """
+    # a system turn would displace the chat template's default one; the user-turn note carries it.
+    if not system_prompt and (request is None or _wants_current_date(request)):
+        return system_prompt

P2 Badge Preserve the date for media-only local prompts

When the date setting is enabled, there is no system prompt, and the only user turn is blank or image-only, this early return removes the previous system-level date carrier, while _append_current_date_note deliberately leaves media-only turns unchanged to preserve their implicit describe/transcribe instruction. The resulting local request therefore contains no date at all; on a later-day media-only follow-up it can likewise retain only the stale start date. Keep a date carrier for these turns without replacing the backend's implicit media instruction.

Useful? React with 👍 / 👎.

Rejected on the mirror

Reply from danielhanchen:

Intentional. The only carriers for a text-less image turn are a system turn, which displaces the template's default system prompt (the bug this PR fixes), or text on that turn, which replaces the backend's describe/transcribe default. The date returns on the first turn with text, and a later-day media-only turn keeps only the start date on main as well.

Round 2: reviewed mirror dee3fb6bce (this PR's da53ab434)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: dee3fb6bce

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror dee3fb6bce (this PR's da53ab434).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 1, 2026
@danielhanchen
danielhanchen merged commit 101b2d6 into unslothai:main Oct 1, 2026
47 of 50 checks passed
danielhanchen added a commit that referenced this pull request Oct 1, 2026
* Fix the tests left red on main by #12408, #12382 and #12436

* Trigger version-compat-ci on the trust-gate test and guard every file it runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants