Skip to content

actor: add ErrMessageDropped for Ask path when mailbox drops#10652

Open
erickcestari wants to merge 1 commit intolightningnetwork:masterfrom
erickcestari:add-err-message-dropped-by-mailbox
Open

actor: add ErrMessageDropped for Ask path when mailbox drops#10652
erickcestari wants to merge 1 commit intolightningnetwork:masterfrom
erickcestari:add-err-message-dropped-by-mailbox

Conversation

@erickcestari
Copy link
Collaborator

When the BackpressureMailbox's RED policy drops a message, Send returns false but neither context is cancelled. The Ask path previously completed the promise with fn.Err[R](ctx.Err()) where ctx.Err() is nil, producing a confusing nil-wrapped error. Add a three-way check that returns ErrMessageDropped in this case.

BackpressureMailbox will be added on: #10219

When the BackpressureMailbox's RED policy drops a message, Send
returns false but neither context is cancelled. The Ask path
previously completed the promise with fn.Err[R](ctx.Err()) where
ctx.Err() is nil, producing a confusing nil-wrapped error. Add a
three-way check that returns ErrMessageDropped in this case.
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 error handling within the actor system's Ask mechanism. It introduces a dedicated error, ErrMessageDropped, to clearly signal when a message is rejected by a mailbox's backpressure policy. This change prevents confusing nil-wrapped errors in scenarios where a message is dropped but no context cancellation has occurred, thereby improving the clarity and predictability of error responses for Ask operations.

Highlights

  • New Error Type: Introduced ErrMessageDropped to specifically indicate when a message is rejected by a mailbox's drop policy (e.g., RED backpressure) without context cancellation.
  • Improved Error Handling in Ask Path: Modified the Ask method in actor/actor.go to return ErrMessageDropped when a message is dropped by the mailbox and neither the actor's context nor the Ask call's context is cancelled, resolving a previous issue where a nil-wrapped error was returned.

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

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.

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

@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 a bug in the Ask pattern where a message dropped by a mailbox's policy would result in a confusing nil-wrapped error. By introducing ErrMessageDropped and adding a three-way check, the new logic properly handles this scenario. My only suggestion is to add unit test coverage for this new error path to ensure its robustness, which might require a minor refactoring to allow injecting a mock mailbox for testing.

Comment on lines +235 to 239
} else {
// Neither context cancelled — the mailbox's drop
// policy (e.g., RED) rejected the message.
promise.Complete(fn.Err[R](ErrMessageDropped))
}

Choose a reason for hiding this comment

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

medium

This change introduces a new error path for when a message is dropped by the mailbox policy. However, there are no tests to cover this new logic. With the current ChannelMailbox, this path is unreachable.

To ensure the correctness of this logic, especially with the future introduction of BackpressureMailbox, I recommend adding a unit test. This might require a small refactoring to allow injecting a mock Mailbox during actor creation for testing purposes. For example, the ActorConfig could be extended to optionally take a Mailbox instance, which would make the actor system more flexible and easier to test.

@saubyk saubyk added this to the v0.22.0 milestone Mar 24, 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