Skip to content

refactor: update registry initialization in CompiledGraph to use Maps for improved immutability#17

Merged
cantemizyurek merged 1 commit intomainfrom
cantemizyurek/fix-graph-mutable
Feb 3, 2026
Merged

refactor: update registry initialization in CompiledGraph to use Maps for improved immutability#17
cantemizyurek merged 1 commit intomainfrom
cantemizyurek/fix-graph-mutable

Conversation

@cantemizyurek
Copy link
Owner

@cantemizyurek cantemizyurek commented Feb 3, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Compiled graphs now remain unchanged when the original graph is modified after compilation, ensuring consistent and reliable execution.
  • Tests

    • Added tests to verify compiled graph integrity following modifications to the source graph.

… for improved immutability and add test for graph immutability after compilation
@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

⚠️ No Changeset found

Latest commit: 65c1c06

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

The PR modifies CompiledGraph's constructor to clone registries (nodeRegistry, edgeRegistry, subgraphRegistry) into new Map instances instead of assigning them directly, preventing shared mutable references. Corresponding immutability tests are added to verify that mutations to the original graph after compilation do not affect the compiled graph.

Changes

Cohort / File(s) Summary
Registry Cloning
src/compiled-graph.ts
Constructor now clones node, edge, and subgraph registries into independent Map instances. Edge registry cloning includes shallow copying of edge arrays to ensure immutable-like behavior.
Immutability Tests
tests/graph.test.ts
New test suite "Graph - Immutability after compile()" verifies that mutating the original graph after compile() does not affect the already compiled graph's execution order.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Cloning registries with care,
Maps and arrays everywhere,
No more shared mutations here,
Compiled graphs now crystal clear!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating registry initialization in CompiledGraph to use Map cloning for improved immutability, which aligns with both the code changes and test additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cantemizyurek/fix-graph-mutable

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cantemizyurek cantemizyurek merged commit 47ef017 into main Feb 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant