Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Drop unused busy() probes and accept retired INACTIVE deployments in rollout waits (#2059)

Regan Belld97a71294bf7
diff --git a/cli/src/backends/aws.ts b/cli/src/backends/aws.ts
index 2fa7cbf5b..5c9d975ea 100644
--- a/cli/src/backends/aws.ts
+++ b/cli/src/backends/aws.ts
@@ -1575,7 +1575,10 @@ async function awaitServiceTargets(
} else {
waiting.push(`${workload} (blue/green traffic shift or bake is still in progress)`);
}
- } else if (deployment.rolloutState !== "COMPLETED" || state.deployments?.length !== 1) {
+ } else if (
+ deployment.rolloutState !== "COMPLETED" ||
+ (state.deployments ?? []).some((item) => item !== deployment && (item.runningCount ?? 0) > 0)
+ ) {
waiting.push(`${workload} (prior tasks are still stopping)`);
}
}
diff --git a/cli/test/aws.test.ts b/cli/test/aws.test.ts
index d0873f127..c91da392d 100644
--- a/cli/test/aws.test.ts
+++ b/cli/test/aws.test.ts
@@ -252,6 +252,7 @@ function statefulAws(
failPromotion?: boolean;
promotionAlreadyCurrent?: boolean;
drainPolls?: number;
+ inactiveDeploymentRunning?: number;
primaryFailedTasks?: boolean;
rolloutFailed?: boolean;
transientFailedTaskPolls?: number;
@@ -387,7 +388,7 @@ else if (a.includes("ecs describe-services")) {
: blueGreenBakePolls
? [{ id: service.deploymentId, status: "PRIMARY", taskDefinition: service.taskDefinition, rolloutState: "COMPLETED", runningCount: service.desiredCount, failedTasks: 0 }]
: [{ id: service.deploymentId, status: "PRIMARY", taskDefinition: service.taskDefinition, rolloutState: "COMPLETED", runningCount: service.desiredCount, failedTasks: transientFailedTaskPolls && s.updated ? 1 : 0 }];
- return [{ serviceName: name, status: "ACTIVE", launchType: "FARGATE", platformVersion: "1.4.0", networkConfiguration: { awsvpcConfiguration: { subnets: ["subnet-a", "subnet-b"], securityGroups: ["sg-core"], assignPublicIp: "ENABLED" } }, desiredCount: service.desiredCount, runningCount: draining ? service.desiredCount + 1 : service.desiredCount, taskDefinition: service.taskDefinition, deploymentConfiguration: { strategy: blueGreenBakePolls ? "BLUE_GREEN" : "ROLLING" }, deployments: deployments.map(deployment => ({ pendingCount: 0, ...deployment })), pendingCount: 0, loadBalancers: service.workload === ${JSON.stringify(frontService)} ? [{ targetGroupArn: ${JSON.stringify(frontTargetArn)}, ...(blueGreenBakePolls ? { advancedConfiguration: { alternateTargetGroupArn: ${JSON.stringify(frontAlternateArn)}, productionListenerRule: ${JSON.stringify(productionRuleArn)} } } : {}) }] : (service.workload === "core" && ${JSON.stringify(coreHosts.length > 0)} ? [{ targetGroupArn: ${JSON.stringify(coreTargetArn)} }] : []), tags: [{ key: "Deployment", value: ${JSON.stringify(opts.foreignServiceTags ? "other" : configured.orgId)} }, { key: "ManagedBy", value: "terraform" }], ...(s.serviceOverrides?.[name] || {}) }];
+ return [{ serviceName: name, status: "ACTIVE", launchType: "FARGATE", platformVersion: "1.4.0", networkConfiguration: { awsvpcConfiguration: { subnets: ["subnet-a", "subnet-b"], securityGroups: ["sg-core"], assignPublicIp: "ENABLED" } }, desiredCount: service.desiredCount, runningCount: draining ? service.desiredCount + 1 : service.desiredCount, taskDefinition: service.taskDefinition, deploymentConfiguration: { strategy: blueGreenBakePolls ? "BLUE_GREEN" : "ROLLING" }, deployments: [...deployments, ...(${JSON.stringify(opts.inactiveDeploymentRunning === undefined ? [] : [{ id: "inactive", status: "INACTIVE", rolloutState: "COMPLETED", runningCount: opts.inactiveDeploymentRunning, failedTasks: 0 }])}).map(deployment => ({ taskDefinition: service.taskDefinition, ...deployment }))].map(deployment => ({ pendingCount: 0, ...deployment })), pendingCount: 0, loadBalancers: service.workload === ${JSON.stringify(frontService)} ? [{ targetGroupArn: ${JSON.stringify(frontTargetArn)}, ...(blueGreenBakePolls ? { advancedConfiguration: { alternateTargetGroupArn: ${JSON.stringify(frontAlternateArn)}, productionListenerRule: ${JSON.stringify(productionRuleArn)} } } : {}) }] : (service.workload === "core" && ${JSON.stringify(coreHosts.length > 0)} ? [{ targetGroupArn: ${JSON.stringify(coreTargetArn)} }] : []), tags: [{ key: "Deployment", value: ${JSON.stringify(opts.foreignServiceTags ? "other" : configured.orgId)} }, { key: "ManagedBy", value: "terraform" }], ...(s.serviceOverrides?.[name] || {}) }];
}), failures: names.filter((name) => !s.services[name]).map((name) => ({ arn: name, reason: "MISSING" })) }));
}
else if (a.includes("ecs list-service-deployments") && ${JSON.stringify(opts.failNativeStatusOnceAfterUpdate ?? false)} && s.updated && !s.nativeStatusFailedOnce) {
@@ -4711,6 +4712,34 @@ test("AWS up still fails fast on a FAILED rollout state — the ECS circuit-brea
}
});
+for (const running of [0, 1]) {
+ test(`AWS up treats a lingering INACTIVE deployment as retired only once its tasks stop: runningCount=${running}`, async () => {
+ const dir = mkdtempSync(join(tmpdir(), "qm-aws-up-inactive-deployment-"));
+ const dockerBin = join(dir, "docker");
+ writeFileSync(dockerBin, "#!/bin/sh\nexit 0\n");
+ chmodSync(dockerBin, 0o755);
+ const fake = statefulAws(dir, oneServiceConfig(), {}, { inactiveDeploymentRunning: running });
+ const priorPath = process.env.PATH;
+ const priorDeadline = process.env.QM_AWS_ROLLOUT_DEADLINE_MS;
+ process.env.PATH = `${dir}:${priorPath}`;
+ process.env.QM_AWS_ROLLOUT_DEADLINE_MS = "1500";
+ try {
+ if (running === 0) await awsUp(oneServiceConfig(), dir, { yes: true });
+ else
+ await assert.rejects(
+ () => awsUp(oneServiceConfig(), dir, { yes: true }),
+ /timed out waiting for the AWS rollout/,
+ );
+ } finally {
+ process.env.PATH = priorPath;
+ if (priorDeadline === undefined) delete process.env.QM_AWS_ROLLOUT_DEADLINE_MS;
+ else process.env.QM_AWS_ROLLOUT_DEADLINE_MS = priorDeadline;
+ fake.restore();
+ rmSync(dir, { recursive: true, force: true });
+ }
+ });
+}
+
test("AWS up preserves the staging tag when stable-label promotion fails", async () => {
const dir = mkdtempSync(join(tmpdir(), "qm-aws-up-promotion-"));
const dockerBin = join(dir, "docker");
diff --git a/src/runs/worker.ts b/src/runs/worker.ts
index 4220d7e1a..fcad0299a 100644
--- a/src/runs/worker.ts
+++ b/src/runs/worker.ts
@@ -138,7 +138,6 @@ export interface Worker {
drained(): Promise<void>;
stop(drainMs?: number): Promise<void>;
releaseInFlight(): Promise<void>;
- busy(): boolean;
}
const STOP_DRAIN_MS = 2_000;
@@ -258,9 +257,6 @@ export function createWorker(deps: WorkerDeps): Worker {
loopDone = null;
});
},
- busy() {
- return inFlight !== null;
- },
async releaseInFlight() {
await stopClaims();
const held = inFlight;
diff --git a/src/util/admitted-work.ts b/src/util/admitted-work.ts
index 1c3a20e53..876929f75 100644
--- a/src/util/admitted-work.ts
+++ b/src/util/admitted-work.ts
@@ -13,7 +13,6 @@ export function createAdmittedWork(options: { paused?: boolean; canStart?: () =>
const canRun = () => context.getStore()?.active === true || (!paused && (options.canStart?.() ?? true));
return {
canRun,
- busy: () => pending.size > 0,
pause() {
paused = true;
},
diff --git a/test/admitted-work.test.ts b/test/admitted-work.test.ts
index 9fd220102..17ffa42aa 100644
--- a/test/admitted-work.test.ts
+++ b/test/admitted-work.test.ts
@@ -8,7 +8,6 @@ test("pause fences new work while accepted work drains, then rollback resumes",
const work = createAdmittedWork();
const finish = Promise.withResolvers<void>();
const accepted = work.run(() => finish.promise);
- assert.equal(work.busy(), true);
work.pause();
await assert.rejects(
work.run(() => assert.fail("ran after pause")),
@@ -26,7 +25,6 @@ test("pause fences new work while accepted work drains, then rollback resumes",
finish.resolve();
await accepted;
await drain;
- assert.equal(work.busy(), false);
});
test("already admitted callbacks can start nested work after pause without leaking admission", async () => {
@@ -67,16 +65,14 @@ test("detached async contexts lose admission when their accepting callback finis
await assert.rejects(delayed, WorkAdmissionClosed);
});
-test("admission is registered before callback execution and errors cannot strand busy state", async () => {
+test("failed work does not strand drained", async () => {
const work = createAdmittedWork();
await assert.rejects(
work.run(() => {
- assert.equal(work.busy(), true);
throw new Error("failed work");
}),
/failed work/,
);
work.pause();
await work.drained();
- assert.equal(work.busy(), false);
});
diff --git a/test/deploy-drain.test.ts b/test/deploy-drain.test.ts
index ed63fba4e..7e5592f0a 100644
--- a/test/deploy-drain.test.ts
+++ b/test/deploy-drain.test.ts
@@ -44,20 +44,23 @@ test("a superseded worker stops claiming; in-flight turns finish; claiming resum
await runs.enqueue({ sessionId: "s1", request: turn, maxAttempts: 3 });
await sleep(50);
- assert.equal(worker.busy(), true, "the first run was claimed");
+ assert.equal(turns.length, 1, "the first run was claimed");
superseded = true;
await sleep(50);
await runs.enqueue({ sessionId: "s2", request: turn, maxAttempts: 3 });
release!();
await sleep(80);
- assert.equal(worker.busy(), false, "the in-flight turn finished");
- const pending = (await runs.list()).filter((r) => r.status === "pending");
- assert.equal(pending.length, 1, "the new run was NOT claimed while superseded");
+ const statuses = (await runs.list()).map((r) => r.status).sort();
+ assert.deepEqual(
+ statuses,
+ ["done", "pending"],
+ "the in-flight turn finished and the new run was NOT claimed while superseded",
+ );
superseded = false;
await sleep(80);
- assert.equal(worker.busy(), true, "claiming resumed once the newer build disappeared");
+ assert.equal(turns.length, 2, "claiming resumed once the newer build disappeared");
release!();
await worker.stop();
await drain.stop();
diff --git a/test/worker-reaper.test.ts b/test/worker-reaper.test.ts
index e62740ac2..98c34fa1e 100644
--- a/test/worker-reaper.test.ts
+++ b/test/worker-reaper.test.ts
@@ -274,14 +274,12 @@ test("shutdown cancels before handback and holds both leases until the turn unwi
await sleep(20);
assert.equal(signal.aborted, true, "shutdown reaches the existing cancellation signal immediately");
assert.equal(released, false, "handback waits for the cancellation checkpoint and finally block");
- assert.equal(worker.busy(), true);
assert.equal((await runs.get(enq.id))?.status, "running");
assert.equal(await runs.claim("replacement", 5_000), null);
assert.equal((await sessions.acquireLease(session.id)).lease, null);
const second = worker.releaseInFlight();
unwind();
await Promise.all([handback, second]);
- assert.equal(worker.busy(), false);
assert.equal((await runs.get(enq.id))?.status, "pending");
assert.equal((await runs.get(enq.id))?.errorAttempts, 0);
const replacement = await runs.claim("replacement", 5_000);