{"record":{"id":"e55d947c2a2f7fb1","repo":"jackwener/OpenCLI","slug":"failed-to-add-username-to-list-listid-malf","errorCode":null,"errorMessage":"Failed to add @${username} to list ${listId}: malformed mutation response envelope","messagePattern":"Failed to add @(.+?) to list (.+?): malformed mutation response envelope","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/twitter/list-add-core.js","lineNumber":212,"sourceCode":"                return JSON.stringify([\n                    r.ok,\n                    r.status,\n                    list ? list.member_count : null,\n                    list ? list.is_member : null,\n                    body && body.errors ? body.errors : null,\n                    raw,\n                    null,\n                ]);\n            } catch (e) {\n                return JSON.stringify([false, 0, null, null, null, null, String(e)]);\n            }\n        }`);\n        const addResultJson = unwrapBrowserResult(addResultJsonRaw);\n        let addResultTuple;\n        try {\n            addResultTuple = JSON.parse(addResultJson);\n        } catch {\n            throw new CommandExecutionError(`Failed to add @${username} to list ${listId}: malformed mutation response envelope`);\n        }\n        const addResult = Object.create(null);\n        addResult.httpOk = Boolean(addResultTuple?.[0]);\n        addResult.status = Number(addResultTuple?.[1]) || 0;\n        addResult.mc = addResultTuple?.[2];\n        addResult.isMember = addResultTuple?.[3];\n        addResult.errors = addResultTuple?.[4];\n        addResult.raw = addResultTuple?.[5];\n        addResult.fetchError = addResultTuple?.[6];\n\n    return [buildListAddMemberRow({ addResult, memberCountBefore, listId, username, userId })];\n}\n","sourceCodeStart":194,"sourceCodeEnd":225,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/twitter/list-add-core.js#L194-L225","documentation":"The ListAddMember mutation runs via page.evaluate and returns a JSON-stringified tuple envelope [httpOk, status, member_count, is_member, errors, raw, fetchError]. The command unwraps it with unwrapBrowserResult and JSON.parse; if the parsed string is not valid JSON, the in-page/result plumbing was corrupted and the mutation outcome is unknowable, so it throws CommandExecutionError('malformed mutation response envelope').","triggerScenarios":"unwrapBrowserResult returns a value that is not the JSON.stringify'd tuple the in-page async function produced — e.g. the evaluate result was stringified as '[object Object]', a serialization wrapper mismatch (opencli >=1.7.x {session,data} envelope handled differently), or the string was truncated/corrupted in transit.","commonSituations":"Running against an older/newer opencli version whose page.evaluate return-value wrapping differs from what unwrapBrowserResult expects; the page navigated or the context was destroyed mid-evaluate; a proxy/interceptor mangled the evaluate result.","solutions":["Check your @jackwener/opencli version: >=1.7.x wraps evaluate results as {session,data}; ensure unwrapBrowserResult matches your installed version (upgrade or downgrade so they agree).","Re-run the command once — a transient page-context interruption can corrupt a single evaluate result.","Add logging around unwrapBrowserResult's raw return to inspect what actually came back from page.evaluate.","If reproducible, verify no page navigation/race occurs during the evaluate (keep the tab on x.com)."],"exampleFix":"// before: mixed versions\nnpm ls @jackwener/opencli  # 1.6.x installed, unwrapBrowserResult expects 1.7.x envelope\n// after\nnpm install @jackwener/opencli@latest  # evaluate wrapper and unwrapBrowserResult in sync","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function isMutationEnvelope(v) {\n  if (typeof v !== 'string') return false;\n  try {\n    const t = JSON.parse(v);\n    return Array.isArray(t) && typeof t[0] === 'boolean' && typeof t[1] === 'number';\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  const result = await listAddUser(page, { listId, username });\n} catch (e) {\n  if (/malformed mutation response envelope/.test(e.message)) {\n    console.error('page.evaluate result did not parse — check opencli version vs unwrapBrowserResult; retrying once.');\n    return retryOnce();\n  }\n  throw e;\n}","preventionTips":["Keep @jackwener/opencli (>=1.7.x) and any local unwrapBrowserResult copy in version sync.","Avoid navigating the page or closing the tab while evaluate calls are in flight.","Pin the opencli version in CI so evaluate result wrapping is stable.","Retry once on this error — it can be a transient context interruption."],"tags":["serialization","browser-automation","twitter"],"backgroundTag":"malformed-response-envelope","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}