{"record":{"id":"8d4c54f0b0d0d7c5","repo":"can1357/oh-my-pi","slug":"memory-reference-is-required-for-write-memory","errorCode":null,"errorMessage":"memory_reference is required for write_memory","messagePattern":"memory_reference is required for write_memory","errorType":"validation","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/debug.ts","lineNumber":1040,"sourceCode":"\t\t\t\t\tthrow new ToolError(\"count is required for read_memory\");\n\t\t\t\t}\n\t\t\t\tconst response = await dapSessionManager.readMemory(\n\t\t\t\t\tparams.memory_reference,\n\t\t\t\t\tparams.count,\n\t\t\t\t\tparams.offset,\n\t\t\t\t\tcombinedSignal,\n\t\t\t\t\ttimeoutSec * 1000,\n\t\t\t\t);\n\t\t\t\tdetails.snapshot = response.snapshot;\n\t\t\t\tdetails.memoryAddress = response.address;\n\t\t\t\tdetails.memoryData = response.data;\n\t\t\t\tdetails.unreadableBytes = response.unreadableBytes;\n\t\t\t\treturn result.text(formatMemoryRead(response.address, response.data, response.unreadableBytes)).done();\n\t\t\t}\n\t\t\tcase \"write_memory\": {\n\t\t\t\trequireCapability(\"supportsWriteMemoryRequest\", \"memory writes\");\n\t\t\t\tif (!params.memory_reference) {\n\t\t\t\t\tthrow new ToolError(\"memory_reference is required for write_memory\");\n\t\t\t\t}\n\t\t\t\tif (!params.data) {\n\t\t\t\t\tthrow new ToolError(\"data is required for write_memory\");\n\t\t\t\t}\n\t\t\t\tconst response = await dapSessionManager.writeMemory(\n\t\t\t\t\tparams.memory_reference,\n\t\t\t\t\tparams.data,\n\t\t\t\t\tparams.offset,\n\t\t\t\t\tparams.allow_partial,\n\t\t\t\t\tcombinedSignal,\n\t\t\t\t\ttimeoutSec * 1000,\n\t\t\t\t);\n\t\t\t\tdetails.snapshot = response.snapshot;\n\t\t\t\tdetails.bytesWritten = response.bytesWritten;\n\t\t\t\treturn result\n\t\t\t\t\t.text(\n\t\t\t\t\t\t[\n\t\t\t\t\t\t\t\"Memory write completed.\",","sourceCodeStart":1022,"sourceCodeEnd":1058,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/debug.ts#L1022-L1058","documentation":"The debug tool's write_memory action issues a DAP writeMemory request and needs a memory_reference identifying the target region. The tool throws a ToolError before contacting the adapter when it is missing or empty. This is a deliberate pre-flight validation so malformed calls fail fast with a clear message instead of an opaque adapter error.","triggerScenarios":"Invoking action=\"write_memory\" without params.memory_reference (undefined/null/empty string). Common when the caller derives the reference from a stale variables response or mistypes the parameter name.","commonSituations":"Automation attempting to patch memory after a session restart invalidated the old reference; tool-call JSON where camelCase memoryReference was used instead of snake_case memory_reference; the adapter never supporting writes so no reference was ever fetched.","solutions":["Supply a memory_reference obtained from the current session's variables/scopes/stack_trace response.","Use snake_case parameter names (memory_reference, data, offset, allow_partial).","Also provide params.data — the next check requires a non-empty string/hex payload.","Confirm the adapter advertises supportsWriteMemoryRequest; otherwise writes are unavailable regardless of parameters."],"exampleFix":"// before\nawait debugTool.run({ action: \"write_memory\", data: \"9090\" });\n// after\nawait debugTool.run({ action: \"write_memory\", memory_reference: ref, data: \"9090\" });","handlingStrategy":"validation","validationCode":"if (typeof memoryRef !== \"string\" || memoryRef.length === 0) throw new Error(\"write_memory requires a memory_reference from the current debug session\");\nif (typeof data !== \"string\" || data.length === 0) throw new Error(\"write_memory requires a non-empty data payload\");","typeGuard":"function isWritableMemory(p: { memory_reference?: string; data?: string }): p is { memory_reference: string; data: string } {\n  return typeof p.memory_reference === \"string\" && p.memory_reference.length > 0 &&\n    typeof p.data === \"string\" && p.data.length > 0;\n}","tryCatchPattern":"try {\n  await debugTool.run({ action: \"write_memory\", memory_reference: ref, data: hex });\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"memory_reference is required\")) {\n    // re-resolve the reference from current variables/scopes before retrying\n  } else throw err;\n}","preventionTips":["Resolve memory references fresh from the live session immediately before writing.","Use snake_case parameter names matching the tool schema when composing calls programmatically.","Gate write_memory behind an explicit capability check (supportsWriteMemoryRequest) in your automation."],"tags":["debugger","dap","parameter-validation","missing-parameter"],"backgroundTag":"missing-required-parameter","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}