From a57d05fe0a83551e928c5832183323cd29456687 Mon Sep 17 00:00:00 2001 From: Nan Gao Date: Wed, 10 Jun 2026 02:33:29 +0200 Subject: [PATCH] fix runtime journal run lifecycle events (#3470) --- .../packages/harness/deerflow/runtime/journal.py | 13 ++++++++++++- backend/tests/test_run_journal.py | 7 ++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/packages/harness/deerflow/runtime/journal.py b/backend/packages/harness/deerflow/runtime/journal.py index b65e1c0bb..74e03f165 100644 --- a/backend/packages/harness/deerflow/runtime/journal.py +++ b/backend/packages/harness/deerflow/runtime/journal.py @@ -164,7 +164,18 @@ class RunJournal(BaseCallbackHandler): metadata={"caller": caller, **(metadata or {})}, ) - def on_chain_end(self, outputs: Any, *, run_id: UUID, **kwargs: Any) -> None: + def on_chain_end( + self, + outputs: Any, + *, + run_id: UUID, + parent_run_id: UUID | None = None, + **kwargs: Any, + ) -> None: + # Nested chain ends fire for internal graph nodes; only the root chain + # represents the user-visible run lifecycle. + if parent_run_id is not None: + return self._put(event_type="run.end", category="outputs", content=outputs, metadata={"status": "success"}) self._flush_sync() diff --git a/backend/tests/test_run_journal.py b/backend/tests/test_run_journal.py index 0b495954b..a68895d27 100644 --- a/backend/tests/test_run_journal.py +++ b/backend/tests/test_run_journal.py @@ -179,15 +179,16 @@ class TestLifecycleCallbacks: assert "run.end" in types @pytest.mark.anyio - async def test_nested_chain_no_run_start(self, journal_setup): - """Nested chains (parent_run_id set) should NOT produce run.start.""" + async def test_nested_chain_no_run_lifecycle_events(self, journal_setup): + """Nested chains (parent_run_id set) should NOT produce root run lifecycle events.""" j, store = journal_setup parent_id = uuid4() j.on_chain_start({}, {}, run_id=uuid4(), parent_run_id=parent_id) - j.on_chain_end({}, run_id=uuid4()) + j.on_chain_end({}, run_id=uuid4(), parent_run_id=parent_id) await j.flush() events = await store.list_events("t1", "r1") assert not any(e["event_type"] == "run.start" for e in events) + assert not any(e["event_type"] == "run.end" for e in events) class TestToolCallbacks: