fix(aws): reconcile AWS projects at startup without waiting for Docker
- New reconcile_aws_projects command (handler, capability, TS wrapper) that App runs on mount regardless of Docker; reconcile_project_statuses now skips AWS projects. Projects reconcile concurrently, 4 at a time, each still bounded at 15 s. - reconcile_task falls back to find_project_task when the stored task is gone or stopped, before calling the project Gone (m3). - An AWS project with no registered tunnel gets a placeholder target id (http://unattached.invalid/<id>/) instead of the last run's loopback URL, so a reused port can't match the wrong project; the death watch still reports it by that id until a re-attach registers (m9). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5e8e67a0a4
commit
2772647690
11 files changed
+180
-33
No files matched your search
@@ -23,6 +23,7 @@
|
||||
"allow-remove-aws-resources",
|
||||
"allow-rebuild-project-container",
|
||||
"allow-reconcile-project-statuses",
|
||||
"allow-reconcile-aws-projects",
|
||||
"allow-list-notes",
|
||||
"allow-save-note",
|
||||
"allow-delete-note",
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"__app-acl__":{"default_permission":null,"permissions":{"allow-acquire-claude-token":{"identifier":"allow-acquire-claude-token","description":"Enables the acquire_claude_token command without any pre-configured scope.","commands":{"allow":["acquire_claude_token"],"deny":[]}},"allow-add-aws-keys-connection":{"identifier":"allow-add-aws-keys-connection","description":"Enables the add_aws_keys_connection command without any pre-configured scope.","commands":{"allow":["add_aws_keys_connection"],"deny":[]}},"allow-add-aws-profile-connection":{"identifier":"allow-add-aws-profile-connection","description":"Enables the add_aws_profile_connection command without any pre-configured scope.","commands":{"allow":["add_aws_profile_connection"],"deny":[]}},"allow-add-marketplace":{"identifier":"allow-add-marketplace","description":"Enables the add_marketplace command without any pre-configured scope.","commands":{"allow":["add_marketplace"],"deny":[]}},"allow-add-marketplace-gh-host-account":{"identifier":"allow-add-marketplace-gh-host-account","description":"Enables the add_marketplace_gh_host_account command without any pre-configured scope.","commands":{"allow":["add_marketplace_gh_host_account"],"deny":[]}},"allow-add-marketplace-token-account":{"identifier":"allow-add-marketplace-token-account","description":"Enables the add_marketplace_token_account command without any pre-configured scope.","commands":{"allow":["add_marketplace_token_account"],"deny":[]}},"allow-add-project":{"identifier":"allow-add-project","description":"Enables the add_project command without any pre-configured scope.","commands":{"allow":["add_project"],"deny":[]}},"allow-add-scheduled-task":{"identifier":"allow-add-scheduled-task","description":"Enables the add_scheduled_task command without any pre-configured scope.","commands":{"allow":["add_scheduled_task"],"deny":[]}},"allow-apply-marketplace-now":{"identifier":"allow-apply-marketplace-now","description":"Enables the apply_marketplace_now command without any pre-configured scope.","commands":{"allow":["apply_marketplace_now"],"deny":[]}},"allow-apply-settings-import":{"identifier":"allow-apply-settings-import","description":"Enables the apply_settings_import command without any pre-configured scope.","commands":{"allow":["apply_settings_import"],"deny":[]}},"allow-aws-connection-identity":{"identifier":"allow-aws-connection-identity","description":"Enables the aws_connection_identity command without any pre-configured scope.","commands":{"allow":["aws_connection_identity"],"deny":[]}},"allow-aws-connection-sso-login":{"identifier":"allow-aws-connection-sso-login","description":"Enables the aws_connection_sso_login command without any pre-configured scope.","commands":{"allow":["aws_connection_sso_login"],"deny":[]}},"allow-aws-policy-document":{"identifier":"allow-aws-policy-document","description":"Enables the aws_policy_document command without any pre-configured scope.","commands":{"allow":["aws_policy_document"],"deny":[]}},"allow-aws-sso-refresh":{"identifier":"allow-aws-sso-refresh","description":"Enables the aws_sso_refresh command without any pre-configured scope.","commands":{"allow":["aws_sso_refresh"],"deny":[]}},"allow-aws-task-log":{"identifier":"allow-aws-task-log","description":"Enables the aws_task_log command without any pre-configured scope.","commands":{"allow":["aws_task_log"],"deny":[]}},"allow-build-gateway-image":{"identifier":"allow-build-gateway-image","description":"Enables the build_gateway_image command without any pre-configured scope.","commands":{"allow":["build_gateway_image"],"deny":[]}},"allow-build-image":{"identifier":"allow-build-image","description":"Enables the build_image command without any pre-configured scope.","commands":{"allow":["build_image"],"deny":[]}},"allow-build-stt-image":{"identifier":"allow-build-stt-image","description":"Enables the build_stt_image command without any pre-configured scope.","commands":{"allow":["build_stt_image"],"deny":[]}},"allow-cancel-aws-deployment":{"identifier":"allow-cancel-aws-deployment","description":"Enables the cancel_aws_deployment command without any pre-configured scope.","commands":{"allow":["cancel_aws_deployment"],"deny":[]}},"allow-cancel-claude-token":{"identifier":"allow-cancel-claude-token","description":"Enables the cancel_claude_token command without any pre-configured scope.","commands":{"allow":["cancel_claude_token"],"deny":[]}},"allow-cancel-marketplace-gh-login":{"identifier":"allow-cancel-marketplace-gh-login","description":"Enables the cancel_marketplace_gh_login command without any pre-configured scope.","commands":{"allow":["cancel_marketplace_gh_login"],"deny":[]}},"allow-check-aws-permissions":{"identifier":"allow-check-aws-permissions","description":"Enables the check_aws_permissions command without any pre-configured scope.","commands":{"allow":["check_aws_permissions"],"deny":[]}},"allow-check-browser-view-support":{"identifier":"allow-check-browser-view-support","description":Line truncated
|
||||
{"__app-acl__":{"default_permission":null,"permissions":{"allow-acquire-claude-token":{"identifier":"allow-acquire-claude-token","description":"Enables the acquire_claude_token command without any pre-configured scope.","commands":{"allow":["acquire_claude_token"],"deny":[]}},"allow-add-aws-keys-connection":{"identifier":"allow-add-aws-keys-connection","description":"Enables the add_aws_keys_connection command without any pre-configured scope.","commands":{"allow":["add_aws_keys_connection"],"deny":[]}},"allow-add-aws-profile-connection":{"identifier":"allow-add-aws-profile-connection","description":"Enables the add_aws_profile_connection command without any pre-configured scope.","commands":{"allow":["add_aws_profile_connection"],"deny":[]}},"allow-add-marketplace":{"identifier":"allow-add-marketplace","description":"Enables the add_marketplace command without any pre-configured scope.","commands":{"allow":["add_marketplace"],"deny":[]}},"allow-add-marketplace-gh-host-account":{"identifier":"allow-add-marketplace-gh-host-account","description":"Enables the add_marketplace_gh_host_account command without any pre-configured scope.","commands":{"allow":["add_marketplace_gh_host_account"],"deny":[]}},"allow-add-marketplace-token-account":{"identifier":"allow-add-marketplace-token-account","description":"Enables the add_marketplace_token_account command without any pre-configured scope.","commands":{"allow":["add_marketplace_token_account"],"deny":[]}},"allow-add-project":{"identifier":"allow-add-project","description":"Enables the add_project command without any pre-configured scope.","commands":{"allow":["add_project"],"deny":[]}},"allow-add-scheduled-task":{"identifier":"allow-add-scheduled-task","description":"Enables the add_scheduled_task command without any pre-configured scope.","commands":{"allow":["add_scheduled_task"],"deny":[]}},"allow-apply-marketplace-now":{"identifier":"allow-apply-marketplace-now","description":"Enables the apply_marketplace_now command without any pre-configured scope.","commands":{"allow":["apply_marketplace_now"],"deny":[]}},"allow-apply-settings-import":{"identifier":"allow-apply-settings-import","description":"Enables the apply_settings_import command without any pre-configured scope.","commands":{"allow":["apply_settings_import"],"deny":[]}},"allow-aws-connection-identity":{"identifier":"allow-aws-connection-identity","description":"Enables the aws_connection_identity command without any pre-configured scope.","commands":{"allow":["aws_connection_identity"],"deny":[]}},"allow-aws-connection-sso-login":{"identifier":"allow-aws-connection-sso-login","description":"Enables the aws_connection_sso_login command without any pre-configured scope.","commands":{"allow":["aws_connection_sso_login"],"deny":[]}},"allow-aws-policy-document":{"identifier":"allow-aws-policy-document","description":"Enables the aws_policy_document command without any pre-configured scope.","commands":{"allow":["aws_policy_document"],"deny":[]}},"allow-aws-sso-refresh":{"identifier":"allow-aws-sso-refresh","description":"Enables the aws_sso_refresh command without any pre-configured scope.","commands":{"allow":["aws_sso_refresh"],"deny":[]}},"allow-aws-task-log":{"identifier":"allow-aws-task-log","description":"Enables the aws_task_log command without any pre-configured scope.","commands":{"allow":["aws_task_log"],"deny":[]}},"allow-build-gateway-image":{"identifier":"allow-build-gateway-image","description":"Enables the build_gateway_image command without any pre-configured scope.","commands":{"allow":["build_gateway_image"],"deny":[]}},"allow-build-image":{"identifier":"allow-build-image","description":"Enables the build_image command without any pre-configured scope.","commands":{"allow":["build_image"],"deny":[]}},"allow-build-stt-image":{"identifier":"allow-build-stt-image","description":"Enables the build_stt_image command without any pre-configured scope.","commands":{"allow":["build_stt_image"],"deny":[]}},"allow-cancel-aws-deployment":{"identifier":"allow-cancel-aws-deployment","description":"Enables the cancel_aws_deployment command without any pre-configured scope.","commands":{"allow":["cancel_aws_deployment"],"deny":[]}},"allow-cancel-claude-token":{"identifier":"allow-cancel-claude-token","description":"Enables the cancel_claude_token command without any pre-configured scope.","commands":{"allow":["cancel_claude_token"],"deny":[]}},"allow-cancel-marketplace-gh-login":{"identifier":"allow-cancel-marketplace-gh-login","description":"Enables the cancel_marketplace_gh_login command without any pre-configured scope.","commands":{"allow":["cancel_marketplace_gh_login"],"deny":[]}},"allow-check-aws-permissions":{"identifier":"allow-check-aws-permissions","description":"Enables the check_aws_permissions command without any pre-configured scope.","commands":{"allow":["check_aws_permissions"],"deny":[]}},"allow-check-browser-view-support":{"identifier":"allow-check-browser-view-support","description":Line truncated
|
||||
@@ -1 +1 @@
|
||||
{"default":{"identifier":"default","description":"Default capabilities for Triple-C. Every entry here is an IPC command a compromised webview can call directly, so the set is an enumeration of what `app/src` actually invokes — plugin and core grants verified against tauri 2.11.0's `PLUGINS` table in tauri's own `build.rs` rather than assumed from a plugin's `default` set, app-command grants (the bare `allow-*` entries) cross-checked by this crate's `build.rs` against `generate_handler!`. `core:default` in particular is NOT used: it is an alias for `core:{path,event,window,webview,app,image,resources,menu,tray}:default`, and `core:image:default` carries `allow-from-path`, whose handler (`tauri-2.11.0/src/image/plugin.rs:41` → `src/image/mod.rs:96`) is a bare `std::fs::read(path)` with no scope mechanism of any kind. Nothing imports `@tauri-apps/api/image`, so the whole plugin is dropped rather than scoped — there is nothing to scope it with. `core:menu` and `core:tray` are dropped for the same reason (no menu, no tray icon); `core:window` and `core:path` because nothing imports them; `core:resources:allow-close` because no frontend value is a `Resource`; and `core:event`'s `allow-emit`/`allow-emit-to` because the frontend only ever *listens* — every emit in this app originates in Rust. Three notes on what is deliberately kept or accepted: (1) `core:webview:allow-internal-toggle-devtools` is not called by `app/src` at all — it is called by Tauri's own injected `toggle-devtools.js`, which binds Ctrl/Cmd+Shift+I. Both that script and the command behind it are `#[cfg(any(debug_assertions, feature = \"devtools\"))]`, so this grant is a `tauri dev` convenience that does not exist in a release bundle. (2) `opener:allow-open-url` is **gone**. It could not be narrowed by host — `TerminalView`'s `WebLinksAddon` opens links Claude printed inside the container, which are arbitrary by construction, so a host allowlist would have deleted the feature rather than bounded it — and it was carried here as an accepted residual risk: a compromised webview could make the OS open an attacker-chosen http(s) URL, an outbound channel. That risk is now closed rather than recorded. Every host-browser open in the app goes through the `open_url_external` command in `url_open.rs`, which exists because the AppImage environment leaks into a cold-launched browser on Linux (triple-c#34) and which re-validates the URL in Rust — scheme allowlist, no embedded credentials, no control characters, length cap, ASCII asserted before `execvp`. On macOS and Windows that command reaches the same plugin as before, via `OpenerExt::open_url`, whose desktop implementation calls `crate::open::open` directly and is therefore not gated by this file at all (`tauri-plugin-opener-2.5.3/src/lib.rs:60`). The plugin stays a dependency for exactly that reason; what is removed is the webview's ability to reach it without passing the Rust validation. (3) `drag:allow-start-drag` is **gone**, together with the OS drag-out it existed for. It could not be scoped — `tauri-plugin-drag` takes the item paths from the caller and has no scope mechanism, so a compromised webview could call `startDrag({ item: ['~/.ssh/id_rsa'] })` against any host path the user can read — and it was carried as an accepted residual risk for one gesture. Drag-out was held back for separate hardening (see branch `hold/disk-and-dragout`) and the plugin is no longer a dependency. Getting a file *out* of a container is either \"Back up container\" on the project's Overview tab, which archives a tree through the Docker API, or the Files tab's per-row \"Save to host…\", which copies one file; getting one *in* is a drop on the Terminal or the Files tab's \"Upload…\". None of the four touches this permission. The Files tab's two are worth separating out here, because they are the only host-path commands in the app whose dialog is opened by **Rust** rather than by the webview — `pick_save_path` and `pick_files_to_upload` in `commands/file_commands.rs` drive `tauri-plugin-dialog` from the backend, so a compromised webview can ask for a picker and nothing more: it cannot name a host path as an *input* to either command. Be precise about the limit of that claim — host paths do still travel outward in error text (`Failed to create /home/j/Documents/x.txt.triple-c-part-1a2b3c4d: Permission denied`), including canonicalized ones, which disclose symlink targets. That is accepted; the app already hands the webview the project paths. What is closed is the direction that mattered — the webview naming where bytes go. That is the shape an earlier revision of this file named as the honest one if the Files tab ever regained host I/O, and it is the shape it regained it in. The `dialog:allow-open` / `dialog:allow-save` grants below are therefore *not* what those two use; they remain for the frontend pickers in Add Project, the Config tab's workspace and access sections, the CA-certificate fielLine truncated
|
||||
{"default":{"identifier":"default","description":"Default capabilities for Triple-C. Every entry here is an IPC command a compromised webview can call directly, so the set is an enumeration of what `app/src` actually invokes — plugin and core grants verified against tauri 2.11.0's `PLUGINS` table in tauri's own `build.rs` rather than assumed from a plugin's `default` set, app-command grants (the bare `allow-*` entries) cross-checked by this crate's `build.rs` against `generate_handler!`. `core:default` in particular is NOT used: it is an alias for `core:{path,event,window,webview,app,image,resources,menu,tray}:default`, and `core:image:default` carries `allow-from-path`, whose handler (`tauri-2.11.0/src/image/plugin.rs:41` → `src/image/mod.rs:96`) is a bare `std::fs::read(path)` with no scope mechanism of any kind. Nothing imports `@tauri-apps/api/image`, so the whole plugin is dropped rather than scoped — there is nothing to scope it with. `core:menu` and `core:tray` are dropped for the same reason (no menu, no tray icon); `core:window` and `core:path` because nothing imports them; `core:resources:allow-close` because no frontend value is a `Resource`; and `core:event`'s `allow-emit`/`allow-emit-to` because the frontend only ever *listens* — every emit in this app originates in Rust. Three notes on what is deliberately kept or accepted: (1) `core:webview:allow-internal-toggle-devtools` is not called by `app/src` at all — it is called by Tauri's own injected `toggle-devtools.js`, which binds Ctrl/Cmd+Shift+I. Both that script and the command behind it are `#[cfg(any(debug_assertions, feature = \"devtools\"))]`, so this grant is a `tauri dev` convenience that does not exist in a release bundle. (2) `opener:allow-open-url` is **gone**. It could not be narrowed by host — `TerminalView`'s `WebLinksAddon` opens links Claude printed inside the container, which are arbitrary by construction, so a host allowlist would have deleted the feature rather than bounded it — and it was carried here as an accepted residual risk: a compromised webview could make the OS open an attacker-chosen http(s) URL, an outbound channel. That risk is now closed rather than recorded. Every host-browser open in the app goes through the `open_url_external` command in `url_open.rs`, which exists because the AppImage environment leaks into a cold-launched browser on Linux (triple-c#34) and which re-validates the URL in Rust — scheme allowlist, no embedded credentials, no control characters, length cap, ASCII asserted before `execvp`. On macOS and Windows that command reaches the same plugin as before, via `OpenerExt::open_url`, whose desktop implementation calls `crate::open::open` directly and is therefore not gated by this file at all (`tauri-plugin-opener-2.5.3/src/lib.rs:60`). The plugin stays a dependency for exactly that reason; what is removed is the webview's ability to reach it without passing the Rust validation. (3) `drag:allow-start-drag` is **gone**, together with the OS drag-out it existed for. It could not be scoped — `tauri-plugin-drag` takes the item paths from the caller and has no scope mechanism, so a compromised webview could call `startDrag({ item: ['~/.ssh/id_rsa'] })` against any host path the user can read — and it was carried as an accepted residual risk for one gesture. Drag-out was held back for separate hardening (see branch `hold/disk-and-dragout`) and the plugin is no longer a dependency. Getting a file *out* of a container is either \"Back up container\" on the project's Overview tab, which archives a tree through the Docker API, or the Files tab's per-row \"Save to host…\", which copies one file; getting one *in* is a drop on the Terminal or the Files tab's \"Upload…\". None of the four touches this permission. The Files tab's two are worth separating out here, because they are the only host-path commands in the app whose dialog is opened by **Rust** rather than by the webview — `pick_save_path` and `pick_files_to_upload` in `commands/file_commands.rs` drive `tauri-plugin-dialog` from the backend, so a compromised webview can ask for a picker and nothing more: it cannot name a host path as an *input* to either command. Be precise about the limit of that claim — host paths do still travel outward in error text (`Failed to create /home/j/Documents/x.txt.triple-c-part-1a2b3c4d: Permission denied`), including canonicalized ones, which disclose symlink targets. That is accepted; the app already hands the webview the project paths. What is closed is the direction that mattered — the webview naming where bytes go. That is the shape an earlier revision of this file named as the honest one if the Files tab ever regained host I/O, and it is the shape it regained it in. The `dialog:allow-open` / `dialog:allow-save` grants below are therefore *not* what those two use; they remain for the frontend pickers in Add Project, the Config tab's workspace and access sections, the CA-certificate fielLine truncated
|
||||
@@ -938,6 +938,12 @@
|
||||
"const": "allow-rebuild-project-container",
|
||||
"markdownDescription": "Enables the rebuild_project_container command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the reconcile_aws_projects command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-reconcile-aws-projects",
|
||||
"markdownDescription": "Enables the reconcile_aws_projects command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the reconcile_project_statuses command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -1886,6 +1892,12 @@
|
||||
"const": "deny-rebuild-project-container",
|
||||
"markdownDescription": "Denies the rebuild_project_container command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the reconcile_aws_projects command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-reconcile-aws-projects",
|
||||
"markdownDescription": "Denies the reconcile_aws_projects command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the reconcile_project_statuses command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
@@ -938,6 +938,12 @@
|
||||
"const": "allow-rebuild-project-container",
|
||||
"markdownDescription": "Enables the rebuild_project_container command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the reconcile_aws_projects command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "allow-reconcile-aws-projects",
|
||||
"markdownDescription": "Enables the reconcile_aws_projects command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Enables the reconcile_project_statuses command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
@@ -1886,6 +1892,12 @@
|
||||
"const": "deny-rebuild-project-container",
|
||||
"markdownDescription": "Denies the rebuild_project_container command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the reconcile_aws_projects command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
"const": "deny-reconcile-aws-projects",
|
||||
"markdownDescription": "Denies the reconcile_aws_projects command without any pre-configured scope."
|
||||
},
|
||||
{
|
||||
"description": "Denies the reconcile_project_statuses command without any pre-configured scope.",
|
||||
"type": "string",
|
||||
|
||||
@@ -1847,25 +1847,9 @@ pub async fn reconcile_project_statuses(
|
||||
continue;
|
||||
}
|
||||
|
||||
// AWS: ECS is the authority. One DescribeTasks per project, bounded
|
||||
// so a slow or unreachable AWS can't hold the app's start; a live
|
||||
// task's tunnel is re-opened in the background.
|
||||
// AWS projects are reconciled by `reconcile_aws_projects`, which the
|
||||
// UI runs at startup whether or not Docker answers.
|
||||
if project.is_aws() {
|
||||
let settings = state.settings_store.get();
|
||||
let store = state.projects_store.clone();
|
||||
if tokio::time::timeout(
|
||||
AWS_RECONCILE_TIMEOUT,
|
||||
crate::host::aws_host::reconcile(project, &settings, store),
|
||||
)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
log::warn!(
|
||||
"Project {}: AWS did not answer within {}s; status left as is",
|
||||
project.id,
|
||||
AWS_RECONCILE_TIMEOUT.as_secs()
|
||||
);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1911,6 +1895,59 @@ pub async fn reconcile_project_statuses(
|
||||
}
|
||||
|
||||
|
||||
/// How many AWS projects reconcile at once.
|
||||
const AWS_RECONCILE_CONCURRENCY: usize = 4;
|
||||
|
||||
/// Reconcile every AWS project against ECS (the authority), independently of
|
||||
/// Docker: an app started without Docker still learns which tasks run and
|
||||
/// re-opens their tunnels. One bounded DescribeTasks per project, a few at a
|
||||
/// time; a live task's tunnel is re-opened in the background.
|
||||
#[tauri::command]
|
||||
pub async fn reconcile_aws_projects(state: State<'_, AppState>) -> Result<Vec<Project>, String> {
|
||||
use futures_util::StreamExt;
|
||||
|
||||
let projects: Vec<Project> = state.projects_store.list().into_iter().filter(|p| p.is_aws()).collect();
|
||||
// A target id left from the last run is a loopback URL whose port a new
|
||||
// tunnel (any project's) may now own; until a re-attach registers, the
|
||||
// project gets an id no tunnel can have (m9).
|
||||
for p in &projects {
|
||||
if let Some(id) = crate::host::aws_host::unattached_container_id(p) {
|
||||
let _ = state.projects_store.set_container_id(&p.id, Some(id));
|
||||
}
|
||||
}
|
||||
let settings = state.settings_store.get();
|
||||
let store = state.projects_store.clone();
|
||||
futures_util::stream::iter(projects.into_iter().filter(|p| {
|
||||
matches!(
|
||||
p.status,
|
||||
ProjectStatus::Running | ProjectStatus::Error | ProjectStatus::Starting | ProjectStatus::Stopping
|
||||
) && crate::project_lock::held(&p.id).is_none()
|
||||
}))
|
||||
.for_each_concurrent(AWS_RECONCILE_CONCURRENCY, |project| {
|
||||
let settings = settings.clone();
|
||||
let store = store.clone();
|
||||
async move {
|
||||
// The store's current copy: the id above may have changed.
|
||||
let project = store.get(&project.id).unwrap_or(project);
|
||||
if tokio::time::timeout(
|
||||
AWS_RECONCILE_TIMEOUT,
|
||||
crate::host::aws_host::reconcile(&project, &settings, store),
|
||||
)
|
||||
.await
|
||||
.is_err()
|
||||
{
|
||||
log::warn!(
|
||||
"Project {}: AWS did not answer within {}s; status left as is",
|
||||
project.id,
|
||||
AWS_RECONCILE_TIMEOUT.as_secs()
|
||||
);
|
||||
}
|
||||
}
|
||||
})
|
||||
.await;
|
||||
Ok(state.projects_store.list())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -888,19 +888,48 @@ pub async fn reconcile_task<T: TaskApi>(
|
||||
let Some(arn) = task_arn_or_find(api, task_arn, find).await? else {
|
||||
return Ok(Reconciled::Gone);
|
||||
};
|
||||
let Some(cluster) = cluster_of_task(&arn) else {
|
||||
return Ok(Reconciled::Gone);
|
||||
};
|
||||
let found = api.describe(cluster, std::slice::from_ref(&arn)).await.map_err(s)?;
|
||||
Ok(match found.into_iter().find(|t| t.arn == arn) {
|
||||
Some(t)
|
||||
if t.desired_status == "RUNNING"
|
||||
&& matches!(t.last_status.as_str(), "PROVISIONING" | "PENDING" | "ACTIVATING" | "RUNNING") =>
|
||||
{
|
||||
Reconciled::Live(Box::new(t))
|
||||
if let Some(cluster) = cluster_of_task(&arn) {
|
||||
let found = api.describe(cluster, std::slice::from_ref(&arn)).await.map_err(s)?;
|
||||
if let Some(t) = found.into_iter().find(|t| t.arn == arn).filter(is_live) {
|
||||
return Ok(Reconciled::Live(Box::new(t)));
|
||||
}
|
||||
_ => Reconciled::Gone,
|
||||
})
|
||||
}
|
||||
// The stored task is gone or stopping. Another start (another machine,
|
||||
// or a crash before the store write) may have left the project a newer
|
||||
// one: look before calling it Gone (m3).
|
||||
if task_arn.is_some() {
|
||||
if let Some(t) =
|
||||
find_project_task(api, &find.cluster, &find.family, &find.owner_user_id, &find.project_id)
|
||||
.await
|
||||
.map_err(s)?
|
||||
.filter(|t| t.arn != arn && is_live(t))
|
||||
{
|
||||
return Ok(Reconciled::Live(Box::new(t)));
|
||||
}
|
||||
}
|
||||
Ok(Reconciled::Gone)
|
||||
}
|
||||
|
||||
fn is_live(t: &TaskInfo) -> bool {
|
||||
t.desired_status == "RUNNING"
|
||||
&& matches!(t.last_status.as_str(), "PROVISIONING" | "PENDING" | "ACTIVATING" | "RUNNING")
|
||||
}
|
||||
|
||||
/// The target id an AWS project gets while it has no registered tunnel, or
|
||||
/// `None` when its stored one is fine (a registered tunnel's, already this
|
||||
/// placeholder, or none). Never a loopback URL, so a port a new tunnel
|
||||
/// reuses can't make the death watch match the wrong project (m9). A valid
|
||||
/// agent URL, so the watch can still report the project by it.
|
||||
pub fn unattached_container_id(p: &Project) -> Option<String> {
|
||||
if !p.is_aws() {
|
||||
return None;
|
||||
}
|
||||
let stored = p.container_id.as_deref()?;
|
||||
if tunnels::get_endpoint(&p.id).is_some_and(|ep| ep.base_url.as_str() == stored) {
|
||||
return None;
|
||||
}
|
||||
let placeholder = format!("http://unattached.invalid/{}/", p.id);
|
||||
(stored != placeholder).then_some(placeholder)
|
||||
}
|
||||
|
||||
/// Reconcile one AWS project the store has as Running (or Starting/
|
||||
|
||||
@@ -727,3 +727,51 @@ fn the_log_task_is_the_stored_one_else_the_last_one_a_start_saw() {
|
||||
p.aws.as_mut().unwrap().task_arn = Some("arn:current".into());
|
||||
assert_eq!(log_task_arn(&p).as_deref(), Some("arn:current"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn reconcile_falls_back_to_a_newer_live_task_when_the_stored_one_stopped() {
|
||||
// m3: another machine restarted the project; the stored ARN is history.
|
||||
let mut p = aws_project(StorageMode::Ephemeral);
|
||||
p.status = ProjectStatus::Running;
|
||||
p.aws.as_mut().unwrap().task_arn = Some(task_arn("old"));
|
||||
let newer = task(&p, "newer", "RUNNING", true);
|
||||
let fake = Fake { listed: Mutex::new(vec![vec![newer.arn.clone()]]), ..Default::default() }
|
||||
.with_task(task(&p, "old", "STOPPED", false))
|
||||
.with_task(newer);
|
||||
let (_d, store) = store_with(&p);
|
||||
assert!(matches!(
|
||||
reconcile_project(&fake, &store, &p, &find(&p)).await.unwrap(),
|
||||
Reconciled::Live(t) if t.arn == task_arn("newer")
|
||||
));
|
||||
let after = store.get(&p.id).unwrap();
|
||||
assert_eq!(after.status, ProjectStatus::Running);
|
||||
assert_eq!(after.aws.unwrap().task_arn, Some(task_arn("newer")));
|
||||
|
||||
// ECS forgot the stored one and nothing else runs: Gone, after looking.
|
||||
let fake = Fake::default();
|
||||
let (_d, store) = store_with(&p);
|
||||
assert_eq!(reconcile_project(&fake, &store, &p, &find(&p)).await.unwrap(), Reconciled::Gone);
|
||||
assert!(fake.called("list"), "it looked for another task first");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn an_unattached_aws_project_gets_a_target_id_no_tunnel_can_have() {
|
||||
// m9: the last run's loopback port may belong to another project's
|
||||
// tunnel now.
|
||||
let mut p = aws_project(StorageMode::Ephemeral);
|
||||
p.status = ProjectStatus::Running;
|
||||
p.container_id = Some("http://127.0.0.1:61400/".into());
|
||||
p.aws.as_mut().unwrap().task_arn = Some(task_arn("u1"));
|
||||
let id = unattached_container_id(&p).expect("replaced");
|
||||
assert_eq!(id, format!("http://unattached.invalid/{}/", p.id));
|
||||
p.container_id = Some(id.clone());
|
||||
assert_eq!(unattached_container_id(&p), None, "idempotent");
|
||||
// The watch still reports it, by that id, and a registered tunnel on the
|
||||
// old port can't be confused with it.
|
||||
let w = watched_task(&p).expect("still watched");
|
||||
assert_eq!(w.target.id(), id);
|
||||
p.container_id = None;
|
||||
assert_eq!(unattached_container_id(&p), None, "nothing stored, nothing to replace");
|
||||
let local = Project::new("l".into(), Vec::new());
|
||||
assert_eq!(unattached_container_id(&local), None);
|
||||
}
|
||||
@@ -556,6 +556,7 @@ pub fn run() {
|
||||
commands::project_commands::remove_aws_resources,
|
||||
commands::project_commands::rebuild_project_container,
|
||||
commands::project_commands::reconcile_project_statuses,
|
||||
commands::project_commands::reconcile_aws_projects,
|
||||
// Notes
|
||||
commands::notes_commands::list_notes,
|
||||
commands::notes_commands::save_note,
|
||||
|
||||
+6
-1
@@ -25,7 +25,7 @@ import { useMarketplaceSyncToasts } from "./hooks/useMarketplace";
|
||||
import { useProjectStatusEvents } from "./hooks/useProjectStatusEvents";
|
||||
import MarketplaceView from "./components/marketplace/MarketplaceView";
|
||||
import { useAppState, isHomeTab, tabKeyId, homeTabKey, MARKETPLACE_TAB_KEY } from "./store/appState";
|
||||
import { reconcileProjectStatuses } from "./lib/tauri-commands";
|
||||
import { reconcileAwsProjects, reconcileProjectStatuses } from "./lib/tauri-commands";
|
||||
|
||||
export default function App() {
|
||||
const { checkDocker, checkImage, startDockerPolling } = useDocker();
|
||||
@@ -81,6 +81,11 @@ export default function App() {
|
||||
// Initialize on mount
|
||||
useEffect(() => {
|
||||
loadSettings();
|
||||
// AWS projects don't need Docker: ECS says which tasks run, and their
|
||||
// tunnels re-open in the background.
|
||||
reconcileAwsProjects()
|
||||
.then(setProjects)
|
||||
.catch((e) => console.error("Failed to reconcile AWS projects:", e));
|
||||
let stopPolling: (() => void) | undefined;
|
||||
checkDocker().then((available) => {
|
||||
if (available) {
|
||||
|
||||
@@ -43,6 +43,8 @@ export const rebuildProjectContainer = (projectId: string) =>
|
||||
invoke<ProjectResetOutcome>("rebuild_project_container", { projectId });
|
||||
export const reconcileProjectStatuses = () =>
|
||||
invoke<Project[]>("reconcile_project_statuses");
|
||||
/** AWS projects against ECS; run at startup whether or not Docker answers. */
|
||||
export const reconcileAwsProjects = () => invoke<Project[]>("reconcile_aws_projects");
|
||||
|
||||
// Notes — per-project, host-side, readable with the container stopped.
|
||||
export const listNotes = (projectId: string) =>
|
||||
|
||||
Reference in new issue
Block a user