lythonic.compose.dag_provenance¶
SQLite-backed storage for DAG run state and node execution traces.
DagProvenance: SQLite-backed storage for DAG run state and node execution traces.
Records the full lifecycle of each DAG run: creation, node-by-node execution (inputs, outputs, timing, errors), and final status. Supports querying for restart and replay scenarios.
Pydantic Inspection Models¶
DagRun, NodeExecution, and EdgeTraversal are Pydantic models returned
by query methods like get_run() and get_recent_runs(). All timestamps
are timezone-aware UTC datetimes. DagRun.nodes is a dict keyed by
node_label. Each NodeExecution has an edges list and a sub_dags
dict (non-None for composite nodes only, keyed by expansion key like
"chunks[0]" or "label[]"). Convenience methods:
DagRun.latest_update()— most recent timestamp across all nodes/edgesDagRun.nodes_changed_since(dt)— nodes updated after a given datetime
Parent Run Tracking¶
Sub-DAG runs link to their parent via parent_run_id. Use
get_child_runs(parent_run_id) to recursively retrieve all descendant runs
(children, grandchildren, etc.) using a recursive CTE.
Batch Operations¶
complete_node_with_edges() and fail_node_and_finish_run() batch multiple
writes (node status + edge traversals, or node failure + run finish) into a
single open_sqlite_db cycle to reduce lock contention.
Who Started a Run¶
Each run records initiated_by: whatever run_initiator holds when
DagRunner.run starts it, e.g. a user id set by the server handling the
request. Set it with the initiated_by context manager:
- Child runs inherit it: sub-DAG runs start in the same asyncio context, and
sync nodes run on executor threads with a copy of it. A thread a node starts
itself does not see it, so runs started there record
Noneunless the node wraps them ininitiated_by. TriggerManagerfires scheduled runs insideinitiated_by(SCHEDULER).DagRunner.replaycreates a new run, attributed to the caller.DagRunner.restartcontinues the same run, which keeps its originalinitiated_by.initiated_by(None)clears an outer initiator, e.g. for a server request with no known caller.- Values are opaque strings. Lythonic only reserves
SCHEDULER; the host defines the rest (user ids,cli:<user>, ...).
create_run falls back to run_initiator when no initiator is passed, which
is only correct on the thread that set it; DagRunner.run reads it before
moving to the executor thread.
Serialization Helpers¶
json_default() and safe_json_dumps() handle Pydantic models and other
non-JSON-serializable types when recording provenance data.
Private _-prefixed methods take a cursor and don't commit — they're building
blocks for batch operations. Public methods open the DB, batch writes, and
commit in one cycle.
DagProvenance
¶
SQLite-backed storage for DAG run state and node execution traces.
Public methods batch related writes into a single open_sqlite_db cycle.
Source code in src/lythonic/compose/dag_provenance.py
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 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 | |
create_run(run_id, dag_nsref, source_inputs, parent_run_id=None, initiator=None)
¶
Create a new run record with status 'running'. initiator defaults to
run_initiator; pass it explicitly when calling from another thread,
which does not see the caller's context.
Source code in src/lythonic/compose/dag_provenance.py
update_run_status(run_id, status)
¶
Update the status of a run without setting finished_at.
Source code in src/lythonic/compose/dag_provenance.py
finish_run(run_id, status, sink_outputs_json=None)
¶
Set final status and finished_at timestamp.
Source code in src/lythonic/compose/dag_provenance.py
record_node_start(run_id, node_label, input_json, is_source=False, is_sink=False)
¶
Record that a node has started execution.
Source code in src/lythonic/compose/dag_provenance.py
record_node_skipped(run_id, node_label, output_json)
¶
Record a node as skipped with a copied output (used in replay).
Source code in src/lythonic/compose/dag_provenance.py
complete_node_with_edges(run_id, node_label, output_json, edges)
¶
Record node completion and all outgoing edge traversals in one batch.
Source code in src/lythonic/compose/dag_provenance.py
fail_node_and_finish_run(run_id, node_label, error)
¶
Record node failure and mark the run as failed in one batch.
Source code in src/lythonic/compose/dag_provenance.py
get_run(run_id)
¶
Get a run record by ID, or None if not found.
Source code in src/lythonic/compose/dag_provenance.py
get_node_executions(run_id)
¶
Get all node execution records for a run.
Source code in src/lythonic/compose/dag_provenance.py
get_node_output(run_id, node_label)
¶
Get the output JSON of a completed or skipped node, or None.
Source code in src/lythonic/compose/dag_provenance.py
get_pending_nodes(run_id)
¶
Get labels of nodes that are not yet completed or skipped.
Source code in src/lythonic/compose/dag_provenance.py
get_edge_traversals(run_id)
¶
Get all edge traversals for a run.
Source code in src/lythonic/compose/dag_provenance.py
inspect_run(run_id)
¶
Get a full DagRun model by ID, with nested nodes, edges, and sub-DAGs.
Source code in src/lythonic/compose/dag_provenance.py
load_io(dag_run, node_labels=None)
¶
Populate io on dag_run and its nodes in a single DB round-trip.
dag_run.io gets source_inputs_json / sink_outputs_json.
node.io gets input_json / output_json for each node, filtered
by node_labels if provided (all nodes if None).
Does NOT recurse into sub-DAGs.
Source code in src/lythonic/compose/dag_provenance.py
get_recent_runs(limit=20, status=None)
¶
List runs with full node/edge data, ordered by started_at descending.
Source code in src/lythonic/compose/dag_provenance.py
get_active_runs()
¶
get_child_runs(parent_run_id)
¶
Recursively get all descendant runs (children, grandchildren, etc.).
Source code in src/lythonic/compose/dag_provenance.py
NullProvenance
¶
No-op provenance -- discards writes, returns None/empty on reads.
Used when DagRunner is created without explicit provenance.
Source code in src/lythonic/compose/dag_provenance.py
DagRun
¶
Bases: BaseModel
A DAG execution record with nested node executions and edge traversals.
Source code in src/lythonic/compose/dag_provenance.py
latest_update()
¶
The most recent timestamp across all nodes and traversals.
Source code in src/lythonic/compose/dag_provenance.py
nodes_changed_since(dt)
¶
Nodes whose started_at or finished_at is after dt.
Source code in src/lythonic/compose/dag_provenance.py
NodeExecution
¶
Bases: BaseModel
Execution record for a single node in a DAG run.
Source code in src/lythonic/compose/dag_provenance.py
EdgeTraversal
¶
Bases: BaseModel
Edge traversed during a DAG run. downstream_label identifies the target node.
Source code in src/lythonic/compose/dag_provenance.py
json_default(obj)
¶
JSON serialization fallback for Pydantic models and other types.
safe_json_dumps(obj)
¶
JSON serialize with Pydantic support. Logs a warning on failure.