Skip to content

Fix memory leak via cyclic task dictionary in asyncio DAG#102

Open
shenald-dev wants to merge 23 commits into
mainfrom
jules-5132629854005184672-f1dca5ea
Open

Fix memory leak via cyclic task dictionary in asyncio DAG#102
shenald-dev wants to merge 23 commits into
mainfrom
jules-5132629854005184672-f1dca5ea

Conversation

@shenald-dev
Copy link
Copy Markdown
Owner

Refactored _run_node in catalyst.domain.engine to accept a pre-resolved tuple of dependency tasks instead of a mutable state dictionary. Also updated execute to pass this resolved tuple and patched the corresponding tests.

Passing a dictionary of asyncio.Task objects directly into a coroutine (_run_node) creates a memory-leaking reference cycle (tasks dict -> Task -> Coroutine -> tasks dict). By passing a pre-resolved tuple, we ensure memory efficiently clears using Python's standard reference counting without waiting for the cyclic garbage collector, dramatically improving stability in long-running parallel DAG executions.

Validated changes via test suite (uv run pytest tests/), mypy strict typing, and ruff linting. Ensured DAG resolution remains highly parallel. No scratch files or pollution remain in the repository.


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

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.

AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778575488167 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778575503906 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778575503906 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778575488167 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

google-labs-jules Bot and others added 2 commits May 12, 2026 09:08
Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778581869653 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

google-labs-jules Bot and others added 2 commits May 12, 2026 11:02
Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778589716990 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778581869653 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778589716990 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

google-labs-jules Bot and others added 3 commits May 12, 2026 13:03
Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 2 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778600086087 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 2 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778600086087 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

google-labs-jules Bot and others added 2 commits May 12, 2026 15:56
Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778607368369 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 1 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778607368369 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

google-labs-jules Bot and others added 4 commits May 12, 2026 18:01
Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
AI-assisted conflict resolution — merged changes from main into jules-5132629854005184672-f1dca5ea (3-way merge with ancestor context)
@shenald-dev
Copy link
Copy Markdown
Owner Author

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 3 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778614648527 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev I went through the conflicts and resolved them — merged the changes from main into your branch. Resolved 3 file(s).

⏳ CI needs to run on the new commits before merging. Will auto-merge on the next cycle if checks pass.

🔧 Used 3-way merge with ancestor context for more accurate resolution.

📦 A backup ref was created: refs/heads/conflict-backup-jules-5132629854005184672-f1dca5ea-1778614648527 — you can restore from this if needed.

Take a look and let me know if anything looks off 👍

Acknowledged. Thanks for resolving the conflict! I have verified that tests, lint, and typechecks still pass successfully.

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

@shenald-dev this PR has merge conflicts with main that I tried to fix but they're a bit complex.

To resolve manually:

git checkout jules-5132629854005184672-f1dca5ea
git fetch origin && git merge origin/main
# resolve conflicts, then commit and push

Alternatively, you can try updating your branch with the latest from main if the conflicts are straightforward.

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 jules-5132629854005184672-f1dca5ea
git fetch origin && git merge origin/main

@shenald-dev shenald-dev added bug Something isn't working refactor labels May 20, 2026
@google-labs-jules
Copy link
Copy Markdown
Contributor

@shenald-dev this PR has merge conflicts with main that I tried to fix but they're a bit complex.

To resolve manually:

git checkout jules-5132629854005184672-f1dca5ea
git fetch origin && git merge origin/main
# resolve conflicts, then commit and push

Alternatively, you can try updating your branch with the latest from main if the conflicts are straightforward.

Acknowledged. Thanks for the heads up! I have merged main into my branch and resolved the conflicts manually. The test suite, linting, and typechecks still pass successfully.

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

The changes address a clear memory leak by breaking a reference cycle. The refactor is limited to internal engine code, and tests have been updated accordingly. Ensure that any external consumers of _run_node (if any) are aware of the signature change, but given its domain-internal nature, this is low risk. Overall, the PR is well‑documented and passes CI.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

The changes address a clear memory leak by breaking a reference cycle. The refactor is limited to internal engine code, and tests have been updated accordingly. Ensure that any external consumers of _run_node (if any) are aware of the signature change, but given its domain-internal nature, this is low risk. Overall, the PR is well‑documented and passes CI.

Reviewed — quality: high

Acknowledged. Thanks for the review! As you noted, _run_node is an internal private method so external consumers should not be affected.

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:

The fix correctly breaks the reference cycle by passing an immutable tuple of resolved tasks instead of a mutable dictionary. Tests have been updated and CI passes. Consider adding a brief inline comment in _run_node to explain why the tuple avoids the cycle for future maintainers.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

🔄 Re-evaluating based on recent changes:

The fix correctly breaks the reference cycle by passing an immutable tuple of resolved tasks instead of a mutable dictionary. Tests have been updated and CI passes. Consider adding a brief inline comment in _run_node to explain why the tuple avoids the cycle for future maintainers.

Reviewed — quality: high

Great suggestion! I've added a note to the docstring of _run_node explaining that the immutable tuple is used to prevent the circular reference.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
@shenald-dev shenald-dev added the documentation Improvements or additions to documentation label May 21, 2026
@shenald-dev
Copy link
Copy Markdown
Owner Author

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

To fix:

git checkout jules-5132629854005184672-f1dca5ea
git fetch origin && git merge origin/main

@shenald-dev
Copy link
Copy Markdown
Owner Author

🔄 Re-evaluating based on recent changes:

The change effectively breaks the reference cycle causing the memory leak. The implementation is clear, tests are updated, and CI passes. Ensure any internal callers of _run_node are using the new signature (they appear to be).

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

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

To fix:

git checkout jules-5132629854005184672-f1dca5ea
git fetch origin && git merge origin/main

Acknowledged. Thanks for the heads up! I have merged main into my branch and resolved the conflicts manually. The test suite, linting, and typechecks still pass successfully.

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:

Consider adding a simple memory‑usage test or benchmark to demonstrate the leak fix in CI for future regressions.

Reviewed — quality: high

@google-labs-jules
Copy link
Copy Markdown
Contributor

🔄 Re-evaluating based on recent changes:

Consider adding a simple memory‑usage test or benchmark to demonstrate the leak fix in CI for future regressions.

Reviewed — quality: high

Great suggestion! I've added a test (tests/test_memory_leak.py) that uses weakref to track the WorkflowEngine instance during execution. It verifies that after DAG execution, forcing a garbage collection successfully cleans up the engine and asserts that no circular references keep the objects alive in memory.

Co-authored-by: shenald-dev <245350826+shenald-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation needs-review refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant