Skip to content

fix(coding-agent): reject null RPC commands instead of crashing - #308

Open
li-xiu-qi wants to merge 1 commit into
stepfun-ai:mainfrom
li-xiu-qi:fix/141-rpc-null-line-crash
Open

li-xiu-qi wants to merge 1 commit into
stepfun-ai:mainfrom
li-xiu-qi:fix/141-rpc-null-line-crash

Conversation

@li-xiu-qi

@li-xiu-qi li-xiu-qi commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #141

Problem

A valid JSON line containing null crashes the RPC agent. After JSON.parse, the value is cast to RpcCommand; handleCommand reads command.id, and the error handler reads it again. Both reads throw for null, 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 null and other non-object JSON payloads with a parse error response before casting to RpcCommand, 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.
  • Two commands delivered by the production JSONL reader in one data chunk.
  • Teardown that releases a controlled startup barrier, waits for startup and tracked input promises, detaches the reader, and restores stdin and 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 object instead 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 check from the repository root: passed.
  • All five regression tests fail against the unpatched source and pass with the fix.
  • Real RPC process from the repository source entry, using an isolated home and agent directory: printf 'null\n{"id":"after-null","type":"foobar"}\n' | pnpm exec tsx --tsconfig tsconfig.json apps/cli/src/main.ts --mode rpc returned the parse error for null, returned Unknown command: foobar for the next line, and exited 0.
  • GitHub CI on Ubuntu with Node 22: CI / build-check-test passed, including build, repository checks, and tests. Commit attribution also passed.

Limitations

Local ./test.sh on Windows stops in the pre-existing install.sh persists inherited PATH and preserves malformed user blocks test: its POSIX-only PATH causes spawnSync bash ENOENT. The same failure reproduces on a clean worktree at upstream main 81e79bc; 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.

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 li-xiu-qi reopened this Oct 26, 2026
@li-xiu-qi
li-xiu-qi force-pushed the fix/141-rpc-null-line-crash branch from a274b11 to 169b426 Compare October 26, 2026 16:16
@li-xiu-qi
li-xiu-qi marked this pull request as ready for review October 26, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RPC agent crashes (unhandled process exit) on a single null input line

1 participant