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
feat(agent_harness_service): migrate agent harness service to gateway (#6155)
Will Hutchinson6401339c2969
diff --git a/Cargo.lock b/Cargo.lockindex 9bbee1e59b..ced8affb89 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -335,6 +335,7 @@ dependencies = ["sqlx","tokio","tokio-util",+ "tower 0.5.3","tracing","url","utoipa",diff --git a/apps/docs/AI/bring-your-own.mdx b/apps/docs/AI/bring-your-own.mdxindex 772bbb1764..b3a87a0f26 100644--- a/apps/docs/AI/bring-your-own.mdx+++ b/apps/docs/AI/bring-your-own.mdx@@ -74,7 +74,7 @@ You need:```toml[macro]- api_url = "https://agent-harness.macro.com"+ api_url = "https://gateway.macro.com/agent-harness"storage_url = "https://gateway.macro.com/dss"[identity]diff --git a/apps/web/scripts/services.ts b/apps/web/scripts/services.tsindex daed0c089f..6210f79b86 100644--- a/apps/web/scripts/services.ts+++ b/apps/web/scripts/services.ts@@ -74,8 +74,8 @@ export const services: Service[] = [},{name: "agent-harness",- dev: "https://agent-harness-dev.macro.com/api-doc/openapi.json",- prod: "https://agent-harness.macro.com/api-doc/openapi.json",+ dev: "https://dev-gateway.macro.com/agent-harness/api-doc/openapi.json",+ prod: "https://gateway.macro.com/agent-harness/api-doc/openapi.json",local: "http://localhost:8101/api-doc/openapi.json",output: "../src/lib/service-clients/service-agent-harness/",orvalKey: "agentHarnessService",diff --git a/apps/web/src/lib/core/constant/servers.ts b/apps/web/src/lib/core/constant/servers.tsindex 306a56bfb5..da3bbb0b49 100644--- a/apps/web/src/lib/core/constant/servers.ts+++ b/apps/web/src/lib/core/constant/servers.ts@@ -43,7 +43,7 @@ const serverHostRemote = {'email-service': `https://email-service${devServerSuffix}.macro.com`,'image-proxy-service': `${gatewayHost}/image-proxy`,'scheduled-action': `https://agent-schedule${devServerSuffix}.macro.com`,- 'agent-harness': `https://agent-harness${devServerSuffix}.macro.com`,+ 'agent-harness': `${gatewayHost}/agent-harness`,} as const;type Servers = Record<keyof typeof serverHostRemote, string>;diff --git a/crates/macro_service_urls/src/lib.rs b/crates/macro_service_urls/src/lib.rsindex 55bb759acd..1379463b68 100644--- a/crates/macro_service_urls/src/lib.rs+++ b/crates/macro_service_urls/src/lib.rs@@ -552,8 +552,8 @@ service_url! {/// routes, which run in the process that owns the live sessions.pub AgentHarnessServiceUrl {local: "http://localhost:8101",- dev: "https://agent-harness-dev.macro.com",- prod: "https://agent-harness.macro.com",+ dev: "https://dev-gateway.macro.com/agent-harness",+ prod: "https://gateway.macro.com/agent-harness",},/// Link unfurl service API URL.pub UnfurlServiceUrl {diff --git a/crates/macro_service_urls/src/test.rs b/crates/macro_service_urls/src/test.rsindex 22059c4850..8d258566c0 100644--- a/crates/macro_service_urls/src/test.rs+++ b/crates/macro_service_urls/src/test.rs@@ -89,6 +89,23 @@ fn static_file_service_url_parses() {assert_parses_for_all_environments(StaticFileServiceUrl::default_for_environment);}+#[test]+fn agent_harness_service_url_parses() {+ assert_parses_for_all_environments(AgentHarnessServiceUrl::default_for_environment);+}++#[test]+fn agent_harness_service_url_has_no_trailing_slash() {+ for environment in ENVS {+ let url = AgentHarnessServiceUrl::default_for_environment(environment);+ assert!(+ !url.as_ref().ends_with('/'),+ "clients concatenate paths, so {} must not end with /",+ url.as_ref()+ );+ }+}+#[test]fn unfurl_service_url_parses() {assert_parses_for_all_environments(UnfurlServiceUrl::default_for_environment);@@ -391,6 +408,10 @@ fn exported_service_urls_match_dev_values() {service_urls.static_file_service_url.as_ref(),"https://static-file-service-dev.macro.com",);+ assert_eq!(+ service_urls.agent_harness_service_url.as_ref(),+ "https://dev-gateway.macro.com/agent-harness",+ );assert_eq!(service_urls.unfurl_service_url.as_ref(),"https://dev-gateway.macro.com/unfurl",@@ -454,6 +475,10 @@ fn exported_service_urls_match_prod_values() {service_urls.static_file_service_url.as_ref(),"https://static-file-service.macro.com",);+ assert_eq!(+ service_urls.agent_harness_service_url.as_ref(),+ "https://gateway.macro.com/agent-harness",+ );assert_eq!(service_urls.unfurl_service_url.as_ref(),"https://gateway.macro.com/unfurl",diff --git a/infra/packages/shared/src/gateway_priorities.ts b/infra/packages/shared/src/gateway_priorities.tsindex 960800db9e..a36b36f89a 100644--- a/infra/packages/shared/src/gateway_priorities.ts+++ b/infra/packages/shared/src/gateway_priorities.ts@@ -10,6 +10,7 @@ export enum GatewayService {CONTACTS_SERVICE = 'CONTACTS_SERVICE',SEARCH_PROCESSING_SERVICE = 'SEARCH_PROCESSING_SERVICE',IMAGE_PROXY_SERVICE = 'IMAGE_PROXY_SERVICE',+ AGENT_HARNESS_SERVICE = 'AGENT_HARNESS_SERVICE',}/**@@ -28,6 +29,7 @@ export const GATEWAY_PRIORITIES: GatewayPriorityMap = {[GatewayService.CONTACTS_SERVICE]: 40,[GatewayService.SEARCH_PROCESSING_SERVICE]: 50,[GatewayService.IMAGE_PROXY_SERVICE]: 60,+ [GatewayService.AGENT_HARNESS_SERVICE]: 70,[GatewayService.CONVERT_SERVICE]: 3000,};diff --git a/infra/packages/shared/src/service_urls.ts b/infra/packages/shared/src/service_urls.tsindex 8fcc0e740c..44699428a1 100644--- a/infra/packages/shared/src/service_urls.ts+++ b/infra/packages/shared/src/service_urls.ts@@ -14,6 +14,7 @@ export enum ServiceUrl {DOCUMENT_COGNITION_SERVICE_URL = 'DOCUMENT_COGNITION_SERVICE_URL',LEXICAL_SERVICE_URL = 'LEXICAL_SERVICE_URL',UNFURL_SERVICE_URL = 'UNFURL_SERVICE_URL',+ AGENT_HARNESS_SERVICE_URL = 'AGENT_HARNESS_SERVICE_URL',}/**@@ -44,6 +45,8 @@ const DEV_SERVICE_URLS: ServiceUrlMap = {[ServiceUrl.LEXICAL_SERVICE_URL]:'https://lexical-service-dev.macroverse.workers.dev',[ServiceUrl.UNFURL_SERVICE_URL]: 'https://dev-gateway.macro.com/unfurl',+ [ServiceUrl.AGENT_HARNESS_SERVICE_URL]:+ 'https://dev-gateway.macro.com/agent-harness',};/**@@ -64,6 +67,8 @@ const PROD_SERVICE_URLS: ServiceUrlMap = {[ServiceUrl.LEXICAL_SERVICE_URL]:'https://lexical-service-prod.macroverse.workers.dev',[ServiceUrl.UNFURL_SERVICE_URL]: 'https://gateway.macro.com/unfurl',+ [ServiceUrl.AGENT_HARNESS_SERVICE_URL]:+ 'https://gateway.macro.com/agent-harness',};/**diff --git a/infra/stacks/agent-harness-service/agent_harness_service.ts b/infra/stacks/agent-harness-service/agent_harness_service.tsindex 8e89628c2e..b39f2ee6da 100644--- a/infra/stacks/agent-harness-service/agent_harness_service.ts+++ b/infra/stacks/agent-harness-service/agent_harness_service.ts@@ -15,10 +15,14 @@ import {BASE_DOMAIN,CLOUD_TRAIL_SNS_TOPIC_ARN,DopplerEcsEnvironment,+ getGatewayAlb,getKafkaClusterPolicy,+ GatewayService,stack,} from '../../packages/shared';+const gatewayLoadBalancer = getGatewayAlb();+const BASE_NAME = pulumi.getProject();const REPO_ROOT = '../../..';@@ -261,6 +265,22 @@ export class AgentHarnessService extends pulumi.ComponentResource {this.serviceAlbSg = serviceAlbSg;this.serviceSg = serviceSg;+ const gatewayTargetGroup = new ServiceTargetGroup(+ `${stack}-${BASE_NAME}`,+ {+ tags: this.tags,+ listenerArn: gatewayLoadBalancer.httpsListenerArn,+ vpcId: vpc.vpcId,+ containerPort: serviceContainerPort,+ service: GatewayService.AGENT_HARNESS_SERVICE,+ healthCheckPath,+ pathPatterns: ['/agent-harness', '/agent-harness/*'],+ serviceSecurityGroupId: serviceSg.id,+ albSecurityGroupId: gatewayLoadBalancer.albSecurityGroupId,+ },+ { parent: this }+ );+const { targetGroup, lb, listener } = serviceLoadBalancer(this, {serviceName: BASE_NAME,serviceContainerPort,@@ -278,11 +298,12 @@ export class AgentHarnessService extends pulumi.ComponentResource {this.lb = lb;this.listener = listener;- // The egress proxy listener, published on the same ALB under its own- // hostname. The default action still forwards to the control API, so- // nothing about the existing surface changes; only requests naming the- // egress host reach the egress port. The component also opens the- // ALB-to-service holes for the egress port.+ // Egress stays host-routed on this dedicated ALB, not the shared+ // gateway. Control API authenticates Macro users; egress authenticates+ // sandbox session tokens on a second container port. Mixing those+ // trust domains onto the gateway (or under `/agent-harness`) would+ // collapse that boundary. This rule's priority 10 is scoped to this+ // listener and does not collide with the gateway's DSS priority 10.// Not `${BASE_NAME}-egress`: with the helper's `-tg` suffix that is 36// chars, and target group names cap at 32.const egress = new ServiceTargetGroup(@@ -338,6 +359,28 @@ export class AgentHarnessService extends pulumi.ComponentResource {// and JWT secrets, so a 0s grace period trips the circuit breaker// before the replacement binds. Ignore those checks until then.healthCheckGracePeriodSeconds: 120,+ // Register the control port in both the dedicated ALB and the+ // gateway target group during cutover. An explicit `loadBalancers`+ // replaces the list awsx derives from `portMappings.targetGroup`,+ // so the legacy control entry and the egress entry must be listed+ // here too.+ loadBalancers: [+ {+ targetGroupArn: targetGroup.arn,+ containerName: 'service',+ containerPort: serviceContainerPort,+ },+ {+ targetGroupArn: gatewayTargetGroup.target_group.arn,+ containerName: 'service',+ containerPort: serviceContainerPort,+ },+ {+ targetGroupArn: this.egressTargetGroup.arn,+ containerName: 'service',+ containerPort: egressContainerPort,+ },+ ],taskDefinitionArgs: {taskRole: {roleArn: this.role.arn,@@ -405,6 +448,10 @@ export class AgentHarnessService extends pulumi.ComponentResource {},{parent: this,+ // ECS refuses a service whose target group is not yet associated+ // with a load balancer; it is the listener rule that creates that+ // association.+ dependsOn: [gatewayTargetGroup.listener_rule],});diff --git a/infra/stacks/agent-harness-service/index.ts b/infra/stacks/agent-harness-service/index.tsindex 0fe1df2561..205802fe07 100644--- a/infra/stacks/agent-harness-service/index.ts+++ b/infra/stacks/agent-harness-service/index.ts@@ -4,6 +4,8 @@ import {config,getAiToolsInfra,getMacroApiToken,+ getServiceUrl,+ ServiceUrl,stack,} from '../../packages/shared';import { get_coparse_api_vpc } from '../../packages/vpc';@@ -119,6 +121,8 @@ const service = new AgentHarnessService(`agent-harness-service-${stack}`, {],});-export const agentHarnessServiceUrl = pulumi.interpolate`${service.domain}`;+export const agentHarnessServiceUrl = getServiceUrl(+ ServiceUrl.AGENT_HARNESS_SERVICE_URL+);export const agentHarnessEgressUrl = pulumi.interpolate`${service.egressDomain}`;export const agentHarnessServiceRoleArn = service.role.arn;diff --git a/packages/sdk/src/config.ts b/packages/sdk/src/config.tsindex 9f684cb8ef..c654d7eede 100644--- a/packages/sdk/src/config.ts+++ b/packages/sdk/src/config.ts@@ -25,7 +25,7 @@ export const WEB_APP_URLS: Record<Env, string> = {export const HOSTS: Record<Env, Record<ServiceName, string>> = {dev: {- 'agent-harness': 'https://agent-harness-dev.macro.com',+ 'agent-harness': 'https://dev-gateway.macro.com/agent-harness',storage: 'https://dev-gateway.macro.com/dss',auth: 'https://auth-service-dev.macro.com',email: 'https://email-service-dev.macro.com',@@ -40,7 +40,7 @@ export const HOSTS: Record<Env, Record<ServiceName, string>> = {unfurl: 'https://dev-gateway.macro.com/unfurl',},prod: {- 'agent-harness': 'https://agent-harness.macro.com',+ 'agent-harness': 'https://gateway.macro.com/agent-harness',storage: 'https://gateway.macro.com/dss',auth: 'https://auth-service.macro.com',email: 'https://email-service.macro.com',diff --git a/services/agent_harness_service/Cargo.toml b/services/agent_harness_service/Cargo.tomlindex ff09fd2a95..aa92aa17cf 100644--- a/services/agent_harness_service/Cargo.toml+++ b/services/agent_harness_service/Cargo.toml@@ -76,6 +76,7 @@ serde = { workspace = true }sqlx = { workspace = true }tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }tokio-util = { workspace = true, features = ["rt"] }+tower = { workspace = true }tracing = { workspace = true }workspace-hack = { version = "0.1", path = "../../crates/workspace-hack" }diff --git a/services/agent_harness_service/src/api.rs b/services/agent_harness_service/src/api.rsindex 8a79d6bd62..932989baea 100644--- a/services/agent_harness_service/src/api.rs+++ b/services/agent_harness_service/src/api.rs@@ -30,6 +30,23 @@ use utoipa_swagger_ui::SwaggerUi;pub mod swagger;+#[cfg(test)]+mod test;++/// Path prefix the shared gateway ALB forwards unmodified. Dual-mounted+/// alongside `/` so the dedicated ALB keeps working during cutover.+const GATEWAY_PATH_PREFIX: &str = "/agent-harness";++fn mount_at_root_and_prefix(inner: Router) -> Router {+ Router::new()+ .merge(inner.clone())+ .nest(GATEWAY_PATH_PREFIX, inner)+}++fn health_router() -> Router {+ Router::new().route("/health", get(health))+}+/// Serve the sandbox-facing egress proxy on its own listener.////// No CORS layer and no Swagger: nothing browses this. Its only client is a@@ -75,7 +92,7 @@ whereAuth: MacroAuthorizationService,Harness: ForwardedCommands,{- let app = api_router(+ let inner = api_router(read_state,control_state,create_state,@@ -83,9 +100,14 @@ whereforward_state,).layer(MacroRequestIdAndTracingLayer::new(Duration::from_millis(200)).into_inner())- .merge(Router::new().route("/health", get(health)))- .layer(macro_cors::cors_layer())- .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()));+ .merge(health_router())+ .layer(macro_cors::cors_layer());+ let app = mount_at_root_and_prefix(inner)+ .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", swagger::ApiDoc::openapi()))+ .merge(SwaggerUi::new("/agent-harness/docs").url(+ "/agent-harness/api-doc/openapi.json",+ swagger::ApiDoc::openapi(),+ ));let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{port}")).awaitdiff --git a/services/agent_harness_service/src/api/test.rs b/services/agent_harness_service/src/api/test.rsnew file mode 100644index 0000000000..cd34517c60--- /dev/null+++ b/services/agent_harness_service/src/api/test.rs@@ -0,0 +1,40 @@+use super::{health_router, mount_at_root_and_prefix};+use axum::{+ body::Body,+ http::{Request, StatusCode},+};+use tower::ServiceExt;++#[tokio::test]+async fn health_is_reachable_at_root_and_gateway_prefix() {+ for path in ["/health", "/agent-harness/health"] {+ let response = mount_at_root_and_prefix(health_router())+ .oneshot(+ Request::builder()+ .uri(path)+ .method("GET")+ .body(Body::empty())+ .unwrap(),+ )+ .await+ .unwrap();++ assert_eq!(response.status(), StatusCode::OK, "{path}");+ }+}++#[tokio::test]+async fn unprefixed_unknown_path_is_not_rewritten_onto_the_prefix() {+ let response = mount_at_root_and_prefix(health_router())+ .oneshot(+ Request::builder()+ .uri("/missing")+ .method("GET")+ .body(Body::empty())+ .unwrap(),+ )+ .await+ .unwrap();++ assert_eq!(response.status(), StatusCode::NOT_FOUND);+}