Repository navigation
Description
rbgo -e 'exit 3' exits 0, where MRI exits 3. Every spelling of a
deliberate non-zero exit is lost, so rbgo cannot signal failure to a shell,
a Makefile or a CI step.
Measured against MRI 4.0.5 (ruby 4.0.5 (2026-05-20) +PRISM [arm64-darwin25])
on the branch of #675:
| program | MRI status | rbgo status |
|---|---|---|
exit 3 |
3 | 0 |
exit false |
1 | 0 |
exit!(4) |
4 | 0 |
abort "boom" |
1 | 0 |
raise "x" |
1 | 1 (correct) |
exit 0 |
0 | 0 (correct) |
Process.exit(5) |
5 | 1, NoMethodError (see below) |
Process.exit!(6) |
6 | 1, NoMethodError (see below) |
The VM half is already correct — only the front-end's last step is missing
This is not a SystemExit implementation gap. Everything inside the VM behaves
as MRI does:
$ rbgo -e 'begin; exit 3; rescue SystemExit => e; puts "status=#{e.status} success=#{e.success?}"; end'
status=3 success=false # identical to MRI
$ rbgo -e 'at_exit { puts "atexit ran" }; exit 3'
atexit ran # identical to MRI; only the status differs
$ rbgo -e 'begin; exit 3; ensure; puts "ensure ran"; end'
ensure ran # identical to MRI; only the status differs
SystemExit is raised, carries the right status and success?, is rescuable,
and at_exit and ensure both run. The defect is at exactly one boundary: the
CLI never translates a terminal SystemExit into the process's exit code. MRI
does this in main() → ruby_run_node → ruby_cleanup, which calls
error_handle and returns ex from the SystemExit's status
(eval.c/ruby.c, tag v3_4_0).
abort follows from the same cause: rb_f_abort raises SystemExit with
status 1 (process.c).
Second, separate defect: Process.exit is private
MRI declares exit, exit! and abort as module functions on Process
(Init_process: rb_define_module_function(rb_mProcess, "exit", ...)), so
Process.exit(5) is public. rbgo only has the private Kernel copies, so the
qualified spelling raises NoMethodError. Worth fixing together, but it is a
different cause from the status loss.
What this does NOT affect
The ruby/spec ratchet is unaffected: scripts/conformance/rubyspec/run.sh
scores each file by parsing the RBGO_RESULT pass=… fail=… line the shim
prints, not by reading the child's exit status. I checked this before filing,
because a harness that read the status would have been scoring every file as a
success. Every conformance total measured so far stands.
Found while verifying which stream Kernel#abort's message reaches, in #667.
Activity
tannevaled commentedon Sep 26, 2026
Correction to this issue's central claim, which was mine and was wrong.
I wrote: "This is not a
SystemExitimplementation gap. Everything inside the VMbehaves as MRI does … The defect is at exactly one boundary: the CLI never
translates a terminal
SystemExitinto the process's exit code."That localisation is false.
internal/vm/vm.go:1131deliberately discards it,and says so:
So no front-end change alone could have fixed it. The status was never handed out
of the VM to be translated.
Why I got it wrong, since the reasoning error is the reusable part. I probed
what Ruby code can observe:
rescue SystemExitsees the right status,at_exitruns,
ensureruns. All three are true. I inferred "everything inside is correct,therefore only the last step outside is missing" — and that does not follow. Those
probes establish that the exception is raised and unwinds correctly; they say
nothing about whether its value survives the VM's own boundary. Observability
from inside the language is not evidence about where a value is dropped on the way
out.
The comment above is also worth reading as its own lesson: the discard was a
correct decision for the problem it was written for (a CLI ending in
exitshouldnot print a backtrace) and became wrong when the exit status started to matter.
The premise moved; the code did not.
Fixed in #693, which had to touch
vm.gofor exactly this reason and flagged it asoutside its granted file set.
Two further corrections from that work, both to figures in this issue's neighbour
#691:
quoted from three runs;
Process.exitbeing private was right, and the fix makes all nine spellingsbyte-identical to MRI 4.0.5 across 20 runs each.
signal+exit: a self-directed signal becomes a Ruby exception, and a d…
tannevaled commentedon Nov 15, 2026
Refuted as written —
exit 3reaches the process. But a different divergence lives in the same family.Measured 2026-11-15 through
cmd/oracleagainst MRI 4.0.7, rbgo built frommain. The oracle reports the exit status as a number, which is this issue'swhole question.
The three forms that agree
puts "start"; exit 3at_exitrunsabort "aborted"at_exitrunsexit falseat_exitrunsAnd directly on the form the title names:
So "rbgo -e 'exit 3' exits 0" does not reproduce. I cannot say when it stopped
reproducing — this is a measurement of the present, not a bisect — so this is a
candidate for closing as not reproducible rather than as completed.
⛔
exit!does diverge, and it is a different defectstart)exit!skipsat_exitin both — correct. The difference is that MRI discardsthe buffered stdout and rbgo flushes it.
⭐ Verified rather than assumed: adding
$stdout.sync = truemakes both printstartand agree byte for byte. That rules out an ordering difference andisolates the flush — rbgo writes what MRI throws away.
rbgo is the "nicer" of the two here and that is exactly why it is wrong:
exit!'s whole purpose is leaving without flushing, which is why it is what aforked child calls. The consequences inside a forked block are measured on #774,
because they belong to
forkrather than to the exit status this issue is about.What a fix would need to hold
exit!leaves without flushing$stdout/$stderr.exit,abortandexit falsekeep flushing and keep runningat_exit—all three are correct today and a change to the exit path must not move them.
$stdout.syncfalse (the default for a pipe):with sync on, the two engines agree and the test would pass either way. That
is the property that makes this easy to "fix" invisibly.
Refs #774, #941
🤖 Generated with Claude Code
tannevaled commentedon Nov 15, 2026
⛔ Correction to my comment above: the diagnosis was wrong, and so was the "verification" I offered for it
I wrote that MRI discards buffered stdout at
exit!and rbgo flushesit, and offered this as proof:
Both halves are wrong. Read in the source:
rbgo does not buffer stdout at all.
os.Stdoutis passed straight through,and
interp.go'sswitchWriter.Writeis a one-line pass-through. Everyputsreaches the file descriptor as it is called.
So there is no buffer for
exit!to discard, and "rbgo flushes where MRIdiscards" describes a mechanism rbgo does not have.
⛔ And the verification was a proxy where two errors cancelled
With
$stdout.sync = truethe two engines agreed — for different reasons:startsyncmade the write immediate, so it was already outsyncchanged nothingAgreement produced by two different mechanisms is not evidence about either.
I presented it as isolating the flush, and it could not have: setting
syncisa no-op in rbgo, so that experiment had no treatment arm on the rbgo side.
What the defect actually is
The flag agrees with MRI and the behaviour does not: rbgo answers
falsewhile writing through. So the real divergence is one layer down from where I put
it, and the
exit!difference is a symptom of it rather than a defect of itsown.
That changes the fix from "do not flush on
exit!" to a choice:$stdoutas MRI does when it is not a tty, and letsync,flush,exit!and a hard kill all mean what they mean in MRI. This is thefaithful option and the largest: it puts a buffer in front of every write and
makes several other behaviours (interleaving with
$stderr, output orderingacross a
systemcall, what survives a crash) depend on getting it right.synchonestly — answertrue, since that is what the writesdo — and accept that
$stdout.sync = falsecannot be honoured. Cheap, and itstops the flag lying, but it diverges from MRI's default value, which a spec
may assert.
I am not choosing between them: option 1 touches output ordering everywhere and
option 2 publishes a different default than MRI's. Both are maintainer calls.
What stands from the comment above
The three agreements and the refutation are unaffected — they are exit statuses
and
at_exit, measured directly:exit 3,abort,exit false: byte for byte with MRI. This issue astitled does not reproduce.
exit!output difference is real as an OBSERVATION; only my explanationof it was wrong.
And the
Process.exit!finding below is unaffected and is a separate, cleandefect.
🤖 Generated with Claude Code
vm: Process.exit! skips at_exit, as Kernel#exit! already did (#947)
vm: flush every open file at interpreter teardown, as MRI does (#948)