Skip to content

fix(database): hash prioritized children in priority order - #16769

Merged
ncooke3 merged 3 commits into
firebase:mainfrom
dajiaohuang:fix/realtimedb-priority-hash-order
Oct 14, 2026
Merged

ncooke3 merged 3 commits into
firebase:mainfrom
dajiaohuang:fix/realtimedb-priority-hash-order

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Hash children in Firebase priority order whenever at least one child has a priority, matching the Realtime Database transaction hash algorithm.
  • Cover a node where every child has a priority and priority order differs from key order; document the transaction maxretry effect under Unreleased with fix(database): hash prioritized children in priority order #16769.

Validation

  • Changed files pass clang-format 23.1.2 and git diff --check.
  • At exact source df437c8, the actual upstream Catalyst Database unit suite executes 430 tests with zero failures, explicitly including testChildrenNodeHashUsesPriorityOrderWhenEveryChildHasPriority: native XCTest log.
  • The separate quickstart dependency conflict remains a broader workflow failure; it does not invalidate the inspected unit result or establish complete workflow acceptance.

@gemini-code-assist

Copy link
Copy Markdown
Contributor
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 the 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 counterproductive. 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.

@paulb777 paulb777 added this to the 13.1.0 - M188 milestone Oct 1, 2026
@paulb777

paulb777 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Agent claims the existing behavior is inconsistent with Android and Web

@paulb777

paulb777 commented Oct 1, 2026

Copy link
Copy Markdown
Member

Thanks for the contribution! A few housekeeping items:

  • CHANGELOG: The entry in FirebaseDatabase/CHANGELOG.md is under # 12.19.0, which has already shipped. Please move it under a # Unreleased heading at the top of the file (add the heading if it isn't there yet).
  • PR number: end the entry with this PR's number, e.g. - [fixed] Description. (#16769).
  • Formatting: after updating, please run scripts/style.sh so the infra.check job passes. It needs clang-format 23 and swiftformat (see scripts/setup_check.sh). If you can't run it locally, the infra.check log lists the files that need formatting.

@paulb777

paulb777 commented Oct 1, 2026

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request fixes the node hashing logic in FChildrenNode.m to correctly use priority order when all children have priorities, by ensuring the check for non-empty priorities is properly negated. A corresponding unit test has been added to verify this behavior. The reviewer suggested a minor improvement to the loop in FChildrenNode.m to use an explicit if statement for better readability and to avoid redundant boolean assignments.

Comment thread FirebaseDatabase/Sources/Snapshot/FChildrenNode.m
@paulb777 paulb777 self-assigned this Oct 1, 2026

@paulb777 paulb777 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, nice catch. Because the check is inverted, a node whose children all have priorities is hashed in key order instead of priority order. That doesn't match the server, or the Android and JS SDKs. The hash is sent with transactions and listens, so transactions on such data can fail with maxretry, and listens re-download data the client already has. The one-character fix matches Android's ChildrenNode.getHashRepresentation.

Optional CHANGELOG wording: - [fixed] Fixed an issue where transactions could fail with a maxretry error when every child of a node had a priority. (#16769)

Comment thread FirebaseDatabase/Tests/Unit/FIRDataSnapshotTests.m
@dajiaohuang

Copy link
Copy Markdown
Contributor Author

Added the literal JS-algorithm golden ioxrlJO1lx052It4dFes/dAFe9Y= alongside the existing ordering assertion. Independently recomputing the SHA-1/IEEE-754 leaf representations also yields that priority-order value and ngiLaZ8GVGzsDXgauGE/6t0CDuA= for key order. This calculation is not an execution of the iOS or JS SDK tests.

Moved the changelog to Unreleased/#16769 using the suggested maxretry wording. Changed Objective-C files were formatted with clang-format 23.1.2 and git diff --check passes. Native Apple XCTest remains unrun locally and requires current-head CI.

@paulb777

paulb777 commented Oct 2, 2026

Copy link
Copy Markdown
Member

/gemini review

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request fixes an issue where transactions could fail with a maxretry error when every child of a node has a priority. The fix corrects the logic in FChildrenNode.m to ensure sawPriority is set to true when a child node's priority is not empty. A corresponding unit test has been added to verify that the children node hash correctly uses priority order. There are no review comments, and I have no feedback to provide.

@paulb777 paulb777 assigned ncooke3 and unassigned paulb777 Oct 2, 2026

@ncooke3 ncooke3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@ncooke3
ncooke3 merged commit e3f4a4b into firebase:main Oct 14, 2026
42 of 43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants