Skip to content

Comments

fix(flagd): use FLAGD_SYNC_PORT for in-process provider with backwards compatibility#345

Open
MridulTailor wants to merge 4 commits intoopen-feature:mainfrom
MridulTailor:fix/flagd-sync-port-config
Open

fix(flagd): use FLAGD_SYNC_PORT for in-process provider with backwards compatibility#345
MridulTailor wants to merge 4 commits intoopen-feature:mainfrom
MridulTailor:fix/flagd-sync-port-config

Conversation

@MridulTailor
Copy link

Fixes #318

This PR

Updates the in-process provider to use FLAGD_SYNC_PORT as the primary environment variable for port configuration, while maintaining backwards compatibility with FLAGD_PORT as a fallback. This aligns the Python SDK with the flagd specification and other OpenFeature SDKs.

Changes made:

  • Added ENV_VAR_SYNC_PORT = "FLAGD_SYNC_PORT" constant to config.py
  • Updated port initialization logic in Config.__init__:
    • In-process mode: FLAGD_SYNC_PORTFLAGD_PORT (fallback) → DEFAULT_PORT_IN_PROCESS (8015)
    • RPC mode: FLAGD_PORTDEFAULT_PORT_RPC (8013) (unchanged)
    • Explicit port parameter always takes precedence
  • Added 5 new test cases in test_config.py:
    • test_in_process_uses_sync_port - Verifies FLAGD_SYNC_PORT is used when set
    • test_in_process_fallback_to_port - Verifies FLAGD_PORT fallback for backwards compatibility
    • test_in_process_sync_port_priority - Verifies FLAGD_SYNC_PORT takes priority when both are set
    • test_rpc_ignores_sync_port - Verifies RPC mode ignores FLAGD_SYNC_PORT
    • test_in_process_default_port_when_no_env_var - Verifies default port when no env vars are set
  • Updated README.md configuration table to document the new environment variable

Related Issues

Fixes #318

Parent issue: open-feature/flagd#1573
Testbed issue: open-feature/flagd-testbed#266

Notes

Backwards Compatibility:

  • Existing code using FLAGD_PORT for in-process mode continues to work
  • New code can use FLAGD_SYNC_PORT for in-process mode (recommended)
  • RPC mode behavior unchanged

How to test

Run the unit tests:

cd providers/openfeature-provider-flagd
uv run pytest tests/test_config.py -v
# Expected: 13 passed

uv run pytest tests --ignore=tests/e2e -v
# Expected: 181 passed

…s compatibility

- Add ENV_VAR_SYNC_PORT constant for FLAGD_SYNC_PORT
- Update port resolution: FLAGD_SYNC_PORT → FLAGD_PORT → default for in-process mode
- Keep RPC mode using FLAGD_PORT only
- Add 5 new tests covering sync port usage, fallback, priority, and RPC isolation
- Update README documentation to reflect new environment variable

Fixes open-feature#318

Signed-off-by: Mridul Tailor <mtailor729@gmail.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @MridulTailor, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the port configuration mechanism for the flagd Python provider, specifically enhancing the in-process resolver. It introduces FLAGD_SYNC_PORT to align with the broader flagd specification, while carefully preserving backward compatibility by allowing FLAGD_PORT to serve as a fallback. The changes ensure a more consistent and robust approach to port management across different operational modes.

Highlights

  • New Environment Variable: Introduced FLAGD_SYNC_PORT as the primary environment variable for configuring the port in in-process mode, aligning with the flagd specification.
  • Backwards Compatibility: Ensured that FLAGD_PORT continues to function as a fallback for in-process mode, preventing breaking changes for existing configurations.
  • Updated Port Resolution Logic: Modified the Config initialization to prioritize FLAGD_SYNC_PORT for in-process, fall back to FLAGD_PORT, and maintain FLAGD_PORT for RPC mode.
  • Comprehensive Testing: Added five new unit tests to validate the new port configuration hierarchy and ensure correct behavior in various scenarios.
  • Documentation Update: Updated the README.md to reflect the new FLAGD_SYNC_PORT environment variable and its usage.
Changelog
  • providers/openfeature-provider-flagd/README.md
    • Updated the configuration table to document FLAGD_SYNC_PORT for in-process mode and clarify FLAGD_PORT's role for RPC or as a fallback.
  • providers/openfeature-provider-flagd/src/openfeature/contrib/provider/flagd/config.py
    • Added ENV_VAR_SYNC_PORT constant.
    • Modified the Config.__init__ method to implement a new port resolution hierarchy: FLAGD_SYNC_PORT takes precedence for in-process mode, followed by FLAGD_PORT as a fallback, and finally DEFAULT_PORT_IN_PROCESS.
    • Ensured RPC mode continues to use FLAGD_PORT exclusively.
    • Updated the __init__ signature to include PLR0915 for line length.
  • providers/openfeature-provider-flagd/tests/test_config.py
    • Imported ENV_VAR_SYNC_PORT.
    • Added five new test cases: test_in_process_uses_sync_port, test_in_process_fallback_to_port, test_in_process_sync_port_priority, test_rpc_ignores_sync_port, and test_in_process_default_port_when_no_env_var to thoroughly test the new port resolution logic.
Activity
  • No human activity (comments, reviews, etc.) has occurred on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the in-process provider to use FLAGD_SYNC_PORT for port configuration, with backwards compatibility for FLAGD_PORT. The changes are logical and well-tested. I've provided a couple of suggestions to improve code readability and documentation formatting.

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.55%. Comparing base (80da6b9) to head (dba8d50).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #345      +/-   ##
==========================================
- Coverage   96.55%   95.55%   -1.00%     
==========================================
  Files           5       16      +11     
  Lines         174      878     +704     
==========================================
+ Hits          168      839     +671     
- Misses          6       39      +33     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Mridul Tailor <71081929+MridulTailor@users.noreply.github.com>
Copy link
Member

@aepfli aepfli left a comment

Choose a reason for hiding this comment

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

Thank you, nice addition, i feel like the gemini input is a good one, which we should implement

@MridulTailor
Copy link
Author

I thought so too, I will resolve it right away.

Refactor port env var resolution for in-process mode to use os.environ.get() chaining instead of nested if/else, as suggested in code review. Logic and behavior are unchanged.

Signed-off-by: Mridul Tailor <mtailor729@gmail.com>
@aepfli
Copy link
Member

aepfli commented Feb 20, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The changes correctly implement the priority for FLAGD_SYNC_PORT in in-process mode while maintaining backwards compatibility with FLAGD_PORT. I have suggested a simplification for the port initialization logic in Config.__init__ which reduces verbosity and fixes a minor regression where ResolverType.FILE would default to the RPC port instead of the in-process port.

FILE resolver was incorrectly defaulting to RPC port (8013) instead
of in-process port (8015). Simplify port resolution using env_or_default
helper to handle RPC, IN_PROCESS, and FILE resolver types correctly.

Signed-off-by: Mridul Tailor <mtailor729@gmail.com>
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.

[flagd] Fix in-process provider to use FLAGD_SYNC_PORT (not FLAGD_PORT) for port configuration (backwards compatibility)

3 participants