Skip to content

Add MAX_EXECUTIONS environment variable limit#5272

Open
jardondiego wants to merge 11 commits into
masterfrom
feature/max-executions
Open

Add MAX_EXECUTIONS environment variable limit#5272
jardondiego wants to merge 11 commits into
masterfrom
feature/max-executions

Conversation

@jardondiego
Copy link
Copy Markdown
Collaborator

@jardondiego jardondiego commented May 12, 2026

This PR introduces a MAX_EXECUTIONS environment variable that limits the number of tasks the bot will execute before exiting cleanly. It will facilitate testing locally moving forward.

This is particularly useful when running a local bot with a COMMAND_OVERRIDE, allowing developers to restrict the bot to a specific number of iterations rather than looping infinitely.

Changes:

  • Added an execution_count tracker to the main task_loop in run_bot.py.
  • The bot will break out of the loop with a clean exit if MAX_EXECUTIONS is set and reached.
  • Added corresponding unit tests in run_bot_test.py.

@jardondiego jardondiego requested a review from a team as a code owner May 12, 2026 19:56
Comment thread src/python/bot/startup/run_bot.py Outdated
Diego Jardon added 4 commits May 13, 2026 15:44
- Fixed the `TypeError: info() takes 1 positional argument but 2 were given` exception when max_executions limit is reached.
- Ensured environment re-evaluation in the `test_max_executions` unit test.
- Mocked `update_task_enabled` correctly during tests.
- Handles ValueError if MAX_EXECUTIONS cannot be parsed as an integer.
- Removes the invalid value from the environment to prevent repeated errors.
- Adds test coverage for the invalid input case.
- Removed extra indentation by utilizing Python's short-circuit evaluation inside a single try-except block.
Copy link
Copy Markdown
Collaborator

@IvanBM18 IvanBM18 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread src/clusterfuzz/_internal/tests/core/bot/startup/run_bot_test.py Outdated
Comment thread src/python/bot/startup/run_bot.py
Comment thread src/python/bot/startup/run_bot.py Outdated
Comment thread src/python/bot/startup/run_bot.py Outdated
jardondiego and others added 3 commits May 19, 2026 21:38
- Fail fast with log_fatal_and_exit on invalid env values
- Move max_task_executions retrieval outside the task loop
- Use correct log format args for metrics.logs.info
- Clean up test mock assignments and assert SystemExit
@jardondiego jardondiego requested a review from letitz May 20, 2026 03:57
Copy link
Copy Markdown
Collaborator

@ViniciustCosta ViniciustCosta left a comment

Choose a reason for hiding this comment

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

Seems good! Could you just add an evidence of it not blocking execution in dev environment?

@jardondiego
Copy link
Copy Markdown
Collaborator Author

Seems good! Could you just add an evidence of it not blocking execution in dev environment?

Will do!

@javanlacerda
Copy link
Copy Markdown
Collaborator

/gcbrun

@javanlacerda
Copy link
Copy Markdown
Collaborator

Seems good! Could you just add an evidence of it not blocking execution in dev environment?

+1

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.

5 participants