mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Add a provider for thread-scoped instructions (#44701)
## What changed - Expose `ThreadInstructionsProvider` through `StartThreadOptions`. Load its snapshot at startup and model-request boundaries, composing it after global instructions and before repository instructions. Empty or blank output clears only the thread contribution. - Reject thread instructions exceeding 10,000 estimated tokens independently of the repository instruction budget. Allow host-provided instructions without a filesystem source and rename the shared future type to `LoadInstructionsFuture`. - Retain the provider across warm resumes; require hosts to supply it again for cold resumes and offline forks. Live forks and subagents inherit applied snapshots without inheriting the source thread's provider, including when the parent is unloaded during setup or reload. - Include thread instructions in guardian reviewer inheritance and reuse decisions. ## Testing Add coverage for composition and clearing, refresh within an active turn, size rejection before sampling, cancellation-safe refresh, fork and resume behavior, parent eviction, and reviewer reuse invalidation. GitOrigin-RevId: 7be9a523cbbfd67704067dfd526188dad89a3c88
This commit is contained in:
1 parent
dc55274818
commit
fc948f8c47
21 files changed
+1303
-153
No files matched your search
@@ -418,6 +418,7 @@ fn foreign_agents_md_uses_environment_native_paths() {
|
||||
let source_path = cwd.join("AGENTS.md").expect("AGENTS.md URI");
|
||||
let loaded = LoadedAgentsMd {
|
||||
user_instructions: None,
|
||||
thread_instructions: None,
|
||||
entries: vec![InstructionEntry {
|
||||
contents: "remote instructions".to_string(),
|
||||
provenance: InstructionProvenance::Project {
|
||||
@@ -451,6 +452,7 @@ fn multi_environment_agents_md_renders_mixed_path_conventions() {
|
||||
.expect("Windows AGENTS.md URI");
|
||||
let loaded = LoadedAgentsMd {
|
||||
user_instructions: None,
|
||||
thread_instructions: None,
|
||||
entries: vec![
|
||||
InstructionEntry {
|
||||
contents: "POSIX instructions".to_string(),
|
||||
@@ -509,7 +511,7 @@ async fn make_config(root: &TempDir, limit: usize, instructions: Option<&str>) -
|
||||
|
||||
let user_instructions = instructions.map(|text| Instructions {
|
||||
text: text.to_owned(),
|
||||
source: config.codex_home.join(DEFAULT_AGENTS_MD_FILENAME),
|
||||
source: Some(config.codex_home.join(DEFAULT_AGENTS_MD_FILENAME)),
|
||||
});
|
||||
TestConfig {
|
||||
config,
|
||||
@@ -558,7 +560,7 @@ async fn make_config_with_project_root_markers(
|
||||
config.project_doc_max_bytes = limit;
|
||||
let user_instructions = instructions.map(|text| Instructions {
|
||||
text: text.to_owned(),
|
||||
source: config.codex_home.join(DEFAULT_AGENTS_MD_FILENAME),
|
||||
source: Some(config.codex_home.join(DEFAULT_AGENTS_MD_FILENAME)),
|
||||
});
|
||||
TestConfig {
|
||||
config,
|
||||
@@ -608,6 +610,7 @@ fn empty_loaded_instructions_are_empty() {
|
||||
fn loaded_instructions_with_only_empty_or_whitespace_entries_are_empty() {
|
||||
let empty = LoadedAgentsMd {
|
||||
user_instructions: None,
|
||||
thread_instructions: None,
|
||||
entries: vec![InstructionEntry {
|
||||
contents: String::new(),
|
||||
provenance: InstructionProvenance::Internal,
|
||||
@@ -615,6 +618,7 @@ fn loaded_instructions_with_only_empty_or_whitespace_entries_are_empty() {
|
||||
};
|
||||
let whitespace = LoadedAgentsMd {
|
||||
user_instructions: None,
|
||||
thread_instructions: None,
|
||||
entries: vec![InstructionEntry {
|
||||
contents: " \n\t".to_string(),
|
||||
provenance: InstructionProvenance::Internal,
|
||||
@@ -686,6 +690,7 @@ async fn total_byte_limit_truncates_later_project_docs() {
|
||||
let loaded = load_agents_md(&config).await.expect("project instructions");
|
||||
let expected = LoadedAgentsMd {
|
||||
user_instructions: None,
|
||||
thread_instructions: None,
|
||||
entries: vec![
|
||||
InstructionEntry {
|
||||
contents: "root".to_string(),
|
||||
@@ -1100,16 +1105,16 @@ async fn zero_byte_limit_disables_docs() {
|
||||
);
|
||||
}
|
||||
|
||||
/// When both system instructions and AGENTS.md docs are present the two
|
||||
/// should be concatenated with the separator.
|
||||
/// User instructions precede project docs without consuming their byte budget.
|
||||
#[tokio::test]
|
||||
async fn merges_existing_instructions_with_agents_md() {
|
||||
let tmp = tempfile::tempdir().expect("tempdir");
|
||||
fs::write(tmp.path().join("AGENTS.md"), "proj doc").unwrap();
|
||||
fs::write(tmp.path().join("AGENTS.md"), "proj document").unwrap();
|
||||
|
||||
const INSTRUCTIONS: &str = "base instructions";
|
||||
let limit = "proj doc".len();
|
||||
|
||||
let res = get_user_instructions(&make_config(&tmp, /*limit*/ 4096, Some(INSTRUCTIONS)).await)
|
||||
let res = get_user_instructions(&make_config(&tmp, limit, Some(INSTRUCTIONS)).await)
|
||||
.await
|
||||
.expect("should produce a combined instruction string");
|
||||
|
||||
@@ -1173,11 +1178,13 @@ secondary doc"#,
|
||||
loaded.sources().collect::<Vec<_>>(),
|
||||
vec![
|
||||
PathUri::from_abs_path(
|
||||
&config
|
||||
config
|
||||
.user_instructions
|
||||
.as_ref()
|
||||
.expect("global instructions")
|
||||
.source,
|
||||
.source
|
||||
.as_ref()
|
||||
.expect("global instruction source"),
|
||||
),
|
||||
PathUri::from_abs_path(&primary.path().join("AGENTS.md").abs()),
|
||||
PathUri::from_abs_path(&primary_nested.join("AGENTS.md").abs()),
|
||||
@@ -1376,6 +1383,7 @@ async fn concatenates_root_and_cwd_docs() {
|
||||
let crate_agents = cfg.cwd.join("AGENTS.md");
|
||||
let expected = LoadedAgentsMd {
|
||||
user_instructions: None,
|
||||
thread_instructions: None,
|
||||
entries: vec![
|
||||
InstructionEntry {
|
||||
contents: "root doc".to_string(),
|
||||
@@ -1513,8 +1521,9 @@ async fn instruction_sources_include_global_before_agents_md_docs() {
|
||||
let expected = LoadedAgentsMd {
|
||||
user_instructions: Some(Instructions {
|
||||
text: "global doc".to_string(),
|
||||
source: global_agents.clone(),
|
||||
source: Some(global_agents.clone()),
|
||||
}),
|
||||
thread_instructions: None,
|
||||
entries: vec![InstructionEntry {
|
||||
contents: "project doc".to_string(),
|
||||
provenance: project_provenance(project_agents.clone(), cfg.cwd.clone()),
|
||||
|
||||
Reference in new issue
Block a user