fix(python): enforce deadlines for external handlers#2043
Closed
chaliy wants to merge 1 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Enforces the configured PythonLimits::max_duration wall-clock budget across awaited external (host) Python function handlers so host callbacks can’t pin Monty execution between VM steps beyond the advertised timeout.
Changes:
- Compute a per-invocation
python_deadlineand wrap external handler awaits with atokio::time::timeoutbased on remaining budget. - Centralize external timeout behavior via helper functions returning a Python
RuntimeErroron budget exhaustion. - Document the behavior and add a regression test verifying the external-handler timeout respects the Python deadline.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
specs/python-builtin.md |
Documents the new timeout behavior and trust-model guidance for external handlers. |
crates/bashkit/src/builtins/python.rs |
Adds deadline tracking + timeout wrapping for external handlers; adds regression test + helper. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
499
to
503
| let tracker = LimitedTracker::new(limits); | ||
| // Important security decision: cap awaited host callbacks with the same wall-clock | ||
| // budget as Monty so external functions cannot pin execution between VM steps. | ||
| let python_deadline = Instant::now().checked_add(py_limits.max_duration); | ||
|
|
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
bashkit | dac2d5b | Commit Preview URL | Jun 12 2026, 01:31 AM |
chaliy
added a commit
that referenced
this pull request
Jun 12, 2026
…on budget Closes #2043, Closes #2044 Wraps each awaited external function handler call in tokio::time::timeout using the remaining PythonLimits::max_duration wall-clock budget. Handlers that exceed the remaining budget get a RuntimeError instead of blocking indefinitely. Instant::checked_add overflow (very large max_duration) is treated as no deadline rather than an immediate timeout. Also removes the merged_env block that merged shell-local ctx.variables into 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).
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.
Superseded by #2058 — rebased cleanly on main.