{"record":{"id":"e7dbca30adc39c21","repo":"can1357/oh-my-pi","slug":"memory-reference-is-required-for-read-memory","errorCode":null,"errorMessage":"memory_reference is required for read_memory","messagePattern":"memory_reference is required for read_memory","errorType":"validation","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/debug.ts","lineNumber":1019,"sourceCode":"\t\t\t\t\tthrow new ToolError(\"instruction_count is required for disassemble\");\n\t\t\t\t}\n\t\t\t\tconst response = await dapSessionManager.disassemble(\n\t\t\t\t\tresolveDisassemblyReference(params.memory_reference),\n\t\t\t\t\tparams.instruction_count,\n\t\t\t\t\tparams.offset,\n\t\t\t\t\tparams.instruction_offset,\n\t\t\t\t\tparams.resolve_symbols,\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.disassembly = response.instructions;\n\t\t\t\treturn result.text(formatDisassembly(response.instructions)).done();\n\t\t\t}\n\t\t\tcase \"read_memory\": {\n\t\t\t\trequireCapability(\"supportsReadMemoryRequest\", \"memory reads\");\n\t\t\t\tif (!params.memory_reference) {\n\t\t\t\t\tthrow new ToolError(\"memory_reference is required for read_memory\");\n\t\t\t\t}\n\t\t\t\tif (params.count === undefined) {\n\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\": {","sourceCodeStart":1001,"sourceCodeEnd":1037,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/debug.ts#L1001-L1037","documentation":"The debug tool's read_memory action forwards a DAP (Debug Adapter Protocol) readMemory request to the active debug adapter session. The DAP protocol requires a memory_reference string identifying which memory region to read. This library throws a ToolError early, before contacting the adapter, when the caller omitted it. It is a fast-fail parameter validation guard, not a protocol failure.","triggerScenarios":"Invoking the debug tool with action=\"read_memory\" while params.memory_reference is undefined, null, or an empty string. Typically happens when the caller never called stack_trace/variables/scopes first to obtain a memoryReference, or passed a wrong params key (e.g. memoryReference vs memory_reference).","commonSituations":"Agents or scripts composing tool calls from LLM output that omit the memory reference; hand-written automation copying a variable reference incorrectly; cases where the debug session was restarted and the previously captured memoryReference was lost; confusing camelCase DAP field names with the tool's snake_case parameter names.","solutions":["Obtain a valid memory_reference first: call read_memory only with a memoryReference returned by an earlier variables/scopes/stack_trace response.","Check the tool params use snake_case: memory_reference, count, offset — not DAP's camelCase memoryReference.","Ensure count is also supplied (it is separately required) and is a positive number.","Verify the active debug adapter actually supports memory reads (supportsReadMemoryRequest capability) — the capability check runs before this one and will surface its own error otherwise."],"exampleFix":"// before\nawait debugTool.run({ action: \"read_memory\", count: 64 });\n// after\nawait debugTool.run({ action: \"read_memory\", memory_reference: memoryRef, count: 64 });","handlingStrategy":"validation","validationCode":"if (typeof memoryRef !== \"string\" || memoryRef.length === 0) throw new Error(\"read_memory requires a memory_reference from a prior variables/scopes call\");\nif (typeof count !== \"number\" || count <= 0) throw new Error(\"read_memory requires a positive count\");","typeGuard":"function hasMemoryRef(p: { memory_reference?: string }): p is { memory_reference: string } {\n  return typeof p.memory_reference === \"string\" && p.memory_reference.length > 0;\n}","tryCatchPattern":"try {\n  await debugTool.run({ action: \"read_memory\", memory_reference: ref, count: 256 });\n} catch (err) {\n  if (err instanceof ToolError && err.message.includes(\"memory_reference is required\")) {\n    // re-fetch a fresh memoryReference via stack_trace/variables, then retry\n  } else throw err;\n}","preventionTips":["Always capture memoryReference values from variables/scopes/stack_trace responses in the same session.","Keep a small wrapper function that builds read_memory calls with required fields enforced by types.","Refresh references after any session restart or breakpoint hit — old ones may be stale."],"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"}