fix(python): cap external function handlers with remaining max_duration budget#2058
Merged
Conversation
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | dc9e00a | Commit Preview URL Branch Preview URL |
Jun 12 2026, 10:10 AM |
There was a problem hiding this comment.
Pull request overview
This PR enforces PythonLimits::max_duration across awaited external Python function handlers by applying tokio::time::timeout using the remaining per-invocation wall-clock budget, preventing host callbacks from blocking past Monty’s configured deadline.
Changes:
- Compute a per-invocation Python deadline and wrap each awaited external handler call in a timeout using the remaining budget.
- Add centralized helpers for remaining-budget calculation and for producing a consistent Python
RuntimeErroron handler timeout. - Add a regression test ensuring external handler awaits observe the Python wall-clock budget, and document the new timeout behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
specs/python-builtin.md |
Documents timeout behavior for awaited external function handlers. |
crates/bashkit/src/builtins/python.rs |
Wraps external handler awaits in remaining-budget timeouts; adds helpers and regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- call_external_with_deadline: treat deadline==None (checked_add overflow) as no cap rather than immediate timeout - Add tightened integration and spec tests from issue #2044: unexported shell vars must not leak into Python os.environ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2043, Closes #2044
Python external function deadline enforcement (issue #2043): wraps each awaited external function handler call in
tokio::time::timeoutusing the remainingPythonLimits::max_durationwall-clock budget. Handlers that exceed the remaining budget get aRuntimeErrorinstead of blocking indefinitely.Instant::checked_addoverflow (very largemax_duration) is treated as no deadline rather than an immediate timeout.Python env scope (issue #2044): removes the
merged_envblock that merged shell-localctx.variablesinto the Python subprocess environment. Only exported variables (ctx.env) are now visible to Python, matching real bash semantics and closing the shell-secret disclosure path (TM-INF). Tightens integration and spec tests to assert unexported variables return"none"fromos.getenv().