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.

feat(agent_schedule_service): migrate agent schedule service to gateway (#6171)

Will Hutchinsond96dbbc6a93e
diff --git a/Cargo.lock b/Cargo.lock
index f0bdab2f4d..29457dcb7e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14109,6 +14109,7 @@ dependencies = [
"sqlx",
"tokio",
"tokio-util",
+ "tower 0.5.3",
"tracing",
"utoipa",
"utoipa-swagger-ui",
diff --git a/apps/web/scripts/services.ts b/apps/web/scripts/services.ts
index 6f1fe2422d..af33fc5d6b 100644
--- a/apps/web/scripts/services.ts
+++ b/apps/web/scripts/services.ts
@@ -106,8 +106,8 @@ export const services: Service[] = [
},
{
name: "scheduled-action",
- dev: "https://scheduled-action-dev.macro.com/api-doc/openapi.json",
- prod: "https://scheduled-action.macro.com/api-doc/openapi.json",
+ dev: "https://dev-gateway.macro.com/scheduled-action/api-doc/openapi.json",
+ prod: "https://gateway.macro.com/scheduled-action/api-doc/openapi.json",
local: "http://localhost:8099/api-doc/openapi.json",
output: "../src/lib/service-clients/service-scheduled-action/",
orvalKey: "scheduledActionService",
diff --git a/apps/web/src/lib/core/constant/servers.ts b/apps/web/src/lib/core/constant/servers.ts
index 8e6e0fc0ca..5a0d7eee82 100644
--- a/apps/web/src/lib/core/constant/servers.ts
+++ b/apps/web/src/lib/core/constant/servers.ts
@@ -12,7 +12,7 @@ const serverHostLocal: Servers = {
contacts: 'http://localhost:8083',
'email-service': 'http://localhost:8087',
'image-proxy-service': 'http://localhost:8097',
- 'scheduled-action': 'http://localhost:8098',
+ 'scheduled-action': 'http://localhost:8099',
'agent-harness': 'http://localhost:8101',
} as const;
@@ -42,7 +42,7 @@ const serverHostRemote = {
contacts: `${gatewayHost}/contacts`,
'email-service': `https://email-service${devServerSuffix}.macro.com`,
'image-proxy-service': `${gatewayHost}/image-proxy`,
- 'scheduled-action': `https://agent-schedule${devServerSuffix}.macro.com`,
+ 'scheduled-action': `${gatewayHost}/scheduled-action`,
'agent-harness': `${gatewayHost}/agent-harness`,
} as const;
@@ -105,7 +105,7 @@ function proxyServers(): Servers | undefined {
contacts: `${proxyOrigin}/contacts`,
'email-service': `${proxyOrigin}/email`,
'image-proxy-service': `${proxyOrigin}/image-proxy`,
- 'scheduled-action': serverHostLocal['scheduled-action'], // no local container
+ 'scheduled-action': `${proxyOrigin}/scheduled-action`,
};
}
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index b5d821a91c..ca5db7ccb7 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -269,6 +269,33 @@ services:
retries: 3
start_period: 10s
+ # ============================================================================
+ # scheduled_action_service (Port 8099)
+ # Scheduled actions API and dispatcher
+ # ============================================================================
+ scheduled_action_service:
+ <<: [*common-env, *rust-services-image]
+ command: ["/app/out/service"]
+ ports:
+ - "8099:8080"
+ environment:
+ OVERRIDE_CONNECTION_GATEWAY_URL: http://connection-gateway:8080
+ depends_on:
+ - postgres
+ - authentication-service
+ - connection_gateway
+ networks:
+ databases:
+ services:
+ aliases:
+ - scheduled-action-service
+ healthcheck:
+ test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
+ interval: 30s
+ timeout: 10s
+ retries: 3
+ start_period: 10s
+
# ============================================================================
# search_processing_service (Port 8092)
# Search indexing worker
diff --git a/infra/packages/shared/src/gateway_priorities.ts b/infra/packages/shared/src/gateway_priorities.ts
index 2fc18f7085..d4fef92c7e 100644
--- a/infra/packages/shared/src/gateway_priorities.ts
+++ b/infra/packages/shared/src/gateway_priorities.ts
@@ -11,6 +11,7 @@ export enum GatewayService {
SEARCH_PROCESSING_SERVICE = 'SEARCH_PROCESSING_SERVICE',
IMAGE_PROXY_SERVICE = 'IMAGE_PROXY_SERVICE',
AGENT_HARNESS_SERVICE = 'AGENT_HARNESS_SERVICE',
+ AGENT_SCHEDULE_SERVICE = 'AGENT_SCHEDULE_SERVICE',
CONNECTION_GATEWAY = 'CONNECTION_GATEWAY',
}
@@ -31,6 +32,7 @@ export const GATEWAY_PRIORITIES: GatewayPriorityMap = {
[GatewayService.SEARCH_PROCESSING_SERVICE]: 50,
[GatewayService.IMAGE_PROXY_SERVICE]: 60,
[GatewayService.AGENT_HARNESS_SERVICE]: 70,
+ [GatewayService.AGENT_SCHEDULE_SERVICE]: 80,
[GatewayService.CONNECTION_GATEWAY]: 90,
[GatewayService.CONVERT_SERVICE]: 3000,
};
diff --git a/infra/stacks/agent-schedule-service/service.ts b/infra/stacks/agent-schedule-service/service.ts
index d7a4a6b983..503235ac65 100644
--- a/infra/stacks/agent-schedule-service/service.ts
+++ b/infra/stacks/agent-schedule-service/service.ts
@@ -8,18 +8,24 @@ import {
datadogAgentContainer,
fargateLogRouterSidecarContainer,
serviceLoadBalancer,
+ ServiceTargetGroup,
} from '../../packages/resources';
import { EcrImage } from '../../packages/service';
import {
BASE_DOMAIN,
CLOUD_TRAIL_SNS_TOPIC_ARN,
DopplerEcsEnvironment,
+ getGatewayAlb,
+ GatewayService,
getKafkaClusterPolicy,
stack,
} from '../../packages/shared';
+const gatewayLoadBalancer = getGatewayAlb();
const BASE_NAME = pulumi.getProject();
const REPO_ROOT = '../../..';
+const GATEWAY_PATH_PREFIX = '/scheduled-action';
+const GATEWAY_DOMAIN_NAME = `${stack === 'prod' ? 'gateway' : 'dev-gateway'}.${BASE_DOMAIN}`;
export const SERVICE_DOMAIN_NAME = `agent-schedule${
stack === 'prod' ? '' : `-${stack}`
@@ -80,7 +86,7 @@ export class AgentScheduleService extends pulumi.ComponentResource {
bucketArns,
} = args;
- this.domain = `https://${SERVICE_DOMAIN_NAME}`;
+ this.domain = `https://${GATEWAY_DOMAIN_NAME}${GATEWAY_PATH_PREFIX}`;
this.cloudStorageClusterName = cloudStorageClusterName;
this.tags = tags;
@@ -205,6 +211,22 @@ export class AgentScheduleService 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_SCHEDULE_SERVICE,
+ healthCheckPath,
+ pathPatterns: [GATEWAY_PATH_PREFIX, `${GATEWAY_PATH_PREFIX}/*`],
+ serviceSecurityGroupId: this.serviceSg.id,
+ albSecurityGroupId: gatewayLoadBalancer.albSecurityGroupId,
+ },
+ { parent: this }
+ );
+
const { targetGroup, lb, listener } = serviceLoadBalancer(this, {
serviceName: BASE_NAME,
serviceContainerPort,
@@ -238,6 +260,18 @@ export class AgentScheduleService extends pulumi.ComponentResource {
enable: true,
rollback: true,
},
+ loadBalancers: [
+ {
+ targetGroupArn: targetGroup.arn,
+ containerName: 'service',
+ containerPort: serviceContainerPort,
+ },
+ {
+ targetGroupArn: gatewayTargetGroup.target_group.arn,
+ containerName: 'service',
+ containerPort: serviceContainerPort,
+ },
+ ],
taskDefinitionArgs: {
taskRole: {
roleArn: this.role.arn,
@@ -297,6 +331,7 @@ export class AgentScheduleService extends pulumi.ComponentResource {
},
{
parent: this,
+ dependsOn: [gatewayTargetGroup.listener_rule],
}
);
diff --git a/nix/cloud-storage.nix b/nix/cloud-storage.nix
index 31fd73eb88..e65567b9ca 100644
--- a/nix/cloud-storage.nix
+++ b/nix/cloud-storage.nix
@@ -517,12 +517,14 @@
localStackDeployServiceNames = [
"agent-harness-service"
+ "agent-schedule-service"
"connection-gateway"
"contacts-service"
"document-cognition-service"
"document-storage-service"
"email-service"
"image-proxy-service"
+ "mcp-server"
"notification-service"
"static-file-service"
"unfurl-service"
diff --git a/packages/sdk/src/config.ts b/packages/sdk/src/config.ts
index 7f884fde26..c45a13242f 100644
--- a/packages/sdk/src/config.ts
+++ b/packages/sdk/src/config.ts
@@ -33,7 +33,7 @@ export const HOSTS: Record<Env, Record<ServiceName, string>> = {
notification: 'https://dev-gateway.macro.com/notification',
properties: 'https://dev-gateway.macro.com/dss',
search: 'https://dev-gateway.macro.com/dss',
- 'scheduled-action': 'https://agent-schedule-dev.macro.com',
+ 'scheduled-action': 'https://dev-gateway.macro.com/scheduled-action',
'static-files': 'https://static-file-service-dev.macro.com',
connection: 'https://dev-gateway.macro.com/connection-gateway',
contacts: 'https://dev-gateway.macro.com/contacts',
@@ -48,7 +48,7 @@ export const HOSTS: Record<Env, Record<ServiceName, string>> = {
notification: 'https://gateway.macro.com/notification',
properties: 'https://gateway.macro.com/dss',
search: 'https://gateway.macro.com/dss',
- 'scheduled-action': 'https://agent-schedule.macro.com',
+ 'scheduled-action': 'https://gateway.macro.com/scheduled-action',
'static-files': 'https://static-file-service.macro.com',
connection: 'https://gateway.macro.com/connection-gateway',
contacts: 'https://gateway.macro.com/contacts',
@@ -63,7 +63,7 @@ export const HOSTS: Record<Env, Record<ServiceName, string>> = {
notification: 'http://localhost:8089',
properties: 'http://localhost:8086',
search: 'http://localhost:8086',
- 'scheduled-action': 'http://localhost:8098',
+ 'scheduled-action': 'http://localhost:8099',
'static-files': 'http://localhost:8100',
connection: 'http://localhost:8082',
contacts: 'http://localhost:8083',
diff --git a/services/scheduled_action/Cargo.toml b/services/scheduled_action/Cargo.toml
index fe7911299f..82d17545d8 100644
--- a/services/scheduled_action/Cargo.toml
+++ b/services/scheduled_action/Cargo.toml
@@ -60,6 +60,7 @@ model_notifications = { path = "../../crates/model_notifications" }
notification = { path = "../../crates/notification" }
utoipa = { workspace = true, features = ["axum_extras", "chrono"] }
utoipa-swagger-ui = { workspace = true }
+tower = { workspace = true }
macro_aws_config = { path = "../../crates/macro_aws_config" }
macro_cors = { path = "../../crates/macro_cors" }
diff --git a/services/scheduled_action/src/bins/service.rs b/services/scheduled_action/src/bins/service.rs
index d7b89ea412..f8ccc92c9f 100644
--- a/services/scheduled_action/src/bins/service.rs
+++ b/services/scheduled_action/src/bins/service.rs
@@ -32,7 +32,11 @@ use tokio_util::{sync::CancellationToken, task::TaskTracker};
use utoipa::OpenApi;
use utoipa_swagger_ui::SwaggerUi;
+#[cfg(test)]
+mod test;
+
const EVENT_BROKER_DRAIN_TIMEOUT: Duration = Duration::from_secs(10);
+const GATEWAY_PATH_PREFIX: &str = "/scheduled-action";
#[tokio::main]
#[tracing::instrument(err)]
@@ -132,9 +136,12 @@ async fn main() -> Result<()> {
let authed_routes = scheduled_action_router::<_, _, ()>(state);
let router = Router::new()
- .route("/health", axum::routing::get(health))
- .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", ApiDoc::openapi()))
- .merge(authed_routes)
+ .merge(mount_at_root_and_prefix(
+ Router::new()
+ .route("/health", axum::routing::get(health))
+ .merge(authed_routes),
+ ))
+ .merge(mount_docs_at_root_and_prefix())
.layer(macro_cors::cors_layer());
let port = config.port;
@@ -171,3 +178,18 @@ async fn main() -> Result<()> {
server_result
}
+
+fn mount_at_root_and_prefix(inner: Router) -> Router {
+ Router::new()
+ .merge(inner.clone())
+ .nest(GATEWAY_PATH_PREFIX, inner)
+}
+
+fn mount_docs_at_root_and_prefix() -> Router {
+ Router::new()
+ .merge(SwaggerUi::new("/docs").url("/api-doc/openapi.json", ApiDoc::openapi()))
+ .merge(SwaggerUi::new(format!("{GATEWAY_PATH_PREFIX}/docs")).url(
+ format!("{GATEWAY_PATH_PREFIX}/api-doc/openapi.json"),
+ ApiDoc::openapi(),
+ ))
+}
diff --git a/services/scheduled_action/src/bins/test.rs b/services/scheduled_action/src/bins/test.rs
new file mode 100644
index 0000000000..1849c6f3f8
--- /dev/null
+++ b/services/scheduled_action/src/bins/test.rs
@@ -0,0 +1,67 @@
+use super::*;
+use axum::{
+ Router,
+ body::Body,
+ http::{Request, StatusCode},
+};
+use tower::ServiceExt;
+
+fn docs_router() -> Router {
+ Router::new()
+ .merge(mount_at_root_and_prefix(
+ Router::new().route("/health", axum::routing::get(health)),
+ ))
+ .merge(mount_docs_at_root_and_prefix())
+}
+
+#[tokio::test]
+async fn openapi_is_served_at_root_and_gateway_prefix() {
+ let app = docs_router();
+
+ for uri in [
+ "/api-doc/openapi.json",
+ "/scheduled-action/api-doc/openapi.json",
+ ] {
+ let response = app
+ .clone()
+ .oneshot(
+ Request::builder()
+ .uri(uri)
+ .method("GET")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+
+ assert_eq!(
+ response.status(),
+ StatusCode::OK,
+ "openapi at {uri} should be 200"
+ );
+ }
+}
+
+#[tokio::test]
+async fn health_is_served_at_root_and_gateway_prefix() {
+ let app = docs_router();
+
+ for uri in ["/health", "/scheduled-action/health"] {
+ let response = app
+ .clone()
+ .oneshot(
+ Request::builder()
+ .uri(uri)
+ .method("GET")
+ .body(Body::empty())
+ .unwrap(),
+ )
+ .await
+ .unwrap();
+ assert_eq!(
+ response.status(),
+ StatusCode::OK,
+ "health at {uri} should be 200"
+ );
+ }
+}
diff --git a/tooling/xtask/crates/xtask_local/src/local/instance.rs b/tooling/xtask/crates/xtask_local/src/local/instance.rs
index 7c48a53c73..50a21eeddf 100644
--- a/tooling/xtask/crates/xtask_local/src/local/instance.rs
+++ b/tooling/xtask/crates/xtask_local/src/local/instance.rs
@@ -108,6 +108,8 @@ pub enum Port {
/// Published on every local instance - it is what the Cursor egress
/// tunnel points at, and Cursor's cloud is outside the compose network.
AgentHarnessEgress = 8102,
+ /// Scheduled actions API and dispatcher (default compose port 8099).
+ ScheduledAction = 8099,
}
impl Port {
diff --git a/tooling/xtask/crates/xtask_local/src/local/instance/test.rs b/tooling/xtask/crates/xtask_local/src/local/instance/test.rs
index 6c2924dee2..f8be084de8 100644
--- a/tooling/xtask/crates/xtask_local/src/local/instance/test.rs
+++ b/tooling/xtask/crates/xtask_local/src/local/instance/test.rs
@@ -91,3 +91,17 @@ fn doc_cognition_host_port_is_instance_derived() {
);
assert_eq!(named.port(Port::DocCognition), 31014);
}
+
+/// New `Port` variants must be appended. Inserting mid-enum shifts named-instance
+/// offsets for every later variant (Kafka, webhooks, agent harness, …).
+#[test]
+fn appended_port_offsets_stay_stable() {
+ assert_eq!(Port::Kafka.offset(), 22);
+ assert_eq!(Port::SdkWebhookSsh.offset(), 23);
+ assert_eq!(Port::SdkWebhookHostReceiver.offset(), 24);
+ assert_eq!(Port::AgentProxy.offset(), 25);
+ assert_eq!(Port::AgentHarness.offset(), 26);
+ assert_eq!(Port::AgentHarnessEgress.offset(), 27);
+ assert_eq!(Port::ScheduledAction.offset(), 28);
+ assert_eq!(Port::ScheduledAction.fixed(), 8099);
+}
diff --git a/tooling/xtask/crates/xtask_local/src/local/inventory.rs b/tooling/xtask/crates/xtask_local/src/local/inventory.rs
index fa0d6eccec..fd50875393 100644
--- a/tooling/xtask/crates/xtask_local/src/local/inventory.rs
+++ b/tooling/xtask/crates/xtask_local/src/local/inventory.rs
@@ -194,6 +194,20 @@ pub const RUST_SERVICES: &[RustService] = &[
opt_in: false,
no_default_features: false,
},
+ RustService {
+ compose_name: "scheduled_action_service",
+ cargo_bin: "service",
+ package: "scheduled_action",
+ host_port: Some(Port::ScheduledAction),
+ path_prefix: Some("/scheduled-action"),
+ is_websocket: false,
+ // Local-only: the binary always boots `PgPollingDispatcher`. Running it
+ // under `run-dev` against the shared-dev MacroDB would race the deployed
+ // agent-schedule-dev service for due schedules.
+ modes: &[Mode::Local],
+ opt_in: false,
+ no_default_features: false,
+ },
RustService {
compose_name: "static_file_service",
cargo_bin: "static_file_service",
diff --git a/tooling/xtask/crates/xtask_local/src/local/inventory/test.rs b/tooling/xtask/crates/xtask_local/src/local/inventory/test.rs
index 3c0c7bdd1b..874e18db99 100644
--- a/tooling/xtask/crates/xtask_local/src/local/inventory/test.rs
+++ b/tooling/xtask/crates/xtask_local/src/local/inventory/test.rs
@@ -3,14 +3,15 @@ use super::*;
#[test]
fn local_binaries_are_unique_and_complete() {
let bins = local_binaries();
- // 16 distinct binaries (the bundled set, including the local-only
+ // 17 distinct binaries (the bundled set, including scheduled_action, the local-only
// search_processing_service, agent harness, mcp_service, and the seed_cli
// shipped for the gmail_forwarder sidecar).
- assert_eq!(bins.len(), 16, "{bins:?}");
+ assert_eq!(bins.len(), 17, "{bins:?}");
assert!(bins.contains(&"pubsub_workers"));
assert!(bins.contains(&"seed_cli"));
assert!(bins.contains(&"document_upload_finalizer_local_worker"));
assert!(bins.contains(&"search_processing_service"));
+ assert!(bins.contains(&"service"));
assert!(bins.contains(&"agent_harness_service"));
assert!(bins.contains(&"mcp_service"));
let mut sorted = bins.clone();
@@ -55,5 +56,15 @@ fn dev_mode_excludes_workers_and_optin() {
.collect();
assert!(!dev.contains(&"email_pubsub_workers"));
assert!(!dev.contains(&"search_processing_service"));
+ assert!(!dev.contains(&"scheduled_action_service"));
assert!(dev.contains(&"authentication-service"));
}
+
+#[test]
+fn scheduled_action_is_local_only() {
+ let svc = RUST_SERVICES
+ .iter()
+ .find(|s| s.compose_name == "scheduled_action_service")
+ .unwrap();
+ assert_eq!(svc.modes, &[Mode::Local]);
+}
diff --git a/tooling/xtask/crates/xtask_local/src/local/proxy.rs b/tooling/xtask/crates/xtask_local/src/local/proxy.rs
index 32df334812..1bf8bd6f6e 100644
--- a/tooling/xtask/crates/xtask_local/src/local/proxy.rs
+++ b/tooling/xtask/crates/xtask_local/src/local/proxy.rs
@@ -19,11 +19,13 @@ pub fn url(instance: &Instance) -> String {
format!("http://localhost:{}", instance.port(Port::Proxy))
}
-/// Write the instance Caddyfile and return its path. Both local and dev route
-/// the frontend through this single origin to the local service containers; the
-/// only difference is the static-file block (dev has no local LocalStack).
-/// With `static_frontend` the proxy also serves the built app bundle at `/app`,
-/// making it the one origin for the whole product.
+/// Write the instance Caddyfile and return its path. Both local and dev keep a
+/// single frontend origin; Local fans every inventory prefix to a local
+/// container, while Dev fans Local-only prefixes (services that must not run
+/// against shared-dev) to the deployed gateway. The static-file block also
+/// differs (dev has no local LocalStack). With `static_frontend` the proxy also
+/// serves the built app bundle at `/app`, making it the one origin for the
+/// whole product.
pub fn write_caddyfile(instance: &Instance, mode: Mode, static_frontend: bool) -> Result<PathBuf> {
let path = caddyfile_path(instance);
if let Some(dir) = path.parent() {
@@ -38,8 +40,6 @@ pub fn write_caddyfile(instance: &Instance, mode: Mode, static_frontend: bool) -
/// Assemble the Caddyfile: the listener head, the generated per-service routes
/// (from the inventory), the special non-inventory routes, the mode's
/// static-file block, the optional static-frontend block, then the tail.
-/// Service routes are identical across modes (they hit the local containers);
-/// only the static-file and frontend blocks differ.
fn caddyfile(mode: Mode, static_frontend: bool) -> String {
let static_block = if mode.spec().static_files_via_localstack {
STATIC_FILE_LOCAL
@@ -54,29 +54,44 @@ fn caddyfile(mode: Mode, static_frontend: bool) -> String {
let frontend_block = if static_frontend { FRONTEND_STATIC } else { "" };
format!(
"{CADDY_HEAD}{routes}{SPECIAL_ROUTES}{mailpit_block}{static_block}{frontend_block}{CADDY_TAIL}",
- routes = service_routes()
+ routes = service_routes(mode)
)
}
+/// Shared-dev gateway origin for Local-only inventory prefixes under `run-dev`.
+/// Keep the path (no strip) — gateway tenants are mounted under this prefix.
+const DEV_GATEWAY_ORIGIN: &str = "https://dev-gateway.macro.com";
+
/// Generate the reverse-proxy routes for every inventoried service that exposes
/// a path prefix. The inventory is the single source, so adding a service's
/// proxy route is one field there — not a hand-edit here that can drift.
-fn service_routes() -> String {
+fn service_routes(mode: Mode) -> String {
let mut out = String::new();
for svc in inventory::RUST_SERVICES {
- if let Some(prefix) = svc.path_prefix {
- out.push_str(&route_block(prefix, svc.compose_name, svc.is_websocket));
+ let Some(prefix) = svc.path_prefix else {
+ continue;
+ };
+ if svc.in_mode(mode) {
+ out.push_str(&local_route_block(
+ prefix,
+ svc.compose_name,
+ svc.is_websocket,
+ ));
+ } else if mode == Mode::Dev && svc.in_mode(Mode::Local) {
+ // Local-only: do not start the binary against shared-dev, but keep
+ // the single-origin proxy by fanning out to the deployed gateway.
+ out.push_str(&dev_gateway_route_block(prefix, svc.is_websocket));
}
}
out
}
-/// One Caddy route to a service container (always on `:8080`). HTTP uses
+/// One Caddy route to a local service container (always on `:8080`). HTTP uses
/// `handle_path` (which strips the prefix); WebSocket needs the bare-prefix
/// `@matcher` + explicit strip so the frontend's trailing-slash-less connect URL
/// still matches. The target is the canonical compose service name, which always
/// resolves on the proxy's networks.
-fn route_block(prefix: &str, target: &str, is_websocket: bool) -> String {
+fn local_route_block(prefix: &str, target: &str, is_websocket: bool) -> String {
if is_websocket {
let m = matcher_name(prefix);
format!(
@@ -87,6 +102,24 @@ fn route_block(prefix: &str, target: &str, is_websocket: bool) -> String {
}
}
+/// Dev route to the shared gateway: keep the path prefix (gateway mounts are
+/// prefixed) and set `Host` so TLS/SNI + ALB host routing work.
+fn dev_gateway_route_block(prefix: &str, is_websocket: bool) -> String {
+ let host = DEV_GATEWAY_ORIGIN
+ .trim_start_matches("https://")
+ .trim_start_matches("http://");
+ if is_websocket {
+ let m = matcher_name(prefix);
+ format!(
+ " {m} path {prefix} {prefix}/*\n handle {m} {{\n reverse_proxy {DEV_GATEWAY_ORIGIN} {{\n header_up Host {host}\n }}\n }}\n"
+ )
+ } else {
+ format!(
+ " handle {prefix}/* {{\n reverse_proxy {DEV_GATEWAY_ORIGIN} {{\n header_up Host {host}\n }}\n }}\n"
+ )
+ }
+}
+
/// A Caddy named-matcher token from a path prefix (drop the slash; hyphens →
/// underscores so it's a single bare token).
fn matcher_name(prefix: &str) -> String {
diff --git a/tooling/xtask/crates/xtask_local/src/local/proxy/test.rs b/tooling/xtask/crates/xtask_local/src/local/proxy/test.rs
index 466bf804e8..9e3421f8ad 100644
--- a/tooling/xtask/crates/xtask_local/src/local/proxy/test.rs
+++ b/tooling/xtask/crates/xtask_local/src/local/proxy/test.rs
@@ -23,6 +23,49 @@ fn generates_a_route_for_every_prefixed_service() {
}
}
+/// Dev keeps a single origin: services that run in Dev hit local containers;
+/// Local-only prefixed services fan out to the shared-dev gateway (no strip).
+#[test]
+fn dev_fans_local_only_prefixes_to_the_gateway() {
+ let caddy = caddyfile(Mode::Dev, false);
+ for svc in inventory::RUST_SERVICES {
+ let Some(prefix) = svc.path_prefix else {
+ continue;
+ };
+ if svc.in_mode(Mode::Dev) {
+ assert!(
+ caddy.contains(&format!("reverse_proxy {}:8080", svc.compose_name)),
+ "Dev Caddyfile missing local route for {}",
+ svc.compose_name
+ );
+ continue;
+ }
+ if !svc.in_mode(Mode::Local) {
+ continue;
+ }
+ assert!(
+ !caddy.contains(&format!("reverse_proxy {}:8080", svc.compose_name)),
+ "Dev must not route {} to an absent local container",
+ svc.compose_name
+ );
+ assert!(
+ caddy.contains(&format!("handle {prefix}/* {{"))
+ || caddy.contains(&format!("path {prefix} {prefix}/*")),
+ "Dev Caddyfile missing gateway handle for {prefix}"
+ );
+ assert!(
+ caddy.contains(&format!("reverse_proxy {DEV_GATEWAY_ORIGIN}")),
+ "Dev Caddyfile missing gateway upstream for {}",
+ svc.compose_name
+ );
+ }
+ // Concrete regression for the scheduled-action / agent-harness pair.
+ assert!(caddy.contains("handle /scheduled-action/* {"));
+ assert!(caddy.contains("handle /agent-harness/* {"));
+ assert!(!caddy.contains("reverse_proxy scheduled_action_service:8080"));
+ assert!(!caddy.contains("reverse_proxy agent_harness_service:8080"));
+}
+
/// WebSocket services use the bare-prefix `@matcher` + explicit strip; HTTP
/// services use `handle_path`.
#[test]