Skip to content

feat: create deterministic name to the operator nodes - #640

Merged
yissellokta merged 2 commits into
mainfrom
feat/deterministic-operator-unique-identifier
Jul 9, 2026
Merged

feat: create deterministic name to the operator nodes#640
yissellokta merged 2 commits into
mainfrom
feat/deterministic-operator-unique-identifier

Conversation

@yissellokta

@yissellokta yissellokta commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description

What problem is being solved?

How is it being solved?

What changes are made to solve it?

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

Summary by CodeRabbit

  • Bug Fixes

    • Operator nodes now keep stable, deterministic labels when graphs are regenerated, making results easier to compare and debug.
    • Error messages for invalid intersection cases now point to the specific failing node.
  • Tests

    • Expanded coverage to verify consistent operator labels and graph structure across regenerations.
    • Added checks for multi-relation and mixed-operator scenarios.

@yissellokta
yissellokta requested a review from a team as a code owner July 9, 2026 15:03
Copilot AI review requested due to automatic review settings July 9, 2026 15:03
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The weighted graph builder now generates deterministic operator node labels using a per-relation index (type#relation:operator:index) instead of random ULIDs, removing the ULID dependency. Tests were updated to match new error messages and add coverage for deterministic labeling across regenerations and relations.

Changes

Deterministic Operator Node Labels

Layer / File(s) Summary
Deterministic label generation
pkg/go/graph/weighted_graph_builder.go
Removes ULID import; Build initializes a per-relation operatorIndex counter passed into parseRewrite, which now builds labels as type#relation:operator:index and threads the shared index pointer through recursive calls.
Test updates and coverage
pkg/go/graph/weighted_graph_builder_test.go
Updates require.ErrorContains assertions to reference specific intersection node identifiers; adds operatorNodeLabels helper and two new tests verifying deterministic operator labels within a relation and across multiple relations/types.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change by describing deterministic naming for operator nodes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/deterministic-operator-unique-identifier

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pkg/go/graph/weighted_graph_builder.go (1)

106-108: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Stale comment: the edge is always added and operatorNode is never nil.

GetOrAddNode always returns a non-nil node and AddEdge runs unconditionally, so the note about a nil operationNode / an edge that "won't be added" no longer reflects the code and is misleading.

♻️ Suggested comment cleanup
-	// add one edge "relation" -> "operation that defined the operator"
-	// Note: if this is a composition of operators, operationNode will be nil and this edge won't be added.
+	// add one edge "relation" -> "operator node"
 	wg.AddEdge(parentNode.GetUniqueLabel(), operatorNodeName, RewriteEdge, parentNodeName, "", nil)

The deterministic labeling logic itself looks correct.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/go/graph/weighted_graph_builder.go` around lines 106 - 108, The comment
near wg.AddEdge in weighted_graph_builder.go is stale because operatorNode is
always present and the edge is added unconditionally. Update or remove the note
in the relevant AddEdge/GetOrAddNode block so it accurately describes the
current behavior, and make sure any mention of a nil operationNode or a skipped
edge is removed from the surrounding comments.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pkg/go/graph/weighted_graph_builder.go`:
- Around line 106-108: The comment near wg.AddEdge in weighted_graph_builder.go
is stale because operatorNode is always present and the edge is added
unconditionally. Update or remove the note in the relevant AddEdge/GetOrAddNode
block so it accurately describes the current behavior, and make sure any mention
of a nil operationNode or a skipped edge is removed from the surrounding
comments.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 23e69bce-165e-46df-8c60-d30d9e0c8409

📥 Commits

Reviewing files that changed from the base of the PR and between 3295e79 and 5241b83.

📒 Files selected for processing (2)
  • pkg/go/graph/weighted_graph_builder.go
  • pkg/go/graph/weighted_graph_builder_test.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Go weighted-graph builder to generate deterministic operator-node unique labels (instead of ULID-based labels), improving reproducibility of graph output and allowing error messages/tests to reference stable node identifiers.

Changes:

  • Replace ULID-based operator node labels with deterministic labels of the form type#relation:operator:index using a per-relation DFS counter.
  • Thread a per-relation operatorIndex through rewrite parsing so nested operators get stable, unique IDs.
  • Update/add Go graph-builder tests to assert deterministic operator labels and to check error messages that include the stable operator-node label.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/go/graph/weighted_graph_builder.go Switch operator-node naming from ULID to deterministic type#relation:operator:index via a per-relation DFS counter.
pkg/go/graph/weighted_graph_builder_test.go Update existing assertions and add new tests to validate deterministic operator-node labels and topology.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/go/graph/weighted_graph_builder.go Outdated
@yissellokta yissellokta changed the title create deterministic name to teh operator nodes feat:create deterministic name to teh operator nodes Jul 9, 2026
@yissellokta
yissellokta requested a review from senojj July 9, 2026 15:41
@yissellokta yissellokta changed the title feat:create deterministic name to teh operator nodes feat: create deterministic name to the operator nodes Jul 9, 2026
@yissellokta
yissellokta added this pull request to the merge queue Jul 9, 2026
Merged via the queue into main with commit b8b1a5a Jul 9, 2026
16 of 19 checks passed
@yissellokta
yissellokta deleted the feat/deterministic-operator-unique-identifier branch July 9, 2026 16:13
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.

3 participants