Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(agent_harness_service): read the public static file base from macro_service_urls (#7881)
Wolf Mermelsteinb06250aac2e7
diff --git a/crates/macro_service_urls/src/lib.rs b/crates/macro_service_urls/src/lib.rsindex 30abe7a114..5c821ed2e4 100644--- a/crates/macro_service_urls/src/lib.rs+++ b/crates/macro_service_urls/src/lib.rs@@ -554,6 +554,15 @@ service_url! {dev: "https://static-file-service-dev.macro.com",prod: "https://static-file-service.macro.com",},+ /// Browser-facing static file base that file links are stamped with.+ /// [`StaticFileServiceUrl`] is the address services call; on a local+ /// stack the two differ, since containers reach the service+ /// in-network while browsers go through the frontend proxy.+ pub StaticFilePublicUrl {+ local: "http://localhost:8100",+ dev: "https://static-file-service-dev.macro.com",+ prod: "https://static-file-service.macro.com",+ },/// Agent harness service API URL. Serves the agent-session control/// routes, which run in the process that owns the live sessions.pub AgentHarnessServiceUrl {diff --git a/crates/macro_service_urls/src/test.rs b/crates/macro_service_urls/src/test.rsindex 6e04c24c81..2766b3d7d6 100644--- a/crates/macro_service_urls/src/test.rs+++ b/crates/macro_service_urls/src/test.rs@@ -144,6 +144,11 @@ fn static_file_service_url_parses() {assert_parses_for_all_environments(StaticFileServiceUrl::default_for_environment);}+#[test]+fn static_file_public_url_parses() {+ assert_parses_for_all_environments(StaticFilePublicUrl::default_for_environment);+}+#[test]fn agent_harness_service_url_parses() {assert_parses_for_all_environments(AgentHarnessServiceUrl::default_for_environment);@@ -755,6 +760,10 @@ fn exported_service_url_override_names_are_derived_from_env_var_names() {StaticFileServiceUrl::local().override_env_var_name(),"OVERRIDE_STATIC_FILE_SERVICE_URL",);+ assert_eq!(+ StaticFilePublicUrl::local().override_env_var_name(),+ "OVERRIDE_STATIC_FILE_PUBLIC_URL",+ );assert_eq!(AgentHarnessEgressUrl::local().override_env_var_name(),"OVERRIDE_AGENT_HARNESS_EGRESS_URL",diff --git a/infra/packages/service/src/ecr.ts b/infra/packages/service/src/ecr.tsindex 9594d8d8df..4b9ec3e6f8 100644--- a/infra/packages/service/src/ecr.ts+++ b/infra/packages/service/src/ecr.ts@@ -56,12 +56,14 @@ export class EcrImage extends pulumi.ComponentResource {rules: [{rulePriority: 1,- description: 'remove untagged images older than 1 day',+ // Count, not age: once `latest` moves, the image the previous task+ // definition pins is untagged, and ECS rollbacks and task+ // replacements still need to pull it.+ description: 'keep the 20 most recent untagged images',selection: {tagStatus: 'untagged',- countType: 'sinceImagePushed',- countUnit: 'days',- countNumber: 1,+ countType: 'imageCountMoreThan',+ countNumber: 20,},action: {type: 'expire',diff --git a/infra/stacks/cloud-storage-cache/index.ts b/infra/stacks/cloud-storage-cache/index.tsindex 36de7b590e..dd17b06dca 100644--- a/infra/stacks/cloud-storage-cache/index.ts+++ b/infra/stacks/cloud-storage-cache/index.ts@@ -27,12 +27,14 @@ new aws.ecr.LifecyclePolicy(`${BASE_NAME}-lifecycle-policy`, {rules: [{rulePriority: 1,- description: 'remove untagged images older than 1 day',+ // Count, not age: once `latest` moves, the image the previous task+ // definition pins is untagged, and ECS rollbacks and task+ // replacements still need to pull it.+ description: 'keep the 20 most recent untagged images',selection: {tagStatus: 'untagged',- countType: 'sinceImagePushed',- countUnit: 'days',- countNumber: 1,+ countType: 'imageCountMoreThan',+ countNumber: 20,},action: {type: 'expire',diff --git a/services/agent_harness_service/src/config.rs b/services/agent_harness_service/src/config.rsindex 89b0f5dc31..23cd48f1c1 100644--- a/services/agent_harness_service/src/config.rs+++ b/services/agent_harness_service/src/config.rs@@ -14,8 +14,6 @@ use macro_uuid::Uuid;use secretsmanager_client::LocalOrRemoteSecret;macro_env_var::env_vars!(- /// Browser-facing static file base, read only when using local AWS.- pub struct StaticFileServiceUrl;/// Local static file bucket, read only when using local AWS.pub struct StaticStorageBucket;/// Comma-separated Kafka bootstrap servers.diff --git a/services/agent_harness_service/src/main.rs b/services/agent_harness_service/src/main.rsindex 00e99c3314..8decba4d0f 100644--- a/services/agent_harness_service/src/main.rs+++ b/services/agent_harness_service/src/main.rs@@ -145,7 +145,7 @@ use macro_event_broker::{};use macro_service_urls::{AgentHarnessEgressUrl, ConnectionGatewayUrl, LexicalServiceUrl, McpServiceUrl,- StaticFileServiceUrl,+ StaticFilePublicUrl, StaticFileServiceUrl,};use mcp_client::domain::models::AesKey;use mcp_client::outbound::pg_server_repo::PgServerRepo;@@ -557,7 +557,7 @@ async fn run() -> anyhow::Result<()> {// Normalize uploaded images before any provider sees them. In addition to// making local URLs reachable, this supplies the MIME type Gemini requires// and decodes formats that providers cannot consume directly.- let public_base = url::Url::parse(config::StaticFileServiceUrl::new()?.as_ref())?;+ let public_base = StaticFilePublicUrl::new()?.parse_url()?;let cdn_base = match (&config.environment, macro_aws_config::LocalAwsUrl::new()) {(Environment::Local, Some(local_aws)) => format!("{}/{}",diff --git a/services/static_file_service/src/api.rs b/services/static_file_service/src/api.rsindex 868207b9c6..1e27048a88 100644--- a/services/static_file_service/src/api.rs+++ b/services/static_file_service/src/api.rs@@ -13,6 +13,7 @@ use axum::Router;use axum::extract::DefaultBodyLimit;use macro_auth::middleware::decode_jwt::JwtValidationArgs;use macro_authorization::{InternalAuthConfig, MacroAuthJwtValidator, MacroAuthorizationState};+use macro_service_urls::StaticFilePublicUrl;use std::sync::Arc;use tower_http::limit::RequestBodyLimitLayer;use utoipa::OpenApi;@@ -61,6 +62,7 @@ pub async fn setup_and_serve(storage_client: Arc::new(storage_client),sqs_client,config: Arc::new(config),+ public_url: Arc::new(StaticFilePublicUrl::new()?),authorization_state,};diff --git a/services/static_file_service/src/api/context.rs b/services/static_file_service/src/api/context.rsindex 67469f2c3d..b1f1e01c2e 100644--- a/services/static_file_service/src/api/context.rs+++ b/services/static_file_service/src/api/context.rs@@ -6,6 +6,7 @@ use axum::extract::FromRef;use macro_authorization::{MacroAuthJwtValidator, MacroAuthorizationServiceImpl, MacroAuthorizationState,};+use macro_service_urls::StaticFilePublicUrl;use std::sync::Arc;/// Concrete authorization service used by the `MacroAuthorizationExtractor` in handlers.@@ -17,5 +18,7 @@ pub struct AppState {pub storage_client: Arc<S3Client>,pub sqs_client: Client,pub config: Arc<Config>,+ /// Base that permalinks are stamped with.+ pub public_url: Arc<StaticFilePublicUrl>,pub authorization_state: MacroAuthorizationState<AuthorizationService>,}diff --git a/services/static_file_service/src/api/file/put_presigned_url.rs b/services/static_file_service/src/api/file/put_presigned_url.rsindex 987aee4669..2c95c6c2d5 100644--- a/services/static_file_service/src/api/file/put_presigned_url.rs+++ b/services/static_file_service/src/api/file/put_presigned_url.rs@@ -50,7 +50,7 @@ pub async fn put_presigned_url(let id: String = Uuid::new_v4().to_string();let static_file_key = s3_key::StaticFileKey::new(&id);let s3_key = static_file_key.to_key();- let permalink = format!("{}/{}", ctx.config.static_file_service_url, s3_key);+ let permalink = format!("{}/{}", ctx.public_url, s3_key);let owner_id = user.authorization.user.macro_user_id.as_ref().to_string();diff --git a/services/static_file_service/src/config.rs b/services/static_file_service/src/config.rsindex 4eeafb7bfe..693511514b 100644--- a/services/static_file_service/src/config.rs+++ b/services/static_file_service/src/config.rs@@ -2,7 +2,6 @@ use anyhow::Context;use macro_auth::InternalApiKey;pub use macro_env::Environment;use macro_env_var::env_vars;-use macro_service_urls::StaticFileServiceUrl;env_vars! {pub struct StaticFileServiceDynamodbTableName;@@ -22,9 +21,6 @@ pub struct Config {pub static_file_service_dynamodb_table_name: StaticFileServiceDynamodbTableName,/// s3 storage bucketpub static_storage_bucket: StaticStorageBucket,- /// service url- #[macro_config_default(StaticFileServiceUrl::unwrap_new().to_string())]- pub static_file_service_url: String,/// Internal API keypub internal_api_key: InternalApiKey,}diff --git a/tooling/xtask/crates/xtask_local/src/local/local_env.rs b/tooling/xtask/crates/xtask_local/src/local/local_env.rsindex 228f7840e6..09e5bb3d19 100644--- a/tooling/xtask/crates/xtask_local/src/local/local_env.rs+++ b/tooling/xtask/crates/xtask_local/src/local/local_env.rs@@ -53,9 +53,10 @@ pub struct LocalEnv {frontend_origin: String,/// Browser-facing route to document cognition's MCP OAuth callback.mcp_public_url: String,- /// Browser-facing base the static file service stamps into permalinks.- /// Only the service itself reads `STATIC_FILE_SERVICE_URL`; callers- /// reach it in-network through the `OVERRIDE_` form below. Without this+ /// Browser-facing base the static file service stamps into permalinks+ /// and the agent harness recognizes in them, as+ /// `OVERRIDE_STATIC_FILE_PUBLIC_URL`. Callers reach the service itself+ /// in-network through `OVERRIDE_STATIC_FILE_SERVICE_URL`. Without this/// a named instance mints `http://localhost:8100/file/...`, the/// single-instance CDN port, which nothing on a named instance serves;/// the proxy's `/static-file/*` block is what does.@@ -140,7 +141,7 @@ impl LocalEnv {env.insert("FRONTEND_ORIGIN".into(), self.frontend_origin.clone());env.insert("MCP_PUBLIC_URL".into(), self.mcp_public_url.clone());env.insert(- "STATIC_FILE_SERVICE_URL".into(),+ "OVERRIDE_STATIC_FILE_PUBLIC_URL".into(),self.static_file_public_url.clone(),);// Pipedream's hosted Connect UI refuses to be opened from an origindiff --git a/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs b/tooling/xtask/crates/xtask_local/src/local/local_env/test.rsindex c14fde2d9a..c2051ba6d4 100644--- a/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs+++ b/tooling/xtask/crates/xtask_local/src/local/local_env/test.rs@@ -303,7 +303,7 @@ fn emits_in_network_service_url_overrides() {fn static_file_permalinks_go_through_the_instance_proxy() {let env = local_env();let permalink_base = env- .get("STATIC_FILE_SERVICE_URL")+ .get("OVERRIDE_STATIC_FILE_PUBLIC_URL").expect("static file permalink base");assert!(permalink_base.starts_with("https://localhost:"),@@ -504,7 +504,7 @@ fn frontend_origin_tracks_how_the_app_is_served() {}assert_eq!(env["MCP_PUBLIC_URL"], format!("{origin}/cognition"));assert_eq!(- env["STATIC_FILE_SERVICE_URL"],+ env["OVERRIDE_STATIC_FILE_PUBLIC_URL"],format!("{origin}/static-file"));assert!(