mirror of
https://github.com/openai/codex.git
synced 2026-11-13 14:46:14 +00:00
Cap project instructions across environments (#37424)
## Why Applying `project_doc_max_bytes` independently to every selected environment allows the total project instruction payload to grow with the number of environments. ## What changed Treat `project_doc_max_bytes` as one shared byte budget. Consume it in selected environment order, truncate the entry that reaches the remaining limit, and skip later environments once the budget is exhausted. Update the configuration descriptions to document the aggregate limit. ## Testing Add unit and integration coverage for partial and exhausted budgets across multiple environments. GitOrigin-RevId: 4664bdf1f23b66986349d503f44cf51560b9024f
This commit is contained in:
1 parent
95c7265e84
commit
85e0661c3b
6 files changed
+110
-24
No files matched your search
@@ -55,17 +55,28 @@ pub(crate) async fn load_project_instructions(
|
||||
environments: &TurnEnvironmentSnapshot,
|
||||
) -> Option<LoadedAgentsMd> {
|
||||
let mut loaded = LoadedAgentsMd::from_user_instructions(user_instructions);
|
||||
let mut remaining = config.project_doc_max_bytes;
|
||||
for turn_environment in environments.turn_environments() {
|
||||
if remaining == 0 {
|
||||
break;
|
||||
}
|
||||
|
||||
let filesystem = turn_environment.environment.get_filesystem();
|
||||
match read_agents_md(
|
||||
config,
|
||||
filesystem.as_ref(),
|
||||
&turn_environment.environment_id,
|
||||
turn_environment.cwd(),
|
||||
remaining,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(Some(docs)) => loaded.entries.extend(docs.entries),
|
||||
Ok(Some(docs)) => {
|
||||
for entry in docs.entries {
|
||||
remaining = remaining.saturating_sub(entry.contents.len());
|
||||
loaded.entries.push(entry);
|
||||
}
|
||||
}
|
||||
Ok(None) => {}
|
||||
Err(e) => {
|
||||
error!(
|
||||
@@ -90,9 +101,8 @@ async fn read_agents_md(
|
||||
fs: &dyn ExecutorFileSystem,
|
||||
environment_id: &str,
|
||||
cwd: &PathUri,
|
||||
max_total: usize,
|
||||
) -> io::Result<Option<LoadedAgentsMd>> {
|
||||
let max_total = config.project_doc_max_bytes;
|
||||
|
||||
if max_total == 0 {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user