feat(components): component index correctness + build caching#12784
Conversation
Lazy asyncio.Lock on ComponentCache (safe under module-import-time constraints), bounded concurrency on dynamic component loading, non-blocking async read of the persisted index, cache-hit short-circuit that skips the full package walk when the installed lfx version matches, atomic + version-stamped writes, stale-index warning. - src/lfx/src/lfx/interface/components.py: all correctness + caching changes - src/lfx/tests/unit/test_component_index.py: parity + correctness tests Observable flow behavior is unchanged: every change is accompanied by a deep parity snapshot test that loads a flow via the component cache and asserts byte-identical final output + vertex execution order.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
- Cache-hit short-circuit now verifies SHA256 inline before promoting the blob; tampered or missing-SHA caches fall through to the rebuild path. - Stale-version caches are unlinked in the peek so the rebuild path can write fresh, instead of warning every cold start indefinitely. - _save_generated_index splits OSError (warning) from unexpected exceptions (error + traceback); silent debug-level failures previously hid disk-full / permission-denied regressions. - Cache peek narrows except to (OSError, JSONDecodeError) and emits a warning so corrupt files don't silently trigger a rebuild. - _load_components_dynamically tracks per-type failure counts and emits one aggregate "N of M modules failed" log alongside the per-module warnings. - _load_selective_dev_mode warns when the merge produces zero components to avoid empty-palette debug-time UX. - _read_component_index outer except includes exc_info=True. - Stale-cache log converted from %-formatting to f-string. Tests live in a new file (test_component_index_correctness.py) so they collect cleanly; the existing test_component_index.py imports a parity-helpers module that does not exist on this branch.
Drop the defensive negatives and second-branch variants. Each remaining test exercises one fix end-to-end: - tampered SHA does not short-circuit (cache-hit SHA verification) - stale-version cache is unlinked (auto-regeneration) - corrupt JSON cache warns and rebuilds (narrow except) - save OSError logs at warning (write-failure visibility) - selective dev mode warns on empty result - load_components_dynamically emits aggregate failure summary 12 tests -> 6 tests, ~370 lines -> ~200.
Move the 6 regression tests for the post-review fixes into the existing test_component_index.py and drop the standalone file. Reuses the file's existing _fake_settings_service / _reset_component_cache_singleton helpers.
8921cd5
into
cold-start/01-measurement-foundation
Summary
Fixes correctness bugs in the component index (concurrency, version stamping, atomic writes, stale detection) and adds a cache-hit short-circuit that brings the index-populated cold-start path from ~3.4s to <500ms by skipping the full package walk when the installed lfx version matches.
Scope
src/lfx/src/lfx/interface/components.py— all index correctness + caching changes:asyncio.Lockproperty onComponentCache(safe under module-import-time constraints)asyncio.Semaphore(16)cap on_load_components_dynamically_read_component_indexwithasyncio.to_threadfor file I/Oversion("lfx")stamp on the persisted index; atomic same-directory tmp +os.replacewritessrc/lfx/tests/unit/test_component_index.py— parity tests (byte-identical flow output + vertex execution order) for every change, plus cache-hit perf assertion (<500ms)Stacked on
PR #12783 (cold-start measurement harness)
Test plan
cd src/lfx && uv run pytest tests/unit/test_component_index.py -v(scope to this file; do not runtests/unit/as a glob)