Skip to content

The Method-copy check compares the second half with the first - #394

Merged
284km merged 4 commits into
mainfrom
method-copy-check-halves
Nov 28, 2026
Merged

284km merged 4 commits into
mainfrom
method-copy-check-halves

Conversation

@284km

@284km 284km commented Nov 28, 2026

Copy link
Copy Markdown
Owner

tools/method_copy_memory_check.py makes 1,000 classes in each batch, gives each of them 20 Method copies, lets them go, collects, and samples RSS. It held max(every batch) / batch 0 to 2.0, core_assertions.rb's leak bound.

On Linux in CI that ratio varied from 1.61 to 2.14 with no leak:

Why it varied

Every sample of five runs on Linux (arm64, in docker, main 491cc5c), in MB. All ten runs had the same shape:

evaluator  92 108 102 112 123 134 141 149 159 174 142 149 164 139 143 150 159 137 144 150 169
VM         74  88  92  99 109 119 123 135 140 119 132 124 131 139 148 119 126 132 143 120 126
ruby       14  14  14  14  14  14  14  14  14  14  14  14  14  14  14  14  14  14  14  14  14
  • RSS climbs for about eight batches and then saws between 120 and 175 MB, without growing.
  • Batch 0 is taken after one warm-up batch, below that climb. So the ratio counted the climb and wherever the highest tooth fell: 1.64 to 1.75 on the evaluator, and 1.90 to 2.42 on the VM.

MERE_RUBY_GC_TIGHT=1 did not steady it. It lowered batch 0 from 95 MB to 80 MB, and the ratio rose to 1.97 to 2.07. The program draws no random numbers, so there is no seed to fix.

The change

  • 30 batches.
  • The peak of batches 21 to 30 is divided by the peak of batches 6 to 15. A leak grows from one half to the other, while the climb and the sawing do not.
  • The median of three runs is taken.
  • The limit is 1.3, where it was 2.0. The limit is on a different ratio now, and 1.3 is where the numbers below put it.
  • --leak-every N keeps every Nth class in a global Array. It is a negative control: the check must fail with it. It does not run in CI.

One run of the check, both sides, takes 25 s on Linux, where it took about 6.

Numbers

Linux (arm64, docker), main 491cc5c, the check itself:

mere: three runs mere: median growth per batch ruby: median
no leak 1.022, 1.153, 1.035 1.035 (passes) 1.1 to 1.2 MB 1.000
--leak-every 10 1.345, 1.337, 1.339 1.339 (fails) 3.2 to 3.3 MB 1.267
--leak-every 5 1.465, 1.411, 1.462 1.462 (fails) 5.3 to 5.4 MB 1.342

So a leak of 3.2 MB a batch fails it, close to the limit. One of 5.3 MB fails it with room to spare.

The growth with no leak (1.1 MB a batch, batch 1 to batch 30) is the climb of the first batches, not a slope. The second half's peak stays at the first half's.

Before the change, with the same program over 30 batches and no leak, three runs on each engine gave the ratio of halves:

  • evaluator: 0.989, 0.996, 1.012;
  • VM: 0.953, 0.966, 1.030.

The VM

CI runs this check on the evaluator only, and it still does.

On the VM the new ratio was 0.95 to 1.03 with no leak, and 1.33 to 1.49 with a leak. Its earlier five runs over 20 batches gave a ratio of halves (16-20 / 6-10) of 1.02 to 1.26.

The VM's Method copies, left for later. The VM's RSS over these batches is below the evaluator's, but it saws further. By the old ratio it is over 2.0 on main as well: 2.13 to 2.42 over five runs. Nothing here says that it leaks. Its ratio of halves over 30 batches is about 1.0. But one run of five reached 175 MB at batch 16 from 148 at batch 13. Looking at that is not part of this change.

Checked

  • The check and its two negative controls on Linux, as above.
  • --leak-every 5 and --leak-every 10 exit 1. No leak exits 0.

The record is loop/2026-11-28-method-copy-check-halves.md. .github/workflows is not touched.

🤖 Generated with Claude Code

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 0a02e142 (tool + record only; ci.yml and its invocation are unchanged).

