Skip to content

fix: return an error instead of panicking when the frame stack empties#52

Open
jtippett wants to merge 1 commit into
TheUncharted:masterfrom
jtippett:fix/vm-empty-frame-panic
Open

fix: return an error instead of panicking when the frame stack empties#52
jtippett wants to merge 1 commit into
TheUncharted:masterfrom
jtippett:fix/vm-empty-frame-panic

Conversation

@jtippett

@jtippett jtippett commented Jul 9, 2026

Copy link
Copy Markdown

Summary

A guest input that empties the VM frame stack panics execute() (frames.last().unwrap()), aborting the whole host process. For an interpreter whose purpose is running untrusted, agent-generated code, guest input should never be able to take down the host. The VM now returns a RuntimeError to the caller instead.

Two minimal reproductions (both abort the process on current master):

// a throw escaping a nested array callback
try { [1].map(a => [2].map(b => { throw "n"; })); } catch (e) {}
// a throw escaping a callback inside a class method
class A { run() { return [1].map(x => { throw "m"; }); } }
try { new A().run(); } catch (e) {}

Note: with this fix the run surfaces RuntimeError("no active call frame") rather than the guest catch observing the throw — the frame-unwinding accounting for callback frames looks like a separate, pre-existing issue (happy to file it with details). This PR only removes the process abort.

Changes

  • The three frames.last().unwrap() dispatch sites return a RuntimeError on an empty frame stack instead of panicking.
  • Two regression tests in tests/error_handling.rs, verified to abort the process without the fix.

Test plan

  • Unit tests pass (cargo test)
  • make lint clean (fmt + clippy -D warnings)
  • New regression tests fail (abort) on master, pass with the fix
  • TC39 Test262 sweep (~48k inputs): zero panics after this change; previously aborted on the first such input
  • CI passes

Related issues

None open — found while running Test262 against the VM. We run this patch in production via ex_zapcode (Elixir bindings pinned to a zapcode-core fork).

execute() called frames.last().unwrap(), so guest input that emptied the
frame stack aborted the whole host process. It now surfaces a RuntimeError
to the caller. Running the TC39 Test262 suite (~48k inputs) went from
aborting on the first such input to zero panics.
@jtippett
jtippett requested a review from TheUncharted as a code owner July 9, 2026 09:28
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@jtippett, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5e057fc1-7ded-4b65-a6c4-80fe0677eb5f

📥 Commits

Reviewing files that changed from the base of the PR and between ebc06fd and 28edb17.

📒 Files selected for processing (2)
  • crates/zapcode-core/src/vm/mod.rs
  • crates/zapcode-core/tests/error_handling.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@TheUncharted

Copy link
Copy Markdown
Owner

Hello @jtippett
Thanks for the PRs you created I will look this week end :)

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