{"record":{"id":"3dce8decce911940","repo":"t8y2/dbx","slug":"response-id-d-does-not-match-request-id-d","errorCode":null,"errorMessage":"response id %d does not match request id %d","messagePattern":"response id (.+?) does not match request id (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/rabbitmq/bench/agent_compare.go","lineNumber":356,"sourceCode":"\t\t\"method\":  method,\n\t\t\"params\":  params,\n\t}\n\tpayload, err := json.Marshal(request)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif _, err := process.stdin.Write(append(payload, '\\n')); err != nil {\n\t\treturn nil, err\n\t}\n\tif !process.reader.Scan() {\n\t\treturn nil, fmt.Errorf(\"agent response unavailable: %v\", process.reader.Err())\n\t}\n\tvar response agentResponse\n\tif err := json.Unmarshal(process.reader.Bytes(), &response); err != nil {\n\t\treturn nil, err\n\t}\n\tif response.ID != process.nextID {\n\t\treturn nil, fmt.Errorf(\"response id %d does not match request id %d\", response.ID, process.nextID)\n\t}\n\tif response.Error != nil {\n\t\treturn nil, errors.New(response.Error.Message)\n\t}\n\treturn response.Result, nil\n}\n\nfunc (process *agentProcess) close() error {\n\t_, callError := process.call(\"shutdown\", map[string]any{})\n\t_ = process.stdin.Close()\n\twaitError := process.command.Wait()\n\tif callError != nil {\n\t\treturn callError\n\t}\n\treturn waitError\n}\n\nfunc (process *agentProcess) kill() {","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/rabbitmq/bench/agent_compare.go#L338-L374","documentation":"The harness correlates responses to requests by incrementing nextID; if the JSON-RPC response's id field does not equal the id just sent, call returns this mismatch error. It indicates responses are being interleaved, duplicated, or shifted.","triggerScenarios":"The agent emits extra stdout lines (logs, notifications) so the harness reads a line out of order, or the agent echoes a stale/zero id in its response.","commonSituations":"Agent logging to stdout between responses desynchronizing line framing; a concurrent call pattern the single-threaded harness doesn't expect; agent bug echoing request id 0.","solutions":["Ensure the agent writes only JSON-RPC response lines to stdout (logs to stderr)","Check each agent response echoes the request's id field unchanged","Verify requests are strictly sequential on the single stdin pipe","Look for notification/broadcast messages the agent emits outside request/response pairs"],"exampleFix":"// agent: wrong\ngo func() { fmt.Println(`{\"event\":\"tick\"}`) }() // pollutes stdout\n// after\n// emit only responses; log to stderr\nfmt.Fprintf(os.Stderr, \"tick\\n\")","handlingStrategy":"validation","validationCode":"// client-side: preflight that the agent echoes ids\ncallCtx := process\nresp, err := process.call(\"connect\", testParams)\n_ = callCtx\nif err == nil && resp == nil {\n    return errors.New(\"agent returned empty result on handshake\")\n}","typeGuard":null,"tryCatchPattern":"res, err := process.call(method, params)\nif err != nil && strings.Contains(err.Error(), \"does not match request id\") {\n    log.Fatalf(\"protocol desync: %v\", err)\n}","preventionTips":["Never write non-response lines (logs, events) to the agent's stdout","Always echo the exact request id in JSON-RPC responses","Keep the protocol strictly request/response on a single pipe"],"tags":["rpc","protocol","json-rpc"],"backgroundTag":"json-rpc-id-mismatch","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}