Skip to content

feat(lifecycle): ResourceLifecycleRegistry for unified resource disposal#161

Open
hernandez42 wants to merge 1 commit into
OpenBMB:mainfrom
hernandez42:feat/resource-lifecycle-registry
Open

feat(lifecycle): ResourceLifecycleRegistry for unified resource disposal#161
hernandez42 wants to merge 1 commit into
OpenBMB:mainfrom
hernandez42:feat/resource-lifecycle-registry

Conversation

@hernandez42
Copy link
Copy Markdown

Summary

PR 1: ResourceLifecycleRegistry + Lifecycle Unification

Add unified lifecycle resource registry for PilotDeck, replacing ad-hoc teardown scattered through createLocalGateway.

Changes

New file: src/lifecycle/runtime/ResourceLifecycleRegistry.ts

  • ResourceLifecycleRegistry: centralized registry for lifecycle resources
  • register(disposer): register a resource for later disposal
  • dispose() / disposeAll(): run all disposers in reverse order (LIFO)
  • Best-effort cleanup: errors collected but do not block subsequent disposers
  • disposeSync(): synchronous variant for contexts where async is not available
  • unregister(), has(), registered(): management APIs

Modified: src/lifecycle/index.ts

  • Export ResourceLifecycleRegistry from the lifecycle module

Modified: src/cli/createLocalGateway.ts

  • dispose() now uses ResourceLifecycleRegistry instead of inline cleanup
  • Resources registered: registry.invalidate(), stopConfigWatching(), stopExtensionWatching(), telemetry.shutdown(), gateway.dispose()
  • dispose() is now async () => Promise<void>

Modified: src/cli/pilotdeck.ts

  • Updated disposeGateway() to await disposeGateway() since dispose is now async

Verification

npm test

Why this matters

Previously, telemetry shutdown, config watcher stop, extension watcher stop, and gateway dispose were separate inline calls. If any threw, others might be skipped. Now they are registered in a registry that:

  1. Runs in reverse order (dependencies cleaned up after dependents)
  2. Best-effort: all disposers attempt to run even if earlier ones fail
  3. Errors are collected and logged, not silently swallowed

TODO follow-up (not in this PR)

  • .pilotdeck-always-on / .apex-mem retention/cleanup strategy
  • MCP/plugin browser process lifecycle audit
  • test vs test:noforce default decision

Co-authored-by: Xuanji xuanji@ouvaton.org

- Add ResourceLifecycleRegistry for centralized, coordinated resource
  disposal. Replaces ad-hoc teardown scattered through createLocalGateway.
  Supports register/dispose/disposeAll with error collection and logging.

- Integrate ResourceLifecycleRegistry into createLocalGateway dispose flow:
  config-store, extension-watch-manager, and telemetry are now registered
  and disposed through the registry. dispose() is now async.

- Update CreateLocalGatewayResult.dispose type from () => void to
  () => Promise<void> and add await to disposeGateway() call in
  pilotdeck.ts server stop handler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant