From 52abe0a21afa8c4c406c8c5e1da2e1714dca7f85 Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Tue, 24 Nov 2026 01:04:43 +0100 Subject: [PATCH] control-plane: the gpt-oss prompt date is a field of the model view, not a process cell (STRA-338) PromptDate was set once by serve into a process OnceLock and read by harmony_prompt::render. It is now ModelView::prompt_date, built from the config in build_state, and prepare_input_tokens hands it to render_prompt/render. The default of a bare AppState is still Utc, as the unset cell was. One process-global exception deleted. --- architecture.json | 1 - control-plane/src/app/state.rs | 3 +++ control-plane/src/responses.rs | 2 +- control-plane/src/responses/harmony_prompt.rs | 18 +++++------------- control-plane/src/responses/intake.rs | 2 +- .../src/responses/intake/intake_stages.rs | 3 ++- control-plane/src/serve/state.rs | 2 +- 7 files changed, 13 insertions(+), 18 deletions(-) diff --git a/architecture.json b/architecture.json index 7fa41e06..5792cd52 100644 --- a/architecture.json +++ b/architecture.json @@ -153,7 +153,6 @@ {"crate": "leleka-gateway-domain", "file": "src/responses/schema.rs", "ratchet": "process-global", "reason": "pure cache: the validity of a tool schema by its compact text, so the dozen schemas of a coding agent are compiled once, not three times per request"}, {"crate": "leleka-gateway-text", "file": "src/prompt/renderer.rs", "ratchet": "process-global", "reason": "the compiled pinned chat template: immutable, built on first use, read by every request"}, {"crate": "leleka-control-plane", "file": "src/request_log.rs", "ratchet": "process-global", "reason": "the process-wide request counters and histograms that /metrics renders; written by every request"}, - {"crate": "leleka-control-plane", "file": "src/responses/harmony_prompt.rs", "ratchet": "process-global", "reason": "the gpt-oss prompt date: configuration set once by serve before the first request"}, {"crate": "leleka-control-plane", "file": "src/stage_trace.rs", "ratchet": "process-global", "reason": "diagnostic stage table of the replay harness and STRATA_STAGE_TRACE: one table per process by design"}, {"crate": "leleka-engine-qwen35-cuda", "file": "src/settings/source.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the engine: ProcessEnv is the adapter of the EnvSource port, and Settings parses every variable into typed fields there (S13)"}, {"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_engine/round_tally/serve_rounds.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per traced port call, only when the bring-up trace is on); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"}, diff --git a/control-plane/src/app/state.rs b/control-plane/src/app/state.rs index a12c15c1..a5494986 100644 --- a/control-plane/src/app/state.rs +++ b/control-plane/src/app/state.rs @@ -66,6 +66,8 @@ pub struct ModelView { pub prefix_cache: Arc, /// The engine's memory-governor report: the pressure gate and the numbers behind `GET /v1/status` `memory`. pub memory: Arc, + /// What a gpt-oss system message says about the date (`prompt_date` in the config). + pub prompt_date: crate::responses::PromptDate, } /// Stores and process-wide services. @@ -120,6 +122,7 @@ impl Default for ModelView { vision: None, prefix_cache: Arc::new(Default::default()), memory: Arc::new(Default::default()), + prompt_date: crate::responses::PromptDate::Utc, } } } diff --git a/control-plane/src/responses.rs b/control-plane/src/responses.rs index 047b9545..f95d90d6 100644 --- a/control-plane/src/responses.rs +++ b/control-plane/src/responses.rs @@ -54,7 +54,7 @@ use serde_json::Map; type SharedCodec = Arc; static NEXT_RESPONSE_ID: AtomicU64 = AtomicU64::new(0); mod harmony_prompt; -pub use harmony_prompt::{PromptDate, set_prompt_date}; +pub use harmony_prompt::PromptDate; mod create; pub use create::create; mod errors; diff --git a/control-plane/src/responses/harmony_prompt.rs b/control-plane/src/responses/harmony_prompt.rs index 96dcc0cb..60646946 100644 --- a/control-plane/src/responses/harmony_prompt.rs +++ b/control-plane/src/responses/harmony_prompt.rs @@ -7,7 +7,6 @@ //! developer message; reasoning of earlier turns is not replayed (the template drops it), except for a //! tool-call message where the template keeps it; custom tools are not supported. -use std::sync::OnceLock; use std::time::{SystemTime, UNIX_EPOCH}; pub use leleka_gateway_domain::responses::PromptDate; @@ -19,22 +18,15 @@ use serde_json::Value; use super::CreateRequest; -static PROMPT_DATE: OnceLock = OnceLock::new(); - -/// Choose the date mode for the rest of the process (once, at start; later calls are ignored). -pub fn set_prompt_date(mode: PromptDate) { - let _ = PROMPT_DATE.set(mode); -} - pub(super) fn today() -> String { civil_date(SystemTime::now().duration_since(UNIX_EPOCH).unwrap_or_default().as_secs()) } -/// Render the Harmony prompt for `request` with today's date. The special markers are written as -/// sentinel characters, which the gpt-oss codec turns into the special tokens: text from the client can -/// never forge a marker. -pub(super) fn render(request: &CreateRequest) -> Result { - match PROMPT_DATE.get().unwrap_or(&PromptDate::Utc) { +/// Render the Harmony prompt for `request` with the date `mode` says (the model view's `prompt_date`). The special +/// markers are written as sentinel characters, which the gpt-oss codec turns into the special tokens: text from the +/// client can never forge a marker. +pub(super) fn render(request: &CreateRequest, mode: &PromptDate) -> Result { + match mode { PromptDate::Utc => render_dated(request, Some(&today()), true), PromptDate::Fixed(date) => render_dated(request, Some(date), true), PromptDate::None => render_dated(request, None, true), diff --git a/control-plane/src/responses/intake.rs b/control-plane/src/responses/intake.rs index d91f6da1..158cb990 100644 --- a/control-plane/src/responses/intake.rs +++ b/control-plane/src/responses/intake.rs @@ -90,7 +90,7 @@ pub(super) async fn prepare_input_tokens( encode_images: bool, ) -> Result> { resolve_previous(state, request).await?; - let (prompt, images) = render_prompt(&tokenizer, request)?; + let (prompt, images) = render_prompt(&tokenizer, request, &state.model.prompt_date)?; let (token_ids, prompt) = tokenize_prompt(tokenizer.clone(), prompt).await?; if images.is_empty() || !encode_images { return Ok(Prepared { diff --git a/control-plane/src/responses/intake/intake_stages.rs b/control-plane/src/responses/intake/intake_stages.rs index 31584953..e4178189 100644 --- a/control-plane/src/responses/intake/intake_stages.rs +++ b/control-plane/src/responses/intake/intake_stages.rs @@ -74,13 +74,14 @@ pub(super) async fn resolve_previous(state: &AppState, request: &mut CreateReque pub(super) fn render_prompt( tokenizer: &SharedCodec, request: &CreateRequest, + date: &crate::responses::PromptDate, ) -> Result<(String, Vec), Box> { let rendered = crate::stage_trace::time("render", || match tokenizer.family() { Family::Qwen35 => { let qwen = tokenizer.qwen().ok_or_else(|| "the Qwen family needs the Qwen tokenizer".to_owned())?; render_request(request, qwen.marks()) } - Family::GptOss => harmony_prompt::render(request).map(|prompt| (prompt, Vec::new())), + Family::GptOss => harmony_prompt::render(request, date).map(|prompt| (prompt, Vec::new())), }); rendered.map_err(|message| { refuse(StatusCode::BAD_REQUEST, "invalid_request_error", "invalid_prompt", Some("input"), &message) diff --git a/control-plane/src/serve/state.rs b/control-plane/src/serve/state.rs index 39182390..c7f02f55 100644 --- a/control-plane/src/serve/state.rs +++ b/control-plane/src/serve/state.rs @@ -48,6 +48,7 @@ pub(super) fn build_state(config: &Config, history: ResponseHistory) -> Result