feat(aws): EFS storage mode

EFS storage is Hybrid plus /workspace on a second access point of the
user's own file system, rooted at /triple-c-workspaces/<owner_key>/<project>
(a sibling of the home roots) and mounted at /workspace. The workspace
access point is found by root + owner + project tags or created, waited
for before RunTask, recorded store-owned, kept when switching to Hybrid or
Ephemeral, and deleted with the home one by a discarding removal. Hybrid
and Ephemeral task definitions are byte-identical to before (pinned
fingerprints).

The entrypoint links home state for efs as for hybrid, warns when
/workspace is not mounted, and marks a clone in progress in its own
.git/config so a clone a killed task cut short is redone on the next start
while existing repositories are still skipped.

The EFS segment is enabled in HostSection, with a note when /workspace
files remain on an access point after switching away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shadowdaoandClaude Opus 5.5 committed 2026-11-15 21:44:17 -08:00
1 parent cbaf6209fd
commit 5477c2cea5
20 files changed
+790 -100

No files matched your search

+33 -5
View File
@@ -362,6 +362,8 @@ pub struct TaskRecord {
pub task_arn: String,
pub access_point_id: Option<String>,
pub task_definition_arn: Option<String>,
/// EFS storage's `/workspace` access point.
pub workspace_access_point_id: Option<String>,
}
/// A connected task.
@@ -373,6 +375,8 @@ pub struct Started {
/// The access point the task mounts (Hybrid). `None` when an existing
/// task was attached to: the store's value stands.
pub access_point_id: Option<String>,
/// The `/workspace` access point (EFS), like `access_point_id`.
pub workspace_access_point_id: Option<String>,
/// This start ran the task (rather than attaching to a running one).
pub created: bool,
}
@@ -433,13 +437,14 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
.await
.map_err(s)?;
let (task, token, access_point_id, created) = if let Some(task) = existing {
let (task, token, access_point_id, workspace_access_point_id, created) = if let Some(task) = existing {
// Attach: never rotate a running task's token (P2).
log::info!("Project {}: attaching to its running task {}", project.id, task.arn);
(inp.on_task)(Some(&TaskRecord {
task_arn: task.arn.clone(),
access_point_id: None,
task_definition_arn: Some(task.task_definition_arn.clone()),
workspace_access_point_id: None,
}));
let token = read_agent_token(rt, &env.name, &ok, &project.id).await.map_err(s)?;
progress(PROGRESS_WAITING);
@@ -447,7 +452,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
Ok(t) => t,
Err(e) => return Err(with_log_tail(tasks, &logs, &task.arn, e.to_string()).await),
};
(task, token, None, false)
(task, token, None, None, false)
} else {
progress(PROGRESS_PREPARING);
let prepared = prepare_workspace(
@@ -461,7 +466,10 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
)
.await
.map_err(s)?;
if let Some(ap) = &prepared.access_point_id {
for ap in [&prepared.access_point_id, &prepared.workspace_access_point_id]
.into_iter()
.flatten()
{
wait_access_point(rt, ap, inp.access_point_wait).await.map_err(s)?;
}
progress(PROGRESS_STARTING);
@@ -482,6 +490,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
task_arn: start.task.arn.clone(),
access_point_id: prepared.access_point_id.clone(),
task_definition_arn: Some(start.task.task_definition_arn.clone()),
workspace_access_point_id: prepared.workspace_access_point_id.clone(),
}));
return Err(START_RACE.into());
}
@@ -490,6 +499,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
task_arn: arn.clone(),
access_point_id: prepared.access_point_id.clone(),
task_definition_arn: Some(prepared.task_definition_arn.clone()),
workspace_access_point_id: prepared.workspace_access_point_id.clone(),
}));
progress(PROGRESS_WAITING);
let task = match wait_ready(tasks, &env.cluster_arn, &arn, &logs, inp.wait, |_| {}).await {
@@ -502,7 +512,13 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
return Err(msg);
}
};
(task, prepared.agent_token, prepared.access_point_id, true)
(
task,
prepared.agent_token,
prepared.access_point_id,
prepared.workspace_access_point_id,
true,
)
};
progress(PROGRESS_CONNECTING);
@@ -530,6 +546,7 @@ pub async fn start_core<T: TaskApi, W: WorkspaceApi, R: RuntimeApi, C: Connector
forward,
endpoint,
access_point_id,
workspace_access_point_id,
created,
})
}
@@ -615,6 +632,9 @@ pub async fn ensure_started(
let access_point_id = started
.access_point_id
.or_else(|| project.aws.as_ref().and_then(|a| a.access_point_id.clone()));
let workspace_access_point_id = started
.workspace_access_point_id
.or_else(|| project.aws.as_ref().and_then(|a| a.workspace_access_point_id.clone()));
let ecs = ecs_task(&started.task)?;
if let Some(old) = tunnels::register(
&project.id,
@@ -628,6 +648,7 @@ pub async fn ensure_started(
forward: started.forward,
endpoint: endpoint.clone(),
access_point_id,
workspace_access_point_id,
task_definition_arn: started.task.task_definition_arn.clone(),
},
) {
@@ -651,7 +672,7 @@ pub fn record_task(store: &ProjectsStore, project_id: &str, rec: Option<&TaskRec
Some(r.task_arn.clone()),
r.access_point_id.clone().or(stored.access_point_id),
r.task_definition_arn.clone().or(stored.task_definition_arn),
stored.workspace_access_point_id, // Task 3: from the record
r.workspace_access_point_id.clone().or(stored.workspace_access_point_id),
),
None => store.set_aws_runtime(
project_id,
@@ -860,6 +881,8 @@ pub async fn remove_resources(
project_id: &project.id,
stored_task_arn: aws.and_then(|a| a.task_arn.as_deref()),
stored_access_point_id: aws.and_then(|a| a.access_point_id.as_deref()),
stored_workspace_access_point_id: aws
.and_then(|a| a.workspace_access_point_id.as_deref()),
discard_data,
},
)
@@ -974,6 +997,7 @@ pub async fn reconcile_project<T: TaskApi>(
task_arn: t.arn.clone(),
access_point_id: None,
task_definition_arn: Some(t.task_definition_arn.clone()),
workspace_access_point_id: None,
}),
);
}
@@ -1072,6 +1096,10 @@ async fn reattach(
forward,
endpoint: endpoint.clone(),
access_point_id: project.aws.as_ref().and_then(|a| a.access_point_id.clone()),
workspace_access_point_id: project
.aws
.as_ref()
.and_then(|a| a.workspace_access_point_id.clone()),
task_definition_arn: task.task_definition_arn.clone(),
};
if !reattach_still_wanted(store, &project.id, &task.arn) {
+84 -4
View File
@@ -155,11 +155,11 @@ impl WorkspaceApi for Fake {
async fn create_access_point(
&self,
_fs: &str,
_root: &str,
root: &str,
_tags: &[(String, String)],
) -> Result<String, AwsError> {
self.log("create-ap");
Ok("fsap-new".into())
Ok(if root.starts_with("/triple-c-workspaces/") { "fsap-ws" } else { "fsap-new" }.into())
}
async fn put_project_secret(
&self,
@@ -309,6 +309,76 @@ async fn a_first_start_prepares_runs_waits_and_connects_in_that_order() {
);
}
#[tokio::test]
async fn an_efs_start_waits_for_both_access_points_and_records_them() {
let p = aws_project(StorageMode::Efs);
let fake = Fake { run: Some(task(&p, "new", "RUNNING", true)), ..Default::default() };
let w = who();
let records = Mutex::new(Vec::new());
let on_task = |r: Option<&TaskRecord>| records.lock().unwrap().push(r.cloned());
let started = start_core(&fake, &fake, &fake, &fake, &inputs(&p, &w, &on_task), &|_| {})
.await
.unwrap();
assert_eq!(started.access_point_id.as_deref(), Some("fsap-new"));
assert_eq!(started.workspace_access_point_id.as_deref(), Some("fsap-ws"));
let calls = fake.calls();
let pos = |c: &str| calls.iter().position(|x| x == c).unwrap_or_else(|| panic!("{c}: {calls:?}"));
assert!(pos("ap-state fsap-new") < pos("run"), "{calls:?}");
assert!(pos("ap-state fsap-ws") < pos("run"), "{calls:?}");
let recs = records.into_inner().unwrap();
let rec = recs[0].as_ref().unwrap();
assert_eq!(rec.access_point_id.as_deref(), Some("fsap-new"));
assert_eq!(rec.workspace_access_point_id.as_deref(), Some("fsap-ws"));
// Hybrid waits for one and records none for /workspace.
let p = aws_project(StorageMode::Hybrid);
let fake = Fake { run: Some(task(&p, "new", "RUNNING", true)), ..Default::default() };
let records = Mutex::new(Vec::new());
let on_task = |r: Option<&TaskRecord>| records.lock().unwrap().push(r.cloned());
let started = start_core(&fake, &fake, &fake, &fake, &inputs(&p, &w, &on_task), &|_| {})
.await
.unwrap();
assert_eq!(started.workspace_access_point_id, None);
assert!(!fake.called("ap-state fsap-ws"));
assert_eq!(records.into_inner().unwrap()[0].as_ref().unwrap().workspace_access_point_id, None);
}
#[test]
fn switching_efs_to_hybrid_keeps_the_stored_workspace_access_point() {
let mut p = aws_project(StorageMode::Hybrid);
p.aws.as_mut().unwrap().workspace_access_point_id = Some("fsap-ws".into());
let (_d, store) = store_with(&p);
// A Hybrid start knows no /workspace access point: the stored one stays.
record_task(
&store,
&p.id,
Some(&TaskRecord {
task_arn: "arn:t".into(),
access_point_id: Some("fsap-home".into()),
task_definition_arn: None,
workspace_access_point_id: None,
}),
);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!(a.workspace_access_point_id.as_deref(), Some("fsap-ws"));
record_task(&store, &p.id, None);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!(a.workspace_access_point_id.as_deref(), Some("fsap-ws"));
// An EFS start records its own.
record_task(
&store,
&p.id,
Some(&TaskRecord {
task_arn: "arn:t2".into(),
access_point_id: None,
task_definition_arn: None,
workspace_access_point_id: Some("fsap-ws2".into()),
}),
);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!(a.workspace_access_point_id.as_deref(), Some("fsap-ws2"));
}
#[tokio::test]
async fn a_running_task_is_attached_with_its_own_token_and_nothing_is_rewritten() {
let p = aws_project(StorageMode::Hybrid);
@@ -666,7 +736,12 @@ fn a_start_records_its_task_and_keeps_the_stored_handles_it_does_not_know() {
record_task(
&store,
&p.id,
Some(&TaskRecord { task_arn: "arn:t".into(), access_point_id: None, task_definition_arn: Some("arn:td:2".into()) }),
Some(&TaskRecord {
task_arn: "arn:t".into(),
access_point_id: None,
task_definition_arn: Some("arn:td:2".into()),
workspace_access_point_id: None,
}),
);
let a = store.get(&p.id).unwrap().aws.unwrap();
assert_eq!((a.task_arn.as_deref(), a.access_point_id.as_deref(), a.task_definition_arn.as_deref()),
@@ -720,7 +795,12 @@ fn the_log_task_is_the_stored_one_else_the_last_one_a_start_saw() {
record_task(
&store,
&p.id,
Some(&TaskRecord { task_arn: "arn:first".into(), access_point_id: None, task_definition_arn: None }),
Some(&TaskRecord {
task_arn: "arn:first".into(),
access_point_id: None,
task_definition_arn: None,
workspace_access_point_id: None,
}),
);
record_task(&store, &p.id, None);
assert_eq!(log_task_arn(&p).as_deref(), Some("arn:first"), "a cleared ARN still has a log");
+1 -1
View File
@@ -132,7 +132,7 @@ impl ProjectHost {
/// AWS: stop the task and remove the project's resources — task
/// definition revisions, the secret (deleted at once) and, only
/// with `discard_data`, the EFS access point (not its files). Docker: nothing (its state
/// with `discard_data`, the EFS access points, home and EFS-mode `/workspace` (not their files). Docker: nothing (its state
/// goes with [`Self::discard_project_state`]).
pub async fn remove_aws_resources(
&self,
+7 -2
View File
@@ -51,6 +51,8 @@ pub struct LiveTunnel {
/// Runtime handles for the store (`set_aws_runtime`).
pub access_point_id: Option<String>,
pub task_definition_arn: String,
/// EFS storage's `/workspace` access point.
pub workspace_access_point_id: Option<String>,
}
/// Where an endpoint's task is: `(connection, region, cluster, task ARN)`.
@@ -123,13 +125,15 @@ pub fn get_endpoint(project_id: &str) -> Option<AgentEndpoint> {
lock().live.get(project_id).map(|t| t.endpoint.clone())
}
/// `(task ARN, access point id, task definition ARN)` of the project's tunnel.
pub fn runtime(project_id: &str) -> Option<(String, Option<String>, String)> {
/// `(task ARN, access point id, task definition ARN, workspace access point
/// id)` of the project's tunnel.
pub fn runtime(project_id: &str) -> Option<(String, Option<String>, String, Option<String>)> {
lock().live.get(project_id).map(|t| {
(
t.task_arn.clone(),
t.access_point_id.clone(),
t.task_definition_arn.clone(),
t.workspace_access_point_id.clone(),
)
})
}
@@ -334,6 +338,7 @@ pub(crate) mod tests {
endpoint: AgentEndpoint::loopback(port, "tok"),
access_point_id: Some("fsap-1".into()),
task_definition_arn: "arn:td:1".into(),
workspace_access_point_id: None,
}
}