Skip to content

fix(interpreter): bound nested bash/sh child shells - #2549

Merged
chaliy merged 1 commit into
mainfrom
claude/fidelity-shell-depth
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/fidelity-shell-depth

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

Nested bash/sh child shells are bounded: each one counts against max_function_depth, plus a dedicated cap of 8 nested child shells. Past the cap the shell fails with maximum nesting depth exceeded (exit 2).

Why

A script that re-runs itself through sh crashed the whole host process with a stack overflow. In a multi-tenant process that aborts every tenant (new TM-DOS-125). Found while bounding recursive $(MAKE) for the upcoming make builtin.

Before

$ bashkit -c 'echo "sh s.sh" > s.sh; sh s.sh; echo rc=$?'
thread 'main' has overflowed its stack
fatal runtime error: stack overflow, aborting

After

$ bashkit -c 'echo "sh s.sh" > s.sh; sh s.sh; echo rc=$?'
sh: maximum nesting depth exceeded
rc=2

Risk

  • Low. Real scripts rarely nest shells more than a few levels deep. The cap of 8 was measured: about 15 bare sh levels fit a 2 MiB debug-build stack, and a level costs several function calls. Recorded as L-PROC-004.
  • Forked background jobs and pipeline stages inherit the depth, because they are polled on the caller's stack.

Checklist

  • Failing test first (recursive_child_shell_is_bounded aborted the test binary before the fix)
  • cargo fmt, cargo clippy --all-targets -D warnings
  • bashkit lib + integration tests pass locally
  • Threat model (knowledge + public), limitations, log updated

https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA


Generated by Claude Code

@chaliy chaliy self-assigned this Oct 7, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 7, 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 d42ae92 Commit Preview URL

Branch Preview URL
Oct 07 2026, 09:25 AM

@chaliy
chaliy force-pushed the claude/fidelity-shell-depth branch 4 times, most recently from 2621cfe to 21de703 Compare October 7, 2026 09:00
A script that re-runs itself through `sh` (`echo 'sh s.sh' > s.sh; sh
s.sh`) nested in-process interpreters until the process stack overflowed,
aborting every tenant in the process. Child shells now count against
max_function_depth and a dedicated cap of 8 (TM-DOS-125, L-PROC-004).

Claude-Session: https://claude.ai/code/session_019aFikmptPc91Fj4N2iDXQA
@chaliy
chaliy force-pushed the claude/fidelity-shell-depth branch from 21de703 to d42ae92 Compare October 7, 2026 09:24
@chaliy
chaliy merged commit 33ebb35 into main Oct 7, 2026
47 checks passed
@chaliy
chaliy deleted the claude/fidelity-shell-depth branch October 7, 2026 09:41
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.

1 participant