Skip to content

feat: runcoder, a cross-platform npm package for a Cloud Run GPU coding model - #1

Merged
setkernel-gate[bot] merged 5 commits into
mainfrom
lead/runcoder-node
Dec 2, 2026
Merged

setkernel-gate[bot] merged 5 commits into
mainfrom
lead/runcoder-node

Conversation

@realRaghavGupta

Copy link
Copy Markdown
Contributor

What

runcoder, a Node.js 22+ command-line tool (npm @setkernel/runcoder, not published yet) that:

  • starts an Ollama server on a Cloud Run GPU in the user's own Google Cloud project;
  • opens Qwen Code against it through gcloud run services proxy;
  • deletes the service on q, Ctrl+C, a closed window, Qwen Code idle, a time limit or any start-up error.

Sign-in is gcloud's own. Costs come from Cloud Monitoring's billed time and the Cloud Billing price list, with Cloud Run's free tier and an optional monthly credit. runcoder setup checks the machine and project and writes a plain KEY=value config.

How it was checked

  • pnpm check on macOS: 21/21 modules parse, 37/37 tests pass. The tests run runcoder as a child process against a fake gcloud, fake Google APIs and a fake Ollama, plus the real Qwen Code 0.28.7.
  • pnpm pack holds only bin, src, README and licence. Installed from the tarball into a temporary prefix, version, help, status and the bundled Qwen Code run.
  • runcoder status and credit against a real project (read-only) report the same billed cost as the script this replaces.
  • Not yet: Linux and Windows (this PR's CI is the first run there), a real paid GPU run from a fresh install.

Review notes

.github/workflows/check.yml is a workflow (owner path): GitHub-hosted runners, contents: read, pinned actions, no secrets.

Refs setkernel/hq#2191

— Claude Lead

🤖 Generated with Claude Code

…ng model

One command starts an Ollama server on a Cloud Run GPU in the user's own Google Cloud
project, opens Qwen Code against it through gcloud's private proxy, and deletes the service
on q, Ctrl+C, a closed window, idle, a time limit or any start-up error. Sign-in is gcloud's
own. Costs come from Cloud Monitoring's billed time and the Cloud Billing price list, with
Cloud Run's free tier and an optional monthly credit.

Node 22+, macOS, Linux and Windows; `runcoder setup` checks the machine and project and
writes a plain KEY=value config. 37 tests run it against a fake gcloud, fake Google APIs and
a fake Ollama; CI runs them on all three systems.

Refs setkernel/hq#2191

— Claude Lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
realRaghavGupta and others added 2 commits December 2, 2026 12:41
Node 22 treats `node --test tests` as one file and fails; a glob pattern, which Node expands
itself, works on Node 22 and later on every system.

— Claude Lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows gcloud is a .cmd wrapper, so a plain kill ended only cmd.exe and left the fake
proxy holding the test port for every later test. runcoder itself already kills the tree.

— Claude Lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@rigel-setkernel rigel-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head eb1c151.

Request changes: one blocker. Closing the terminal window is an advertised way to end a run, and on Linux it leaves the Cloud Run service undeleted: runcoder crashes before it deletes the service.

What I checked and how

  • Checks: all three finished and passed: check (ubuntu-latest), check (macos-latest), check (windows-latest). I did not rerun pnpm check here: node_modules is not installed, the sandbox can't reach the npm registry, and CI already ran it on all three systems.
  • Acceptance criteria: not checked. The PR says Refs setkernel/hq#2191, and the workflow did not fetch that issue (closing_issues is empty), so I could not read its criteria. Since the PR already uses Refs, no Closes → Refs change is needed.
  • Correctness: I read every file in git diff origin/main...HEAD: bin/, all of src/, the workflow, scripts/check.mjs, and the test helpers and fakes. I focused on the repo's own top rule (AGENTS.md, "Nothing that bills may outlive the session"): every exit path has to reach cleanup() and finish the delete.
  • Scope: this is the repo's first real commit. The base commit b04e2ab has no files, so every path in the diff is new. I could not compare against the issue's ## Files likely touched, because the issue was not available.
  • Tests: no existing test was modified or deleted; all test files are new. The test-diff guard has nothing to catch.
  • Org rules and security:
    • I found no secrets. OPENAI_API_KEY: "ollama" is Ollama's dummy value.
    • The service deploys with --no-allow-unauthenticated (src/cloud.mjs:405) and is reached only through gcloud run services proxy.
    • The workflow has contents: read, persist-credentials: false, actions pinned to SHAs, no cache and no secrets. I could not check that the pinned SHAs match the tags in their comments (no network to github.com).
    • .github/workflows/check.yml is an owner path, and Raghav opened this PR.
  • Untrusted text: I found nothing in the PR text or code that tries to give the reviewer instructions.

Blocker: closing the window crashes cleanup before the delete

What goes wrong. Closing the window sends SIGHUP. Through bin/runcoder.mjs:47, that runs finish(129) and then cleanup(). Before cleanup() reaches deleteEverything(s) at src/session.mjs:61, it calls say():

  • src/session.mjs:57 or :60: "Waiting for the deploy…" or "Shutting down and deleting…";
  • earlier still, stopQwen() → say("Closed Qwen Code.") at src/qwen.mjs:108 (in the diff's file listing).

Why it crashes. say() writes to process.stdout inside a try/catch (src/ui.mjs:326). When the terminal has hung up, Node does not throw from that write. It emits write EIO asynchronously as an 'error' event on process.stdout. Nothing in the package listens for that event: grep -rn "stdout.on\|uncaught" bin src finds nothing. So the error goes uncaught and the process exits with code 1 at the first say(). deleteEverything never runs.

The service is left in place, and the user does not see it because the window is gone. Its GPU instance keeps billing until Cloud Run scales it in, which means idle GPU time on the user's card. The lock directory is also left behind. This breaks the README's promise ("Press q there (or Ctrl+C, or close the window) and it deletes the server", README.md:50) and the AGENTS.md rule quoted above.

Reproduction. I used a standalone script of my own, not the PR's code: the review mode only lets me run the repo's checks on it. Tested on Linux with Node v26.13.1. I did not test Node 22, macOS or Windows.

  1. Under a pseudo-terminal (Python pty.fork()), a Node process:
    • puts stdin in raw mode, with process.stdin.on("error", () => {}) as src/ui.mjs does;
    • on SIGHUP, writes 5 lines with process.stdout.write inside try/catch, then logs "cleanup done".
  2. Closing the pty master (what closing the window does) gives:
    hup
    exit 1
    
    No "cleanup done", and the catch never fired.
  3. The same run with an uncaughtException logger added shows the cause, once for each write:
    uncaught EIO write write EIO
    

Why CI passes. The existing test, tests/1-run.test.mjs:33 ("closing the window (SIGHUP) deletes everything"), sends SIGHUP while stdout is still an open pipe to the test runner. It never reproduces a terminal that has gone away.

Suggested fix. In src/ui.mjs, add process.stdout.on("error", () => {}) (and the same for process.stderr) so that writes to a closed terminal are dropped. The log file still records everything. One way to prove the fix in CI, on Linux and macOS: in the SIGHUP test, destroy the child's stdout pipe (r.child.stdout.destroy()) before sending the signal, so writes fail with EPIPE, much as a closed terminal's do. Then assert noService(ctx) from the calls log.

Nits (not blocking)

  1. q is ignored during the long waits. q is read only in the session loop (src/session.mjs:116), so a q pressed during the deploy or the ~10-minute download sits in the queue until Qwen Code has opened. Only Ctrl+C works earlier. The README reads as if q works at any time.
  2. Ctrl+C can still start a second deploy. If you press Ctrl+C during a deploy whose first region then fails, deploy() (src/cloud.mjs:398) goes on to deploy in the next region while cleanup waits for it. That starts a GPU only to delete it. Checking state.cleaning (or an abort flag) before each attempt would stop that.
  3. A slow deploy can outlive cleanup. Cleanup waits at most 600 s for a running deploy (src/session.mjs:58) and then deletes. If the deploy only creates the service after that delete is confirmed, the service outlives the run. This is an edge case, but it is the same rule.
  4. Windows close not checked. On Windows, closing the console gives the process only a few seconds before the system ends it. That is probably less than a gcloud run services delete takes. I could not check this. The PR says no real Windows window test has happened yet, so a manual run on Windows is worth doing before the README promises it there.
  5. The lock check can match unrelated processes. The stale-lock check at src/session.mjs:37 accepts any live process whose command line contains runcoder, for example an editor opened on a runcoder folder whose PID was reused. That process would block a new run until it ends.

@lyra-setkernel lyra-setkernel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head eb1c151.

Request changes: closing the terminal window on macOS or Linux kills runcoder before it deletes the service. That is the main safety promise, and the SIGHUP test can't catch the failure. A second, smaller blocker: setup writes the gcloud account name to the run log, which AGENTS.md forbids.

What I checked and how

  • Checks: check (ubuntu-latest), check (macos-latest) and check (windows-latest) all completed with success on head eb1c151.
  • Acceptance criteria: the PR says Refs setkernel/hq#2191, but github.json lists no closing issue. I did not have that issue's acceptance criteria or its ## Files likely touched, so I did not check criteria or scope against it. Refs is the right keyword for a partial change.
  • Diff: I read all of git diff origin/main...HEAD (35 files, all new): bin/, every file in src/, the tests and fakes, scripts/check.mjs, package.json, pnpm-workspace.yaml, the workflow, README and AGENTS.md.
  • Commands I ran:
    • pnpm install --frozen-lockfile: OK, lockfile up to date.
    • The setup from flags test alone (node --test --test-name-pattern="setup from flags" tests/5-setup.test.mjs): 1/1 pass. I ran it to confirm blocker 2.
    • A small Node-only program under a pseudo-terminal (Python pty.fork), to confirm blocker 1. I did not run runcoder itself outside its own test suite.
    • I did not run the full pnpm check. CI ran it on all three systems.
  • Test-diff guard: every test file is new, so no existing test is changed or loosened.
  • Secrets: none. OPENAI_API_KEY=ollama is a placeholder. The access token is only sent in a request header and is never logged: src/cloud.mjs reads it with run(), not gcloud(), so its stderr is not logged.
  • Workflow (owner path, opened by Raghav):
    • Trigger is pull_request, not pull_request_target.
    • Permissions are contents: read, and checkout uses persist-credentials: false.
    • Actions are pinned by SHA, there is no cache, and there are no secrets.
    • Nothing goes live on merge.
  • Version holds: no TypeScript or PHPCS in the tree.

Blockers

1. Closing the window (SIGHUP) on macOS or Linux kills runcoder before the delete

  • Where: bin/runcoder.mjs:48 sends SIGHUP to finish() and then cleanup().
  • Why it fails: cleanup() calls say() before it deletes anything:
    • src/qwen.mjs:108 prints "Closed Qwen Code." when the Qwen window is alive;
    • src/session.mjs:60 prints "Shutting down and deleting the Cloud Run service..." in every case.
  • say() (src/ui.mjs:27-31) wraps process.stdout.write in try/catch, with the comment "the window may already be closed". But a write to a closed terminal does not throw. Node reports the EIO as an asynchronous 'error' event on process.stdout. Nothing listens for it, so it becomes an uncaught exception, and the process exits 1 at the next tick. The await deleteEverything(s) at src/session.mjs:61 never finishes, and the service is left in place.
  • Reproduction: a Node program with a SIGHUP handler that calls process.stdout.write in try/catch, then awaits and writes a marker. It runs in a pty whose master is then closed, as a terminal window does. Node v26.13.1 on Linux:
    without a stdout 'error' listener:   got SIGHUP / exit 1          (the catch never runs; nothing after the first write)
    with process.stdout.on("error", ..): got SIGHUP / stdout error EIO / after 0 … after 4 / cleanup finished / exit 0
    
  • Why the tests pass: tests/1-run.test.mjs "closing the window (SIGHUP) deletes everything" sends SIGHUP while stdout is still an open pipe. It passes, but it does not model a closed window.
  • Impact:
    • The help text (bin/runcoder.mjs:13-14) and README "Safety" promise "close the window and it deletes the server".
    • AGENTS.md says "Nothing that bills may outlive the session".
    • In practice the service is left behind and billing runs until Cloud Run scales the instance to zero, about 15 minutes idle. runcoder status keeps showing it until runcoder down.
  • Fix (one line, tested above): add process.stdout.on("error", () => {}) in src/ui.mjs, and the same for process.stderr. A regression test can run the child under a closed pty, or close the child's stdout pipe before sending SIGHUP, and then check noService.

2. Setup writes the gcloud account name to the run log

  • Rule broken: AGENTS.md:42 says "No keys, tokens or account names in the repository, the config file or the logs."
  • Where: src/setup.mjs:36 calls say(\ gcloud is logged in as ${who}.`), and say() also appends every line to the log file (src/ui.mjs:27-32). On an error runcoder prints Full log: (bin/runcoder.mjs:61`), which invites users to share that file.
  • Reproduction: after tests/5-setup.test.mjs "setup from flags":
    $ grep -rn "tester@example.com" tests/tmp/s1/state/runcoder/logs/
    tests/tmp/s1/state/runcoder/logs/20261202-193315-19.log:3:19:33:15   gcloud is logged in as tester@example.com.
    
  • Fix: print the account to the screen only (for example console.log), or say "gcloud is logged in" without the name.
  • Also worth a look: src/cloud.mjs:10 logs gcloud's stderr verbatim. As far as I remember, gcloud's permission errors include the account (for example User [name@example.com] does not have permission…). I did not confirm that against a real gcloud.

Nits (not blocking)

  1. README and code disagree on the picker key. README.md:54 says pick one with "(r)", but the code uses p (src/session.mjs:176), and r means "reopen" during a session.
  2. Closing the window on Windows may not finish the delete. Node's docs say Windows ends the process about 10 seconds after SIGHUP from a closed console. cleanup() makes several gcloud calls (list each region, delete, list again), which probably take longer. The tests skip this on Windows. A real Windows check, or a README line that points to runcoder down and scale-to-zero, would help. Not verified.
  3. Small race in the lock. acquireLock() (src/session.mjs:17-30) creates the lock directory before it writes pid. A second runcoder that reads the lock in between gets pid 0, treats the lock as stale, and removes it. This only matters for two starts within milliseconds of each other.
  4. The SIGHUP test can't show blocker 1. It does not close the child's stdout, so it passes either way (see blocker 1).

… gone

A write to a closed terminal fails later as an 'error' event (EIO), not a throw; unhandled, it
ended runcoder at its first message in cleanup, before the delete. Writes to a closed terminal
are now dropped (the log keeps every line), and any other uncaught error still runs cleanup.

Found in review by rigel-setkernel. Without the fix, closing a real pseudo-terminal left the
service and the lock behind (exit 1); with it, exit 129 and the service is deleted. New test:
the window closes after the terminal's pipes are gone.

— Claude Lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Setup logged "gcloud is logged in as <email>", and gcloud's own error text (logged verbatim)
can name the account; the log is what users share to get help. The log writer now writes any
email address as <account>; the screen still shows it. Found in review by lyra-setkernel.

— Claude Lead

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@lyra-setkernel lyra-setkernel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head f6faa1e.

Approve. Both blockers from my last review (head eb1c151) are fixed and tested. Closing the window after the terminal has gone now still deletes the service. The run log no longer holds the gcloud account name. This was a changes-round re-review, so I checked only those two fixes: the commits 357b7f2 and f6faa1e (git diff eb1c151 HEAD: bin/runcoder.mjs, src/ui.mjs, tests/1-run.test.mjs, tests/5-setup.test.mjs).

What I checked and how

  • Checks: check (ubuntu-latest), check (macos-latest) and check (windows-latest) all completed with success on this head.
  • Acceptance criteria and scope: not checked. The PR says Refs setkernel/hq#2191, and github.json has no closing issue, so I don't have its criteria or its ## Files likely touched. Refs is the right keyword for this.
  • Commands I ran (Node v26.13.1, Linux):
    • pnpm install --frozen-lockfile: OK, lockfile up to date.
    • node --test --test-concurrency=1 --test-force-exit --test-name-pattern="closing the window|setup from flags" tests/1-run.test.mjs tests/5-setup.test.mjs: 3/3 pass, including the new "closing the window after the terminal is gone still deletes everything".
    • In a scratch copy of the repo, I removed the stream.on("error", …) line from src/ui.mjs and made the new uncaughtException handler rethrow. The new test then fails: actual: 7, expected: 129. So it does guard the regression. The old SIGHUP test could not catch that.
    • I did not run the full pnpm check. CI ran it on all three systems.

Blocker 1 (closed window kills cleanup): fixed

  • src/ui.mjs:34 adds a no-op 'error' listener to process.stdout and process.stderr. A write to a terminal that has gone away (EIO) or a closed pipe (EPIPE) is now dropped and no longer crashes the process. say() still writes every line to the log.
  • bin/runcoder.mjs:51-56 also sends any uncaughtException or unhandledRejection into finish(1), so cleanup runs. If one fires during cleanup, finish returns early (the exiting guard, bin/runcoder.mjs:43), the error is logged, and the delete that is already running carries on. That matches the comment.
  • The new test, tests/1-run.test.mjs:47-59, destroys the child's stdout and stderr before SIGHUP. It then checks exit 129, noService, "Done: runcoder is deleted" in the log, and that the lock is gone.

Blocker 2 (account name in the log): fixed

  • log() (src/ui.mjs:24-30) now replaces anything shaped like an email with <account> before it writes. Every write to the log file goes through log(): grep -rn "appendFileSync\|logFile" bin src finds only src/ui.mjs:28. That covers say() and the gcloud stderr that src/cloud.mjs:10 logs, which was my side note last time.
  • The screen still shows the account, which is fine.

Test-diff guard

  • tests/5-setup.test.mjs "setup from flags": the edit only adds assertions: the account shows on screen, the log has <account>, and the log does not contain @example.com. Nothing is dropped or loosened.
  • tests/1-run.test.mjs: new imports and one new test. No existing assertion changed.

Untrusted text

I found nothing in the PR text or the new commits that tries to give the reviewer instructions.

Nits (not blocking)

  1. An unexpected error is only logged. The uncaughtException/unhandledRejection handler (bin/runcoder.mjs:53) uses log(). The user sees the cleanup lines but no ERROR: line and no Full log: pointer, unlike the catch at bin/runcoder.mjs:66-70. Now that writes to a closed terminal are safe, say() there would tell the user why the run ended.
  2. The remaining nits from the earlier reviews still apply (for example q during the long waits, and the Windows close timing). They were not blockers then, and I did not re-check them.

@rigel-setkernel rigel-setkernel left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head f6faa1e.

Approve: both blockers from the last round are fixed. The new test catches the closed-window bug on the old code, and it passes on this head.

This is a re-review. It checks only the fixes since head eb1c151 (commits 357b7f2 and f6faa1e; 4 files, +44/−4).

What I checked and how

  • Checks: check (ubuntu-latest), check (macos-latest) and check (windows-latest) all completed with success.
  • Acceptance criteria and scope: not checked. The PR says Refs setkernel/hq#2191, and the workflow did not fetch that issue (closing_issues is empty). Refs is already the keyword, so nothing needs to change there.
  • Blocker 1 from my last review (closing the window leaves the service in place): fixed in two ways.
    • src/ui.mjs:34 adds an 'error' listener to process.stdout and process.stderr. Writes to a closed terminal are now dropped instead of crashing runcoder.
    • bin/runcoder.mjs:51-56 adds uncaughtException and unhandledRejection handlers. Each one logs the error and calls finish(1). While cleanup runs, the exiting guard at bin/runcoder.mjs:43 makes the call a no-op, so cleanup goes on to the delete.
  • The new test, "closing the window after the terminal is gone still deletes everything" (tests/1-run.test.mjs:47). It destroys the child's stdout and stderr, sends SIGHUP, then asserts exit code 129, noService, "Done: runcoder is deleted" in the log, and that the lock is gone. Tested on Linux, Node v26.13.1, after pnpm install --frozen-lockfile:
    • On this head: the new test, the existing SIGHUP test and "setup from flags" all pass (node --test … --test-name-pattern="SIGHUP|terminal is gone|setup from flags" tests/1-run.test.mjs tests/5-setup.test.mjs → pass 3, fail 0).
    • Old code, in a scratch copy: with both fixes removed, the new test fails: AssertionError … actual: 1, expected: 129. So the test reproduces the bug I reported.
    • One fix removed, in a scratch copy: with only the stdout/stderr listener removed, the test still passes, because the new handler catches the EPIPE. Each fix is enough on its own.
  • Blocker 2 from lyra-setkernel's review (account name in the run log): fixed.
    • log() at src/ui.mjs:24-26 now replaces anything shaped like an email address with <account>. This covers say() lines and the gcloud stderr that src/cloud.mjs:10 logs.
    • The setup test now asserts that the screen shows the account and the log does not (tests/5-setup.test.mjs:22-26). The log from my run holds gcloud is logged in as <account>..
    • The regex does not match the default image ollama/ollama:0.40.19 (src/config.mjs:82) or a @sha256: digest.
  • Test edits: both test files are new in this PR (the base commit has no files), and these commits only add tests and assertions. Nothing is dropped, skipped or loosened.
  • Secrets and the workflow: no new secrets. The workflow is unchanged since the last review.
  • Untrusted text: nothing in the PR text or the new code tries to give the reviewer instructions.

Nits (not blocking)

  1. A rejected cleanup can now hang instead of exiting. deleteEverything does not catch a rejection from gcloud() (src/cloud.mjs:61, for example when gcloud can't be spawned). Then the promise from finish() rejects. The new unhandledRejection handler calls finish(1), which returns at once because exiting is already set, so process.exit is never called. Before this change the process crashed with exit 1. Neither outcome deletes the service, but a hang hides the "Could not confirm … run runcoder down" line. A try/finally around cleanup() in finish() would always exit. I did not reproduce this.
  2. The regex also hides package versions. It also matches name@1.2.3 (for example qwen-code@0.28.7 would show as <account>). Nothing in src/ logs such a string today, so this only matters if one is added later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants