Skip to content

vm: flush every open file at interpreter teardown, as MRI does - #948

Merged
tannevaled merged 4 commits into
mainfrom
close-ios-at-shutdown
Nov 16, 2026
Merged

tannevaled merged 4 commits into
mainfrom
close-ios-at-shutdown

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Closes #643.

A Ruby program that writes a file and exits without closing it lost its data.
That is ordinary practice in a short script, and nothing reported it: the
program exited 0 and the file existed, empty.

file size
MRI 4.0.7 12 bytes — never closed is on disk
rbgo (before) 0 bytes — the write is gone

MRI closes every open IO at shutdown: ruby_cleanup runs rb_ec_teardown (the
at_exit handlers), then the object-space finalizer reaches each stream's
fptr_finalize, which fflushes it. runAtExit ran only the first half, so it
is now that teardown, in MRI's order — handlers, then the flush, which is
why a file an at_exit handler itself writes reaches disk too.

⛔ The ordering trap, which is why this takes every exit

"Close everything at the end" is right for exit, abort and falling off the
end, and wrong for exit!: rb_f_exit_bang calls _exit(2), which bypasses
the libc exit handlers and the finalizer alike, so MRI loses the buffer there. A
fix that flushed unconditionally would have handed exit! a flush MRI does not
perform — and the exit STATUS, which is what an exit test naturally asserts, is
identical either way.

Measured: the differential, 16 cases, 0 diverge

/opt/homebrew/opt/ruby/bin/ruby (MRI 4.0.7, +PRISM, arm64-darwin25) against
this branch's cmd/rbgo. Each case runs as its own process and the file is
read afterwards, because the question cannot be asked from inside: at the moment
an at_exit handler could read the file back, neither engine has flushed yet
(measured — both print "").

case MRI 4.0.7 rbgo
exit payload payload ✓
exit_status_3 payload payload ✓
abort payload payload ✓
falls_off_the_end payload payload ✓
at_exit_writes_too payload+handler payload+handler ✓
exit_bang empty empty ✓
process_exit_bang empty empty ✓
raise_uncaught payload payload ✓
File.new_w payload payload ✓
File.open_append payload payload ✓
File.open_r_plus AB23456789 AB23456789 ✓
IO.sysopen_for_fd payload payload ✓
IO#pwrite_r_plus AB23456789 AB23456789 ✓
IO#pwrite_on_r 0123456789 0123456789 ✓
two_streams_one_unclosed payload payload ✓
closed_then_rewritten written after the close written after the close ✓

On the first run of that differential, with the fix as first written, two
cases diverged. Both were real, and neither came from reading the call sites.

⛔ raise_uncaught — an uncaught exception is a program end too

Run returned the error having run no teardown, so not only the bytes but
the handlers were lost:

at_exit { puts "handler ran" }; puts "before"; raise "boom"
  MRI   exit 1, stdout "before\nhandler ran"
  rbgo  exit 1, stdout "before"

MRI reports the exception only after tearing down (ruby_cleanup:
rb_ec_teardown, then error_handle). Run now tears down on that path and
still returns the error — an uncaught exception is what happened, and the host
decides what to print.

⛔ IO.sysopen_for_fd — the fifth door, with four already wired

IO.for_fd — and IO.new(fd), and File.new(fd) — builds a second IOObj
over the descriptor, sharing the first one's path and buffer, and the program
writes through that one. Tracking IO.sysopen's own stream left the file empty
where MRI held payload. The fifth site is ioAdoptDescriptor, the chokepoint
all three reach.

This is a mechanism wired at only some of its doors again — three of six socket
open classes, one of two exit! spellings, the interpreter's missing safepoint.
TestEveryWayToGetAWritableFileFlushesAtShutdown now takes the doors one by one
in Ruby's own vocabulary, so a failure names the constructor rather than the
symptom.

⛔ A teardown flush must NOT raise — refuted by two existing tests

This was written the other way first: re-raise the first Errno, on the
reasoning that a silent teardown failure is worse than a loud one. TestIOForFd
and TestIOForFdModeCompat refuted it within the hour. ioFlush re-opens the
path
, having no descriptor, so

Dir.mktmpdir { |d| IO.for_fd(File.open(File.join(d, "f"), "w").fileno, "w").write("foo") }

gets ENOENT once the block has removed the directory, and a program that had
ended cleanly came back as Errno::ENOENT @ rb_sysopen. MRI ignores a failing
fflush at shutdown, and by then no rescue can run.

The cost is stated rather than hidden: such a stream loses its bytes, where MRI —
holding a descriptor to an unlinked file — would still write them. That is the
buffer-backed model's own limit (see IOObj), not a decision taken here.

Resource bound

The tracked set is the streams that can lose data: writable, path-backed, not
yet closed
. A read-only sweep over thousands of files retains nothing. Closed
entries are compacted out at the slice's growth point rather than untracked at
each of the five places that set IOObj.closed — one site to get right instead
of five, and the slice cannot outgrow the set of streams open at once by more
than one growth step. TestTrackOpenFileDropsClosedStreamsInsteadOfGrowing
opens and closes 64 streams and asserts at most 2 remain tracked.

What this does NOT claim

IO#pwrite is marked dirty and tracked, so its bytes survive. It is still not on
disk until a flush, where MRI's rb_io_pwrite calls pwrite(2) on the
descriptor and is on disk the moment it returns. That is recorded in the code as
a separate divergence of the buffer-backed model, not as something fixed here.

Refs #676, #941

🤖 Generated with Claude Code

tannevaled and others added 2 commits November 15, 2026 22:22
A Ruby program that writes a file and exits without closing it lost its
data. Measured against MRI 4.0.7, writing 12 bytes and never closing:

    MRI 4.0.7   12 bytes on disk
    rbgo         0 bytes

The program exited 0 and the file existed, empty, so nothing reported it.
This is ordinary practice in a short script.

MRI closes every open IO at shutdown — ruby_cleanup runs rb_ec_teardown
(the at_exit handlers), then the object-space finalizer reaches each
stream's fptr_finalize, which fflushes it. rbgo's runAtExit ran only the
first half. It is now that teardown, in MRI's order: handlers, then the
flush, so a file an at_exit handler itself writes reaches disk too.

⛔ The ordering trap. "Close everything at the end" is right for exit,
abort and falling off the end, and WRONG for exit!: rb_f_exit_bang calls
_exit(2), which bypasses the libc exit handlers and the finalizer alike,
so MRI loses the buffer there. Measured: exit leaves 12 bytes, exit!
leaves 0. runAtExit's exitImmediate return now drops the tracked streams
instead of flushing them, and the test takes all the exits rather than
the common one.

⛔ A second divergence, found by the differential rather than by reading:
an UNCAUGHT exception ran no teardown at all. MRI reports the exception
only after tearing down (ruby_cleanup: rb_ec_teardown, then
error_handle), so

    at_exit { puts "handler ran" }; puts "before"; raise "boom"
      MRI   exit 1, stdout "before\nhandler ran"
      rbgo  exit 1, stdout "before"

lost its handler and its bytes both. Run now tears down on that path too
and still returns the error.

⛔ And the door this mechanism was missing when first written with four:
IO.for_fd — and IO.new(fd), and File.new(fd) — builds a SECOND IOObj over
the descriptor, sharing the first one's path and buffer, and the program
writes through THAT one. Tracking IO.sysopen's own stream left the file
empty where MRI held "payload". The fifth site is ioAdoptDescriptor, the
chokepoint all three reach.

⛔ And a teardown flush must NOT RAISE. This was written the other way
first — re-raise the first Errno, because a silent teardown failure is
worse than a loud one — and TestIOForFd and TestIOForFdModeCompat refuted
it: ioFlush re-opens the path, having no descriptor, so

    Dir.mktmpdir { |d| IO.for_fd(File.open(File.join(d,"f"),"w").fileno,"w").write("foo") }

gets ENOENT once the block has removed the directory, and a program that
had ended cleanly came back as Errno::ENOENT @ rb_sysopen. MRI ignores a
failing fflush at shutdown, and by then no rescue can run. The cost is
stated rather than hidden: such a stream loses its bytes, where MRI —
holding a descriptor to an unlinked file — would still write them. That
is the buffer-backed model's limit, not a decision taken here.

The tracked set is the streams that can lose data: writable, path-backed,
not yet closed. A read-only sweep over thousands of files retains nothing.
Closed entries are compacted out at the slice's growth point rather than
untracked at each of the five places that set IOObj.closed — one site to
get right instead of five, and the slice cannot outgrow the set of streams
open at once.

Measured with the differential in rbgo-643-oracle: 16 cases, 0 diverge.

Closes #643
Refs #676, #941

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The flush closes #643, so the table needs no row for "an unclosed file
loses its data". It needs the two things that are STILL true and were
measured against MRI 4.0.7 while fixing it, both the same root as the
`File#stat` row above them — rbgo's streams are buffered by path and hold
no descriptor:

  - `IO#pwrite` puts its bytes in the buffer, not on disk. MRI's
    rb_io_pwrite calls pwrite(2) and is on disk the moment it returns.
    The bytes are no longer lost, only late.
  - a file whose directory is removed before the program ends loses its
    bytes, because teardown re-opens the path to flush it and gets
    ENOENT. MRI writes through its descriptor to the unlinked file.
    Teardown reports nothing, as MRI's shutdown ignores a failing fflush.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…own ENOENT one

Both rows were added without a tracker reference, which is the one thing
every other row in that table carries. #949 is the pwrite/pread
immediacy, filed with the measurement; the ENOENT-at-teardown row has no
issue of its own because it is the same root as #635 — streams buffered
by path, holding no descriptor — and now says so.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ught

CI was red on NINE lanes for two causes, both mine.

⛔ 1. `undefined: runSrcErr` — seven lanes, including every "compile on
every target" one. The helper lives behind `//go:build !windows && !wasm`,
so the test compiled on darwin and broke wasip1, js, windows and the
windows test lane's vet.

THE ANSWER WAS ALREADY WRITTEN, WITH ITS WHY, IN A SIBLING FILE:
runKeepingError (alloc_bounds_internal_test.go:20) is the same function
without the constraint, and its comment says exactly this —

    runSrcErr does the same but lives behind
    `//go:build !windows && !wasm`, and these tests must compile on every
    lane — CI vets the test binary for GOOS=wasip1 and GOOS=js.

I reached for the first helper I had seen rather than the one whose
comment answers the question. The cheap local gate is three commands:
GOOS=windows / GOOS=wasip1 / GOOS=js `go vet ./internal/vm/`, all three
clean now.

⛔ 2. The coverage ratchet, on macOS AND ubuntu: flushOneAtTeardown
83.3%, "was fully covered". The untested branch is the one that matters
most — a Ruby error is swallowed at teardown, a GO FAULT IS NOT. The
repository draws that line deliberately in callNative: a fault caused by
Ruby input becomes a rescuable exception so a host cannot be crashed by a
program it ran, while a broken VM invariant stays loud instead of being
laundered into something a host would log and move past.

TestATeardownFlushSwallowsARubyErrorButNotAGoFault asserts it, with the
fault synthesised because no real flush produces one: ioFlush raises
Errno, which is the other branch. flushOneAtTeardown, flushOpenFiles and
trackOpenFile all measure 100.0% now.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit f826070 into main Nov 16, 2026
26 checks passed
@tannevaled
tannevaled deleted the close-ios-at-shutdown branch November 16, 2026 00:14
tannevaled added a commit that referenced this pull request Nov 16, 2026
#951)

* vm: derive the `open` doors instead of listing them, and wire the fourth

`Klass.open { |x| … }` yields, closes however the block leaves, and
answers with the BLOCK's value. `smethods["open"] = smethods["new"]`
gives none of that — `new` has no block parameter, so the block is
discarded in silence and the call still looks like it worked. That one
line cost #916 its 27 hung library/net-http files.

⛔ AND THE LIST OF DOORS IS WHAT KEPT DRIFTING. #931 wrote the socket
doors out in prose and the prose had already lost UNIXServer; #939
re-derived them from the source, fixed three, and found a FOURTH nobody
had written down — Resolv::DNS, outside the socket family — which it
filed rather than fixed. A hand-written list of doors is the same
artefact as any other hand-written list.

So TestEveryOpenDoorIsAccountedFor holds none. It parses the package with
go/ast, on EVERY platform (go/parser ignores build tags, which is how the
windows-only UNIX doors get counted — the prose list missed UNIXServer in
exactly such a file), finds all 18 `smethods["open"]` assignments, and
compares them to testdata/open-doors.txt BOTH WAYS: a door missing from
the table fails, and a row for a door that no longer exists fails too.

The ALIAS form is refused outright, because no configuration of it can be
correct. Mutation control: putting the alias back prints
`⛔ 1 open door(s) are an ALIAS … resolv.go:dns`, naming file and
receiver. TestTheOpenDoorClassifierTellsTheShapesApart feeds the four
shapes to the classifier directly — without it every assertion would
pass against a classifier that answered "block helper" for everything.

## The fourth door, measured against MRI 4.0.7

    Resolv::DNS.open { |dns| :from_block }
      MRI   yields, returns :from_block
      rbgo  did NOT yield, returned #<Resolv::DNS…>
    Resolv::DNS#close
      MRI   nil, and a second close is fine
      rbgo  NotImplementedError, both times

Both halves are ONE fix: socketOpenWithBlock closes through the class's
own #close, so leaving #close on the NotImplementedError list would have
turned every `Resolv::DNS.open { … }` into a NotImplementedError raised
from the ensure — a block that now runs, and a program that now fails.
Same trap as #948's teardown flush.

⛔ And #close takes NO arguments. The pre-existing TestResolvDNS asserted
that `close("x")` raises, and it did — with NotImplementedError, which is
the right verdict for the wrong reason: the stub raised for every call,
so the test could not tell "close rejects an argument" from "close does
nothing at all". A no-op close turned it red, which is the test finally
asking its own question. MRI 4.0.7: ArgumentError "wrong number of
arguments (given 1, expected 0)", arity 0, `close` → nil. `close` comes
off that loop's hand-written list (which mirrored the production one) and
is asserted on its MESSAGE and its arity instead.

rubydiff against MRI 4.0.7 now AGREES on both witnesses — stdout, stderr
and exit status — where it diverged on three rows before.

## What the derivation exposed: #950

Two doors take a block and discard it: Augeas.open (augeas.go:71, shared
with Augeas.create) and Images::Image.open (images.go:93), both `_ *Proc`.
The other seven inline handlers were read one by one and all honour
theirs (File, IO, StringIO, Dir, Net::FTP, SQLite3::Database, bbolt).

NOT measured, and it is the whole decision: whether the reference gems
accept a block at all. Neither is installed here. Images::Image.open may
be CORRECT — ruby-vips and MiniMagick spell this without a block. Listed
in the table as unverified, with #950 carrying the command that settles
it, so two doors are countable rather than quiet.

⚠ There is no issue to close for the fourth door. "#939 filed it" — which
is what its own text and the recurrence ledger both say — meant RECORDED
IN PROSE, inside #939: `gh issue list --search "Resolv in:title"` over
every state answers `[]`. A door named only in a merged pull request's
body is as findable as one named nowhere, which is the same lesson as the
prose list it was found by.

Refs #931, #916, #939, #950, #948

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* testdata: the Augeas reference was READ, so the row may not say 'recalled'

The table said ruby-augeas is 'BELIEVED to yield and close, but that is
recalled and not read'. It has now been read, so that sentence was the
exact shape it warns against — a dated claim left standing in a file
whose only job is to be honest about what is verified.

ruby-augeas lib/augeas.rb:

    def self.open(root = nil, loadpath = nil, flags = NONE, &block)
        aug = open3(root, loadpath, flags)
        if block_given?
            begin
                rv = yield aug
                return rv
            ensure
                aug.close
            end
        else
            return aug
        end
    end

Same parameters as rbgo's, and exactly socketOpenWithBlock's contract.
So Augeas.open is a CONFIRMED defect, not an open question.

Still not fixed here, and the reason is new: rbgo's Augeas has no #close
AT ALL (git grep close internal/vm/augeas.go is empty), so the helper
would yield without closing and aug.close in Ruby is a NoMethodError.
Adding #close means reading go-augeas's handle API, which is its own
change.

