Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/lib/actions/sandbox/start.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,43 @@ describe("startSandbox", () => {
expect(output).toContain("openshell-my-sandbox");
});

it("continues gateway recovery when the container runtime is running and health is starting", async () => {
const h = harness();
h.recoverDockerDriverSandbox.mockReturnValue({
recovered: false,
via: null,
containerName: "openshell-my-sandbox",
detail:
"docker container openshell-my-sandbox did not become ready after recovery " +
"(runtime=running, health=starting)",
});

const result = await startSandbox("my-sandbox", h.deps);

expect(result.exitCode).toBe(0);
expect(h.probeSandbox).toHaveBeenCalledWith("my-sandbox");
expect(h.log.mock.calls.map(([line]) => line).join("\n")).toContain(
"running but still starting; continuing with gateway recovery",
);
});

it("does not probe after a terminal Docker readiness failure", async () => {
const h = harness();
h.recoverDockerDriverSandbox.mockReturnValue({
recovered: false,
via: null,
containerName: "openshell-my-sandbox",
detail:
"docker container openshell-my-sandbox did not become ready after recovery " +
"(runtime=exited, health=unhealthy)",
});

const result = await startSandbox("my-sandbox", h.deps);

expect(result.exitCode).toBe(1);
expect(h.probeSandbox).not.toHaveBeenCalled();
});

it("still probes when the container was already running (#6026)", async () => {
const h = harness();
h.findLabeledSandboxContainers.mockReturnValue([
Expand Down
18 changes: 16 additions & 2 deletions src/lib/actions/sandbox/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ function loadDockerUnpause(): DockerUnpauseFn {

const DOCKER_UNPAUSE_TIMEOUT_MS = 30_000;

function isRunningContainerStillStarting(
recovery: ReturnType<typeof recoverDockerDriverSandbox>,
): boolean {
if (recovery.recovered || !recovery.containerName) return false;
return (
recovery.detail ===
`docker container ${recovery.containerName} did not become ready after recovery (runtime=running, health=starting)`
);
}

// Paused containers report `Up N minutes (Paused)` from `docker ps`, so the
// recovery classifier counts them as running and would no-op — while
// `docker start` on them fails outright. `docker unpause` is the only verb
Expand Down Expand Up @@ -97,7 +107,7 @@ export async function startSandbox(
log(` Container '${paused.name}' unpaused.`);
} else {
const recovery = (deps.recoverDockerDriverSandbox ?? recoverDockerDriverSandbox)(sandboxName);
if (!recovery.recovered) {
if (!recovery.recovered && !isRunningContainerStillStarting(recovery)) {
return {
exitCode: 1,
message:
Expand All @@ -106,7 +116,11 @@ export async function startSandbox(
};
}

if (recovery.via === "started-running-original") {
if (!recovery.recovered) {
log(
` Container '${recovery.containerName}' is running but still starting; continuing with gateway recovery.`,
);
} else if (recovery.via === "started-running-original") {
log(` Sandbox '${sandboxName}' is already running.`);
} else {
log(` Container '${recovery.containerName ?? sandboxName}' started.`);
Expand Down
Loading