mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Enforce filesystem permissions when loading AGENTS.md (#39653)
## Why Project instructions must respect the selected environment's filesystem read permissions. Tightening those permissions for a later turn must not allow previously cached instructions to reach the model. ## What changed - Apply each environment's filesystem sandbox while discovering and reading `AGENTS.md` files. - Fail thread or turn setup when sandboxing blocks a discovered instruction file, while allowing a restricted project with no instructions to start. - Clear cached instructions before refresh and include the Windows sandbox level in the cache key. - Ignore inaccessible ancestor marker probes so readable instructions in the selected working directory can still load. ## Testing Added coverage for restricted projects, denied instruction files, cache invalidation after permissions tighten, and unreadable ancestor markers. GitOrigin-RevId: 6ea1a27b9c873a6260e4f87d42ae1317a6a4ae4b
This commit is contained in:
1 parent
ab82cddd04
commit
7ece061767
12 files changed
+407
-60
No files matched your search
@@ -3,7 +3,9 @@ use crate::agents_md::load_project_instructions;
|
||||
use crate::config::Config;
|
||||
use crate::environment_selection::TurnEnvironmentSnapshot;
|
||||
use codex_extension_api::UserInstructions;
|
||||
use codex_protocol::config_types::WindowsSandboxLevel;
|
||||
use codex_protocol::protocol::TurnEnvironmentSelection;
|
||||
use std::io;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@@ -16,6 +18,7 @@ pub(crate) struct AgentsMdManager {
|
||||
#[derive(Default)]
|
||||
struct AgentsMdCache {
|
||||
selections: Option<Vec<TurnEnvironmentSelection>>,
|
||||
windows_sandbox_level: Option<WindowsSandboxLevel>,
|
||||
loaded: Option<Arc<LoadedAgentsMd>>,
|
||||
}
|
||||
|
||||
@@ -29,19 +32,41 @@ impl AgentsMdManager {
|
||||
}
|
||||
|
||||
#[tracing::instrument(name = "agents_md.refresh", skip_all)]
|
||||
pub(crate) async fn refresh(&self, config: &Config, environments: &TurnEnvironmentSnapshot) {
|
||||
let selections = environments.to_selections();
|
||||
if self.cache.lock().await.selections.as_ref() == Some(&selections) {
|
||||
return;
|
||||
pub(crate) async fn refresh(
|
||||
&self,
|
||||
config: &Config,
|
||||
environments: &TurnEnvironmentSnapshot,
|
||||
windows_sandbox_level: WindowsSandboxLevel,
|
||||
) -> io::Result<()> {
|
||||
let selections = environments
|
||||
.turn_environments()
|
||||
.map(|environment| environment.selection.clone())
|
||||
.collect::<Vec<_>>();
|
||||
{
|
||||
let mut cache = self.cache.lock().await;
|
||||
if cache.selections.as_ref() == Some(&selections)
|
||||
&& cache.windows_sandbox_level == Some(windows_sandbox_level)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
cache.selections = None;
|
||||
cache.windows_sandbox_level = None;
|
||||
cache.loaded = None;
|
||||
}
|
||||
|
||||
let loaded =
|
||||
load_project_instructions(config, self.user_instructions.clone(), environments)
|
||||
.await
|
||||
.map(Arc::new);
|
||||
let loaded = load_project_instructions(
|
||||
config,
|
||||
self.user_instructions.clone(),
|
||||
environments,
|
||||
windows_sandbox_level,
|
||||
)
|
||||
.await?
|
||||
.map(Arc::new);
|
||||
let mut cache = self.cache.lock().await;
|
||||
cache.selections = Some(selections);
|
||||
cache.windows_sandbox_level = Some(windows_sandbox_level);
|
||||
cache.loaded = loaded;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) async fn get_loaded(&self) -> Option<Arc<LoadedAgentsMd>> {
|
||||
|
||||
Reference in new issue
Block a user