Skip to content

Commit efc81b0

Browse files
firecowclaude
andcommitted
Fix wait command to always check replica count
Previously, the wait command had two issues: 1. It would trust UpdateStatus.State when present without verifying that all replicas were actually running. 2. The desired-state:running filter excluded tasks being scheduled (which have DesiredState:"ready"), causing the command to see 0 tasks and incorrectly exit with success. Now we: - Remove the desired-state filter to see all tasks - Compare running task count against the service's configured replica count (Spec.Mode.Replicated.Replicas) This matches the behavior of docker-stack-wait. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d782389 commit efc81b0

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/commands/wait-cmd.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ export async function handler (args: ArgumentsCamelCase) {
4141

4242
serviceStateMap = new Map<string, string>();
4343
services = await dockerode.listServices({filters: {label: [`com.docker.stack.namespace=${appName}`]}});
44-
tasks = await dockerode.listTasks({filters: {"label": [`com.docker.stack.namespace=${appName}`], "desired-state": ["running"]}}) as Task[];
44+
tasks = await dockerode.listTasks({filters: {"label": [`com.docker.stack.namespace=${appName}`]}}) as Task[];
4545

4646
for (const s of services) {
47-
if (s.UpdateStatus?.State) {
47+
const runningTasks = tasks.filter((t) => t.Status.State === "running" && t.ServiceID === s.ID);
48+
const desiredReplicas = s.Spec?.Mode?.Replicated?.Replicas ?? 0;
49+
50+
// Always check replica count first - compare running tasks against desired replicas
51+
if (runningTasks.length < desiredReplicas) {
52+
serviceStateMap.set(s.ID, "replicating");
53+
} else if (s.UpdateStatus?.State && !["completed", "rollback_completed"].includes(s.UpdateStatus.State)) {
4854
serviceStateMap.set(s.ID, s.UpdateStatus.State);
49-
} else {
50-
const runningTasks = tasks.filter((t) => t.Status.State === "running" && t.ServiceID === s.ID);
51-
const totalTasks = tasks.filter((t) => t.ServiceID === s.ID);
52-
if (totalTasks.length > runningTasks.length) {
53-
serviceStateMap.set(s.ID, "replicating");
54-
}
5555
}
5656
}
5757

0 commit comments

Comments
 (0)