Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(codex): a codex session provisions without a repository url (#6458)

Wolf Mermelstein89302bc5d40d
diff --git a/crates/agent_harness/src/domain/ports.rs b/crates/agent_harness/src/domain/ports.rs
index 7953c01628..a58341e93e 100644
--- a/crates/agent_harness/src/domain/ports.rs
+++ b/crates/agent_harness/src/domain/ports.rs
@@ -282,11 +282,18 @@ pub trait SandboxEgressProvisioner: Send + Sync + 'static {
/// [`AgentMcpServers::OwnerConnections`] the owner's enabled apps are
/// advertised; under [`AgentMcpServers::Selected`] exactly the listed
/// apps are, connected or not.
+ ///
+ /// `repo_url` is [`None`] for a session that clones nothing from this
+ /// deployment's repository - a Codex cloud session works in the cloud
+ /// environment's own checkout - and the deployment's configured URL
+ /// otherwise, which is validated here so a session whose git traffic
+ /// could never resolve fails at provisioning rather than at the agent's
+ /// first clone.
fn provision(
&self,
session: AgentSessionId,
owner: &MacroUserIdStr<'static>,
- repo_url: &str,
+ repo_url: Option<&str>,
selection: &AgentMcpServers,
) -> impl Future<Output = Result<ProvisionedEgress>> + Send;
diff --git a/crates/agent_harness/src/domain/service/deliver.rs b/crates/agent_harness/src/domain/service/deliver.rs
index 4a56459e77..2399692d2d 100644
--- a/crates/agent_harness/src/domain/service/deliver.rs
+++ b/crates/agent_harness/src/domain/service/deliver.rs
@@ -97,7 +97,7 @@ where
.provision(
session_id,
&session.owner_id,
- session.repo_url.as_deref().unwrap_or_default(),
+ session.repo_url.as_deref(),
&AgentMcpServers::Selected {
servers: Vec::new(),
},
diff --git a/crates/agent_harness/src/domain/service/open.rs b/crates/agent_harness/src/domain/service/open.rs
index ab43060729..51f64ff7b4 100644
--- a/crates/agent_harness/src/domain/service/open.rs
+++ b/crates/agent_harness/src/domain/service/open.rs
@@ -157,6 +157,10 @@ where
};
}
let defaults = self.inner.defaults.for_bot(bot_id);
+ // A Codex cloud session clones nothing here: it works in its cloud
+ // environment's own checkout, so this deployment's repository URL is
+ // neither stored on the row nor validated at provisioning.
+ let repo_url = (kind != AgentKind::CodexCloud).then(|| defaults.repo_url.clone());
let sandbox_size = self
.inner
.sessions
@@ -169,7 +173,12 @@ where
let egress = self
.inner
.egress
- .provision(session_id, &request.owner, &defaults.repo_url, &mcp_servers)
+ .provision(
+ session_id,
+ &request.owner,
+ repo_url.as_deref(),
+ &mcp_servers,
+ )
.await
.map_err(into_session_error)?;
let session = self
@@ -183,7 +192,7 @@ where
originating_message_id: None,
model,
harness,
- repo_url: (kind != AgentKind::CodexCloud).then(|| defaults.repo_url.clone()),
+ repo_url,
// Managed sandboxes run in the path baked into their image.
workspace: agent_session::MANAGED_CONTAINER_WORKSPACE.to_owned(),
sandbox_size,
@@ -331,7 +340,9 @@ where
} = command;
tracing::Span::current().record("agent.session.id", tracing::field::display(session_id));
let defaults = self.defaults.for_bot(bot_id);
- let repo_url = defaults.repo_url.clone();
+ // See the request path: a Codex cloud session has no repository URL
+ // of this deployment's to clone, store, or validate.
+ let repo_url = (runtime.kind != AgentKind::CodexCloud).then(|| defaults.repo_url.clone());
let sandbox_size = self.sessions.user_sandbox_size(&origin.sender).await?;
// Provisioned before the session exists, because the row is what makes
@@ -341,7 +352,12 @@ where
// credentials, so there is nowhere else it could correctly come from.
let egress = self
.egress
- .provision(session_id, &origin.sender, &repo_url, &runtime.mcp_servers)
+ .provision(
+ session_id,
+ &origin.sender,
+ repo_url.as_deref(),
+ &runtime.mcp_servers,
+ )
.await?;
let session = self
@@ -354,7 +370,7 @@ where
originating_message_id: Some(origin.message_id),
model: runtime.model.clone(),
harness: runtime.harness.clone(),
- repo_url: (runtime.kind != AgentKind::CodexCloud).then(|| repo_url.clone()),
+ repo_url,
// Managed sandboxes run in the path baked into their image.
workspace: agent_session::MANAGED_CONTAINER_WORKSPACE.to_owned(),
sandbox_size,
diff --git a/crates/agent_harness/src/outbound/egress.rs b/crates/agent_harness/src/outbound/egress.rs
index 148c1d0293..8728972555 100644
--- a/crates/agent_harness/src/outbound/egress.rs
+++ b/crates/agent_harness/src/outbound/egress.rs
@@ -126,13 +126,16 @@ where
&self,
session: AgentSessionId,
owner: &MacroUserIdStr<'static>,
- repo_url: &str,
+ repo_url: Option<&str>,
selection: &AgentMcpServers,
) -> Result<ProvisionedEgress> {
// Validated even though nothing here uses it: it is the deployment's
// repository URL, and a session whose git traffic could never resolve
// should fail at provisioning rather than at the agent's first clone.
- repo_slug(repo_url)?;
+ // A session that clones nothing has no URL to validate.
+ if let Some(repo_url) = repo_url {
+ repo_slug(repo_url)?;
+ }
let token = SessionToken::mint();
diff --git a/crates/agent_harness/src/outbound/egress/test.rs b/crates/agent_harness/src/outbound/egress/test.rs
index 190ef4beb2..45fe764851 100644
--- a/crates/agent_harness/src/outbound/egress/test.rs
+++ b/crates/agent_harness/src/outbound/egress/test.rs
@@ -97,7 +97,7 @@ async fn lists_enabled_app_slugs_verbatim() {
.provision(
AgentSessionId::new(),
&MacroUserIdStr::try_from_email("[email protected]").expect("a valid user id"),
- "https://github.com/macro-inc/macro",
+ Some("https://github.com/macro-inc/macro"),
&AgentMcpServers::OwnerConnections,
)
.await
@@ -112,6 +112,30 @@ async fn lists_enabled_app_slugs_verbatim() {
assert_eq!(slugs, ["linear", "google_sheets"]);
}
+/// A session that clones nothing from this deployment provisions without a
+/// repository URL: a Codex cloud session works in its cloud environment's own
+/// checkout, and there is no configured URL to hold it to.
+#[tokio::test]
+async fn provisions_a_session_that_has_no_repository_url() {
+ let provisioner = EgressProvisioner::new(
+ Arc::new(FixedConnections(vec![connection("linear", true)])),
+ "https://egress.macro.com",
+ );
+
+ let provisioned = provisioner
+ .provision(
+ AgentSessionId::new(),
+ &MacroUserIdStr::try_from_email("[email protected]").expect("a valid user id"),
+ None,
+ &selected(&[]),
+ )
+ .await
+ .expect("provisioned");
+
+ assert!(provisioned.sandbox.mcp_servers.is_empty());
+ assert!(!provisioned.session_token_hash.is_empty());
+}
+
/// `restore` rebuilds the same environment around a token that already
/// exists: nothing is minted, and the server list is read fresh.
#[tokio::test]
@@ -169,7 +193,7 @@ async fn a_selected_list_is_advertised_regardless_of_connections() {
.provision(
AgentSessionId::new(),
&MacroUserIdStr::try_from_email("[email protected]").expect("a valid user id"),
- "https://github.com/macro-inc/macro",
+ Some("https://github.com/macro-inc/macro"),
&selected(&["notion", "linear", "Not A Slug!"]),
)
.await
@@ -212,7 +236,7 @@ async fn an_empty_selection_offers_nothing_of_the_owners() {
.provision(
AgentSessionId::new(),
&MacroUserIdStr::try_from_email("[email protected]").expect("a valid user id"),
- "https://github.com/macro-inc/macro",
+ Some("https://github.com/macro-inc/macro"),
&selected(&[]),
)
.await
diff --git a/crates/agent_harness/src/testing/helpers/egress.rs b/crates/agent_harness/src/testing/helpers/egress.rs
index 8e51a6866c..6bbe22a382 100644
--- a/crates/agent_harness/src/testing/helpers/egress.rs
+++ b/crates/agent_harness/src/testing/helpers/egress.rs
@@ -11,7 +11,7 @@ use crate::domain::ports::SandboxEgressProvisioner;
/// One recorded provisioning: session, owner, repository URL, and the MCP
/// selection it was asked to advertise.
-pub type RecordedProvisioning = (AgentSessionId, String, String, AgentMcpServers);
+pub type RecordedProvisioning = (AgentSessionId, String, Option<String>, AgentMcpServers);
/// A [`SandboxEgressProvisioner`] that records who it was asked for and hands
/// back a fixed environment. Cloning shares one record.
@@ -43,7 +43,7 @@ impl SandboxEgressProvisioner for EgressProvisionerMock {
&self,
session: AgentSessionId,
owner: &MacroUserIdStr<'static>,
- repo_url: &str,
+ repo_url: Option<&str>,
selection: &AgentMcpServers,
) -> Result<ProvisionedEgress> {
self.provisioned
@@ -52,7 +52,7 @@ impl SandboxEgressProvisioner for EgressProvisionerMock {
.push((
session,
owner.to_string(),
- repo_url.to_owned(),
+ repo_url.map(str::to_owned),
selection.clone(),
));