Skip to content

fix(workflow): implement save_execution_data on the Celery node-execution repository - #44018

Closed
Winoren wants to merge 2 commits into
langgenius:mainfrom
Winoren:fix/celery-node-repo-save-execution-data
Closed

Winoren wants to merge 2 commits into
langgenius:mainfrom
Winoren:fix/celery-node-repo-save-execution-data

Conversation

@Winoren

@Winoren Winoren commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CeleryWorkflowNodeExecutionRepository is missing save_execution_data, one of the four methods declared by the WorkflowNodeExecutionRepository protocol, so with the Celery node-execution repository configured every node's execution data is silently dropped instead of persisted.

The protocol (api/core/repositories/factory.py:35-46) declares four methods:

class WorkflowNodeExecutionRepository(Protocol):
    def save(self, execution: WorkflowNodeExecution): ...

    def save_synchronously(self, execution: WorkflowNodeExecution) -> None: ...

    def save_execution_data(self, execution: WorkflowNodeExecution): ...

    def get_by_workflow_execution(
        self,
        workflow_execution_id: str,
        order_config: OrderConfig | None = None,
    ) -> Sequence[WorkflowNodeExecution]: ...

SQLAlchemyWorkflowNodeExecutionRepository (:420) and
LogStoreWorkflowNodeExecutionRepository (:287) both implement all four.
CeleryWorkflowNodeExecutionRepository implements only three — save,
save_synchronously, get_by_workflow_execution.

Why it fails silently instead of loudly

The Celery class explicitly subclasses the protocol
(class CeleryWorkflowNodeExecutionRepository(WorkflowNodeExecutionRepository)),
so the missing method is not an AttributeError — it is inherited from the
protocol as its ... stub and becomes a no-op:

>>> "save_execution_data" in CeleryWorkflowNodeExecutionRepository.__dict__
False
>>> [b.__name__ for b in CeleryWorkflowNodeExecutionRepository.__mro__
...  if "save_execution_data" in getattr(b, "__dict__", {})]
['WorkflowNodeExecutionRepository']        # body is `...`

Where it is called

core/app/workflow/layers/persistence.py calls it right after save() on the
main node-completion paths:

  • _handle_node_retry() (line 271-272)
  • _update_node_execution() (line 463-464)

With CORE_WORKFLOW_NODE_EXECUTION_REPOSITORY set to
core.repositories.celery_workflow_node_execution_repository.CeleryWorkflowNodeExecutionRepository
(the setting is configurable — see
docker/envs/core-services/shared.env.example:405), those calls do nothing:
truncated node inputs/outputs and their offload records are never written.

Changes

  • api/core/repositories/celery_workflow_node_execution_repository.py: add
    save_execution_data, implemented exactly like the neighbouring
    save_synchronously() — delegate to the composed
    SQLAlchemyWorkflowNodeExecutionRepository, then refresh the in-memory cache
    and the workflow-execution mapping. The cache refresh matters because the
    SQLAlchemy repository mutates the domain model in place
    (set_truncated_inputs / set_truncated_outputs / ...), so cached reads must
    keep exposing the same, now-truncated instance.
  • api/tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:
    new test_save_execution_data_delegates_and_refreshes_cache.

No refactor, no schema change, no change to the default (SQLAlchemy) backend.

Verification

Run from api/:

uv run --project api pytest tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py -q -o addopts="" --basetemp=/tmp/x_pt
  • Before: 15 passed. After: 16 passed.
  • Test validity self-check: restoring the pristine
    celery_workflow_node_execution_repository.py while keeping the new test
    gives 1 failed, 15 passed — the new test fails with
    AssertionError: Expected 'save_execution_data' to be called once. Called 0 times.,
    i.e. the inherited protocol stub really is a no-op. Restoring the fix returns
    16 passed.
  • Direct evidence of the silent no-op (pristine code, in the project env):
    "save_execution_data" in CeleryWorkflowNodeExecutionRepository.__dict__
    is False, and the only class in the MRO providing it is
    WorkflowNodeExecutionRepository with body ....
  • ruff check (repo pin ruff>=0.16.9, run via uvx ruff@0.16.9) on both
    touched files: All checks passed!; ruff format --diff:
    2 files already formatted.
  • Baseline proof: the pristine local copies have blob sha
    c393f6afd512afe7e232063aa449dab00fe71b7f and
    e064879b946682ffb1ded5a5ebefb1540a17cd2f, which are exactly the shas
    reported by GET /repos/langgenius/dify/contents/<path>?ref=main; the branch
    is based on upstream main at cc4aaebc9797827afdc46103a69411301c2c6160.

Screenshots

Not applicable — backend-only change, no UI impact.

Checklist

  • This change requires a documentation update, included: Dify Document — no doc update needed; the method is already part of the repository protocol.
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) — no issue precedes this; happy to open one and link it first if the maintainers prefer.
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly. — no doc change needed.
  • I ran make lint && make type-check (backend) and vp staged (frontend) — for the touched files I ran the backend lint equivalent (ruff check / ruff format --diff at the repo's pinned ruff version); full-repo make lint was not run locally.

From WorkBuddy

Coverage follow-up

The save_execution_data regression now covers a previously uncached execution, an already-registered execution (without duplicate IDs), and a standalone execution without a workflow run ID. The repository unit file passes all 18 tests locally; coverage records all executable lines and both outcomes of each conditional in the new method. Targeted Ruff lint and format checks pass. Remote Codecov still needs to validate the new revision.

From Codex

Superseded by upstream

The Graphon 0.8 orchestration migration in #40277 added the missing save_execution_data implementation in commit 823f40e. The current Celery repository deliberately queues the complete payload through save/save_many, so retaining this older synchronous offload implementation would conflict with that lifecycle. Verified the unchanged current upstream repository test module: 39 passed. Closing this proposal as superseded; no replacement PR is needed.

From Codex

…tion repository

`WorkflowNodeExecutionRepository` declares four methods (core/repositories/factory.py):

    def save(self, execution: WorkflowNodeExecution): ...
    def save_synchronously(self, execution: WorkflowNodeExecution) -> None: ...
    def save_execution_data(self, execution: WorkflowNodeExecution): ...
    def get_by_workflow_execution(...) -> Sequence[WorkflowNodeExecution]: ...

`SQLAlchemyWorkflowNodeExecutionRepository` and
`LogStoreWorkflowNodeExecutionRepository` both implement all four.
`CeleryWorkflowNodeExecutionRepository` implements only three — it has no
`save_execution_data`.

Because it subclasses the Protocol, the missing method does not raise
AttributeError; it silently inherits the Protocol's `...` stub:

    >>> "save_execution_data" in CeleryWorkflowNodeExecutionRepository.__dict__
    False
    >>> [b.__name__ for b in C.__mro__ if "save_execution_data" in b.__dict__]
    ['WorkflowNodeExecutionRepository']   # body is `...`

The workflow persistence layer calls it on every node completion —
`core/app/workflow/layers/persistence.py` `_update_node_execution()` and
`_handle_node_retry()` both do `save()` followed by
`save_execution_data()`. So with
`CORE_WORKFLOW_NODE_EXECUTION_REPOSITORY` pointed at the Celery repository,
every node's execution data (truncated inputs/outputs and their offload
records) is silently dropped instead of persisted.

Implement it the same way the neighbouring `save_synchronously()` already
does: delegate to the composed `SQLAlchemyWorkflowNodeExecutionRepository`
and refresh the in-memory cache, since the SQLAlchemy repository mutates the
domain model in place (`set_truncated_inputs` / `set_truncated_outputs`).
@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Oct 13, 2026
@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-17 19:00:47.976020265 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-17 19:00:39.051940687 +0000
@@ -3636,36 +3636,6 @@
    --> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval_methods.py:145:33
 ERROR Argument `None` is not assignable to parameter `text` with type `str` in function `core.rag.splitter.text_splitter.RecursiveCharacterTextSplitter.split_text` [bad-argument-type]
     --> tests/unit_tests/core/rag/splitter/test_text_splitter.py:1873:42
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-  --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:73:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-  --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:89:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:102:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:119:50
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:131:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:147:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:181:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:202:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:218:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:241:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:257:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:279:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:311:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:333:53
-ERROR Cannot instantiate `CeleryWorkflowNodeExecutionRepository` because the following members are abstract: `save_execution_data` [bad-instantiation]
-   --> tests/unit_tests/core/repositories/test_celery_workflow_node_execution_repository.py:385:53
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
   --> tests/unit_tests/core/repositories/test_human_input_repository.py:56:56
 ERROR Argument `Literal['invalid']` is not assignable to parameter `session_factory` with type `Engine | sessionmaker[Unknown]` in function `core.repositories.sqlalchemy_workflow_execution_repository.SQLAlchemyWorkflowExecutionRepository.__init__` [bad-argument-type]

@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 75.37% 75.37% -0.01%
Strict coverage 75.04% 75.04% -0.01%
Typed symbols 62,419 62,420 +1
Untyped symbols 20,485 20,492 +7
Modules 3802 3802 0

@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.99%. Comparing base (cc4aaeb) to head (e6d3a2d).
⚠️ Report is 125 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #44018      +/-   ##
==========================================
+ Coverage   79.84%   88.99%   +9.14%     
==========================================
  Files        5247     5353     +106     
  Lines      311056   333189   +22133     
  Branches    64724    66051    +1327     
==========================================
+ Hits       248363   296505   +48142     
+ Misses      58555    31491   -27064     
- Partials     4138     5193    +1055     
Flag Coverage Δ
api 88.59% <100.00%> (+16.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Winoren Winoren closed this Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: medium ghfind author score; see https://ghfind.com size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant