Repository navigation
Conversation
Guard parsed JSON before casting to RpcCommand so null and other non-object payloads return a parse error instead of terminating the RPC process. Return the input handler promise so callers and tests can settle it; the JSONL reader still ignores the return value. Carry forward @dangzitou's unmerged fix from stepfun-ai#142 and add regression coverage for null, other JSON primitives, and two commands delivered in one JSONL input chunk. Fixes stepfun-ai#141 Co-authored-by: Dang Zitou <dengzitao888@163.com>
li-xiu-qi
force-pushed
the
fix/141-rpc-null-line-crash
branch
from
October 26, 2026 16:16
a274b11 to
169b426
Compare
li-xiu-qi
marked this pull request as ready for review
October 26, 2026 16:27
li-xiu-qi
requested review from
MelodyVAR,
Uking-xxx,
ZouR-Ma and
liuedcson
as code owners
October 26, 2026 16:27
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.
Fixes #141
Problem
A valid JSON line containing
nullcrashes the RPC agent. AfterJSON.parse, the value is cast toRpcCommand;handleCommandreadscommand.id, and the error handler reads it again. Both reads throw fornull, so the rejection escapes the input handler and terminates the process.Changes
This PR carries forward @dangzitou's unmerged fix from the closed #142 and adds regression coverage. Reject
nulland other non-object JSON payloads with aparseerror response before casting toRpcCommand, then continue reading subsequent commands.The input reader callback now returns the input handler promise. The production JSONL reader still ignores that return value, but tests can settle each forwarded command instead of guessing with a fixed delay.
Regression coverage includes:
null, string, number, and boolean payloads, each followed by a command that must still be handled.stdinand signal listeners even when a test fails early.Behavior and compatibility
Valid command objects and unknown object commands retain their existing behavior. Valid JSON primitives that are not command objects now receive
Failed to parse command: expected a JSON objectinstead of reaching command dispatch. No valid RPC command, persisted data, or public interface changes.Validation
Windows, Node.js 24.21.0:
pnpm exec vitest --run test/suite/regressions/141-rpc-null-payload.test.ts: 5 tests passed.pnpm exec vitest --run --pool=threads --no-file-parallelism --maxWorkers=1 test/rpc*.test.ts test/suite/regressions/141-rpc-null-payload.test.ts: 6 files passed and 1 skipped; 16 tests passed and 18 skipped.npm run checkfrom the repository root: passed.printf 'null\n{"id":"after-null","type":"foobar"}\n' | pnpm exec tsx --tsconfig tsconfig.json apps/cli/src/main.ts --mode rpcreturned theparseerror fornull, returnedUnknown command: foobarfor the next line, and exited 0.CI / build-check-testpassed, including build, repository checks, and tests.Commit attributionalso passed.Limitations
Local
./test.shon Windows stops in the pre-existinginstall.sh persists inherited PATH and preserves malformed user blockstest: its POSIX-onlyPATHcausesspawnSync bash ENOENT. The same failure reproduces on a clean worktree at upstream main81e79bc; it is unrelated to this RPC change.One local combined RPC test run once exited with a native segfault (139). The exact command passed on rerun and the cause is not determined; current GitHub CI passes.