Skip to content

Add input validation to RPC command handler #254

Description

@m-aebrer

Add input validation to RPC command handler

The RPC command handler in rpc-mode.ts does not validate incoming JSONL commands before processing them. When a client sends a malformed command (e.g., {"type":"prompt","content":"..."} instead of the required {"type":"prompt","message":"..."}), the undefined field propagates into agent-session.ts and crashes with an opaque error:

Cannot read properties of undefined (reading 'startsWith')

Current Behavior

  • No schema validation on incoming RPC commands
  • Missing/misspelled fields pass through as undefined
  • Crashes surface as internal JS errors rather than actionable RPC error responses

Proposed Behavior

  • Validate required fields before dispatching commands (at minimum: message on prompt, steer, and follow_up)
  • Return a clear RPC error response for invalid commands, e.g.:
    {"type":"response","command":"prompt","success":false,"error":"Missing required field 'message' in prompt command"}
  • Never let undefined reach session.prompt()

Relevant Files

  • packages/coding-agent/src/modes/rpc/rpc-mode.tshandleCommand() dispatch
  • packages/coding-agent/src/modes/rpc/rpc-types.tsRpcCommand type definitions

Context

Discovered via issue 253 — a client sent content instead of message, which crashed the agent instead of returning a validation error. Low priority since the fix is on the client side, but better error messages would save debugging time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions