can1357/oh-my-pi · error · ToolError

memory_reference is required for write_memory

Error message

memory_reference is required for write_memory

What it means

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.

Source

Thrown at packages/coding-agent/src/tools/debug.ts:1040

					throw new ToolError("count is required for read_memory");
				}
				const response = await dapSessionManager.readMemory(
					params.memory_reference,
					params.count,
					params.offset,
					combinedSignal,
					timeoutSec * 1000,
				);
				details.snapshot = response.snapshot;
				details.memoryAddress = response.address;
				details.memoryData = response.data;
				details.unreadableBytes = response.unreadableBytes;
				return result.text(formatMemoryRead(response.address, response.data, response.unreadableBytes)).done();
			}
			case "write_memory": {
				requireCapability("supportsWriteMemoryRequest", "memory writes");
				if (!params.memory_reference) {
					throw new ToolError("memory_reference is required for write_memory");
				}
				if (!params.data) {
					throw new ToolError("data is required for write_memory");
				}
				const response = await dapSessionManager.writeMemory(
					params.memory_reference,
					params.data,
					params.offset,
					params.allow_partial,
					combinedSignal,
					timeoutSec * 1000,
				);
				details.snapshot = response.snapshot;
				details.bytesWritten = response.bytesWritten;
				return result
					.text(
						[
							"Memory write completed.",

View on GitHub (pinned to 9690622007)

Solutions

  1. Supply a memory_reference obtained from the current session's variables/scopes/stack_trace response.
  2. Use snake_case parameter names (memory_reference, data, offset, allow_partial).
  3. Also provide params.data — the next check requires a non-empty string/hex payload.
  4. Confirm the adapter advertises supportsWriteMemoryRequest; otherwise writes are unavailable regardless of parameters.

Example fix

// before
await debugTool.run({ action: "write_memory", data: "9090" });
// after
await debugTool.run({ action: "write_memory", memory_reference: ref, data: "9090" });
Defensive patterns

Strategy: validation

Validate before calling

if (typeof memoryRef !== "string" || memoryRef.length === 0) throw new Error("write_memory requires a memory_reference from the current debug session");
if (typeof data !== "string" || data.length === 0) throw new Error("write_memory requires a non-empty data payload");

Type guard

function isWritableMemory(p: { memory_reference?: string; data?: string }): p is { memory_reference: string; data: string } {
  return typeof p.memory_reference === "string" && p.memory_reference.length > 0 &&
    typeof p.data === "string" && p.data.length > 0;
}

Try / catch

try {
  await debugTool.run({ action: "write_memory", memory_reference: ref, data: hex });
} catch (err) {
  if (err instanceof ToolError && err.message.includes("memory_reference is required")) {
    // re-resolve the reference from current variables/scopes before retrying
  } else throw err;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/8d4c54f0b0d0d7c5. Report an issue: GitHub.