Skip to content

fix(python): cap external function handlers with remaining max_duration budget#2058

Merged
chaliy merged 2 commits into
mainfrom
fix/pr-2043-python-deadline
Jun 12, 2026
Merged

fix(python): cap external function handlers with remaining max_duration budget#2058
chaliy merged 2 commits into
mainfrom
fix/pr-2043-python-deadline

Conversation

@chaliy

@chaliy chaliy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Closes #2043, Closes #2044

Python external function deadline enforcement (issue #2043): 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.

Python env scope (issue #2044): 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). Tightens integration and spec tests to assert unexported variables return "none" from os.getenv().

Copilot AI review requested due to automatic review settings June 12, 2026 10:01
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 12, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 RuntimeError on 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.

Comment thread crates/bashkit/src/builtins/python.rs
Comment thread crates/bashkit/src/builtins/python.rs
- 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
@chaliy chaliy merged commit 4901049 into main Jun 12, 2026
36 checks passed
@chaliy chaliy deleted the fix/pr-2043-python-deadline branch June 12, 2026 10:35
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