From 2f91ecc047f95bd485ab618c5e316eece71b5780 Mon Sep 17 00:00:00 2001 From: lyra-setkernel <341047397+lyra-setkernel@users.noreply.github.com> Date: Wed, 2 Dec 2026 22:15:45 +0000 Subject: [PATCH 1/5] fix: shutdown edge cases from the first review (#3) - q stops the run from the deploy on (deploy, download, warm-up), not only in the session. - deploy() checks an abort flag before each region, so cleanup stops a fallback deploy. - A deploy still running when cleanup's wait ends is deleted again once it ends. - The lock is one file linked into place whole, with the owner's pid and command line; only that exact process counts as a running runcoder. - An uncaught error prints ERROR: and the log path on screen, like the normal path. - README names the c and p keys the code uses. Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +- bin/runcoder.mjs | 22 ++++++--- src/cloud.mjs | 6 ++- src/session.mjs | 84 +++++++++++++++++++++------------ src/ui.mjs | 8 ++++ tests/1-run.test.mjs | 31 ++++++++++-- tests/2-recovery.test.mjs | 47 ++++++++++++++++-- tests/fake/gcloud.mjs | 4 +- tests/fake/unexpected-error.mjs | 14 ++++++ 9 files changed, 172 insertions(+), 49 deletions(-) create mode 100644 tests/fake/unexpected-error.mjs diff --git a/README.md b/README.md index fd8acd9..42efe4d 100644 --- a/README.md +++ b/README.md @@ -48,10 +48,11 @@ runcoder ~/code/my-project 3. It opens Qwen Code in a new terminal window, in your folder, pointed at the server. 4. The first window stays as the control panel: every 10 minutes it prints the time and cost so far. **Press q there (or Ctrl+C, or close the window) and it deletes the server**, then prints - what the session cost. + what the session cost. q works from the deploy on, also while the model downloads. While the + session runs, r reopens Qwen Code where you left off. If the folder has earlier Qwen Code sessions, runcoder asks whether to continue the latest -(c), pick one (r), or start fresh. `-c`, `-p` and `-n` answer that in advance. +(c), pick one (p), or start fresh (Enter). `-c`, `-p` and `-n` answer that in advance. Other commands: diff --git a/bin/runcoder.mjs b/bin/runcoder.mjs index 94d2446..55a66f4 100644 --- a/bin/runcoder.mjs +++ b/bin/runcoder.mjs @@ -46,11 +46,15 @@ async function finish(rc) { } // Ctrl+C, a closed window (SIGHUP, also on Windows) or a kill all end in the same cleanup. for (const [sig, rc] of [["SIGINT", 130], ["SIGTERM", 143], ["SIGHUP", 129]]) process.on(sig, () => finish(rc)); -// Any error nothing else caught still ends in cleanup, so the server is deleted; during cleanup it is -// logged and cleanup carries on. +// Any error nothing else caught is shown like any other and still ends in cleanup, so the server is +// deleted; during cleanup it is only logged and cleanup carries on. for (const ev of ["uncaughtException", "unhandledRejection"]) { process.on(ev, (e) => { - log(`${ev}: ${e?.stack || e}`); + if (exiting) log(`${ev}: ${e?.stack || e}`); + else { + say(`ERROR: ${e?.stack || e}`); + say(`Full log: ${logFile}`); + } finish(1); }); } @@ -61,11 +65,15 @@ try { else if (cmd === "status") await cmdStatus(s); else if (cmd === "credit") await cmdCredit(s); else if (cmd === "down") cmdDown(s); - else await cmdUp(s, cmd === undefined ? [] : [cmd, ...rest]); + else await cmdUp(s, cmd === undefined ? [] : [cmd, ...rest], () => finish(0)); await finish(0); } catch (e) { - if (e instanceof Stop) say(`ERROR: ${e.message}`); - else say(`ERROR: ${e.stack || e}`); - say(`Full log: ${logFile}`); + // q, Ctrl+C or a closed window during start-up leaves start-up to fail on the closed tunnel; that + // is not news, so only log it. + if (exiting) log(`after cleanup started: ${e.stack || e}`); + else { + say(`ERROR: ${e instanceof Stop ? e.message : e.stack || e}`); + say(`Full log: ${logFile}`); + } await finish(1); } diff --git a/src/cloud.mjs b/src/cloud.mjs index ec9f32d..f310347 100644 --- a/src/cloud.mjs +++ b/src/cloud.mjs @@ -102,9 +102,11 @@ export async function preflight(s) { if (!(await apiEnabled(s, "run.googleapis.com"))) die(`The Cloud Run API is off in ${s.project}. Run: runcoder setup`); } -// Starts the GPU service, trying each region in turn. Returns the region it runs in. -export async function deploy(s, onAttempt) { +// Starts the GPU service, trying each region in turn. Returns the region it runs in, or null once +// aborted() is true (cleanup has started): no further region is tried. +export async function deploy(s, onAttempt, aborted = () => false) { for (const region of s.regions) { + if (aborted()) return null; say(`Starting the GPU server in ${region} (takes 1-2 minutes)...`); onAttempt(region); const r = await gcloud(s, [ diff --git a/src/session.mjs b/src/session.mjs index 862ffaf..a4a83df 100644 --- a/src/session.mjs +++ b/src/session.mjs @@ -1,6 +1,6 @@ // One run from start to delete, plus status, credit and down. -import { mkdirSync, readFileSync, writeFileSync, rmSync, statSync, realpathSync } from "node:fs"; +import { mkdirSync, readFileSync, writeFileSync, linkSync, rmSync, statSync, realpathSync } from "node:fs"; import { resolve } from "node:path"; import { paths, configExists } from "./config.mjs"; import { serviceRegions, deleteEverything, activeInstances, preflight, deploy } from "./cloud.mjs"; @@ -8,37 +8,43 @@ import * as cost from "./cost.mjs"; import { Tunnel, httpCode, modelReady, freePort, waitForTunnel, waitForModel, warmModel, keepAwake } from "./tunnel.mjs"; import { writeQwenSettings, qwenSessions, openQwen, qwenAlive, stopQwen } from "./qwen.mjs"; import { alive, commandOf, killTree, sleep } from "./proc.mjs"; -import { say, warn, die, notify, key, startKeyboard, stopKeyboard, logFile, isInteractive } from "./ui.mjs"; +import { say, warn, die, notify, key, quitOnQ, startKeyboard, stopKeyboard, logFile, isInteractive } from "./ui.mjs"; // What cleanup needs to know about this run. export const state = { deploying: null, own: false, locked: false, deployStart: 0, tunnel: null, awake: null, c: null, s: null, cleaning: false }; const liveSeconds = () => (state.deployStart ? (Date.now() - state.deployStart) / 1000 : 0); const costSoFar = () => cost.money(state.c, cost.sessionCost(state.c, liveSeconds())); -function acquireLock() { - mkdirSync(paths.state, { recursive: true }); +// The lock is a file with its owner's process ID and command line. It is written whole first and +// then linked into place in one step, so another run never finds a lock without its contents. +function acquireLock(contents) { + const tmp = `${paths.lock}.${process.pid}`; + writeFileSync(tmp, contents); try { - mkdirSync(paths.lock); + linkSync(tmp, paths.lock); + state.locked = true; + return true; } catch { - let pid = 0; - try { - pid = Number(readFileSync(`${paths.lock}/pid`, "utf8")); - } catch {} - return pid; + return false; + } finally { + rmSync(tmp, { force: true }); } - writeFileSync(`${paths.lock}/pid`, String(process.pid)); - state.locked = true; - return 0; } async function lock() { - const other = acquireLock(); - if (!other) return; - // Only a live runcoder counts; a stale lock whose process ID was reused does not. - if (alive(other) && (await commandOf(other)).includes("runcoder")) { - die(`runcoder is already running (process ${other}). Use that window, or run: runcoder down`); + mkdirSync(paths.state, { recursive: true }); + const mine = JSON.stringify({ pid: process.pid, command: await commandOf(process.pid) }); + if (acquireLock(mine)) return; + let other = {}; + try { + other = JSON.parse(readFileSync(paths.lock, "utf8")); + } catch {} + // Only the runcoder that wrote the lock counts: a process ID reused since has another command + // line. If the command line could not be read then, any live process with that ID counts. + if (other.pid && alive(other.pid) && (!other.command || (await commandOf(other.pid)) === other.command)) { + die(`runcoder is already running (process ${other.pid}). Use that window, or run: runcoder down`); } rmSync(paths.lock, { recursive: true, force: true }); - if (acquireLock()) die("Could not take the lock; another runcoder is starting."); + if (!acquireLock(mine)) die("Could not take the lock; another runcoder is starting."); } // Runs once, on q, a limit, Ctrl+C, a closed window or an error: closes Qwen Code and the tunnel, @@ -52,13 +58,22 @@ export async function cleanup(rc) { if (state.awake) killTree(state.awake.pid); if (state.own) { const { s, c } = state; - if (state.deploying) { + const deploying = state.deploying?.then(() => true, () => true); // true once the deploy has ended, however + let late = false; + if (deploying) { // Deleting while gcloud is still deploying fails or races it; let the deploy finish first. say("Waiting for the deploy in progress to finish, then deleting..."); - await Promise.race([state.deploying.catch(() => {}), sleep(600)]); + late = !(await Promise.race([deploying, sleep(600 * s.timeScale)])); } say("Shutting down and deleting the Cloud Run service..."); - if (await deleteEverything(s)) { + let gone = await deleteEverything(s); + if (late) { + // A deploy that ends after that delete leaves a service behind; delete again once it ends. + say("The deploy is still running; deleting again as soon as it ends..."); + await deploying; + gone = await deleteEverything(s); + } + if (gone) { if (state.deployStart && c) { say(`This session ran ${Math.floor(liveSeconds() / 60)} minutes and cost about ${costSoFar()}.`); if (cost.creditEnabled(c)) say(cost.creditLine(c, liveSeconds())); @@ -113,11 +128,7 @@ async function session(s, workdir, tunnel, region) { say("Press q here when you are done (or Ctrl+C, or close this window): everything is shut down and deleted."); say(`Press r to reopen Qwen Code where you left off. It stops by itself after ${s.maxMinutes} minutes.`); for (;;) { - const k = isInteractive() ? await key(s.tick) : (await sleep(s.tick), ""); - if (/^[qQ]$/.test(k)) { - say("q pressed."); - return; - } + const k = isInteractive() ? await key(s.tick) : (await sleep(s.tick), ""); // q is quitOnQ's, from cmdUp if (/^[rR]$/.test(k)) { await openQwen(s, workdir, "--continue"); qwenSeen = false; @@ -180,7 +191,8 @@ async function chooseQwenSession(s, workdir, chosen) { return mode; } -export async function cmdUp(s, argv) { +// quit() ends the run with cleanup and exit code 0 (q pressed). +export async function cmdUp(s, argv, quit) { let dir = ""; let mode = null; // null: ask for (const a of argv) { @@ -229,12 +241,22 @@ export async function cmdUp(s, argv) { state.own = true; } state.awake = await keepAwake(); - state.deploying = deploy(s, () => { - state.own = true; - state.deployStart ||= Date.now(); // a fallback region keeps counting from the first attempt + // From the deploy on, q stops the run at once, also during the deploy, download and warm-up. + quitOnQ(() => { + say("q pressed."); + quit(); }); + state.deploying = deploy( + s, + () => { + state.own = true; + state.deployStart ||= Date.now(); // a fallback region keeps counting from the first attempt + }, + () => state.cleaning, // cleanup has started: no next region + ); const region = await state.deploying; state.deploying = null; + if (state.cleaning) return; // cleanup ends the run (and deletes what the deploy made) if (region !== s.regions[0]) state.c = await cost.loadCost(s, region); // prices differ by region const tunnel = (state.tunnel = new Tunnel(s, region)); tunnel.start(); diff --git a/src/ui.mjs b/src/ui.mjs index a3a821d..17d4009 100644 --- a/src/ui.mjs +++ b/src/ui.mjs @@ -87,7 +87,15 @@ export function startKeyboard(isInteractive) { process.stdin.on("error", () => {}); process.stdin.resume(); } +// From now on q (or Q) calls fn at once, whatever runcoder is doing or waiting for; a q typed +// earlier and not yet read counts too. +let onQuit = null; +export function quitOnQ(fn) { + onQuit = fn; + if (queue.some((k) => /^[qQ]$/.test(k))) fn(); +} function push(k) { + if (onQuit && /^[qQ]$/.test(k)) return onQuit(); if (waiting) { const w = waiting; waiting = null; diff --git a/tests/1-run.test.mjs b/tests/1-run.test.mjs index 87bf639..1709e4a 100644 --- a/tests/1-run.test.mjs +++ b/tests/1-run.test.mjs @@ -1,9 +1,9 @@ -// A normal run, Ctrl+C, closing the window, and falling back to the second region. +// A normal run, Ctrl+C, closing the window, q during start-up, and falling back to the second region. import { test, before, after } from "node:test"; import assert from "node:assert/strict"; -import { readdirSync, readFileSync, existsSync } from "node:fs"; +import { readdirSync, readFileSync, existsSync, writeFileSync } from "node:fs"; import { join } from "node:path"; -import { sandbox, start, startGoogle, noService, touch, calls, killLeftovers, windows } from "./helpers.mjs"; +import { sandbox, start, startGoogle, noService, touch, fake, calls, killLeftovers, windows } from "./helpers.mjs"; let server; before(async () => (server = await startGoogle())); @@ -69,3 +69,28 @@ test("falls back to the next region and cleans both", async () => { assert.equal(await r.done(), 0, r.out()); assert.ok(noService(ctx)); }); + +test("q during the download deletes everything", async () => { + const ctx = sandbox("t2q", { readyAfter: 30 }); + const r = start(ctx); + assert.ok(await r.waitFor("Downloading", 30), r.out()); + r.press("q"); + assert.equal(await r.done(30), 0, r.out()); + assert.ok(!r.has("Model downloaded"), r.out()); // stopped at once, not when the session began + assert.ok(r.has("q pressed."), r.out()); + assert.ok(r.has("Done: runcoder is deleted"), r.out()); + assert.ok(noService(ctx), calls(ctx)); +}); + +test("q during the deploy: no next region is tried, everything is deleted", async () => { + const ctx = sandbox("t4q"); + touch(ctx, "deployfail-us-central1"); + writeFileSync(fake(ctx, "deploy_seconds"), "3"); + const r = start(ctx); + assert.ok(await r.waitFor("Starting the GPU server in us-central1", 30), r.out()); + r.press("q"); + assert.equal(await r.done(60), 0, r.out()); + assert.ok(r.has("Done: runcoder is deleted"), r.out()); + assert.doesNotMatch(calls(ctx), /run deploy \S+ --region=europe-west4/); + assert.ok(noService(ctx), calls(ctx)); +}); diff --git a/tests/2-recovery.test.mjs b/tests/2-recovery.test.mjs index b12e0ac..eb42b41 100644 --- a/tests/2-recovery.test.mjs +++ b/tests/2-recovery.test.mjs @@ -1,8 +1,11 @@ -// Tunnel and server trouble, a second copy, a busy port, status/down, failed deletes, leftovers. +// Tunnel and server trouble, a second copy, a stale lock, a slow deploy, an unexpected error, a busy +// port, status/down, failed deletes, leftovers. import { test, before, after } from "node:test"; import assert from "node:assert/strict"; -import { rmSync, existsSync } from "node:fs"; -import { sandbox, start, once, startGoogle, noService, touch, fake, setReady, calls, killLeftovers, sleep, PORT, windows } from "./helpers.mjs"; +import { rmSync, existsSync, mkdirSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; +import { pathToFileURL } from "node:url"; +import { sandbox, start, once, startGoogle, noService, touch, fake, setReady, calls, killLeftovers, sleep, PORT, ROOT, windows } from "./helpers.mjs"; import { startOllama } from "./fake/ollama.mjs"; let server; @@ -73,6 +76,44 @@ test("a second copy is refused and leaves the first alone", async () => { assert.ok(noService(ctx)); }); +test("a lock left by a process ID another program now has is taken over", async () => { + const ctx = sandbox("t7b"); + mkdirSync(ctx.state, { recursive: true }); + // This test process is alive, but is not the runcoder whose command line the lock records. + writeFileSync(join(ctx.state, "lock"), JSON.stringify({ pid: process.pid, command: "node /old/runcoder/bin/runcoder.mjs -n /work" })); + const r = start(ctx); + assert.ok(await r.waitFor("Press q here", 60), r.out()); + assert.ok(!r.has("already running"), r.out()); + r.press("q"); + assert.equal(await r.done(), 0, r.out()); + assert.ok(noService(ctx)); + assert.ok(!existsSync(join(ctx.state, "lock"))); +}); + +test("a deploy still running when cleanup's wait ends is deleted once it ends", async () => { + const ctx = sandbox("t25"); + writeFileSync(fake(ctx, "deploy_seconds"), "8"); + // A time scale of 0.005 makes cleanup's 600-second wait for the deploy 3 seconds. + const r = start(ctx, ["-n", ctx.work], { env: { RUNCODER_TIME_SCALE: "0.005" } }); + assert.ok(await r.waitFor("Starting the GPU server in us-central1", 30), r.out()); + r.press("q"); + assert.ok(await r.waitFor("deleting again as soon as it ends", 30), r.out()); + assert.equal(await r.done(60), 0, r.out()); + assert.ok(r.has("Done: runcoder is deleted"), r.out()); + assert.ok(noService(ctx), calls(ctx)); // the fake service only appears when the deploy ends +}); + +test("an unexpected error is shown with the log path, and everything is deleted", async () => { + const ctx = sandbox("t26", { readyAfter: 30 }); + const preload = pathToFileURL(join(ROOT, "tests", "fake", "unexpected-error.mjs")).href; + const r = start(ctx, ["-n", ctx.work], { env: { NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --import=${preload}` } }); + assert.equal(await r.done(60), 1, r.out()); + assert.ok(r.has("ERROR: Error: fake unexpected error"), r.out()); + assert.ok(r.has("Full log: "), r.out()); + assert.ok(r.has("Done: runcoder is deleted"), r.out()); + assert.ok(noService(ctx), calls(ctx)); +}); + test("a port used by another program is refused before anything starts", async () => { const ctx = sandbox("t8"); const other = await startOllama({ port: PORT, model: "x" }); diff --git a/tests/fake/gcloud.mjs b/tests/fake/gcloud.mjs index 296d999..c843337 100644 --- a/tests/fake/gcloud.mjs +++ b/tests/fake/gcloud.mjs @@ -3,6 +3,7 @@ // deletefail / listfail delete or list fails loggedout no active account // apioff- that API is off nobilling billing is off // ready_after seconds before the fake model is ready (read by the fake tunnel) +// deploy_seconds how long a deploy takes (1 by default); the service exists once it ends import { appendFileSync, existsSync, writeFileSync, rmSync, readFileSync } from "node:fs"; import { join } from "node:path"; import { startOllama } from "./ollama.mjs"; @@ -39,7 +40,8 @@ else if (cmd === "run services list") { if (has("listfail")) fail("ERROR: network"); if (has(`svc-${region}`)) out(`${service}\n`); } else if (cmd.startsWith("run deploy")) { - await new Promise((r) => setTimeout(r, 1000)); + const seconds = Number(has("deploy_seconds") ? readFileSync(join(F, "deploy_seconds"), "utf8") : 1); + await new Promise((r) => setTimeout(r, seconds * 1000)); writeFileSync(join(F, `svc-${region}`), ""); if (has(`deployfail-${region}`)) fail(`ERROR: (gcloud.run.deploy) fake capacity error in ${region}`); out("Service deployed\n"); diff --git a/tests/fake/unexpected-error.mjs b/tests/fake/unexpected-error.mjs new file mode 100644 index 0000000..ac7f605 --- /dev/null +++ b/tests/fake/unexpected-error.mjs @@ -0,0 +1,14 @@ +// Loaded into runcoder with --import by a test: once the fake service exists, an error nothing +// catches (an unhandled rejection), as a bug in runcoder would raise. Other node processes (the +// fake gcloud) are left alone. +import { existsSync } from "node:fs"; +import { join } from "node:path"; + +if (/runcoder\.mjs$/.test(process.argv[1] ?? "")) { + const timer = setInterval(() => { + if (!existsSync(join(process.env.FAKE_DIR, "svc-us-central1"))) return; + clearInterval(timer); + Promise.reject(new Error("fake unexpected error")); + }, 100); + timer.unref(); +} From 7047a15baa06d802137ea051e479a9161000b091 Mon Sep 17 00:00:00 2001 From: lyra-setkernel <341047397+lyra-setkernel@users.noreply.github.com> Date: Wed, 2 Dec 2026 22:38:14 +0000 Subject: [PATCH 2/5] fix: stop the session loop once cleanup has started; README says when q works (#3) Review nits on #5: after q the loop kept running during cleanup and could print "The tunnel stopped; reopening it." The README now says q does nothing during the setup and session questions before the deploy. Co-Authored-By: Claude Opus 5.5 --- README.md | 5 +++-- src/session.mjs | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 42efe4d..9b11d89 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,9 @@ runcoder ~/code/my-project 3. It opens Qwen Code in a new terminal window, in your folder, pointed at the server. 4. The first window stays as the control panel: every 10 minutes it prints the time and cost so far. **Press q there (or Ctrl+C, or close the window) and it deletes the server**, then prints - what the session cost. q works from the deploy on, also while the model downloads. While the - session runs, r reopens Qwen Code where you left off. + what the session cost. q works from the deploy on, also while the model downloads (not during + the setup and session questions before it). While the session runs, r reopens Qwen Code where + you left off. If the folder has earlier Qwen Code sessions, runcoder asks whether to continue the latest (c), pick one (p), or start fresh (Enter). `-c`, `-p` and `-n` answer that in advance. diff --git a/src/session.mjs b/src/session.mjs index a4a83df..b6352f6 100644 --- a/src/session.mjs +++ b/src/session.mjs @@ -129,6 +129,7 @@ async function session(s, workdir, tunnel, region) { say(`Press r to reopen Qwen Code where you left off. It stops by itself after ${s.maxMinutes} minutes.`); for (;;) { const k = isInteractive() ? await key(s.tick) : (await sleep(s.tick), ""); // q is quitOnQ's, from cmdUp + if (state.cleaning) return; // q or Ctrl+C: cleanup ends the run; don't reopen the tunnel it closed if (/^[rR]$/.test(k)) { await openQwen(s, workdir, "--continue"); qwenSeen = false; From eb979b05d6df424b0265c142f98aa7d9602c9943 Mon Sep 17 00:00:00 2001 From: lyra-setkernel <341047397+lyra-setkernel@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:18:38 +0000 Subject: [PATCH 3/5] test: give the slow-deploy and unexpected-error tests their own sandboxes (#3) The two new tests in 2-recovery used sandboxes t25 and t26, which 4-cost already uses. The test files run in parallel, and sandbox() deletes and recreates tests/tmp/, so when the tests overlap, each wipes the other's fake gcloud state and lock. Run together, both t25 tests fail: one with "runcoder is already running". They now use t29 and t30, which no other test uses. Co-Authored-By: Claude Opus 5.5 --- tests/2-recovery.test.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/2-recovery.test.mjs b/tests/2-recovery.test.mjs index eb42b41..eb2c766 100644 --- a/tests/2-recovery.test.mjs +++ b/tests/2-recovery.test.mjs @@ -91,7 +91,7 @@ test("a lock left by a process ID another program now has is taken over", async }); test("a deploy still running when cleanup's wait ends is deleted once it ends", async () => { - const ctx = sandbox("t25"); + const ctx = sandbox("t29"); writeFileSync(fake(ctx, "deploy_seconds"), "8"); // A time scale of 0.005 makes cleanup's 600-second wait for the deploy 3 seconds. const r = start(ctx, ["-n", ctx.work], { env: { RUNCODER_TIME_SCALE: "0.005" } }); @@ -104,7 +104,7 @@ test("a deploy still running when cleanup's wait ends is deleted once it ends", }); test("an unexpected error is shown with the log path, and everything is deleted", async () => { - const ctx = sandbox("t26", { readyAfter: 30 }); + const ctx = sandbox("t30", { readyAfter: 30 }); const preload = pathToFileURL(join(ROOT, "tests", "fake", "unexpected-error.mjs")).href; const r = start(ctx, ["-n", ctx.work], { env: { NODE_OPTIONS: `${process.env.NODE_OPTIONS ?? ""} --import=${preload}` } }); assert.equal(await r.done(60), 1, r.out()); From 4d416603addd277901206b214c3a61ee1fba97d2 Mon Sep 17 00:00:00 2001 From: lyra-setkernel <341047397+lyra-setkernel@users.noreply.github.com> Date: Thu, 3 Dec 2026 02:09:23 +0000 Subject: [PATCH 4/5] docs: tell Windows users to press q, not close the window (#3) Node's docs say Windows ends a process about 10 seconds after its console window closes. Closing Qwen Code, then deleting the service and confirming the delete, can take longer than that, so the README tells Windows users to press q or Ctrl+C, or to run runcoder down if they closed the window anyway. Nobody has run this on Windows yet. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9b11d89..d353db1 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ runcoder ~/code/my-project far. **Press q there (or Ctrl+C, or close the window) and it deletes the server**, then prints what the session cost. q works from the deploy on, also while the model downloads (not during the setup and session questions before it). While the session runs, r reopens Qwen Code where - you left off. + you left off. **On Windows, press q or Ctrl+C rather than closing the window**: Windows ends a + closed console's programs about 10 seconds later, which can be before the delete is done. If + you closed it anyway, run `runcoder down`. If the folder has earlier Qwen Code sessions, runcoder asks whether to continue the latest (c), pick one (p), or start fresh (Enter). `-c`, `-p` and `-n` answer that in advance. @@ -68,7 +70,7 @@ Other commands: Something that bills by the second must never be left running. runcoder deletes the server when: -- you press q, press Ctrl+C, or close its window; +- you press q, press Ctrl+C, or close its window (on Windows, see the note under "Use" above); - Qwen Code has been closed for 15 minutes (`RUNCODER_QWEN_IDLE_MINUTES`); - the session reaches 150 minutes (`RUNCODER_MAX_MINUTES`); - the model is lost and does not come back after three tries; From 9ce2a87d1c742e622e2d0f81dbc1a6cbc5edd1d6 Mon Sep 17 00:00:00 2001 From: lyra-setkernel <341047397+lyra-setkernel@users.noreply.github.com> Date: Thu, 3 Dec 2026 02:21:47 +0000 Subject: [PATCH 5/5] fix: a lock whose live owner's command line can't be read still counts as running (#3) Review nit on #6: commandOf returns "" when ps or PowerShell fails for a moment; that no longer lets a second run take a live runcoder's lock. Co-Authored-By: Claude Opus 5.5 --- src/session.mjs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/session.mjs b/src/session.mjs index b6352f6..028dbe1 100644 --- a/src/session.mjs +++ b/src/session.mjs @@ -39,8 +39,9 @@ async function lock() { other = JSON.parse(readFileSync(paths.lock, "utf8")); } catch {} // Only the runcoder that wrote the lock counts: a process ID reused since has another command - // line. If the command line could not be read then, any live process with that ID counts. - if (other.pid && alive(other.pid) && (!other.command || (await commandOf(other.pid)) === other.command)) { + // line. If the command line could not be read, then or now, any live process with that ID counts. + const now = other.pid && alive(other.pid) ? await commandOf(other.pid) : null; + if (now !== null && (!other.command || !now || now === other.command)) { die(`runcoder is already running (process ${other.pid}). Use that window, or run: runcoder down`); } rmSync(paths.lock, { recursive: true, force: true });