{"record":{"id":"81fff7278c37a71c","repo":"can1357/oh-my-pi","slug":"memory-id-is-required","errorCode":null,"errorMessage":"memory_id is required","messagePattern":"memory_id is required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/mnemopi/src/core/streaming.ts","lineNumber":112,"sourceCode":"\t\t(ArrayBuffer.isView(value) && !(value instanceof DataView))\n\t);\n}\n\nexport class MemoryEvent {\n\treadonly eventType: EventType;\n\treadonly memoryId: string;\n\treadonly timestamp: string;\n\treadonly sessionId: string | null;\n\treadonly content: string | null;\n\treadonly source: string | null;\n\treadonly importance: number | null;\n\treadonly metadata: Record<string, unknown> | null;\n\treadonly delta: Record<string, unknown> | null;\n\n\tconstructor(init: MemoryEventInit) {\n\t\tthis.eventType = normalizeEventType(init.eventType ?? init.event_type);\n\t\tthis.memoryId = init.memoryId ?? init.memory_id ?? \"\";\n\t\tif (this.memoryId.length === 0) throw new TypeError(\"memory_id is required\");\n\t\tthis.timestamp = init.timestamp ?? new Date().toISOString();\n\t\tthis.sessionId = init.sessionId ?? init.session_id ?? null;\n\t\tthis.content = init.content ?? null;\n\t\tthis.source = init.source ?? null;\n\t\tthis.importance = init.importance ?? null;\n\t\tthis.metadata = init.metadata ?? null;\n\t\tthis.delta = init.delta ?? null;\n\t}\n\ttoDict(): MemoryEventDict {\n\t\tconst out: MemoryEventDict = {\n\t\t\tevent_type: this.eventType,\n\t\t\tmemory_id: this.memoryId,\n\t\t\ttimestamp: this.timestamp,\n\t\t};\n\t\tif (this.sessionId !== null) out.session_id = this.sessionId;\n\t\tif (this.content !== null) out.content = this.content;\n\t\tif (this.source !== null) out.source = this.source;\n\t\tif (this.importance !== null) out.importance = this.importance;","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/mnemopi/src/core/streaming.ts#L94-L130","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst event = new MemoryEvent({ eventType: \"update\", content: \"hello\" });\n// after\nconst event = new MemoryEvent({ eventType: \"update\", memoryId: memory.id, content: \"hello\" });","handlingStrategy":"validation","validationCode":"function toMemoryEvent(init) {\n\tconst id = init.memoryId ?? init.memory_id;\n\tif (typeof id !== \"string\" || id.length === 0) throw new TypeError(\"memory_id is required before constructing MemoryEvent\");\n\treturn new MemoryEvent({ ...init, memoryId: id });\n}","typeGuard":"function hasMemoryId(init) {\n\treturn typeof (init.memoryId ?? init.memory_id) === \"string\" && (init.memoryId ?? init.memory_id).length > 0;\n}","tryCatchPattern":"try {\n\tconst event = new MemoryEvent(init);\n} catch (err) {\n\tif (err instanceof TypeError && err.message === \"memory_id is required\") {\n\t\tlogger.warn(\"dropping memory event without id\", { init });\n\t\treturn null;\n\t}\n\tthrow err;\n}","preventionTips":["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"],"tags":["validation","constructor","missing-argument"],"backgroundTag":"missing-required-identifier","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}