Skip to content

Conversation

@leavesster
Copy link
Contributor

Summary

  • Change node_id property to return Optional[str] instead of magic strings "unknown" and "none"
  • Return None when node_id is not available

Problem

Original code returned magic strings:

if len(self.__block_info.stacks) > 0:
    return self.__block_info.stacks[-1].get("node_id", "unknown")
else:
    return "none"

This is problematic because:

  • Callers can't distinguish between a real node called "unknown" and missing data
  • Magic strings are error-prone and hard to document

Solution

Return None when data is not available:

@property
def node_id(self) -> Optional[str]:
    if len(self.__block_info.stacks) > 0:
        return self.__block_info.stacks[-1].get("node_id")
    return None

Test Plan

  • All existing tests pass
  • Context tests verify node_id property behavior

Previously node_id returned "unknown" or "none" as special values,
which is confusing and error-prone. Now it returns None when the
node_id is unavailable, which is a clearer API contract.
Copilot AI review requested due to automatic review settings January 31, 2026 09:28
@coderabbitai
Copy link

coderabbitai bot commented Jan 31, 2026

Warning

Rate limit exceeded

@leavesster has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 56 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.


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

Copy link
Contributor

Copilot AI left a comment

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 changes the node_id property to return Optional[str] instead of magic strings ("unknown" and "none"), improving type safety and API clarity.

Changes:

  • Modified node_id property return type from str to Optional[str]
  • Returns None instead of magic strings when node_id is unavailable
  • Added comprehensive docstring explaining when None is returned
  • Updated internal usage at line 386 to handle Optional return type with fallback

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

Comment on lines +294 to +303
def node_id(self) -> Optional[str]:
"""Get the node_id from the current execution stack.

Returns:
The node_id if available, or None when running in contexts
without a node_id (e.g., run_block).
"""
if len(self.__block_info.stacks) > 0:
return self.__block_info.stacks[-1].get("node_id", "unknown")
else:
return "none"
return self.__block_info.stacks[-1].get("node_id")
return None
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The change from returning str to Optional[str] is a breaking API change. While the internal usage at line 386 has been properly updated to handle None, external callers of this property (such as executor/python_executor/block.py lines 134 and 146) are not updated in this PR and will break when node_id is None. These call sites use node_id directly in string formatting and file path construction, which will fail with None values.

Consider one of these approaches:

  1. Update all known call sites in the same PR to handle the Optional return type
  2. Add a deprecation period where the property returns "unknown" by default but logs a warning, giving consumers time to migrate
  3. Document this as a breaking change and coordinate updates across all dependent code

Copilot uses AI. Check for mistakes.
@leavesster leavesster changed the title fix: return Optional[str] for node_id instead of magic strings fix(oocana): return Optional[str] for node_id instead of magic strings Jan 31, 2026
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.

2 participants