The change is sound and I have no Critical/Major/Minor findings.

  • The new metric (peak of batches 21–30 over peak of batches 6–15, median of three) removes exactly the two things the samples in the body show were moving the old ratio: the climb of the first ~8 batches and the position of the highest saw tooth. The old "max over all batches / batch 0" could not separate those from growth.
  • Failure handling stays strict: any run that exits non-zero, hits the outer RSS/wall limit, or is incomplete leaves median as None, so the side is unhealthy. A fast leak that reaches RSS_KB therefore still fails.
  • The negative control is the right evidence that the bound is not vacuous: --leak-every 10 (≈3.3 MB/batch) fails at 1.339 and --leak-every 5 (≈5.4 MB/batch) at 1.462, against 1.035 without a leak.

Suggestions (non-blocking):

  1. The margin at --leak-every 10 is thin (1.339 vs 1.3). The body already states the 5.4 MB/batch row as the size that reliably fails; it may be worth saying the same in the docstring, so a later reader does not read "3 MB a batch must fail" as a guarantee.
  2. The no-leak row shows mere still growing about 1.1–1.2 MB per batch while ruby is flat. It stays under the bound, but it looks like a small real per-batch retention rather than noise; worth a line in the loop record as something to look at later, together with the VM numbers.
  3. Worst case is now 6 × WALL (600 s) per job instead of 2 ×. Normal runs are 25 s, so this only matters when something hangs; fine as is, just noting it.

… with no leak and the worst time are in the record

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head c20b0c2 against current main/base 856e61b, the earlier review and the current consumers. The updated explanation appropriately distinguishes the observed negative-control margin and possible residual retention. The new driver fails closed for truncated observations, missing completion markers, nonzero exits, resource-limit events and a zero first-window peak. However, two Major/P2 integration regressions remain: existing result consumers cannot read the new JSON, and diagnostic consumers import a workload that no longer satisfies their locked-input contracts (inline).

Independent validation used the actual base/head driver main functions with controlled supervisor transcripts, not real memory measurements. A healthy base transcript is accepted by the current compiler-comparison consumer; a healthy head result instead raises KeyError for samples_kb/post_gc_peak_to_initial and has incompatible bounds. Six head rejection controls (growth above 1.3, truncation, nonzero exit, resource limit, missing marker, zero denominator) all exit 1. The supervisor calls retain the original 600-second/2-GiB outer limits. The imported program's hash and diagnostic-prefix checks match on main and fail on head. No interpreter build or actual Linux/macOS RSS/negative-control rerun is claimed.

Hosted compiler-comparison and build/test jobs are still running or queued. No merge: the two integration issues and recorded hold_all_merges/new_failure_review_required remain. This metric change does not establish a runtime memory repair or clear historical original-check failures. COMMENT because the authenticated account owns the PR.

