Skip to content

Refactor _run_node to break reference cycle#96

Open
shenald-dev wants to merge 4 commits into
mainfrom
fix-run-node-memory-leak-1503152313454917982
Open

Refactor _run_node to break reference cycle#96
shenald-dev wants to merge 4 commits into
mainfrom
fix-run-node-memory-leak-1503152313454917982

Conversation

@shenald-dev
Copy link
Copy Markdown
Owner

This change resolves a memory leak / reference cycle in WorkflowEngine._run_node by passing a tuple of specific dependency tasks instead of the entire tasks dictionary. This breaks the cycle (tasks dict -> Task object -> Coroutine -> tasks dict). The dependencies are eagerly resolved synchronously inside execute before creating the task.


PR created automatically by Jules for task 1503152313454917982 started by @shenald-dev

…fic dependencies

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@shenald-dev
Copy link
Copy Markdown
Owner Author

Hey @shenald-dev, heads up — this PR has merge conflicts with main.

To fix:

git checkout fix-run-node-memory-leak-1503152313454917982
git fetch origin && git merge origin/main

@shenald-dev shenald-dev added bug Something isn't working refactor labels May 12, 2026
@shenald-dev
Copy link
Copy Markdown
Owner Author

The PR addresses a real memory leak by breaking a reference cycle, which is good. However, there are merge conflicts with main that need to be resolved. Please rebase or merge origin/main into your branch and fix any conflicts. Additionally, consider adding a unit test or a stress test to confirm that the reference cycle is eliminated and that workflow execution still behaves correctly. Once conflicts are resolved and tests are in place, this PR should be ready to merge.

Reviewed — quality: medium

@shenald-dev
Copy link
Copy Markdown
Owner Author

🔄 Re-evaluating based on recent changes:

Please resolve merge conflicts with main and consider adding a unit test to verify the memory leak fix.

Reviewed — quality: medium

@google-labs-jules
Copy link
Copy Markdown
Contributor

🔄 Re-evaluating based on recent changes:

Please resolve merge conflicts with main and consider adding a unit test to verify the memory leak fix.

Reviewed — quality: medium

I have resolved the merge conflicts with main and added the requested unit test (test_memory_leak_fix in tests/test_engine.py) to verify that the memory leak fix works correctly.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@shenald-dev
Copy link
Copy Markdown
Owner Author

🔄 Re-evaluating based on recent changes:

Good job identifying and fixing the reference cycle. The added unit test helps ensure the leak is resolved. Consider adding a brief comment in _run_node explaining why a tuple of dependencies is passed instead of the whole tasks dictionary for future maintainers.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

🔄 Re-evaluating based on recent changes:

Good job identifying and fixing the reference cycle. The added unit test helps ensure the leak is resolved. Consider adding a brief comment in _run_node explaining why a tuple of dependencies is passed instead of the whole tasks dictionary for future maintainers.

Reviewed — quality: high

Added a comment in _run_node explaining that passing a tuple instead of the dictionary prevents reference cycles and memory leaks.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@shenald-dev
Copy link
Copy Markdown
Owner Author

Hey @shenald-dev, heads up — this PR has merge conflicts with main.

To fix:

git checkout fix-run-node-memory-leak-1503152313454917982
git fetch origin && git merge origin/main

@google-labs-jules
Copy link
Copy Markdown
Contributor

Hey @shenald-dev, heads up — this PR has merge conflicts with main.

To fix:

git checkout fix-run-node-memory-leak-1503152313454917982
git fetch origin && git merge origin/main

I have previously resolved the merge conflicts with main. The PR should be up to date and conflict-free now.

@shenald-dev
Copy link
Copy Markdown
Owner Author

The PR effectively resolves the reference cycle memory leak by passing only needed dependencies and adds a unit test to verify the fix. All CI checks pass and merge conflicts have been resolved. The changes are well-contained and documented.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

The PR effectively resolves the reference cycle memory leak by passing only needed dependencies and adds a unit test to verify the fix. All CI checks pass and merge conflicts have been resolved. The changes are well-contained and documented.

Reviewed — quality: high

Thank you for the review. Acknowledged.

@shenald-dev
Copy link
Copy Markdown
Owner Author

Hey @shenald-dev, heads up — this PR has merge conflicts with main.

To fix:

git checkout fix-run-node-memory-leak-1503152313454917982
git fetch origin && git merge origin/main

@google-labs-jules
Copy link
Copy Markdown
Contributor

Hey @shenald-dev, heads up — this PR has merge conflicts with main.

To fix:

git checkout fix-run-node-memory-leak-1503152313454917982
git fetch origin && git merge origin/main

I have successfully fetched and merged origin/main to resolve the latest merge conflicts. The tests pass and the PR is up to date.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@shenald-dev
Copy link
Copy Markdown
Owner Author

The PR effectively resolves the memory leak by breaking the reference cycle. Tests have been added and CI passes. Consider adding a simple stress test or benchmark in the future to ensure the fix holds under load, but overall the change is solid and ready to merge.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

The PR effectively resolves the memory leak by breaking the reference cycle. Tests have been added and CI passes. Consider adding a simple stress test or benchmark in the future to ensure the fix holds under load, but overall the change is solid and ready to merge.

Reviewed — quality: high

Thank you for the review! I've noted the suggestion about adding a stress test for future benchmarking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs-review refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant