can1357/oh-my-pi · error · TypeError
Plugin must implement onInvalidate
Error message
Plugin must implement onInvalidate
What it means
MnemopiPlugin's onInvalidate is a throwing stub that subclasses must override; the host calls it when a memory id is invalidated. This TypeError means an invalidation event reached a plugin that never implemented the hook.
Source
Thrown at packages/mnemopi/src/core/plugins.ts:46
initialize(): void {
this.initialized = true;
}
shutdown(): void {
this.initialized = false;
}
onRemember(_memory: MemoryDict): void {
throw new TypeError("Plugin must implement onRemember");
}
onRecall(_memory: MemoryDict): void {
throw new TypeError("Plugin must implement onRecall");
}
onConsolidate(_summary: MemoryDict): void {
throw new TypeError("Plugin must implement onConsolidate");
}
onInvalidate(_memoryId: string): void {
throw new TypeError("Plugin must implement onInvalidate");
}
toDict(): Record<string, unknown> {
return {
name: this.name,
version: this.version,
enabled: this.enabled,
initialized: this.initialized,
config: this.config,
};
}
}
function previewContent(content: unknown, maxLen = 80): string {
const text = typeof content === "string" ? content : "";
if (text.length <= maxLen) return text;
return `${text.slice(0, maxLen)}...`;
}
View on GitHub (pinned to 9690622007)
Solutions
- Override onInvalidate(memoryId: string): void in the plugin subclass
- Add a no-op override if invalidation events are irrelevant to the plugin
- Confirm the exact method name/casing matches onInvalidate so the override actually binds
Example fix
// before
class MyPlugin extends MnemopiPlugin { override onConsolidate(s: MemoryDict): void {} }
// after
class MyPlugin extends MnemopiPlugin { override onConsolidate(s: MemoryDict): void {} override onInvalidate(id: string): void { /* ... */ } } Defensive patterns
Strategy: type-guard
Validate before calling
function implementsOnInvalidate(p: MnemopiPlugin): boolean {
return p.onInvalidate !== MnemopiPlugin.prototype.onInvalidate;
}
if (!implementsOnInvalidate(plugin)) throw new Error(`plugin ${plugin.name} must override onInvalidate`); Type guard
function overridesOnInvalidate<P extends MnemopiPlugin>(p: P): p is P & { onInvalidate(id: string): void } {
return p.onInvalidate !== MnemopiPlugin.prototype.onInvalidate;
} Try / catch
try {
host.invalidate(memoryId);
} catch (err) {
if (err instanceof TypeError && err.message === "Plugin must implement onInvalidate") {
logger.error(`plugin ${plugin.name} lacks onInvalidate; skipping invalidation event`);
} else throw err;
} Prevention
- Scaffold plugins with all four hook overrides present
- Verify exact method casing (onInvalidate) — near-misses silently fall through to the stub
- Use `override` keyword so the compiler flags missing base-hook implementations
- Add a conformance check at plugin registration time comparing against MnemopiPlugin.prototype
When it happens
Trigger: A registered plugin subclass without an onInvalidate override, triggered whenever a memory is invalidated/deleted and the host calls plugin.onInvalidate(memoryId).
Common situations: Plugins covering only remember/recall/consolidate hooks; a copy of the plugin predating the onInvalidate hook; typos like onInvalidate(s) vs oninvalidate breaking the override.
Related errors
- Plugin must implement onRemember
- Plugin must implement onRecall
- Plugin must implement onConsolidate
- MnemopiPlugin is abstract
- Destination option ${key} must be a string
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/235b1a414b543db6.
Report an issue: GitHub.