fix(tracing): detach orphan spans before database flush - #14243
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
WalkthroughMissing parent references are detached before topological sorting, and database flush tests verify spans are persisted with ChangesSpan parent detachment
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 9✅ Passed checks (9 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
✅ Test Coverage AdvisorNo source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉
|
fix(tracing): detach spans from missing parents
fix(tracing): detach spans from missing parents
Summary
Prevent native trace persistence from aborting workflow execution when a completed span references a parent that is not present in the trace's single flush batch.
The existing topological sort already keeps valid parents before children. This change additionally detaches spans from parents that cannot be inserted, preserving the span as a root instead of sending an invalid
span.parent_span_idforeign key to the database.Root cause
topological_sort_spans()treated a parent outside the current batch as though it had already been persisted. Native tracing writes a trace and all of its spans in one batch, so that assumption is invalid for a new trace: an out-of-batch parent row is missing, and PostgreSQL rejects the child row.Disabling session autoflush does not resolve that case because the referenced row does not exist. It would also change flush semantics for every Langflow database session, well beyond tracing.
Validation
uv run pytest -q src/backend/tests/unit/services/tracing/test_native_tracer.py— 81 passeduv run ruff check src/backend/base/langflow/services/tracing/span_sorting.py src/backend/tests/unit/services/tracing/test_native_tracer.pyThe regression tests cover both layers:
parent_span_id=Nonefor that span;Credit
Thanks to @ashutoshdharibm for reporting the production impact and investigating the trace flush path in #14229. That PR prompted this focused re-audit of the foreign-key failure.
Relates to DSLF-524.
Summary by CodeRabbit
Bug Fixes
Tests