Images::Image.open moves the other way: go-ruby-images' README documents
no Ruby Image.open and no block form at all, only the Go-level
images.Open(path). It is UNSPECIFIED, not a known defect, and the two
rows no longer read as if they were in the same state.

Refs #950

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
tannevaled added a commit that referenced this pull request Nov 16, 2026
CI: `internal/vm/augeas.go registerAugeas 94.4% (was fully covered)`.
The uncovered branch is Augeas.open's arity guard — the gem's open takes
three positional arguments, a fourth is an ArgumentError, and I wrote
the guard and never executed it. create's two-argument case was tested;
open's four-argument case was not, and they are different functions now.

⛔⛔ SECOND TIME IN ONE SESSION. #948 came back on
`flushOneAtTeardown 83.3%`; this is `registerAugeas 94.4%`. 49 and 64
minutes of CI for a branch I had just written.

And it is neither a missing tool nor a missing note.
scripts/coverage/README.md gives the exact recipe — `covratchet -profile
<x>.func -require <names>`, which REFUSES a name that matched nothing
and prints its denominator — and states its own reason for existing:

    It exists because the ratchet, correct as it is, only refuses AFTER
    the spend. […] A gate that refuses after the spend teaches the
    lesson; one that refuses before it prevents the mistake.

I ran gofmt, `buildscan --vet` and the full suite. NONE of the three
answers "are the functions this commit claims to cover actually at
100%". Taken now, before pushing:

    required 7 function(s), matched 7 record(s) in a profile of 7627
    all required functions at 100%

(registerAugeas, registerAugeasMethods, augCreateOpts, augInterp, plus
#948's trackOpenFile, flushOpenFiles, flushOneAtTeardown.)

⛔ Two things that measurement taught, both worth writing down:

  - `-require compareOpenDoors` matched NOTHING and the tool refused
    rather than reporting clean. Correct: it is defined in a _test.go
    file, so it is not in any profile. My -require list was wrong, not
    the code — which is the failure mode the tool was built to name.
  - the FULL `-record` comparison against BELOW100.macos-latest reported
    87 functions "newly below 100%" from this profile. That is not a
    finding: the profile is `./internal/vm/` only, while the record is
    kept by a lane running `./...`, so compiler and bytecode coverage is
    absent by construction. Judge and subject must count alike. For a
    selective profile the `-require` form is the valid question, exactly
    as that README says.

Refs #948, #950

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tannevaled added a commit that referenced this pull request Nov 16, 2026
…agreed (#953)

"### What does not work yet" opens by saying what every entry under it was
measured against:

    Every entry below was re-checked on `fc8ca1a` (darwin/arm64, 2026-10-08)
    by running it against **MRI 4.0.7 on the same host**.

and forty-six lines later its table said:

    | | how it differs from MRI 4.0.5 |

4.0.5 was an EARLIER campaign's oracle. The section was re-measured against
4.0.7 and the sentence was updated; the header was not. rbgo itself now
reports 4.0.9, so the header named a version matching neither the
measurement nor the runtime.

⛔ And it was not harmless. Two rows added under that header yesterday
(#948) inherited the wrong oracle, and I repeated "MRI 4.0.5" from it in
that PR's text without noticing. A header is read as the column's
definition.

⛔ WHY NO GATE SAW IT. TestReadmeRubyVersionMatchesTheRuntime checks the
version the runtime REPORTS, against kernel_introspect.go, in both
directions, with an exemption for historical lines. This header is a
DIFFERENT claim — the version rbgo was COMPARED WITH — and nothing read
it. A document can hold two version claims that are each individually
plausible and still contradict each other; only reading both and
comparing them catches that, and both facts are in the file, so the gate
needs no runtime and no network.

TestTheDivergenceTableNamesTheSectionsOwnOracle does that. It finds the
section, takes the version from its "re-checked … against **MRI x.y.z"
sentence and the version from each "differs from MRI x.y.z" table header,
and requires them equal. A table header is not prose and gets no
historical exemption: the rows under it are claims about the code as it
is now.

⛔⛔ THE FIRST VERSION OF THAT GATE READ LINE BY LINE AND FOUND NOTHING.
The sentence is wrapped at 80 columns, so "re-checked" is on one line and
"against **MRI 4.0.7" on the next. It reported the absence and failed
ONLY because "neither side found" is a failure in this test rather than
nothing to report. Written the ordinary way it would have gone green on
the very defect it exists for. The match is over the joined section text
now, with the line number computed from the offset.

Also: the row citing #799 now says that issue is CLOSED (2026-11-02). It
is cited for "the list of what each of the 27 needs" — the move is done,
the 27 are not, and a reader following a closed link should not expect
otherwise. A closed issue is not finished work.

The section's other 4.0.5 mentions are left alone on purpose: README.md
lines 156-159 state that rows are "left as they were measured rather than
rewritten", and those are other campaigns' oracles, not this table's.

Measured:
  - the gate was run BEFORE the fix and named the defect at README.md:872
    against README.md:826; it passes after, logging "section
    README.md:823..885 measured against MRI 4.0.7; 1 table header(s)
    checked";
  - the two existing README gates still pass, with their denominators: 2
    present-tense version claims against 4.0.9 plus 2 exempt, and 7
    cross-references, 0 dangling;
  - gofmt clean; buildscan --vet: "go vet passed under all 19".

Refs #799, #948

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
tannevaled added a commit that referenced this pull request Nov 16, 2026
* vm(augeas): #close, the block form, and create's real signature

#950's row in testdata/open-doors.txt said Augeas.open's discarded block
could not be fixed because "rbgo's Augeas has no #close method at all, so
the helper would yield without closing", and go-ruby-augeas's handle
exposes no Close either.

⛔ THAT WAS THE WRONG LAYER. The gem's #close frees a C handle, but what
it makes OBSERVABLE is two things, and neither needs anything from the
dependency:

    VALUE augeas_close (VALUE s) {
        augeas *aug = aug_handle(s);
        aug_close(aug);
        DATA_PTR(s) = NULL;
        return Qnil;
    }

    /* aug_handle, which EVERY method calls first */
    if (aug == NULL) {
        rb_raise(rb_eSystemCallError, "Failed to retrieve connection");
    }

It answers nil, and afterwards every method raises — including a second
#close, because aug_handle runs before aug_close. That is a flag plus a
guard. I asked what #close FREES; the question was what it makes
observable.

The guard goes in augeas_bind.go's `self` accessor, which all seventeen
instance methods already go through and nothing else does — the one-door
shape #951 had to derive with a parser because `open` had five.

Reading the reference properly also turned up a divergence nobody had
filed: `create` and `open` were THE SAME positional native, and in the
gem they are not the same function at all.

    lib/augeas.rb:  def self.open(root = nil, loadpath = nil, flags = NONE, &block)
    lib/augeas.rb:  def self.create(opts={}, &block)   -> Augeas::Facade::create

create takes an OPTIONS HASH. Three things about facade.rb's single
`opts.each_key` pass are reproduced because each is what a tidier
reimplementation gets wrong:

  - a flag is armed by its KEY'S PRESENCE, never its value, so
    create(type_check: false) sets TYPE_CHECK;
  - :root and :loadpath are excluded by the final elsif's own condition,
    not removed from the hash;
  - validation and assembly share ONE pass, so the FIRST offending key
    raises. create(save_mode: :bogus, nonsense: 1) says "Invalid save
    mode bogus." and the same two keys the other way round say "Unknown
    argument nonsense." Both orders are asserted, because agreeing with
    one of them is not agreeing with the gem.

⛔ BREAKING for this binding: Augeas.create("/root", "/lens", 5) was
accepted and is now a TypeError. Below v1 that is a MINOR bump.

⛔⛔ AND THE RATCHET I LANDED YESTERDAY WAS BLIND TO ITS OWN SUBJECT.
TestEveryOpenDoorIsAccountedFor marked every derived door `seen`,
block-helper ones included, then called a table row stale only when no
door carried its key. So it asked "does this door still exist?" when the
question is "does this door still NEED a row?". Augeas.open went from an
inline block-discarding handler to socketOpenWithBlock and the test
stayed GREEN with the row still reading "⛔ CONFIRMED DEFECT" about it: a
gate that cannot see the repair it exists to ask for goes on publishing a
defect that is gone — the same artefact #931's prose was, in the other
direction.

It was not found by re-reading the test. It was found by changing the
code the gate watches and noticing THE GATE DID NOT MOVE. The verdict is
now compareOpenDoors, a pure function with its own control
(TestTheDoorTableComparisonFailsInBothDirections, 7 cases) because the
live package can only ever show the comparison AGREEING. Confirmed by
hand too: re-adding the row makes the live test red and names the fix.

Measured, not recalled:

  - the gem's lib/augeas.rb, lib/augeas/facade.rb and
    ext/augeas/_augeas.c were READ. There is no oracle to run here: the
    augeas gem is a C extension over libaugeas and is not installed, so
    the reference is the source, quoted in the code.
  - TestEveryMethodOfAClosedAugeasRaises derives the method population
    from Augeas.instance_methods(false) (18) rather than listing it, so a
    method added later that reaches the handle another way is in the test
    the day it exists.
  - the flag arithmetic is asserted as NUMBERS, not re-derived from the
    constants the code uses. It earned that immediately: [2, 8, 16] was
    written from memory for the three save modes, the test went red, and
    the source settled it against the test — SaveBackup 1<<0,
    SaveNewFile 1<<1, SaveNoop 1<<4, which is augeas.h's AUG_* order.
  - gofmt clean; buildscan --vet: "go vet passed under all 19".

Refs #950, #951, #931

#950 stays OPEN: this is its Augeas half. Images::Image.open still
discards its block, and that half is not a known defect — go-ruby-images
documents no Ruby Image.open and no block form at all, so what it needs
is a reference, not a patch. #951 is merged; it is named here because its
ratchet is what this change repairs. #931 is untouched.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* test(augeas): cover open's own arity guard, which the ratchet caught

CI: `internal/vm/augeas.go registerAugeas 94.4% (was fully covered)`.
The uncovered branch is Augeas.open's arity guard — the gem's open takes
three positional arguments, a fourth is an ArgumentError, and I wrote
the guard and never executed it. create's two-argument case was tested;
open's four-argument case was not, and they are different functions now.

⛔⛔ SECOND TIME IN ONE SESSION. #948 came back on
`flushOneAtTeardown 83.3%`; this is `registerAugeas 94.4%`. 49 and 64
minutes of CI for a branch I had just written.

And it is neither a missing tool nor a missing note.
scripts/coverage/README.md gives the exact recipe — `covratchet -profile
<x>.func -require <names>`, which REFUSES a name that matched nothing
and prints its denominator — and states its own reason for existing:

    It exists because the ratchet, correct as it is, only refuses AFTER
    the spend. […] A gate that refuses after the spend teaches the
    lesson; one that refuses before it prevents the mistake.

I ran gofmt, `buildscan --vet` and the full suite. NONE of the three
answers "are the functions this commit claims to cover actually at
100%". Taken now, before pushing:

    required 7 function(s), matched 7 record(s) in a profile of 7627
    all required functions at 100%

(registerAugeas, registerAugeasMethods, augCreateOpts, augInterp, plus
#948's trackOpenFile, flushOpenFiles, flushOneAtTeardown.)

⛔ Two things that measurement taught, both worth writing down:

  - `-require compareOpenDoors` matched NOTHING and the tool refused
    rather than reporting clean. Correct: it is defined in a _test.go
    file, so it is not in any profile. My -require list was wrong, not
    the code — which is the failure mode the tool was built to name.
  - the FULL `-record` comparison against BELOW100.macos-latest reported
    87 functions "newly below 100%" from this profile. That is not a
    finding: the profile is `./internal/vm/` only, while the record is
    kept by a lane running `./...`, so compiler and bytecode coverage is
    absent by construction. Judge and subject must count alike. For a
    selective profile the `-require` form is the valid question, exactly
    as that README says.

Refs #948, #950

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
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.

The VM closes no IO at interpreter shutdown, where MRI closes every one

1 participant