Skip to content

Add MAX_EXECUTIONS environment variable limit#5272

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

Add MAX_EXECUTIONS environment variable limit#5272
jardondiego wants to merge 6 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.

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
execution_count += 1
max_executions = environment.get_value('MAX_EXECUTIONS')
if max_executions and execution_count >= int(max_executions):
logs.info('Reached MAX_EXECUTIONS limit (%s). Exiting.', max_executions)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: Can you format using f strings?

Suggested change
logs.info('Reached MAX_EXECUTIONS limit (%s). Exiting.', max_executions)
logs.info(f'Reached MAX_EXECUTIONS limit {max_executions}. Exiting.')

We don't really format strings that way in the project.
Besides i think that using the logs.info() method that way would result in the following log:

....
extras :{
  max_executions: 5
},
message: "Reached MAX_EXECUTIONS limit (%s). Exiting."
....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! Thanks!

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

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