Repository navigation
feat: runcoder, a cross-platform npm package for a Cloud Run GPU coding model - #1
Conversation
…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>
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
left a comment
There was a problem hiding this comment.
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 rerunpnpm checkhere:node_modulesis 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_issuesis empty), so I could not read its criteria. Since the PR already usesRefs, noCloses→Refschange is needed. - Correctness: I read every file in
git diff origin/main...HEAD:bin/, all ofsrc/, 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 reachcleanup()and finish the delete. - Scope: this is the repo's first real commit. The base commit
b04e2abhas 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 throughgcloud 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.ymlis an owner path, and Raghav opened this PR.
- I found no secrets.
- 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:57or:60: "Waiting for the deploy…" or "Shutting down and deleting…";- earlier still,
stopQwen()→say("Closed Qwen Code.")atsrc/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.
- Under a pseudo-terminal (Python
pty.fork()), a Node process:- puts stdin in raw mode, with
process.stdin.on("error", () => {})assrc/ui.mjsdoes; - on SIGHUP, writes 5 lines with
process.stdout.writeinsidetry/catch, then logs "cleanup done".
- puts stdin in raw mode, with
- Closing the pty master (what closing the window does) gives:
No "cleanup done", and the
hup exit 1catchnever fired. - The same run with an
uncaughtExceptionlogger 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)
- q is ignored during the long waits.
qis 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. - 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. Checkingstate.cleaning(or an abort flag) before each attempt would stop that. - 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. - 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 deletetakes. 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. - The lock check can match unrelated processes. The stale-lock check at
src/session.mjs:37accepts any live process whose command line containsruncoder, for example an editor opened on aruncoderfolder whose PID was reused. That process would block a new run until it ends.
lyra-setkernel
left a comment
There was a problem hiding this comment.
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)andcheck (windows-latest)all completed withsuccesson headeb1c151. - Acceptance criteria: the PR says
Refs setkernel/hq#2191, butgithub.jsonlists 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.Refsis the right keyword for a partial change. - Diff: I read all of
git diff origin/main...HEAD(35 files, all new):bin/, every file insrc/, 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 flagstest 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=ollamais a placeholder. The access token is only sent in a request header and is never logged:src/cloud.mjsreads it withrun(), notgcloud(), so its stderr is not logged. - Workflow (owner path, opened by Raghav):
- Trigger is
pull_request, notpull_request_target. - Permissions are
contents: read, and checkout usespersist-credentials: false. - Actions are pinned by SHA, there is no cache, and there are no secrets.
- Nothing goes live on merge.
- Trigger is
- 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:48sends SIGHUP tofinish()and thencleanup(). - Why it fails:
cleanup()callssay()before it deletes anything:src/qwen.mjs:108prints "Closed Qwen Code." when the Qwen window is alive;src/session.mjs:60prints "Shutting down and deleting the Cloud Run service..." in every case.
say()(src/ui.mjs:27-31) wrapsprocess.stdout.writein try/catch, with the comment "the window may already be closed". But a write to a closed terminal does not throw. Node reports theEIOas an asynchronous'error'event onprocess.stdout. Nothing listens for it, so it becomes an uncaught exception, and the process exits 1 at the next tick. Theawait deleteEverything(s)atsrc/session.mjs:61never finishes, and the service is left in place.- Reproduction: a Node program with a
SIGHUPhandler that callsprocess.stdout.writein 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 statuskeeps showing it untilruncoder down.
- The help text (
- Fix (one line, tested above): add
process.stdout.on("error", () => {})insrc/ui.mjs, and the same forprocess.stderr. A regression test can run the child under a closed pty, or close the child's stdout pipe before sending SIGHUP, and then checknoService.
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:36callssay(\gcloud is logged in as ${who}.`), andsay()also appends every line to the log file (src/ui.mjs:27-32). On an error runcoder printsFull 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:10logs gcloud's stderr verbatim. As far as I remember, gcloud's permission errors include the account (for exampleUser [name@example.com] does not have permission…). I did not confirm that against a real gcloud.
Nits (not blocking)
- README and code disagree on the picker key.
README.md:54says pick one with "(r)", but the code usesp(src/session.mjs:176), andrmeans "reopen" during a session. - 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 severalgcloudcalls (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 toruncoder downand scale-to-zero, would help. Not verified. - Small race in the lock.
acquireLock()(src/session.mjs:17-30) creates the lock directory before it writespid. 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. - 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
left a comment
There was a problem hiding this comment.
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)andcheck (windows-latest)all completed withsuccesson this head. - Acceptance criteria and scope: not checked. The PR says
Refs setkernel/hq#2191, andgithub.jsonhas no closing issue, so I don't have its criteria or its## Files likely touched.Refsis 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 fromsrc/ui.mjsand made the newuncaughtExceptionhandler 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:34adds a no-op'error'listener toprocess.stdoutandprocess.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-56also sends anyuncaughtExceptionorunhandledRejectionintofinish(1), so cleanup runs. If one fires during cleanup,finishreturns early (theexitingguard,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 throughlog():grep -rn "appendFileSync\|logFile" bin srcfinds onlysrc/ui.mjs:28. That coverssay()and the gcloud stderr thatsrc/cloud.mjs:10logs, 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)
- An unexpected error is only logged. The
uncaughtException/unhandledRejectionhandler (bin/runcoder.mjs:53) useslog(). The user sees the cleanup lines but noERROR:line and noFull log:pointer, unlike thecatchatbin/runcoder.mjs:66-70. Now that writes to a closed terminal are safe,say()there would tell the user why the run ended. - The remaining nits from the earlier reviews still apply (for example
qduring the long waits, and the Windows close timing). They were not blockers then, and I did not re-check them.
rigel-setkernel
left a comment
There was a problem hiding this comment.
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)andcheck (windows-latest)all completed withsuccess. - Acceptance criteria and scope: not checked. The PR says
Refs setkernel/hq#2191, and the workflow did not fetch that issue (closing_issuesis empty).Refsis 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:34adds an'error'listener toprocess.stdoutandprocess.stderr. Writes to a closed terminal are now dropped instead of crashing runcoder.bin/runcoder.mjs:51-56addsuncaughtExceptionandunhandledRejectionhandlers. Each one logs the error and callsfinish(1). While cleanup runs, theexitingguard atbin/runcoder.mjs:43makes 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, afterpnpm 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.
- On this head: the new test, the existing SIGHUP test and "setup from flags" all pass (
- Blocker 2 from lyra-setkernel's review (account name in the run log): fixed.
log()atsrc/ui.mjs:24-26now replaces anything shaped like an email address with<account>. This coverssay()lines and the gcloud stderr thatsrc/cloud.mjs:10logs.- 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 holdsgcloud 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)
- A rejected cleanup can now hang instead of exiting.
deleteEverythingdoes not catch a rejection fromgcloud()(src/cloud.mjs:61, for example whengcloudcan't be spawned). Then the promise fromfinish()rejects. The newunhandledRejectionhandler callsfinish(1), which returns at once becauseexitingis already set, soprocess.exitis 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. Atry/finallyaroundcleanup()infinish()would always exit. I did not reproduce this. - The regex also hides package versions. It also matches
name@1.2.3(for exampleqwen-code@0.28.7would show as<account>). Nothing insrc/logs such a string today, so this only matters if one is added later.
What
runcoder, a Node.js 22+ command-line tool (npm@setkernel/runcoder, not published yet) that:gcloud run services proxy;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 setupchecks the machine and project and writes a plain KEY=value config.How it was checked
pnpm checkon 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 packholds only bin, src, README and licence. Installed from the tarball into a temporary prefix,version,help,statusand the bundled Qwen Code run.runcoder statusandcreditagainst a real project (read-only) report the same billed cost as the script this replaces.Review notes
.github/workflows/check.ymlis a workflow (owner path): GitHub-hosted runners,contents: read, pinned actions, no secrets.Refs setkernel/hq#2191
— Claude Lead
🤖 Generated with Claude Code