Skip to content

Conversation

@kdawgwilk
Copy link
Contributor

  • Fix Cloud Functions v1/v2 error wrapping to retain HTTP status so 429/RESOURCE_EXHAUSTED surfaces correctly instead of being lost on rethrow.
  • Broaden retry code parsing in the deploy executor to check nested original.status, letting quota errors re-queue instead of silently succeeding.
  • This ensures quota-hit deploys actually retry and fail properly instead of yielding false-positive success.

- Keep Cloud Functions v1/v2 errors carrying HTTP status so
  429/RESOURCE_EXHAUSTED isn't dropped on rethrow.
- Teach deploy executor to read nested original.status when detecting
  retryable quota errors.
- Deploys that hit quota now requeue/fail correctly instead of showing
  false success.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kdawgwilk, 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 addresses a critical issue where Cloud Functions deployments encountering quota exhaustion errors would not correctly surface these errors, leading to silent failures or misleading success reports. The changes involve preserving HTTP status codes during error wrapping and enhancing the retry mechanism to accurately recognize these statuses. As a result, the system will now reliably detect and handle quota-related deployment failures, ensuring proper retries and preventing incorrect deployment outcomes.

Highlights

  • Error Status Preservation: Cloud Functions v1 and v2 error wrapping has been fixed to retain HTTP status codes, such as 429 (RESOURCE_EXHAUSTED), which were previously lost during error rethrowing.
  • Enhanced Retry Logic: The deploy executor's retry code parsing has been broadened to check for nested original.status within errors, allowing quota-related errors to correctly trigger retries.
  • Reliable Quota Handling: This ensures that deployments encountering quota limits will now properly retry or fail, preventing false-positive success reports and providing accurate deployment outcomes.
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 correctly addresses an issue with error handling for function deployments, ensuring that quota-related errors are properly retried. The changes to propagate the HTTP status code are well-implemented. I have a couple of suggestions to make the status code extraction more robust against unexpected error types by ensuring the extracted status is always a number.

* @param err The error returned from the operation.
*/
function functionsOpLogReject(funcName: string, type: string, err: any): void {
const status = err?.context?.response?.statusCode || err?.status;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While err.status is expected to be a number from FirebaseError, the type of err is any, which doesn't guarantee this. If err.status were a non-numeric string (e.g., an error status string like 'RESOURCE_EXHAUSTED'), it would be assigned to status. This could lead to incorrect behavior, as status === 429 would fail and a non-numeric value would be passed to the FirebaseError constructor, which expects a number. To make this more robust, consider ensuring the extracted value is a number.

Suggested change
const status = err?.context?.response?.statusCode || err?.status;
const code = err?.context?.response?.statusCode || err?.status;
const status = typeof code === "number" ? code : undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error paths feeding these handlers already give us numeric status codes: responseToError sets statusCode as a number, gax errors use numeric code, and FirebaseError stores a numeric status (default 500). If a strange upstream ever handed us a string like "RESOURCE_EXHAUSTED", the 429 check would simply skip the quota branch and the FirebaseError would carry that string, but it wouldn’t change retry behavior because the executor’s parseErrorCode still looks for numeric codes.

* @param err The error returned from the operation.
*/
function functionsOpLogReject(func: InputCloudFunction, type: string, err: any): void {
const status = err?.context?.response?.statusCode || err?.status;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the v1 file, err.status is not guaranteed to be a number since err is of type any. If it were a string, it could cause issues with status code checks and when constructing the FirebaseError. To improve type safety and prevent potential runtime issues, it's safer to ensure that status is a number.

Suggested change
const status = err?.context?.response?.statusCode || err?.status;
const code = err?.context?.response?.statusCode || err?.status;
const status = typeof code === "number" ? code : undefined;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error paths feeding these handlers already give us numeric status codes: responseToError sets statusCode as a number, gax errors use numeric code, and FirebaseError stores a numeric status (default 500). If a strange upstream ever handed us a string like "RESOURCE_EXHAUSTED", the 429 check would simply skip the quota branch and the FirebaseError would carry that string, but it wouldn’t change retry behavior because the executor’s parseErrorCode still looks for numeric codes.

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.

1 participant