ratios = [run['second_half_peak_to_first'] for run in runs if run['ok']]
median = statistics.median(ratios) if len(ratios) == RUNS else None
healthy = median is not None and median <= GROWTH
result['sides'][side] = dict(runs=runs, median=median, healthy=healthy,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Migrate the existing result consumers with this schema change. tools/cache_compiler_compare.py::collect still prints each side's post_gc_peak_to_initial immediately after invoking this driver. The new result has only runs, median, healthy and binary_sha256, so even a successful measurement now aborts that collector with KeyError: 'post_gc_peak_to_initial', before its core-case comparisons. This PR directly triggers the Cache compiler RSS comparison workflow, whose matrix runs that collector. Its assessor also expects top-level samples_kb/execution and the old bounds object. I reproduced a healthy head driver result with controlled supervisor transcripts: its exit is 0, but the actual consumer raises KeyError; the equivalent current-main result is accepted. Preserve a versioned legacy measurement for the locked comparison, or migrate the collector and assessors together without relabeling historical 2x evidence as the new metric. iclass_resource_replay.py also reads the removed field; audit the other consumers.

collect.call
sample.call(0)
20.times do |batch|
BATCHES.times do |batch|

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major / P2] Keep the locked diagnostic workload separate from the new gate workload. PROGRAM is imported by rss_native_probe.py and method_copy_retention.py, rather than being private to this driver. The former requires its SHA-256 to equal the original PROGRAM_SHA and still requires exactly 21 RSS samples; the latter refuses to run unless PROGRAM.count('20.times do |batch|') == 1. With this changed 30-batch program, the hash check fails and the prefix count is zero, so those existing diagnostic entry points reject the workload before collecting their evidence. Both contracts match on current main and fail on this head. Keep an explicit unchanged legacy program for the fixed-input diagnostic/replay tools, or deliberately update their contracts and provenance alongside the new program; changing only this exporter leaves the tools unusable.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed c20b0c23..38dfc632 against the two automated Majors.

  • Result consumers: fixed. --legacy runs the unchanged 20-batch PROGRAM and writes the old result shape (samples_kb, execution, post_gc_peak_to_initial, old bounds), judged against 2.0 as on main. cache_compiler_compare.collect passes --legacy. iclass_resource_replay passes it only when the root's driver has it, so older roots keep working. The halves result keeps its own fields, so no 2.0-era value is relabelled as the new metric.
  • Importers of PROGRAM: fixed. PROGRAM is byte-identical to main's program (the author reports the SHA-256 matching rss_native_probe's pin, and 20.times do |batch| appears exactly once). The new gate workload is HALVES_PROGRAM.
  • --legacy with --leak-every is refused, which is right.

Minor nit, non-blocking: detecting --legacy support by substring in the driver's text works, but would also match a comment mentioning the flag. Asking --help or checking for the add_argument('--legacy' line would be stricter.

No blocking findings from me. Please add the Cache compiler RSS comparison run's result to the PR when it finishes. The merge waits for the automated reviewer on this head and for #373.

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up on exact head 38dfc63 against current main 856e61b. Both earlier Major/P2 integration findings are fixed in code: PROGRAM is byte-identical to main and retains the pinned diagnostic hash and 20-batch prefix; the comparison collector explicitly requests --legacy, and the resource replay selects it for drivers that support it. Legacy results retain their original schema and 2.0 bound, separately from the new halves metric. No new actionable issue found in this update. I have not resolved anyone's review threads.

Independent validation: cache-compiler comparison 16/16, iclass resource replay 18/18, clone-RSS heap 7/7, native RSS probe 12/12, page RSS probe 12 passed/3 skipped. Thirteen controlled driver cases cover healthy results, growth rejection, truncated/missing-marker transcripts, nonzero exits and resource limits in both modes, plus zero-denominator rejection in the new mode. The actual comparison consumer accepts a healthy legacy result, and supervisor calls retain 600 seconds/2 GiB. These are transcript/compatibility checks, not fresh interpreter or RSS measurements. The legacy zero-initial-sample path still raises the same TypeError as main; this predates the PR and does not establish a new regression.

Actual Linux/macOS RSS and negative-control acceptance, and hosted compiler comparisons, remain separate evidence requirements. No merge: the recorded hold_all_merges/new_failure_review_required is active. This test-metric change does not clear historical runtime memory failures.

@284km
284km merged commit a2f2e37 into main Nov 28, 2026
13 of 22 checks passed
@284km

284km commented Nov 28, 2026

Copy link
Copy Markdown
Owner Author

The Cache compiler RSS comparison workflow on 38dfc63: run 46095681058, success. Both subjects' ordinary-rss jobs ran the collector to its end through --legacy. Each printed its four METHOD lines, read from post_gc_peak_to_initial:

  • 90c83c6: mere 1.852, 1.903, 1.542, 1.821 (parent, candidate, candidate, parent); reference 1.084 to 1.085.
  • ae6bd8c: mere 2.074, 1.707, 1.810, 1.761; reference 1.085.

On c20b0c2, before the legacy mode, the same jobs stopped with KeyError 'post_gc_peak_to_initial'. These are the old metric's values: max / batch 0 over 20 batches. They vary from 1.54 to 2.07 between alternate runs of one binary, which is why the gate moved off it.

🤖 Generated with Claude Code

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