Commit 940a798
committed
Address CoPilot review feedback on Langfuse observer
Five real catches from the PR #81 review, all behavioral or
correctness fixes — no spec-touching changes.
1. Detached-subgraph link observation in main Trace was opened but
never ended. Capture the handle returned by client.span(...) and
call .end() immediately — the link observation is intentionally
zero-duration metadata-only, mirroring the OTel observer's
checkpoint-event synthetic-span pattern.
2. Synthetic subgraph dispatch / fan-out per-instance dispatch
observations only close on namespace-cursor moves. A subgraph at
the tail of an invocation never gets its close trigger fired.
Added close_invocation(invocation_id) and shutdown() drain
methods mirroring the OTel observer's lifecycle. close_invocation
walks per-invocation state in child→parent order (LLM
observations → leaf nodes sorted deepest-first → per-instance
fan-out dispatches → subgraph dispatches), ending each.
shutdown() iterates every in-flight invocation_id and calls
close_invocation. Idempotent.
3. detached_child_trace_ids side-cache was never cleared on
fan-out node completion. Cyclic graphs re-entering the same
fan-out would accumulate prior-iteration trace ids into the next
iteration's list, overwriting the link metadata. Pop the entry
in _handle_completed's fan-out-completion branch alongside the
existing fan_out_parent_node_name pop.
4. _resolve_llm_parent_observation_id docstring claimed a
leaf-ancestor walk fallback that the impl doesn't have. The
actual precedence (exact-leaf > per-instance fan-out dispatch >
subgraph dispatch longest-prefix-first > None) is correct
because the dispatch fallbacks cover the wrapped-call cases an
ancestor walk would have caught. Docstring updated to describe
the real chain.
5. cast("list[str]", link_ids) used the string-form unnecessarily.
With from __future__ import annotations on, the type expression
form cast(list[str], link_ids) is the right shape and survives
strict pyright settings.
New unit test verifies the close_invocation drain path: a graph
whose last subtree is a subgraph leaves the dispatch observation
in-flight after invoke + drain; shutdown() ends it cleanly.1 parent 835b8e1 commit 940a798
2 files changed
Lines changed: 103 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
309 | 315 | | |
310 | 316 | | |
311 | 317 | | |
| |||
566 | 572 | | |
567 | 573 | | |
568 | 574 | | |
569 | | - | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
570 | 581 | | |
571 | 582 | | |
572 | 583 | | |
573 | 584 | | |
574 | 585 | | |
| 586 | + | |
575 | 587 | | |
576 | 588 | | |
577 | 589 | | |
| |||
685 | 697 | | |
686 | 698 | | |
687 | 699 | | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
688 | 753 | | |
689 | 754 | | |
690 | 755 | | |
| |||
783 | 848 | | |
784 | 849 | | |
785 | 850 | | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
791 | 861 | | |
792 | 862 | | |
793 | 863 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
317 | | - | |
| 317 | + | |
318 | 318 | | |
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
0 commit comments