{"record":{"id":"cbada171066a8b19","repo":"xai-org/grok-build","slug":"failed-to-build-request-e","errorCode":null,"errorMessage":"failed to build request: {e}","messagePattern":"failed to build request: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-pager/src/worktree_cmd/mod.rs","lineNumber":139,"sourceCode":"    method: &str,\n    params: &T,\n) -> Result<acp::ExtRequest, serde_json::Error> {\n    let params = serde_json::value::to_raw_value(params)?;\n    Ok(acp::ExtRequest::new(method, params.into()))\n}\n/// ACP extension responses are wrapped in `{ \"result\": T, \"error\": ... }`.\n#[derive(serde::Deserialize)]\nstruct ExtEnvelope<T> {\n    result: Option<T>,\n    error: Option<serde_json::Value>,\n}\nasync fn ext_call<T: serde::de::DeserializeOwned>(\n    tx: &xai_acp_lib::AcpAgentTx,\n    method: &str,\n    params: &impl serde::Serialize,\n) -> Result<T> {\n    let req =\n        ext_request(method, params).map_err(|e| anyhow::anyhow!(\"failed to build request: {e}\"))?;\n    let resp = acp_send(req, tx)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"{e}\"))?;\n    let envelope: ExtEnvelope<T> = serde_json::from_str(resp.0.get())\n        .map_err(|e| anyhow::anyhow!(\"response parse error: {e}\"))?;\n    if let Some(err) = envelope.error {\n        bail!(\"ACP error: {err}\");\n    }\n    envelope\n        .result\n        .ok_or_else(|| anyhow::anyhow!(\"ACP response missing result field\"))\n}\nasync fn cmd_list(\n    tx: &xai_acp_lib::AcpAgentTx,\n    repo: Option<String>,\n    types: Vec<String>,\n    json: bool,\n    all: bool,","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-pager/src/worktree_cmd/mod.rs#L121-L157","documentation":"This error is raised by `ext_call` in the worktree command module when `ext_request` cannot construct the JSON-RPC request for an ACP extension method call. The underlying cause is a serialization failure of the `params` argument or an invalid method string, wrapped via anyhow with the original formatter error. It aborts the worktree subcommand before anything is sent over the ACP transport.","triggerScenarios":"Calling any worktree subcommand (list, show, rm, gc, db) whose params type fails `serde_json::to_value` serialization inside `ext_request`, e.g. params containing a non-string map key or a value serde_json rejects (NaN, non-string keys).","commonSituations":"A newly added CLI flag introduces a params field that fails to serialize; a params struct uses HashMap with non-string keys; serde feature mismatch after a dependency version change makes a field unserializable.","solutions":["Inspect the inner `{e}` message to identify which params field failed to serialize.","Check the params struct for types serde_json cannot represent (non-string map keys, f64::NAN, untagged enums that fail).","Replace HashMap keys with String or BTreeMap<String, T> in the params type.","Add a Serialize derive/unit test that round-trips the params struct to catch regressions early."],"exampleFix":"// before\nlet params = serde_json::Map::new(); // built with non-string keys somewhere upstream\n// after\n#[derive(serde::Serialize)]\nstruct WorktreeListParams { repo: Option<String>, types: Vec<String> }\nlet params = WorktreeListParams { repo, types }; // guaranteed serializable","handlingStrategy":"validation","validationCode":"fn assert_serializable<T: serde::Serialize>(params: &T) -> Result<(), String> {\n    serde_json::to_value(params).map(|_| ()).map_err(|e| e.to_string())\n}\n// call before ext_call: assert_serializable(&params)?;","typeGuard":null,"tryCatchPattern":"match ext_call::<WorktreeList>(tx, \"worktree/list\", &params).await {\n    Ok(list) => render(list),\n    Err(e) if e.to_string().contains(\"failed to build request\") => {\n        eprintln!(\"params serialization failed: {e:#}\");\n    }\n    Err(e) => eprintln!(\"worktree command failed: {e:#}\"),\n}","preventionTips":["Keep params types to serde_json-friendly shapes (String keys, no NaN floats).","Add round-trip serialization unit tests for every extension params struct.","Wrap ext_request in a debug assertion during CI to catch serialization issues before release."],"tags":["rust","anyhow","serde","serialization","acp"],"backgroundTag":"request-serialization-failed","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}