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.
This commit is contained in:
@@ -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"},
|
||||
|
||||
@@ -66,6 +66,8 @@ pub struct ModelView {
|
||||
pub prefix_cache: Arc<crate::prefix_view::PrefixView>,
|
||||
/// The engine's memory-governor report: the pressure gate and the numbers behind `GET /v1/status` `memory`.
|
||||
pub memory: Arc<crate::memory_view::MemoryView>,
|
||||
/// 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ use serde_json::Map;
|
||||
type SharedCodec = Arc<dyn TextCodec>;
|
||||
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;
|
||||
|
||||
@@ -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<PromptDate> = 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<String, String> {
|
||||
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<String, String> {
|
||||
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),
|
||||
|
||||
@@ -90,7 +90,7 @@ pub(super) async fn prepare_input_tokens(
|
||||
encode_images: bool,
|
||||
) -> Result<Prepared, Box<Response>> {
|
||||
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 {
|
||||
|
||||
@@ -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<String>), Box<Response>> {
|
||||
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)
|
||||
|
||||
@@ -48,6 +48,7 @@ pub(super) fn build_state(config: &Config, history: ResponseHistory) -> Result<a
|
||||
model: app::ModelView {
|
||||
name: config.model.clone(),
|
||||
aliases: Arc::new(config.aliases.clone()),
|
||||
prompt_date: config.prompt_date.clone(),
|
||||
..Default::default()
|
||||
},
|
||||
services: services(config, history),
|
||||
@@ -108,7 +109,6 @@ pub(super) fn apply_prompt_settings(config: &Config) {
|
||||
config.prompt_date
|
||||
);
|
||||
}
|
||||
leleka_control_plane::responses::set_prompt_date(config.prompt_date.clone());
|
||||
if config.tool_call_recovery {
|
||||
leleka_control_plane::elog!(
|
||||
"tool_call_recovery is ON (experimental): a declared tool's call written in a drifted form is run as \
|
||||
|
||||
Reference in New Issue
Block a user