Avoid persisting project trust for projectless directories (#46328)

## Why

Starting a thread in a directory without a project could persist trust and
preapprove project configuration added later.

## What changed

Track whether configuration discovery found no project-root marker, Git checkout,
or project-local `.codex` directory. Skip implicit project trust in `thread/start`
for these directories. Preserve existing trust decisions and permission checks.

## Testing

Add regression coverage for starting a thread with full access, then adding
project configuration and verifying that a read-only thread does not load it or
persist trust. Add loader tests for projectless classification, project markers,
saved trust, managed configuration, and skipped discovery.

GitOrigin-RevId: da490c649d272494f65d4e22da1ebf89f9085477
This commit is contained in:
viyatb-oai authored and copyberry committed 2026-09-18 00:16:50 +00:00
1 parent 5492c2b06e
commit 608e4cc9a1
6 files changed
+267 -5

No files matched your search

+7
View File
@@ -57,6 +57,13 @@ stdio servers. The existing `mcp_2026_07_28` flag still governs eligible other
servers, regardless of whether their names or URLs resemble hosted Apps.
App-server does not persist this selection.
# Project trust
`thread/start` does not persist project trust for a directory where configuration
discovery finds no project-root marker, Git checkout, or project-local `.codex`
directory. Starting a task there does not preapprove project configuration added
later. Existing trust decisions and permission checks for projects are unchanged.
# Thread removal
`thread/archive` and `thread/delete` reject attempts to remove a live internal
@@ -1360,6 +1360,7 @@ impl ThreadRequestProcessor {
if requested_cwd.is_some()
&& config.active_project.trust_level.is_none()
&& !config.config_layer_stack.is_projectless()
&& effective_permissions_trust_project
{
let trust_target = resolve_root_git_project_for_trust(LOCAL_FS.as_ref(), &config.cwd)
@@ -1693,6 +1693,50 @@ async fn thread_start_with_nested_git_cwd_respects_effective_permissions_for_pro
Ok(())
}
#[tokio::test]
async fn thread_start_projectless_does_not_preapprove_later_project_config() -> Result<()> {
let server = create_mock_responses_server_repeating_assistant("Done").await;
let codex_home = TempDir::new()?;
create_config_toml_without_approval_policy(codex_home.path(), &server.uri())?;
let workspace = TempDir::new()?;
let config_path = codex_home.path().join("config.toml");
let config_before = std::fs::read_to_string(&config_path)?;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
.build_initialized()
.await?;
let response = mcp
.start_thread(ThreadStartParams {
cwd: Some(workspace.path().display().to_string()),
sandbox: Some(SandboxMode::DangerFullAccess),
..Default::default()
})
.await?;
assert_eq!(
response.sandbox,
codex_app_server_protocol::SandboxPolicy::DangerFullAccess
);
assert_eq!(std::fs::read_to_string(&config_path)?, config_before);
let project_config_dir = workspace.path().join(".codex");
std::fs::create_dir(&project_config_dir)?;
std::fs::write(
project_config_dir.join("config.toml"),
"model_reasoning_effort = \"high\"\n",
)?;
let response = mcp
.start_thread(ThreadStartParams {
cwd: Some(workspace.path().display().to_string()),
sandbox: Some(SandboxMode::ReadOnly),
..Default::default()
})
.await?;
assert_eq!(response.reasoning_effort, None);
assert_eq!(std::fs::read_to_string(&config_path)?, config_before);
Ok(())
}
#[tokio::test]
async fn thread_start_with_read_only_sandbox_does_not_persist_project_trust() -> Result<()> {
let server = create_mock_responses_server_repeating_assistant("Done").await;
@@ -1701,6 +1745,7 @@ async fn thread_start_with_read_only_sandbox_does_not_persist_project_trust() ->
create_config_toml_without_approval_policy(codex_home.path(), &server.uri())?;
let workspace = TempDir::new()?;
std::fs::create_dir(workspace.path().join(".codex"))?;
let mut mcp = TestAppServer::builder()
.with_codex_home(codex_home.path())
@@ -1728,6 +1773,7 @@ async fn thread_start_preserves_untrusted_project_trust() -> Result<()> {
create_config_toml_without_approval_policy(codex_home.path(), &server.uri())?;
let workspace = TempDir::new()?;
std::fs::create_dir(workspace.path().join(".codex"))?;
let config_path = codex_home.path().join("config.toml");
let workspace_key = workspace.path().display().to_string();
let mut config_toml =