{"record":{"id":"38b606114a143bf7","repo":"t8y2/dbx","slug":"invalid-json","errorCode":"invalid_json","errorMessage":"Invalid worker request JSON: {err}","messagePattern":"Invalid worker request JSON: (.+?)","errorType":"error_code","errorClass":"DuckDbWorkerError","httpStatus":null,"severity":"error","filePath":"agents/drivers/duckdb/src/runtime.rs","lineNumber":440,"sourceCode":"        let line = lines.next_line().await.map_err(|e| e.to_string())?;\n        let Some(line) = line else {\n            // Parent closed stdin (exit or crash). Idle workers checkpoint and\n            // remove their WAL on the normal return path; a worker still running\n            // a query must not wait for it (nor drop a poisoned connection),\n            // so it keeps the legacy immediate exit and the WAL replays on the\n            // next open.\n            if !runtime.close_session_for_shutdown() {\n                std::process::exit(0);\n            }\n            break;\n        };\n        if line.trim().is_empty() {\n            continue;\n        }\n        let request: DuckDbWorkerRequest = match serde_json::from_str(&line) {\n            Ok(request) => request,\n            Err(err) => {\n                let response = DuckDbWorkerResponse::err(\n                    \"\",\n                    DuckDbWorkerError::new(\"invalid_json\", format!(\"Invalid worker request JSON: {err}\")),\n                );\n                write_response(stdout.clone(), &response).await;\n                continue;\n            }\n        };\n        let result = runtime.handle_request(request, stdout.clone()).await;\n        if let Some(response) = result.response {\n            write_response(stdout.clone(), &response).await;\n        }\n        if result.shutdown {\n            break;\n        }\n    }\n    Ok(())\n}\n","sourceCodeStart":422,"sourceCodeEnd":458,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/duckdb/src/runtime.rs#L422-L458","documentation":"run_stdio_worker reads newline-delimited JSON requests from stdin and parses them with serde_json; any malformed line yields an invalid_json error response (with empty request id) that is written back to stdout, and processing continues. The error message embeds the serde error describing exactly what was wrong.","triggerScenarios":"Writing a line to the worker's stdin (runtime.rs:440) that is not a valid DuckDbWorkerRequest JSON: truncated output, wrong field names/types, duplicate fields, or non-UTF8/binary garbage on the pipe.","commonSituations":"Host and worker binary version mismatch (schema drift in DuckDbWorkerRequest); host writing partial JSON due to a pipe buffering bug; a parent process flushing logs/JSON into the same stdin; console noise injected into the protocol stream.","solutions":["Log the offending line and compare against the DuckDbWorkerRequest schema expected by the worker binary; align host and worker versions.","Ensure each request is written as exactly one complete JSON object followed by a newline, and flush after each write.","Validate/serialize requests with the same serde types (or the generated bindings) instead of hand-building JSON strings."],"exampleFix":"// before\nstdin.write(`{\"id\":1,\"method\":execute}`); // invalid JSON, unquoted method\n// after\nconst req = JSON.stringify({ id: \"1\", method: \"execute\", params: {} });\nstdin.write(req + \"\\n\");","handlingStrategy":"validation","validationCode":"// TS: validate before writing to the worker's stdin\nconst req = { id, method, params };\nconst line = JSON.stringify(req);\nJSON.parse(line); // throws locally if serialization is broken\nworkerStdin.write(line + \"\\n\");","typeGuard":"function isValidRequest(r: unknown): r is DuckDbWorkerRequest {\n  return typeof r === \"object\" && r !== null\n    && typeof (r as any).id === \"string\"\n    && typeof (r as any).method === \"string\";\n}","tryCatchPattern":"if (response.error?.code === \"invalid_json\") {\n  console.error(\"request rejected:\", response.error.message);\n  // fix serializer / version-align host and worker, then resend\n}","preventionTips":["Always serialize requests with JSON.stringify from typed objects, never hand-built strings.","Write one complete JSON object per line and flush after each write.","Keep host and worker protocol schemas/version in lockstep."],"tags":["rust","json","serialization","stdio","ipc"],"backgroundTag":"invalid-json-request","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}