Skip to content

fix: ensure workflows set a FunctionGroups instance_name#815

Merged
rapids-bot[bot] merged 3 commits intoNVIDIA:developfrom
willkill07:wkk_fix-function-group-workflow-naming
Sep 18, 2025
Merged

fix: ensure workflows set a FunctionGroups instance_name#815
rapids-bot[bot] merged 3 commits intoNVIDIA:developfrom
willkill07:wkk_fix-function-group-workflow-naming

Conversation

@willkill07
Copy link
Member

@willkill07 willkill07 commented Sep 18, 2025

Description

Functions have their corresponding "name" be whatever what specified in the workflow.
Function Groups should do the same.

This PR addresses an overlooked feature parity with Functions by automatically setting the instance_name (e.g. what is presented to the tools / user) based on the workflow component's name.

Example

function-group:
  my-group:
    type: my_fn_group
    include: [foo, bar]

Before:

Would expose as: my_fn_group.foo and my_fn_group.bar

After:

Will expose as: my-group.foo and my-group.bar

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • New Features

    • Function groups can have their instance name updated at runtime; function identifiers and listings reflect the new name.
    • Workflow builds now apply the workflow-provided name to function groups for consistent naming across views.
  • Tests

    • Test expectations and lookups updated to use group instance names (e.g., math_group, includes_group) so tests reflect the runtime naming behavior.

Signed-off-by: Will Killian <wkillian@nvidia.com>
@willkill07 willkill07 requested a review from a team as a code owner September 18, 2025 14:23
@willkill07 willkill07 added bug Something isn't working non-breaking Non-breaking change labels Sep 18, 2025
@coderabbitai
Copy link

coderabbitai bot commented Sep 18, 2025

Walkthrough

Adds a public mutator and read-only property to FunctionGroup to change and read its instance name at runtime; WorkflowBuilder now sets that instance name on the built FunctionGroup before returning the configured result. Tests updated to use the new instance-name-based function identifiers.

Changes

Cohort / File(s) Summary of Changes
FunctionGroup instance name API
src/nat/builder/function.py
Added set_instance_name(self, instance_name: str) and instance_name property. self._instance_name can be updated at runtime; name-dependent function identifier generation (_get_fn_name) and function listing keys reflect the new instance name. Existing LambdaFunction objects unchanged.
WorkflowBuilder post-build assignment
src/nat/builder/workflow_builder.py
After building a FunctionGroup, calls build_result.set_instance_name(name) before wrapping and returning ConfiguredFunctionGroup. No signature or error-flow changes.
Test updates for instance-name usage
tests/nat/builder/test_builder.py
Updated test expectations and function lookups to use group instance-name prefixes (e.g., includes_group.*, excludes_group.*, all_includes_group.*, all_excludes_group.*, math_group.*, empty_group) instead of previous internal config names. No semantic changes to tests beyond identifiers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant WB as WorkflowBuilder
  participant Builder as GroupBuilder
  participant FG as FunctionGroup

  Caller->>WB: _build_function_group(name, config, ...)
  WB->>Builder: build(...)
  Builder-->>WB: FunctionGroup instance (FG)
  WB->>FG: set_instance_name(name)
  note right of FG #e6f7ff: Updates internal _instance_name\naffects future identifier generation
  WB-->>Caller: ConfiguredFunctionGroup(config, instance=FG)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ 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 succinctly and accurately describes the primary change—ensuring workflows set a FunctionGroup's instance_name—uses imperative mood ("ensure"), and is within the ~72-character guideline; it directly matches the PR objectives and the code changes described.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@willkill07 willkill07 self-assigned this Sep 18, 2025
Signed-off-by: Will Killian <wkillian@nvidia.com>
Signed-off-by: Will Killian <wkillian@nvidia.com>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/nat/builder/test_builder.py (1)

1156-1163: Prefer public APIs over private registry access in tests

Reaching into builder._functions couples tests to internals. Use group introspection and get_function instead.

-        assert "math_group.add" in builder._functions
-        assert "math_group.multiply" in builder._functions
-        # Test that non-included functions are not accessible
-        assert "math_group.subtract" not in builder._functions
-        # Test that no functions were included from empty group
-        empty_group_functions = [k for k in builder._functions.keys() if k.startswith("empty_group.")]
+        group = builder.get_function_group("math_group")
+        assert set(group.get_accessible_functions().keys()) == {"math_group.add", "math_group.multiply"}
+        # Non-included function should not be globally accessible
+        with pytest.raises(ValueError):
+            builder.get_function("math_group.subtract")
+        # Verify empty group exposes nothing
+        empty_group = builder.get_function_group("empty_group")
+        assert empty_group.get_accessible_functions() == {}
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c470ec and 92835fb.

📒 Files selected for processing (1)
  • tests/nat/builder/test_builder.py (7 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
tests/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Unit tests must live under tests/ and use configured markers (e2e, integration, etc.)

Files:

  • tests/nat/builder/test_builder.py

⚙️ CodeRabbit configuration file

tests/**/*.py: - Ensure that tests are comprehensive, cover edge cases, and validate the functionality of the code. - Test functions should be named using the test_ prefix, using snake_case. - Any frequently repeated code should be extracted into pytest fixtures. - Pytest fixtures should define the name argument when applying the pytest.fixture decorator. The fixture
function being decorated should be named using the fixture_ prefix, using snake_case. Example:
@pytest.fixture(name="my_fixture")
def fixture_my_fixture():
pass

Files:

  • tests/nat/builder/test_builder.py
**/*.py

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.py: Follow PEP 8/20 style; format with yapf (column_limit=120) and use 4-space indentation; end files with a single newline
Run ruff (ruff check --fix) per pyproject.toml; fix warnings unless explicitly ignored; ruff is linter-only
Use snake_case for functions/variables, PascalCase for classes, and UPPER_CASE for constants
Treat pyright warnings as errors during development
Exception handling: preserve stack traces and avoid duplicate logging
When re-raising exceptions, use bare raise and log with logger.error(), not logger.exception()
When catching and not re-raising, log with logger.exception() to capture stack trace
Validate and sanitize all user input; prefer httpx with SSL verification and follow OWASP Top‑10
Use async/await for I/O-bound work; profile CPU-heavy paths with cProfile/mprof; cache with functools.lru_cache or external cache; leverage NumPy vectorization when beneficial

**/*.py: Programmatic use: create TestLLMConfig(response_seq=[...], delay_ms=...), add with builder.add_llm("", cfg).
When retrieving the test LLM wrapper, use builder.get_llm(name, wrapper_type=LLMFrameworkEnum.) and call the framework’s method (e.g., ainvoke, achat, call).

Files:

  • tests/nat/builder/test_builder.py
**/tests/**/*.py

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/tests/**/*.py: Test functions must use the test_ prefix and snake_case
Extract repeated test code into pytest fixtures; fixtures should set name=... in @pytest.fixture and functions named with fixture_ prefix
Mark expensive tests with @pytest.mark.slow or @pytest.mark.integration
Use pytest with pytest-asyncio for async code; mock external services with pytest_httpserver or unittest.mock

Files:

  • tests/nat/builder/test_builder.py
**/*.{py,sh,md,yml,yaml,toml,ini,json,ipynb,txt,rst}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{py,sh,md,yml,yaml,toml,ini,json,ipynb,txt,rst}: Every file must start with the standard SPDX Apache-2.0 header; keep copyright years up‑to‑date
All source files must include the SPDX Apache‑2.0 header; do not bypass CI header checks

Files:

  • tests/nat/builder/test_builder.py
**/*.{py,md}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

Never hard‑code version numbers in code or docs; versions are derived by setuptools‑scm

Files:

  • tests/nat/builder/test_builder.py
**/*.{py,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/nat-test-llm.mdc)

**/*.{py,yaml,yml}: Configure response_seq as a list of strings; values cycle per call, and [] yields an empty string.
Configure delay_ms to inject per-call artificial latency in milliseconds for nat_test_llm.

Files:

  • tests/nat/builder/test_builder.py
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values.
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • tests/nat/builder/test_builder.py
🧬 Code graph analysis (1)
tests/nat/builder/test_builder.py (3)
src/nat/builder/workflow_builder.py (4)
  • get_function (462-468)
  • get_function (1130-1136)
  • get_function_group (471-477)
  • get_function_group (1139-1145)
src/nat/builder/builder.py (2)
  • get_function (75-76)
  • get_function_group (79-80)
src/nat/builder/function.py (1)
  • get_accessible_functions (470-506)
🔇 Additional comments (6)
tests/nat/builder/test_builder.py (6)

1032-1036: Exclude-only group assertions are correct

No globals exposed; availability verified via group-accessible functions using instance prefix.

Also applies to: 1044-1044


1075-1077: All-includes group: correct global exposure via instance prefix

Lookups using "all_includes_group.*" are accurate.


1099-1103: All-excludes group: correct non-exposure globally

Expectations for ValueError on global lookups are right.


1229-1231: Excluded set uses instance-name prefixes — good

Asserting "excludes_group.*" in excluded list matches the new naming.


1312-1316: Execution via instance-name retrieval works

Retrieval and ainvoke of "math_group.add"/"multiply" validates the end-to-end behavior.


1011-1012: Instance-name lookups updated correctly

Switched tests to "includes_group.". Ran the suggested regex search for the old group-type prefixes followed by '.' — no matches found; tests/nat/builder/test_builder.py (lines 1011–1012 and 1019) reference includes_group..

@willkill07
Copy link
Member Author

/merge

@rapids-bot rapids-bot bot merged commit 92315dc into NVIDIA:develop Sep 18, 2025
17 checks passed
@willkill07 willkill07 deleted the wkk_fix-function-group-workflow-naming branch October 23, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants