can1357/oh-my-pi · error · TypeError
memory_id is required
Error message
memory_id is required
What it means
MemoryEvent's constructor requires a non-empty memoryId identifying which memory the event refers to. Both camelCase (memoryId) and snake_case (memory_id) init keys are accepted, but if neither is provided (or both are empty/undefined), the id defaults to "" and the constructor throws a TypeError. This is a fail-fast guard so events are never persisted or streamed without a valid memory reference.
Source
Thrown at packages/mnemopi/src/core/streaming.ts:112
(ArrayBuffer.isView(value) && !(value instanceof DataView))
);
}
export class MemoryEvent {
readonly eventType: EventType;
readonly memoryId: string;
readonly timestamp: string;
readonly sessionId: string | null;
readonly content: string | null;
readonly source: string | null;
readonly importance: number | null;
readonly metadata: Record<string, unknown> | null;
readonly delta: Record<string, unknown> | null;
constructor(init: MemoryEventInit) {
this.eventType = normalizeEventType(init.eventType ?? init.event_type);
this.memoryId = init.memoryId ?? init.memory_id ?? "";
if (this.memoryId.length === 0) throw new TypeError("memory_id is required");
this.timestamp = init.timestamp ?? new Date().toISOString();
this.sessionId = init.sessionId ?? init.session_id ?? null;
this.content = init.content ?? null;
this.source = init.source ?? null;
this.importance = init.importance ?? null;
this.metadata = init.metadata ?? null;
this.delta = init.delta ?? null;
}
toDict(): MemoryEventDict {
const out: MemoryEventDict = {
event_type: this.eventType,
memory_id: this.memoryId,
timestamp: this.timestamp,
};
if (this.sessionId !== null) out.session_id = this.sessionId;
if (this.content !== null) out.content = this.content;
if (this.source !== null) out.source = this.source;
if (this.importance !== null) out.importance = this.importance;View on GitHub (pinned to 9690622007)
Solutions
- Pass memoryId (or memory_id) with a non-empty string in the MemoryEventInit object
- Validate/require the id at the call site before constructing the event, e.g. assert the source record has memory_id
- If the id may legitimately be absent, do not construct a MemoryEvent — handle that case before instantiation
Example fix
// before
const event = new MemoryEvent({ eventType: "update", content: "hello" });
// after
const event = new MemoryEvent({ eventType: "update", memoryId: memory.id, content: "hello" }); Defensive patterns
Strategy: validation
Validate before calling
function toMemoryEvent(init) {
const id = init.memoryId ?? init.memory_id;
if (typeof id !== "string" || id.length === 0) throw new TypeError("memory_id is required before constructing MemoryEvent");
return new MemoryEvent({ ...init, memoryId: id });
} Type guard
function hasMemoryId(init) {
return typeof (init.memoryId ?? init.memory_id) === "string" && (init.memoryId ?? init.memory_id).length > 0;
} Try / catch
try {
const event = new MemoryEvent(init);
} catch (err) {
if (err instanceof TypeError && err.message === "memory_id is required") {
logger.warn("dropping memory event without id", { init });
return null;
}
throw err;
} Prevention
- Always populate memoryId when constructing MemoryEvent
- Type the init object with a required memoryId field so TS catches omissions
- Validate incoming JSON/webhook payloads for memory_id before use
- Check source rows for null memory_id before mapping to events
When it happens
Trigger: Calling new MemoryEvent({eventType: ...}) without memoryId or memory_id; passing memoryId: "" or memory_id: null explicitly; spreading a partial record that lacks the id field; mapping over events where some rows have no memory_id column value.
Common situations: Constructing events from loose JSON payloads (e.g. webhook or IPC messages) that omit the id; refactoring call sites where the field was renamed; reading legacy rows whose memory_id column is empty; typing the init object as a broader Record so TypeScript can't catch the omission.
Related errors
- Pass at least one model selector, e.g. `omp bench opus gpt-5
- No snippet provided. Pass inline text, --file <path>, or pip
- cloud start requires --repo-id, --repo-url, and --environmen
- ${status} requires a rationale
- program is required for launch
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/81fff7278c37a71c.
Report an issue: GitHub.