Wednesday, 2 December 2026

Building the Measuring Stick Before Looking at the Data

An AI coding agent adds features and fixes over dozens or hundreds of changes. Where does the new code land? Why do a few classes end up swallowing almost everything near them?

That is what this study asks. To keep it concrete, we use a physical picture. Every word in it is a measured number.

  • Births. Opening a new class for new code instead of adding to an existing one.
  • Mass and size. How many earlier changes put code in a class, and how much code sits inside it.
  • Sinew. Repeated changes to a class keep binding to the same core fields and methods. It happens more often than chance would explain.
  • Forcing. New code binds to a class's own members. Once it touches that class's state or methods, it could not easily live somewhere else.
  • The loop, event horizon, and black hole. Suppose sinew raises the odds that arriving code is forced. Suppose forced code adds more sinew. Past an event horizon, half of the arriving code is forced. The class becomes a black hole that pulls in nearly everything near it.

We test two forms of code on the same problems. Spring uses handlers and methods. OfficeFloor uses function injection, which opens new classes for new functions. Alongside that comparison, we test forecasts. Can these forces predict where code goes and which classes turn into black holes better than code shape and quality metrics?

Why build and lock the pipeline first

In an earlier study (placement-gravity-study) and a later Petclinic exploration, we built the hypotheses after looking at the data. Looking at data to invent hypotheses proves nothing if you test them on the same data.

So for this study, the confirmatory data are locked in the code. runs.yaml marks the confirmatory datasets as confirmation. Those are ui-primary for Paper A, and open-source-human-confirm and open-source-agent for Paper B. The scripts refuse to fetch, measure, fit, or even list them until a manual git tag named plan-v1 is an ancestor of HEAD.

Phase 0 builds the measuring and modelling pipeline first. Then it tests the pipeline on synthetic worlds where we already know the true numbers.

How we know the model and tests work

step02_selftest.sh ran four checks. All results come from labnotes/briefs/phase0.md.

1. Automated tests and the code lock

From results/selftest/TESTS.md, all 33 tests passed in 167.78s. There were 2 RuntimeWarning overflow messages in placement_choice/model/fitting.py. The suite includes the test proving the lock blocks confirmatory data before plan-v1.

2. Recovering known forces

From results/selftest/recovery/RECOVERY.md, we generated 100 synthetic datasets of 10 chains each. Each dataset came from known birth, choice, and forcing weights. We ran them back through the measurement pipeline (placement_choice.model.recovery) and fitted the model. A parameter passes when its 95% interval covers the true value at least 85% of the time, targeting 95%.

All 14 checks passed.

  • birth.one had true value -1.0. Mean estimate was -0.991 with coverage 0.940.
  • birth.mutative had true value -0.5. Mean estimate was -0.504 with coverage 0.960.
  • choice.mass had true value 1.5. Mean estimate was 1.491 with coverage 0.890.
  • choice.size had true value 0.5. Mean estimate was 0.505 with coverage 0.950.
  • choice.home had true value 0.7. Mean estimate was 0.725 with coverage 0.950.
  • choice.sinew had true value -0.3. Mean estimate was -0.307 with coverage 0.920.
  • forcing.sinew had true value 0.6. Mean estimate was 0.592 with coverage 0.950.
  • forcing.mass had true value -0.3. Mean estimate was -0.305 with coverage 0.940.
  • loop.forced_minus_chosen must sit above 0. Its mean was 0.601 with SD 0.235.

This check caught a real bug from our earlier Petclinic exploration. Sometimes one checkpoint places new lines into several existing classes at once. The exploration treated the other chosen classes as rejected alternatives. That biased every choice weight toward zero. Replacing it with a set likelihood summed over drawing orders removed the bias. This is recorded in PLAN.md §11 row 5.

3. Testing the tests where there is nothing to find

From results/selftest/size/SIZE.md, we ran placement_choice.model.size on 100 synthetic datasets per world. Each dataset had 10 chains per arm and 200 bootstrap draws. A test fails the check if it passes in more than 10% of runs.

  • A world with no force. Here sinew does not raise forcing, while each class keeps a lasting leaning of its own (SD 1.5 on the logit). H1 passed in 7.0%. H3 within a class passed in 7.0% on the first arm and 0.0% on both arms. H4 passed in 0.0%. All passed the check.
  • Why pooling classes fails. We also ran the old pooled slope beside the table. It mixed differences between classes with changes inside a class. It falsely passed in 23.0% of runs. That is why H3 now tests within a class (PLAN.md §11 row 10).
  • A world on the edge of the band. Here the first arm's sinew slope is 0.8 of the second arm's. The H3 "one law" test passed in 0.0%.

4. Checking the Python fit against R

From results/selftest/crosscheck/CROSSCHECK.md, we fitted the same conditional logit data in Python and in R using survival::clogit and mclogit.

  • mass was 1.397081 in all three, with SE 0.161326.
  • size was 0.415097, with SE 0.137825.
  • home was 1.330063, with SE 0.472059.
  • sinew was -0.369249, with SE 0.122586.

The largest gap was 4.02e-09 on estimates (tolerance 0.0001) and 1.95e-10 on standard errors (tolerance 0.001).

What comes next

The pipeline passed every synthetic check. This brief ran on a dirty tree at commit e68b0f770, so we will rerun on a clean commit before registration. Next is Phase 1. We run all eight exploratory Petclinic datasets through the real pipeline using ./step03_pin_chains.sh through ./step07_phase1_report.sh. That will show what holds, what changes, and what needs work before looking at open source histories.

No comments:

Post a Comment