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:
vkg-oai authored and copyberry committed 2026-09-11 01:57:54 +00:00
1 parent dc55274818
commit fc948f8c47
21 files changed
+1303 -153

No files matched your search

+3 -3
View File
@@ -4,7 +4,7 @@ use std::sync::Arc;
use std::sync::Mutex;
use codex_extension_api::Instructions;
use codex_extension_api::LoadUserInstructionsFuture;
use codex_extension_api::LoadInstructionsFuture;
use codex_extension_api::LoadedUserInstructions;
use codex_extension_api::UserInstructionsProvider;
use codex_utils_absolute_path::AbsolutePathBuf;
@@ -70,7 +70,7 @@ impl CodexHomeUserInstructionsProvider {
return LoadedUserInstructions {
instructions: Some(Instructions {
text: trimmed.to_string(),
source: path,
source: Some(path),
}),
warnings,
};
@@ -84,7 +84,7 @@ impl CodexHomeUserInstructionsProvider {
}
impl UserInstructionsProvider for CodexHomeUserInstructionsProvider {
fn load_user_instructions(&self) -> LoadUserInstructionsFuture<'_> {
fn load_user_instructions(&self) -> LoadInstructionsFuture<'_> {
Box::pin(async move {
let mut loaded = self.load_from_codex_home().await;
let mut state = self
@@ -27,8 +27,10 @@ fn expected(
LoadedUserInstructions {
instructions: Some(Instructions {
text: text.to_string(),
source: AbsolutePathBuf::try_from(home.path().join(filename))
.expect("absolute source path"),
source: Some(
AbsolutePathBuf::try_from(home.path().join(filename))
.expect("absolute source path"),
),
}),
warnings,
}