An open-source, faster Devin alternative
TypeScript
Computers: review fixes for failure reasons
Igor Zalutski via Computer11af20e8971c
diff --git a/services/managed-agents/src/computer/durable-object.ts b/services/managed-agents/src/computer/durable-object.tsindex 48df443a..5ca46f30 100644--- a/services/managed-agents/src/computer/durable-object.ts+++ b/services/managed-agents/src/computer/durable-object.ts@@ -2816,13 +2816,14 @@ export class ComputerDurableObject extends DurableObject<ComputerEdgeEnv> {// Work 105: nothing here can start the operator's VM; the message waits for its host.notice = OFFLINE_NOTICE;} else if (row.state === "failed") {+ // Claimed per reason below: a thread told of one failure still hears of a different one.notice = failureNotice(row.failureCode, publicOrigin(this.env));}if (!notice) return;const inserted = this.ctx.storage.sql.exec("INSERT OR IGNORE INTO notices (thread_key, kind) VALUES (?, ?)",threadKey,- notice === WAKING_NOTICE ? "waking" : notice === STARTING_NOTICE ? "starting" : notice === RESIZING_NOTICE ? "resizing" : notice === OFFLINE_NOTICE ? "offline" : "failed",+ notice === WAKING_NOTICE ? "waking" : notice === STARTING_NOTICE ? "starting" : notice === RESIZING_NOTICE ? "resizing" : notice === OFFLINE_NOTICE ? "offline" : `failed:${row?.failureCode ?? ""}`,);// Off the chain (work 068 §3b): the notice is claimed above, synchronously, so it posts once.if (inserted.rowsWritten > 0) {diff --git a/services/managed-agents/src/computer/lifecycle.ts b/services/managed-agents/src/computer/lifecycle.tsindex 307840e3..020f49b4 100644--- a/services/managed-agents/src/computer/lifecycle.ts+++ b/services/managed-agents/src/computer/lifecycle.ts@@ -190,6 +190,8 @@ function failureCode(error: unknown, fatal: boolean): FailureCode {if (error instanceof ComputersNotConfigured) return "not_configured";if (error instanceof CloudError) {if (error.code === "not_configured") return "not_configured";+ // A disk or a network card can be refused for quota too, not only the VM.+ if (isCapacity(error.code, error.message)) return "capacity";// Refused outright: nothing a retry changes. Otherwise it was worth retrying, and never got through.return fatal ? "internal" : "unavailable";}@@ -412,7 +414,7 @@ export class ComputerLifecycle {const now = this.now();if (row) {this.deps.sql.exec(- `UPDATE computer SET state = 'ready', attempts = 0, last_error = NULL, wake_after_park = 0, delete_disk = 0,+ `UPDATE computer SET state = 'ready', attempts = 0, last_error = NULL, failure_code = NULL, wake_after_park = 0, delete_disk = 0,replace_failed_vm = 0, tags_pending = 0, updated_at = ? WHERE id = 1`,now,);diff --git a/services/managed-agents/test/computer-lifecycle.test.ts b/services/managed-agents/test/computer-lifecycle.test.tsindex 9abe2b2f..43b28ac2 100644--- a/services/managed-agents/test/computer-lifecycle.test.ts+++ b/services/managed-agents/test/computer-lifecycle.test.ts@@ -263,6 +263,13 @@ describe("computer lifecycle", () => {expect(failed()).toMatchObject([{ code: "capacity", from: "provisioning" }]);});+ it("capacity: quota refuses something other than the VM", async () => {+ await lifecycle.create(ORG, OPTIONS);+ cloud.failNext = new CloudError(400, "QuotaExceeded", "Operation could not be completed as it results in exceeding approved quota");+ await lifecycle.tick();+ expect(lifecycle.row()).toMatchObject({ state: "failed", failureCode: "capacity" });+ });+it("inconsistent: a resource is another organization's", async () => {cloud.resources.set("dataDisk", { provisioningState: "Succeeded", organization: "org_other" });await lifecycle.create(ORG, OPTIONS);