mirror of
https://github.com/openai/codex.git
synced 2026-05-03 21:01:55 +03:00
fix(core) Preserve base_instructions in SessionMeta (#9427)
## Summary This PR consolidates base_instructions onto SessionMeta / SessionConfiguration, so we ensure `base_instructions` is set once per session and should be (mostly) immutable, unless: - overridden by config on resume / fork - sub-agent tasks, like review or collab In a future PR, we should convert all references to `base_instructions` to consistently used the typed struct, so it's less likely that we put other strings there. See #9423. However, this PR is already quite complex, so I'm deferring that to a follow-up. ## Testing - [x] Added a resume test to assert that instructions are preserved. In particular, `resume_switches_models_preserves_base_instructions` fails against main. Existing test coverage thats assert base instructions are preserved across multiple requests in a session: - Manual compact keeps baseline instructions: core/tests/suite/compact.rs:199 - Auto-compact keeps baseline instructions: core/tests/suite/compact.rs:1142 - Prompt caching reuses the same instructions across two requests: core/tests/suite/prompt_caching.rs:150 and core/tests/suite/prompt_caching.rs:157 - Prompt caching with explicit expected string across two requests: core/tests/suite/prompt_caching.rs:213 and core/tests/suite/prompt_caching.rs:222 - Resume with model switch keeps original instructions: core/tests/suite/resume.rs:136 - Compact/resume/fork uses request 0 instructions for later expected payloads: core/tests/suite/compact_resume_fork.rs:215
This commit is contained in:
@@ -167,6 +167,23 @@ pub enum ResponseItem {
|
||||
Other,
|
||||
}
|
||||
|
||||
pub const BASE_INSTRUCTIONS_DEFAULT: &str = include_str!("prompts/base_instructions/default.md");
|
||||
|
||||
/// Base instructions for the model in a thread. Corresponds to the `instructions` field in the ResponsesAPI.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema, TS)]
|
||||
#[serde(rename = "base_instructions", rename_all = "snake_case")]
|
||||
pub struct BaseInstructions {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
impl Default for BaseInstructions {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
text: BASE_INSTRUCTIONS_DEFAULT.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Developer-provided guidance that is injected into a turn as a developer role
|
||||
/// message.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema, TS)]
|
||||
|
||||
Reference in New Issue
Block a user