Skip to content

fix: make the function handler timeout 5 seconds#1348

Merged
WilliamBergamin merged 6 commits intomainfrom
bump-timout-for-synchronous-function-execution
Aug 13, 2025
Merged

fix: make the function handler timeout 5 seconds#1348
WilliamBergamin merged 6 commits intomainfrom
bump-timout-for-synchronous-function-execution

Conversation

@WilliamBergamin
Copy link
Contributor

Summary

The function_executed event is the only event with a timeout longer then 3 seconds, this PR aims to allow bolt to timeout function handlers after 5 seconds rather then 3. This will allow developer to call ack up to 5 seconds after they receive the function_executed event.

Testing

  1. Built this branch locally with the scripts/build_pypi_package.sh command
  2. Follow these steps to set up an app with a custom step
  3. Import the local build to the project
  4. Configure the function to maually handle the auto acknowledge behavior and and let the handler sleep for more then 3 seconds
@app.function("sample_custom_step", auto_acknowledge=False)
def sample_step_callback(ack: Ack, inputs: dict, fail: Fail, complete: Complete):
    try:
        message = inputs["message"]
        time.sleep(4.5)
        complete(
            outputs={
                "message": f":wave: You submitted the following message: \n\n>{message}"
            }
        )
        ack()
    except Exception as e:
        fail(f"Failed to handle a custom step request (error: {e})")
        raise e
    finally:
        ack()

Category

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Document pages under /docs
  • Others

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run ./scripts/install_all_and_run_tests.sh after making the changes.

Comment on lines 60 to 63
def setup_time_mocks(self, *, monkeypatch: pytest.MonkeyPatch, time_mock: Mock, sleep_mock: AsyncMock):
monkeypatch.setattr(time, "time", time_mock)
monkeypatch.setattr(asyncio, "sleep", sleep_mock)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This just make the tests run faster 🚀

@codecov
Copy link

codecov bot commented Aug 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.95%. Comparing base (eb3a519) to head (21ab6c4).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1348      +/-   ##
==========================================
- Coverage   90.96%   90.95%   -0.01%     
==========================================
  Files         222      222              
  Lines        7501     7507       +6     
==========================================
+ Hits         6823     6828       +5     
- Misses        678      679       +1     

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

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@WilliamBergamin LGTM! And what an interesting addition to Bolt! ⚡

If I'm understanding right, this change avoids warning outputs for function_executed events if the application doesn't respond in time which will match the Slack API server behavior?

Testing found this new timeout works as expected but I did leave a few comments that'd be nice to address before merging this.

It might also be nice to note that 3 seconds is no longer a strict requirement for certain events in docs: https://docs.slack.dev/tools/bolt-python/concepts/acknowledge/ 📚


# await for the completion of ack() in the async listener execution
while ack.response is None and time.time() - starting_time <= 3:
while ack.response is None and time.time() - starting_time <= listener.acknowledgement_timeout:
Copy link
Member

Choose a reason for hiding this comment

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

👾 praise: Love to see this!

WilliamBergamin and others added 4 commits August 13, 2025 17:17
Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com>
Co-authored-by: Eden Zimbelman <eden.zimbelman@salesforce.com>
@WilliamBergamin WilliamBergamin merged commit 974816e into main Aug 13, 2025
14 checks passed
@WilliamBergamin WilliamBergamin deleted the bump-timout-for-synchronous-function-execution branch August 13, 2025 21:28
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.

2 participants