fix(plugin): add dispose lifecycle for full teardown on reload
Plugin created managers, hooks, intervals, and process listeners on every load but had no teardown mechanism. On plugin reload, old instances remained alive causing cumulative memory leaks. - Add createPluginDispose() orchestrating shutdown sequence: backgroundManager.shutdown() → skillMcpManager.disconnectAll() → disposeHooks() - Add disposeHooks() aggregator with safe optional chaining - Wire dispose into index.ts to clean previous instance on reload - Make dispose idempotent (safe to call multiple times) Tests: 4 pass, 8 expects
This commit is contained in:
+22
-1
@@ -11,6 +11,20 @@ import { createSkillHooks } from "./plugin/hooks/create-skill-hooks"
|
||||
|
||||
export type CreatedHooks = ReturnType<typeof createHooks>
|
||||
|
||||
type DisposableHook = { dispose?: () => void } | null | undefined
|
||||
|
||||
export type DisposableCreatedHooks = {
|
||||
runtimeFallback?: DisposableHook
|
||||
todoContinuationEnforcer?: DisposableHook
|
||||
autoSlashCommand?: DisposableHook
|
||||
}
|
||||
|
||||
export function disposeCreatedHooks(hooks: DisposableCreatedHooks): void {
|
||||
hooks.runtimeFallback?.dispose?.()
|
||||
hooks.todoContinuationEnforcer?.dispose?.()
|
||||
hooks.autoSlashCommand?.dispose?.()
|
||||
}
|
||||
|
||||
export function createHooks(args: {
|
||||
ctx: PluginContext
|
||||
pluginConfig: OhMyOpenCodeConfig
|
||||
@@ -58,9 +72,16 @@ export function createHooks(args: {
|
||||
availableSkills,
|
||||
})
|
||||
|
||||
return {
|
||||
const hooks = {
|
||||
...core,
|
||||
...continuation,
|
||||
...skill,
|
||||
}
|
||||
|
||||
return {
|
||||
...hooks,
|
||||
disposeHooks: (): void => {
|
||||
disposeCreatedHooks(hooks)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user