Skip to content

fix: preserve stack space during recursive shell execution - #318

Draft
gautamsirdeshmukh wants to merge 1 commit into
strands-agents:mainfrom
gautamsirdeshmukh:fix/recursive-shell-stack
Draft

gautamsirdeshmukh wants to merge 1 commit into
strands-agents:mainfrom
gautamsirdeshmukh:fix/recursive-shell-stack

Conversation

@gautamsirdeshmukh

Copy link
Copy Markdown
Contributor

Description

Recursive shell functions can exhaust a normal worker stack before reaching the configured recursion limit. Kernel callbacks then run with too little stack. In Box, this makes Cedar report recursion limit reached and deny commands even when the policies are not recursive.

Grow the native stack when polling or dropping recursive execution futures. Execution stays on the same thread and keeps borrowing the caller's process, with the same Tokio task locals. The configured depth limit stays in effect. WASM retains its host stack behavior.

Native execution can allocate additional 4 MiB stack segments. Allocation failure panics, and performance overhead has not been benchmarked. The guards protect recursive execution; other recursive algorithms in the crate keep their current stack behavior.

Related Issues

Related to strands-agents/staging-boxy#585. Box's diagnostic buffering and exit presentation are separate work.

Documentation PR

The runtime requirements in src/lib.rs describe the native stack behavior.

Type of Change

Bug fix

Testing

On macOS arm64:

  • The released Box 0.2.0 reproduces the policy failures with 40 recursive calls. Box built with this Shell change completes both 40 and 60 calls on its normal worker stack, with no recursion warnings or recorded internal faults.

  • Regression tests cover kernel callback headroom, preserved policy denials, captured execution, the configured depth limit, and cancellation of deeply nested futures.

  • cargo +1.98.1 xtask check --rust-only passes: formatting, clippy, all 2,642 Rust tests without skips, and documentation with RUSTDOCFLAGS=-D warnings. Existing lint warnings remain.

  • Linux, Windows, Python, Node.js, and WASM were not exercised locally.

  • I ran the relevant test suites for the bindings I touched (cargo test --workspace --all-targets, pytest tests/python, npm test)

  • If I touched Rust, I ran cargo fmt and cargo clippy

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added the bug Something isn't working label Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant