Skip to content

fix(python): enforce deadlines for external handlers#2043

Closed
chaliy wants to merge 1 commit into
mainfrom
2026-06-12-propose-fix-for-python-handler-timeout-issue
Closed

fix(python): enforce deadlines for external handlers#2043
chaliy wants to merge 1 commit into
mainfrom
2026-06-12-propose-fix-for-python-handler-timeout-issue

Conversation

@chaliy

@chaliy chaliy commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Superseded by #2058 — rebased cleanly on main.

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

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_deadline and wrap external handler awaits with a tokio::time::timeout based on remaining budget.
  • Centralize external timeout behavior via helper functions returning a Python RuntimeError on 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);

@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 dac2d5b Commit Preview URL Jun 12 2026, 01:31 AM

@chaliy chaliy closed this Jun 12, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants