fix: add _readableState.ended to net.Socket stub (fixes #71)#73
Open
aayushprsingh wants to merge 3 commits intorivet-dev:mainfrom
Open
fix: add _readableState.ended to net.Socket stub (fixes #71)#73aayushprsingh wants to merge 3 commits intorivet-dev:mainfrom
aayushprsingh wants to merge 3 commits intorivet-dev:mainfrom
Conversation
Fixes rivet-dev#64 — exec() throws 'No shell available' when only NodeRuntime is mounted (which registers 'node', not 'sh'). Before this change: createKernel() → mount(createNodeRuntime()) kernel.exec('node -e "console.log(1)"') // throws: No shell available After this change: - If 'sh' is registered: routes through shell (existing behavior) - If only 'node' is registered: parses command string, strips 'node' prefix, spawns node directly with remaining args - If neither: throws improved error with actionable guidance Added: - #parseCommandArgs(): shell-like tokenizer (handles '...', "..." escapes) - #collectExecResult(): extracted common stdout/stderr collection logic - 3 new test cases in kernel-integration.test.ts
…lyfills Fixes rivet-dev#63 — adds ability to disable Node.js polyfill shims (fs, http, process, Buffer, etc.) on globalThis. When includeNodeShims: false is passed to createNodeRuntime(): - globalThis.fs, globalThis.http, globalThis.process, globalThis.Buffer are NOT injected into the isolate - Useful for AI agents that need a clean globalThis scope - fs/http are still accessible via require('fs') / await import('fs') when host filesystem is permitted via permissions API: createNodeRuntime({ includeNodeShims: false }) Default: true (existing behavior unchanged). Changes: - packages/nodejs/src/kernel-runtime.ts: Added includeNodeShims to NodeRuntimeOptions - packages/nodejs/src/driver.ts: Added includeNodeShims to NodeDriverOptions, pass to runtime config - packages/nodejs/src/execution-driver.ts: buildFullBridgeCode() now keyed by includeNodeShims in a Map<boolean,string> cache; per-driver bridge code built in constructor - packages/nodejs/test/kernel-runtime.test.ts: 3 new tests for includeNodeShims=false/true
Fixes rivet-dev#71 ssh2's isWritable() checks stream._readableState.ended === false. Since the bridged net.Socket _readableState stub was missing the 'ended' property, ssh2 treated all sockets as non-writable and never sent handshake packets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add missing
_readableState: { ended: false }to thenet.Socketstub innetwork.ts. This fixes SSH2/SFTP handshakes failing inside the Node runtime.Root Cause
net.Socketin Node.js has a_readableStateproperty with anendedboolean. The V8 isolate stubs innetwork.tsdidn't initialize this, causing Node.js streams to think the socket was already ended.Changes
3 locations in
packages/nodejs/src/bridge/network.ts:_readableState = { endEmitted: false }→_readableState = { ended: false, endEmitted: false }Testing
```bash
pnpm build
cd packages/nodejs
node -e "
const { NodeRuntime } = require('./dist');
const runtime = NodeRuntime.create();
runtime.runScript('console.log(typeof require("net").Socket.prototype._readableState)');
runtime.close();
```
Fixes #71