Serialize default thread permissions as a permission profile (#60472)

## What changed

Initialize thread metadata's `sandbox_policy` with a serialized `PermissionProfile::read_only()`, matching the format used by turn contexts and session settings. Remove the legacy `SandboxPolicy` field from `ThreadMetadataBuilder` and redundant rollout metadata defaults.

## Testing

Extend thread-store tests to cover reading the default read-only permission profile from SQLite and accepting both string and serialized legacy `danger-full-access` policies.

GitOrigin-RevId: ec9b88a47799a20529e28ef8ca6f5f7c2c8faf9e
This commit is contained in:
ioanbudea-OAI
2026-11-10 00:06:35 +00:00
committed by copyberry
parent caae161dd0
commit 486c779c37
5 changed files with 55 additions and 46 deletions
+2 -1
View File
@@ -852,7 +852,8 @@ mod tests {
title: String::new(),
name: None,
preview: None,
sandbox_policy: "read-only".to_string(),
sandbox_policy: serde_json::to_string(&PermissionProfile::read_only())
.unwrap_or_default(),
approval_mode: "on-request".to_string(),
tokens_used: 1,
first_user_message: None,
+4 -7
View File
@@ -3,9 +3,9 @@ use chrono::DateTime;
use chrono::Utc;
use codex_protocol::SanitizedGitUrl;
use codex_protocol::ThreadId;
use codex_protocol::models::PermissionProfile;
use codex_protocol::openai_models::ReasoningEffort;
use codex_protocol::protocol::AskForApproval;
use codex_protocol::protocol::SandboxPolicy;
use codex_protocol::protocol::SessionSource;
use codex_protocol::protocol::ThreadHistoryMode;
use codex_protocol::protocol::ThreadSource;
@@ -171,7 +171,7 @@ pub struct ThreadMetadata {
pub name: Option<String>,
/// Best available user-facing preview for discovery and list display.
pub preview: Option<String>,
/// The sandbox policy (stringified enum).
/// Serialized permission profile or legacy sandbox value.
pub sandbox_policy: String,
/// The approval mode (stringified enum).
pub approval_mode: String,
@@ -236,8 +236,6 @@ pub struct ThreadMetadataBuilder {
pub cwd: PathBuf,
/// Version of the CLI that created the thread.
pub cli_version: Option<String>,
/// The sandbox policy.
pub sandbox_policy: SandboxPolicy,
/// The approval mode.
pub approval_mode: AskForApproval,
/// The archive timestamp, if the thread is archived.
@@ -276,7 +274,6 @@ impl ThreadMetadataBuilder {
model_provider: None,
cwd: PathBuf::new(),
cli_version: None,
sandbox_policy: SandboxPolicy::new_read_only_policy(),
approval_mode: AskForApproval::OnRequest,
archived_at: None,
git_sha: None,
@@ -288,7 +285,6 @@ impl ThreadMetadataBuilder {
/// Build canonical thread metadata, filling missing values from defaults.
pub fn build(&self, default_provider: &str) -> ThreadMetadata {
let source = crate::extract::enum_to_string(&self.source);
let sandbox_policy = crate::extract::enum_to_string(&self.sandbox_policy);
let approval_mode = crate::extract::enum_to_string(&self.approval_mode);
let created_at = canonicalize_datetime(self.created_at);
let updated_at = self
@@ -335,7 +331,8 @@ impl ThreadMetadataBuilder {
name: (guardian_review && self.history_mode == ThreadHistoryMode::Paginated)
.then(|| crate::GUARDIAN_THREAD_TITLE.to_string()),
preview: guardian_review.then(|| crate::GUARDIAN_THREAD_PREVIEW.to_string()),
sandbox_policy,
sandbox_policy: serde_json::to_string(&PermissionProfile::read_only())
.unwrap_or_default(),
approval_mode,
tokens_used: 0,
first_user_message: None,
+3 -3
View File
@@ -5,12 +5,12 @@ use chrono::Utc;
#[cfg(test)]
use codex_protocol::ThreadId;
#[cfg(test)]
use codex_protocol::models::PermissionProfile;
#[cfg(test)]
use codex_protocol::openai_models::ReasoningEffort;
#[cfg(test)]
use codex_protocol::protocol::AskForApproval;
#[cfg(test)]
use codex_protocol::protocol::SandboxPolicy;
#[cfg(test)]
use codex_protocol::protocol::ThreadHistoryMode;
#[cfg(test)]
use std::path::Path;
@@ -68,7 +68,7 @@ pub(super) fn test_thread_metadata(
title: String::new(),
name: None,
preview: Some("hello".to_string()),
sandbox_policy: crate::extract::enum_to_string(&SandboxPolicy::new_read_only_policy()),
sandbox_policy: serde_json::to_string(&PermissionProfile::read_only()).unwrap_or_default(),
approval_mode: crate::extract::enum_to_string(&AskForApproval::OnRequest),
tokens_used: 0,
first_user_message: Some("hello".to_string()),