--- id: host-finalize-instance name: Add finalizeInstance to HostConfig status: pending depends_on: [fiber-disposal] created: 2026-05-18T16:22:57.323634873Z modified: 2026-05-18T16:22:57.323635316Z scope: single risk: low impact: component level: implementation --- # Description Add the optional `finalizeInstance?(instance: Instance, ctx: RootCtx): void` method to the `HostConfig` interface. This method allows hosts to perform per-instance cleanup when an instance is removed (e.g., releasing GPU buffer slots, closing database connections, removing graphology nodes). This is a backward-compatible change: the method is optional, so existing `HostConfig` implementations continue to work without modification. The reconciler calls `finalizeInstance` during `disposeFiber` after children are disposed but before the fiber's own state is cleared. ## Acceptance Criteria - [ ] `finalizeInstance?(instance: Instance, ctx: RootCtx): void` added to `HostConfig` interface - [ ] Method is optional (existing hosts don't need to implement it) - [ ] Called by `disposeFiber` during fiber tree disposal - [ ] Called bottom-up: children's `finalizeInstance` before parent's - [ ] Updated in `src/host/config.ts` interface definition - [ ] TypeScript compiles (`npm run build:tsc`) - [ ] Existing tests pass (existing HostConfig implementations don't break) - [ ] New test: host implementing `finalizeInstance` receives calls during disposal ## References - docs/architecture/lifecycle.md — Host Notification section, finalizeInstance interface - docs/architecture/host-config.md — Open Question 3 (should HostConfig include finalizeInstance) ## Notes > To be filled by implementation agent ## Summary > To be filled on completion