{"record":{"id":"dfb223a8ed9281c1","repo":"wavetermdev/waveterm","slug":"command-packets-may-not-have-resid-set","errorCode":null,"errorMessage":"command packets may not have resid set","messagePattern":"command packets may not have resid set","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/wshutil/wshrpc.go","lineNumber":163,"sourceCode":"func (r *RpcMessage) Validate() error {\n\tif r.ReqId != \"\" && r.ResId != \"\" {\n\t\treturn fmt.Errorf(\"request packets may not have both reqid and resid set\")\n\t}\n\tif r.Cancel {\n\t\tif r.Command != \"\" {\n\t\t\treturn fmt.Errorf(\"cancel packets may not have command set\")\n\t\t}\n\t\tif r.ReqId == \"\" && r.ResId == \"\" {\n\t\t\treturn fmt.Errorf(\"cancel packets must have reqid or resid set\")\n\t\t}\n\t\tif r.Data != nil {\n\t\t\treturn fmt.Errorf(\"cancel packets may not have data set\")\n\t\t}\n\t\treturn nil\n\t}\n\tif r.Command != \"\" {\n\t\tif r.ResId != \"\" {\n\t\t\treturn fmt.Errorf(\"command packets may not have resid set\")\n\t\t}\n\t\tif r.Error != \"\" {\n\t\t\treturn fmt.Errorf(\"command packets may not have error set\")\n\t\t}\n\t\tif r.DataType != \"\" {\n\t\t\treturn fmt.Errorf(\"command packets may not have datatype set\")\n\t\t}\n\t\treturn nil\n\t}\n\tif r.ReqId != \"\" {\n\t\tif r.ResId == \"\" {\n\t\t\treturn fmt.Errorf(\"request packets must have resid set\")\n\t\t}\n\t\tif r.Timeout != 0 {\n\t\t\treturn fmt.Errorf(\"non-command request packets may not have timeout set\")\n\t\t}\n\t\treturn nil\n\t}","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/wshutil/wshrpc.go#L145-L181","documentation":"Packet validation error: COMMAND packets must not set resid. A resid is assigned to responses/cancels to correlate with a request; a fresh command cannot reference one, so such a packet is rejected.","triggerScenarios":"Calling Validate on an RpcMessage with Command set and ResId non-empty (with Cancel false).","commonSituations":"A responder that echoes the incoming message struct back and forgets to clear ResId before setting Command; middleware rewriting packets between directions.","solutions":["Clear ResId on the outgoing command packet","Set Command = \"\" if the message is really a response","Validate the message right after construction to catch field leakage early"],"exampleFix":"// before\nmsg := wshutil.RpcMessage{Command: \"event.subscribe\", ResId: incomingResId}\n// after\nmsg := wshutil.RpcMessage{Command: \"event.subscribe\"}","handlingStrategy":"validation","validationCode":"if msg.Command != \"\" {\n\tmsg.ResId = \"\"\n}\nif err := msg.Validate(); err != nil { return err }","typeGuard":"func isCommandNotResponse(msg wshutil.RpcMessage) bool {\n\treturn msg.Command != \"\" && msg.ResId == \"\"\n}","tryCatchPattern":"if err := msg.Validate(); err != nil {\n\treturn fmt.Errorf(\"command packet carries resid: %w\", err)\n}","preventionTips":["Clear incoming-message fields before reusing a struct for an outgoing command","Use distinct types/constructors for requests vs responses","Validate before send in debug mode"],"tags":["wsh","rpc","validation","protocol"],"backgroundTag":"invalid-rpc-packet","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}