Skip to content

Conversation

@davidfirst
Copy link
Member

Summary

RFC and implementation for rewriting the component loading mechanism. The current WorkspaceComponentLoader is ~1,000 lines of complex code that's hard to understand, modify, and debug.

Key Problems Being Addressed

  • Complex caching with inconsistent keys (12 options, only 4 used in cache key)
  • Recursive loading that's hard to trace (component → env → env-of-env → extensions)
  • Legacy hooks that jump between code and Harmony unpredictably
  • Multiple overlapping caches with no unified invalidation

Approach: Strangler Fig Pattern

  • Build V2 loader alongside existing code
  • Migrate command-by-command with parallel execution for comparison
  • Remove V1 only after all e2e tests pass

See docs/rfcs/component-loading-rewrite/ for full RFC, task tracking, and architecture decisions.

- Create WorkspaceComponentLoaderV2 class that wires all 6 phases together
- Implements getMany() interface matching V1 loader for compatibility
- Executes pipeline: Discovery → Resolution → Hydration → Enrichment → Assembly → Execution
- Feature flag support: BIT_FEATURES=component-loader-v2
- Unified caching with explicit cache key computation
- Detailed logging and profiling support
- Export orchestrator from loader-v2/index.ts
- Wire V2 loader into Workspace class with BIT_FEATURES=component-loader-v2
- V2 currently delegates to V1 while full pipeline is developed
- Feature flag mechanism working: logs '[V2] Using WorkspaceComponentLoaderV2' when enabled
- Fix import paths and TypeScript errors in phases
- Stub WorkspaceSource and update ScopeSource
- All existing commands work with V2 enabled

This establishes the foundation for V2 loader development. The architecture
is in place (phases, sources, orchestrator) and the feature flag works.
Next steps will be to implement the actual V2 pipeline logic.
Implements the complete V2 component loading pipeline with 6 phases:
- Discovery: Find components in workspace/scope
- Resolution: Build dependency-ordered load plan
- Hydration: Load raw data from sources
- Enrichment: Add env and dependency metadata
- Assembly: Build Component objects
- Execution: Run onComponentLoad slots

Key improvements:
- WorkspaceSource: Loads components from workspace filesystem
- ScopeSource: Extracts extensions from Version object (component.head.extensions)
- Graceful degradation: Components proceed even if enrichment fails
- Feature flag: BIT_FEATURES=component-loader-v2

The V2 loader successfully loads both workspace and scope components.
Enrichment failures for scope components result in warnings but don't
prevent command completion.
- Fix ExtensionResolver to use workspace.componentExtensions with
  loadExtensions: false to avoid recursion when discovering env IDs
- Add skipDependencyResolution option to prevent recursive workspace.get()
  calls through dependency resolution path
- Restore proper load groups in Resolution phase (core-envs → envs → components)
- Process LoadPlan phases sequentially through full pipeline to ensure
  envs are registered before dependent components
- Add loadComponentsExtensions call to load external envs as aspects
- Change default loadExtensions and executeLoadSlot to true (matching V1)
- Add recursion prevention in EnvsMain.getEnvComponentByEnvId
The V2 loader was incorrectly marking all components as modified because
the status check was using components with empty dependencies.

Root cause: When status check called consumer.loadComponents(), an
onComponentLoad subscriber called workspace.get() which triggered V2's
skipDependencyResolution path, stripping dependencies from components.

Fix: Pass originatedFromHarmony: true to status check's loadComponents()
to bypass the subscriber and preserve full dependencies for accurate
hash comparison.
V2 is now enabled by default. To use V1, set BIT_FEATURES=component-loader-v1
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.

2 participants