Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🐛 bug: skip non-string state keys during iteration#4048

Merged
ReneWerner87 merged 1 commit intomainfrom
skip-non-string-keys-in-state.go
Feb 4, 2026
Merged

🐛 bug: skip non-string state keys during iteration#4048
ReneWerner87 merged 1 commit intomainfrom
skip-non-string-keys-in-state.go

Conversation

@gaby
Copy link
Member

@gaby gaby commented Feb 3, 2026

Motivation

  • Prevent iteration over the internal State.dependencies sync.Map from aborting when encountering non-string keys so valid string keys and service entries are always discovered.
  • Ensure service discovery and key enumeration remain correct when the backing map contains mixed-type entries and when string keys are inserted before and after non-string keys.

Description

  • Change Keys() to continue iterating (return true) when a sync.Map key is not a string instead of stopping the iteration.
  • Change serviceKeys() to continue iterating when a sync.Map key is not a string so non-string entries don't interrupt service discovery.
  • Add test TestState_Keys_SkipsNonStringKeys_WithMixedOrder to verify string keys inserted before and after a non-string key are still returned, and extend service-key tests with with-non-string-key and with-non-service-keys scenarios to cover mixed-type entries.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gaby, 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 resolves an issue where the internal sync.Map's iteration methods (Keys() and serviceKeys()) could prematurely terminate upon encountering non-string keys. The change ensures that these methods gracefully handle mixed-type entries by skipping non-string keys and continuing the iteration, thereby guaranteeing complete and accurate retrieval of all valid string-based keys and service entries. This improves the robustness of key enumeration and service discovery within the system.

Highlights

  • Bug Fix: Robust sync.Map Iteration: Modified State.Keys() and State.serviceKeys() to prevent iteration from aborting when encountering non-string keys in the internal sync.Map. Iteration now skips non-string keys and continues, ensuring all valid string keys and service entries are discovered.
  • Enhanced Test Coverage: Added new tests TestState_Keys_SkipsNonStringKeys and TestState_Keys_SkipsNonStringKeys_WithMixedOrder to specifically verify that non-string keys are correctly skipped during key enumeration. Existing service-key tests were extended with with-non-string-key and with-non-service-keys scenarios to cover mixed-type entries.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • state.go
    • Modified func (s *State) Keys(): Changed return false to return true when key.(string) type assertion fails, allowing iteration to continue past non-string keys.
    • Modified func (s *State) serviceKeys(): Changed return false to return true when key.(string) type assertion fails, allowing iteration to continue past non-string keys.
  • state_test.go
    • Added TestState_Keys_SkipsNonStringKeys to verify that Keys() correctly returns only string keys when non-string keys are present.
    • Added TestState_Keys_SkipsNonStringKeys_WithMixedOrder to ensure Keys() handles non-string keys correctly regardless of their insertion order relative to string keys.
    • Extended TestState_Service with a new sub-test with-non-string-key to confirm serviceKeys() correctly identifies service keys even when non-string keys are present.
    • Extended TestState_Service with a new sub-test with-non-service-keys to confirm serviceKeys() correctly identifies service keys when other non-service string keys and non-string keys are present.
Activity
  • The author ran make audit, which failed due to govulncheck reporting Go standard-library vulnerabilities in the toolchain.
  • The author successfully ran make generate, make betteralign, make modernize, make format, and make lint with no reported issues.
  • The author ran make test, and the full test suite passed, including the newly added tests.
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.

@ReneWerner87 ReneWerner87 added this to v3 Feb 3, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 3, 2026

Walkthrough

The changes modify the Keys() and serviceKeys() methods to continue iterating over non-string keys instead of terminating early, ensuring all string keys are collected without premature exit. Comprehensive test coverage validates the new behavior across various scenarios.

Changes

Cohort / File(s) Summary
State iteration logic
state.go
Modified Keys() and serviceKeys() Range callbacks to return true on non-string keys instead of false, allowing complete iteration over all string keys in the collection.
Test coverage
state_test.go
Added four new test cases: TestState_Keys_SkipsNonStringKeys, TestState_Keys_SkipsNonStringKeys_WithMixedOrder, and two subtests under TestState_Service ("with-non-string-key" and "with-non-service-keys") to validate non-string key filtering behavior.

Suggested labels

☢️ Bug

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • efectn

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 Two little loops that skip with care,
Now finish their race without despair!
Non-string keys hop away as they should,
While string ones are gathered—the fix works good! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description provides clear motivation and detailed description of changes, but omits most required template sections like type of change, checklist items, and other required elements. Complete the PR description by selecting appropriate 'Type of change' options (e.g., 'Bug fix', 'Enhancement'), checking relevant checklist items (self-review, tests, documentation), and addressing any missing template sections.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the bug fix: skipping non-string state keys during iteration, which directly matches the core changes in the PR.

✏️ 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 skip-non-string-keys-in-state.go

Important

Action Needed: IP Allowlist Update

If your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:

  • 136.113.208.247/32 (new)
  • 34.170.211.100/32
  • 35.222.179.152/32

Failure to add the new IP will result in interrupted reviews.


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.

@ReneWerner87 ReneWerner87 added this to the v3 milestone Feb 3, 2026
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 pull request effectively addresses a bug where sync.Map iteration would prematurely stop upon encountering non-string keys in Keys() and serviceKeys() methods. By changing return false to return true when a non-string key is found, the iteration now correctly skips these keys and continues to discover all valid string keys. The added tests in state_test.go adequately cover these new behaviors, including scenarios with mixed-type keys and mixed insertion orders, ensuring the robustness of the fix.

@codecov
Copy link

codecov bot commented Feb 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.17%. Comparing base (81435e6) to head (8274e66).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4048      +/-   ##
==========================================
- Coverage   91.21%   91.17%   -0.04%     
==========================================
  Files         119      119              
  Lines       11117    11121       +4     
==========================================
  Hits        10140    10140              
- Misses        620      624       +4     
  Partials      357      357              
Flag Coverage Δ
unittests 91.17% <100.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

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 fixes a bug where iterating over the internal State.dependencies sync.Map would abort prematurely when encountering non-string keys, preventing valid string keys inserted after non-string keys from being discovered.

Changes:

  • Modified Keys() and serviceKeys() methods to continue iteration instead of stopping when non-string keys are encountered
  • Added comprehensive test coverage for mixed-type entries in the sync.Map, including tests for key insertion order and service discovery with non-string keys

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
state.go Fixed iteration logic in Keys() and serviceKeys() to skip non-string keys by returning true instead of false
state_test.go Added three new test cases to verify string keys are correctly returned when non-string keys are present in various orders

@ReneWerner87 ReneWerner87 merged commit 2d5f4d8 into main Feb 4, 2026
27 checks passed
@ReneWerner87 ReneWerner87 deleted the skip-non-string-keys-in-state.go branch February 4, 2026 16:05
@github-project-automation github-project-automation bot moved this to Done in v3 Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants