Skip to content

Implement two-phase initialization model (discovery → registration) #1009

@willgriffin

Description

@willgriffin

Problem

Currently, class discovery and registration happen interleaved — a class can be registered at any time (decorator evaluation, manifest loading, lazy discovery during getInheritanceChain). This makes initialization order-dependent and non-deterministic.

Proposed Solution

Phase 1: Discovery

  • Scan all installed SMRT packages (using discoverSmrtPackages())
  • Load and parse all manifest.json files
  • Build a global name → qualified-name → manifest-entry map
  • Detect and report name ambiguities before any class is registered
  • No mutations to ObjectRegistry.classes

Phase 2: Registration

  • Compute topological order based on extends declarations
  • Register all classes in dependency order (parents before children)
  • After registration, compute and cache all inheritance chains
  • Lock the discovery cache — no further lazy discovery permitted

Benefits

  • Ambiguity detected upfront with clear error messages
  • Inheritance chains guaranteed correct (parents always registered first)
  • No side effects during read operations
  • Deterministic regardless of import/evaluation order

Key Files

  • packages/core/src/registry.ts
  • packages/core/src/manifest/manifest-loader.ts
  • packages/core/src/manifest/discover-smrt-packages.ts

Part of epic #1003.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions