Skip to content

Commit 35e2d05

Browse files
committed
fix(services): preserve replay URLs and SDK source compatibility
Signed-off-by: Taylor Mutch <taylormutch@gmail.com>
1 parent 4c5aba7 commit 35e2d05

9 files changed

Lines changed: 170 additions & 58 deletions

File tree

‎crates/openshell-server/README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,11 @@ equality tokens, not resumable cursors or an ordering across gateway replicas.
345345
`supervisor.app_listener.public_url` is an optional HTTPS origin matching the
346346
listener domain. It requires explicit listener enablement. Service responses
347347
return preferred `url`, configured `application_url`, and a gateway alternative
348-
`gateway_url`. Sandbox creation supplies equivalent service-name maps. Current
349-
deployment origins are recomputed for durable replay without repeating the
350-
mutation or changing resource identities. These are configured addresses, not
351-
installation, ingress acceptance, or application health signals.
348+
`gateway_url`. Sandbox creation supplies equivalent service-name maps. Durable
349+
replays preserve the recorded `url` and `service_urls` values and refresh only
350+
the explicit application/gateway fields, without repeating the mutation. These
351+
are configured addresses, not installation, ingress acceptance, or application
352+
health signals.
352353

353354
Application hostname mode follows `service_hostname_format` for both access
354355
paths. The gateway sends each canonical app hostname in `SandboxServiceRoute`;

‎crates/openshell-server/src/grpc/mutation_replay/tests.rs‎

Lines changed: 114 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use crate::grpc::test_support::{authed_request, test_server_state};
77
use openshell_core::proto::datamodel::v1::ObjectMeta;
88
use openshell_core::proto::open_shell_server::OpenShell;
99
use openshell_core::proto::{
10-
CreateSandboxRequest, SandboxServiceExposure, SandboxSpec, SandboxWorkloadConfig,
11-
SandboxWorkloadTemplate, SandboxWorkloadTemplateSpec, ServiceAuthorizationMode,
12-
WorkspaceMember, WorkspaceRole,
10+
CreateSandboxRequest, ExposeServiceRequest, SandboxServiceExposure, SandboxSpec,
11+
SandboxWorkloadConfig, SandboxWorkloadTemplate, SandboxWorkloadTemplateSpec,
12+
ServiceAuthorizationMode, WorkspaceMember, WorkspaceRole,
1313
};
1414
use openshell_core::rpc_error::StatusExt;
1515
use std::collections::HashMap;
@@ -93,8 +93,7 @@ fn canonical_payload_ignores_map_order_and_id_but_preserves_presence() {
9393
assert_ne!(absent, fingerprint(&template).unwrap());
9494
}
9595

96-
#[tokio::test]
97-
async fn service_url_replay_uses_current_origin_without_repeating_mutation() {
96+
async fn url_replay_state() -> (Arc<ServerState>, tempfile::TempDir) {
9897
let directory = tempfile::tempdir().unwrap();
9998
let key = directory.path().join("private-key");
10099
std::fs::write(&key, b"test-only stable private fingerprint material").unwrap();
@@ -107,26 +106,35 @@ async fn service_url_replay_uses_current_origin_without_repeating_mutation() {
107106
gateway_id: "test".into(),
108107
ttl_secs: None,
109108
});
109+
(state, directory)
110+
}
111+
112+
#[tokio::test]
113+
async fn create_replay_preserves_recorded_urls_and_refreshes_explicit_origins() {
114+
let (mut state, _directory) = url_replay_state().await;
110115
let request = CreateSandboxRequest {
111116
name: "origin-replay".into(),
112117
spec: Some(SandboxSpec::default()),
113118
workspace_scope: Some(openshell_core::proto::workspace_selector("default")),
114-
service_exposures: vec![SandboxServiceExposure {
115-
service: "web".into(),
116-
target_port: 8080,
117-
..Default::default()
118-
}],
119+
service_exposures: ["", "web"]
120+
.into_iter()
121+
.map(|service| SandboxServiceExposure {
122+
service: service.into(),
123+
target_port: 8080,
124+
..Default::default()
125+
})
126+
.collect(),
119127
request_id: uuid::Uuid::new_v4().to_string(),
120128
..Default::default()
121129
};
122130
let original = run(&state, authed_request(request.clone()))
123131
.await
124132
.unwrap()
125133
.into_inner();
126-
Arc::get_mut(&mut state)
127-
.unwrap()
128-
.config
129-
.supervisor_app_listener = openshell_core::app_listener::AppListenerConfig {
134+
let config = &mut Arc::get_mut(&mut state).unwrap().config;
135+
config.service_routing.base_domains = vec!["gateway.example.com".into()];
136+
config.bind_address.set_port(12443);
137+
config.supervisor_app_listener = openshell_core::app_listener::AppListenerConfig {
130138
enabled: true,
131139
port: 9443,
132140
domain: "services.example.com".into(),
@@ -138,17 +146,103 @@ async fn service_url_replay_uses_current_origin_without_repeating_mutation() {
138146
original.sandbox.as_ref().unwrap().metadata,
139147
replay.get_ref().sandbox.as_ref().unwrap().metadata
140148
);
149+
assert_eq!(replay.get_ref().service_urls, original.service_urls);
150+
for (service, label) in [
151+
("", "default--origin-replay"),
152+
("web", "default--origin-replay--web"),
153+
] {
154+
assert_eq!(
155+
replay.get_ref().application_service_urls[service],
156+
format!("https://{label}.services.example.com:10443/")
157+
);
158+
let gateway = url::Url::parse(&replay.get_ref().gateway_service_urls[service]).unwrap();
159+
assert_eq!(
160+
gateway.host_str(),
161+
Some(format!("{label}.gateway.example.com").as_str())
162+
);
163+
assert_eq!(gateway.port(), Some(12443));
164+
assert_ne!(
165+
replay.get_ref().gateway_service_urls[service],
166+
original.gateway_service_urls[service]
167+
);
168+
}
169+
}
170+
171+
#[tokio::test]
172+
async fn expose_replay_preserves_recorded_url_when_origins_change_or_are_disabled() {
173+
let (mut state, _directory) = url_replay_state().await;
174+
Arc::get_mut(&mut state)
175+
.unwrap()
176+
.config
177+
.supervisor_app_listener = openshell_core::app_listener::AppListenerConfig {
178+
enabled: true,
179+
port: 9443,
180+
domain: "old.example.com".into(),
181+
public_url: Some("https://old.example.com:10443".into()),
182+
};
183+
run(
184+
&state,
185+
authed_request(CreateSandboxRequest {
186+
name: "expose-replay".into(),
187+
spec: Some(SandboxSpec::default()),
188+
workspace_scope: Some(openshell_core::proto::workspace_selector("default")),
189+
..Default::default()
190+
}),
191+
)
192+
.await
193+
.unwrap();
194+
let request = ExposeServiceRequest {
195+
sandbox: "expose-replay".into(),
196+
name: "web".into(),
197+
workspace_scope: Some(openshell_core::proto::workspace_selector("default")),
198+
target_port: 8080,
199+
request_id: uuid::Uuid::new_v4().to_string(),
200+
..Default::default()
201+
};
202+
let original = run(&state, authed_request(request.clone()))
203+
.await
204+
.unwrap()
205+
.into_inner();
206+
assert_eq!(
207+
original.url,
208+
"https://default--expose-replay--web.old.example.com:10443/"
209+
);
210+
let config = &mut Arc::get_mut(&mut state).unwrap().config;
211+
config.service_routing.base_domains = vec!["gateway.example.com".into()];
212+
config.bind_address.set_port(12443);
213+
config.supervisor_app_listener.domain = "new.example.com".into();
214+
config.supervisor_app_listener.public_url = Some("https://new.example.com:11443".into());
215+
let replay = run(&state, authed_request(request.clone())).await.unwrap();
216+
assert_eq!(replay.metadata().get("openshell-replayed").unwrap(), "true");
217+
assert_eq!(replay.get_ref().endpoint, original.endpoint);
218+
assert_eq!(replay.get_ref().url, original.url);
141219
assert_eq!(
142-
replay.get_ref().service_urls["web"],
143-
"https://default--origin-replay--web.services.example.com:10443/"
220+
replay.get_ref().application_url,
221+
"https://default--expose-replay--web.new.example.com:11443/"
144222
);
223+
let gateway = url::Url::parse(&replay.get_ref().gateway_url).unwrap();
145224
assert_eq!(
146-
replay.get_ref().application_service_urls,
147-
replay.get_ref().service_urls
225+
gateway.host_str(),
226+
Some("default--expose-replay--web.gateway.example.com")
227+
);
228+
assert_eq!(gateway.port(), Some(12443));
229+
let config = &mut Arc::get_mut(&mut state).unwrap().config;
230+
config.supervisor_app_listener.enabled = false;
231+
config.supervisor_app_listener.public_url = None;
232+
let without_application = run(&state, authed_request(request)).await.unwrap();
233+
assert_eq!(
234+
without_application
235+
.metadata()
236+
.get("openshell-replayed")
237+
.unwrap(),
238+
"true"
148239
);
240+
assert_eq!(without_application.get_ref().url, original.url);
241+
assert_eq!(without_application.get_ref().endpoint, original.endpoint);
242+
assert!(without_application.get_ref().application_url.is_empty());
149243
assert_eq!(
150-
replay.get_ref().gateway_service_urls,
151-
original.gateway_service_urls
244+
without_application.get_ref().gateway_url,
245+
replay.get_ref().gateway_url
152246
);
153247
}
154248

‎crates/openshell-server/src/grpc/sandbox.rs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,15 +4340,14 @@ async fn run_exec_with_russh(
43404340
// Tests
43414341
// ---------------------------------------------------------------------------
43424342

4343-
/// Replays preserve original service names and sandbox identity while using
4344-
/// current deployment origins. No service mutation is performed here.
4343+
/// Refresh explicit access paths while preserving the recorded service URL map.
43454344
pub(super) fn refresh_response_urls(state: &ServerState, response: &mut SandboxResponse) {
43464345
let Some(sandbox) = response.sandbox.as_ref() else {
43474346
return;
43484347
};
43494348
response.application_service_urls.clear();
43504349
response.gateway_service_urls.clear();
4351-
for (service, url) in &mut response.service_urls {
4350+
for service in response.service_urls.keys() {
43524351
let gateway = crate::service_routing::endpoint_url(
43534352
&state.config,
43544353
sandbox.object_workspace(),
@@ -4364,8 +4363,7 @@ pub(super) fn refresh_response_urls(state: &ServerState, response: &mut SandboxR
43644363
);
43654364
response
43664365
.gateway_service_urls
4367-
.insert(service.clone(), gateway.clone());
4368-
*url = application.clone().unwrap_or(gateway);
4366+
.insert(service.clone(), gateway);
43694367
if let Some(application) = application {
43704368
response
43714369
.application_service_urls

‎crates/openshell-server/src/grpc/service.rs‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,15 @@ fn service_endpoint_response(
519519
..Default::default()
520520
};
521521
refresh_response_urls(state, &mut response);
522+
response.url = if response.application_url.is_empty() {
523+
response.gateway_url.clone()
524+
} else {
525+
response.application_url.clone()
526+
};
522527
response
523528
}
524529

525-
/// Recompute presentation from current configuration, including durable replays.
530+
/// Refresh explicit access paths without changing a replay's recorded URL.
526531
pub(super) fn refresh_response_urls(state: &ServerState, response: &mut ServiceEndpointResponse) {
527532
let Some(endpoint) = response.endpoint.as_ref() else {
528533
return;
@@ -544,11 +549,6 @@ pub(super) fn refresh_response_urls(state: &ServerState, response: &mut ServiceE
544549
state.config.service_routing_discriminator(),
545550
)
546551
.unwrap_or_default();
547-
response.url = if response.application_url.is_empty() {
548-
response.gateway_url.clone()
549-
} else {
550-
response.application_url.clone()
551-
};
552552
}
553553

554554
#[allow(clippy::result_large_err)]
@@ -818,19 +818,18 @@ mod tests {
818818
domain: "services.example.com".into(),
819819
public_url: Some("https://services.example.com:10443".into()),
820820
};
821-
let mut response = ServiceEndpointResponse {
822-
endpoint: Some(ServiceEndpoint {
821+
let response = service_endpoint_response(
822+
&state,
823+
ServiceEndpoint {
823824
metadata: Some(ObjectMeta {
824825
workspace: "default".into(),
825826
..Default::default()
826827
}),
827828
sandbox: "demo".into(),
828829
name: "web".into(),
829830
..Default::default()
830-
}),
831-
..Default::default()
832-
};
833-
refresh_response_urls(&state, &mut response);
831+
},
832+
);
834833
let gateway = url::Url::parse(&response.gateway_url).unwrap();
835834
let label =
836835
service_routing::service_route_hash_label("gateway-a", "default", "demo", Some("web"));

‎crates/openshell-server/src/grpc/service_discovery.rs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,17 @@ mod tests {
660660
);
661661
assert_eq!(*hostname, format!("{label}.services.example.com"));
662662
assert_eq!(*hostname, report.routes[0].application_hostname);
663-
let endpoint = state
664-
.store
665-
.get_message::<openshell_core::proto::ServiceEndpoint>("endpoint")
666-
.await
667-
.unwrap()
668-
.unwrap();
669-
let mut response = openshell_core::proto::ServiceEndpointResponse {
670-
endpoint: Some(endpoint),
671-
..Default::default()
672-
};
673-
super::super::service::refresh_response_urls(&state, &mut response);
663+
let response = super::super::service::handle_get_service(
664+
&state,
665+
authed_request(openshell_core::proto::GetServiceRequest {
666+
workspace_scope: Some(openshell_core::proto::workspace_selector("default")),
667+
sandbox: "demo".into(),
668+
name: "web".into(),
669+
}),
670+
)
671+
.await
672+
.unwrap()
673+
.into_inner();
674674
assert_eq!(
675675
response.application_url,
676676
format!("https://{hostname}:10443/")

‎docs/how-it-works/gateways/configuration.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,9 +2095,10 @@ When configured, service responses return the application address as `url` and
20952095
Create-time exposure returns corresponding preferred, application, and gateway
20962096
URL maps. CLI and SDK callers preserve the application origin, including its
20972097
port, when the gateway is reached through a port-forward. Without `public_url`,
2098-
the existing gateway URL behavior remains. Replayed mutations retain their
2099-
original resource identities and use the current URL configuration. A configured
2100-
URL does not mean that a supervisor installed the route or ingress is ready.
2098+
the existing gateway URL behavior remains. Idempotent retries preserve the
2099+
original `url` and `service_urls` values. The explicit application and gateway
2100+
fields use the current URL configuration. A configured URL does not mean that a
2101+
supervisor installed the route or ingress is ready.
21012102

21022103
Upgrade the CLI alongside the gateway when enabling `public_url`. Older CLI
21032104
versions can replace the public application port with the gateway connection's

‎proto/openshell.proto‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,8 @@ message SandboxResponse {
16091609
Sandbox sandbox = 1;
16101610
// Service URLs created by CreateSandbox, keyed by service name. The empty
16111611
// key identifies the unnamed service. Other sandbox RPCs return an empty map.
1612+
// Idempotent retries preserve the recorded URLs; the explicit access-path
1613+
// maps below use the current configuration.
16121614
map<string, string> service_urls = 2;
16131615
// Configured application origins for the same services. These are
16141616
// authoritative public addresses, not installation or health evidence.
@@ -2001,6 +2003,8 @@ message ServiceEndpoint {
20012003
message ServiceEndpointResponse {
20022004
ServiceEndpoint endpoint = 1;
20032005
// Preferred address: application_url when configured, otherwise gateway_url.
2006+
// Idempotent retries preserve the originally returned address; the explicit
2007+
// access-path fields below use the current configuration.
20042008
string url = 2;
20052009
// Authoritative configured public application address. Preserve its port.
20062010
string application_url = 3;

‎sdk/typescript/src/client.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
POLICY_SOURCE_NAMES,
2121
Pushable,
2222
SandboxClient,
23+
type SandboxRef,
2324
SandboxTemplateClient,
2425
SCOPE_NAMES,
2526
ServiceAuthorizationMode,
@@ -700,6 +701,20 @@ describe('watchLogs', () => {
700701
});
701702

702703
describe('create', () => {
704+
it('accepts the existing SandboxRef shape without explicit access-path maps', () => {
705+
const ref: SandboxRef = {
706+
id: 'sb-id',
707+
name: 'sb',
708+
workspace: 'default',
709+
phase: 'ready',
710+
labels: {},
711+
resourceVersion: '1',
712+
serviceUrls: {},
713+
restartCount: 0,
714+
};
715+
expect(ref.serviceUrls).toEqual({});
716+
});
717+
703718
it('sends create-time service exposures', async () => {
704719
let created: {
705720
serviceExposures?: Array<{ service?: string; targetPort?: number; authorizationMode?: number }>;
@@ -746,7 +761,7 @@ describe('create', () => {
746761
},
747762
]);
748763
expect(result.applicationServiceUrls).toEqual(result.serviceUrls);
749-
expect(result.gatewayServiceUrls['']).toBe('https://sb.gateway.test:8080/');
764+
expect(result.gatewayServiceUrls?.['']).toBe('https://sb.gateway.test:8080/');
750765
expect(result.serviceUrls).toEqual({
751766
'': 'https://sb.example.test/',
752767
metrics: 'https://metrics.sb.example.test/',

‎sdk/typescript/src/client.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ export interface SandboxRef {
247247
createdFromWorkloadTemplate?: SandboxWorkloadTemplateProvenance;
248248
/** Service URLs returned by creation, keyed by service name. */
249249
serviceUrls: Record<string, string>;
250-
applicationServiceUrls: Record<string, string>;
251-
gatewayServiceUrls: Record<string, string>;
250+
applicationServiceUrls?: Record<string, string>;
251+
gatewayServiceUrls?: Record<string, string>;
252252
restartCount: number;
253253
/** Creation time in epoch milliseconds; absent when the gateway omits it. */
254254
createdAtMs?: number;

0 commit comments

Comments
 (0)