Skip to content

guard: say which road the stopped run hole came by - #91

Merged
donislawdev merged 1 commit into
mainfrom
guard/held-open-asserted
Sep 8, 2026
Merged

guard: say which road the stopped run hole came by#91
donislawdev merged 1 commit into
mainfrom
guard/held-open-asserted

Conversation

@donislawdev

Copy link
Copy Markdown
Owner

Follow-up to #90, found by analysing the merged change rather than by a failure.

The gap

The hole that TestARunStoppedPartWayNamesEveryFileThatFinished is about had two roads to it, and the guard could not tell them apart.

drain asks about cancellation after taking an index, so the writer holding index zero can lose the processor in between, come back to a cancelled context and return without ever reaching its generator. Same hole, same manifest, weaker proof - a file that never started is not a file cut off half way.

The measurement decided the shape of the fix

Measured with tools/probes/stoprace -held before changing anything:

condition generator never entered
idle machine 0 in 50
CPU starved, 24 busy loops 0 in 25

So the second road is one the construction allows and the machine does not take.

That is why the cancellation condition is not rebuilt. Requiring the generator to have started before cancelling would be a change with no measured effect that carries its own risk - a generator that never started would end the run in success. What is added instead is a net: the generator records that it was reached, and the guard asserts it as a fourth assertion beside the three it already makes about its own reach.

It turns "measured once, did not happen" into "cannot happen unnoticed", which matters because the sizes and the cancellation condition above it are both things a later change can move.

Verified

  • 50 runs, 30 of them under CPU starvation, zero failures - the new assertion does not introduce flakiness of its own
  • the prefix mutation still reddens the guard
  • -race clean over 5 runs, staticcheck v0.8.1, gofmt, vet clean
  • seven neighbours, all code shape ceilings, document consistency guards, staleness.py (912 patterns, each occurring exactly once)

Deliberately absent: a mutation for the new assertion. No mutation of product code reddens it alone, so it stands in the same category as the three assertions beside it.

Not run: the full suite and preflight - this goes to CI.

🤖 Generated with Claude Code

The hole this guard is about had two roads to it and the guard could not
tell them apart. drain asks about cancellation AFTER taking an index, so
the writer holding index zero can lose the processor in between, come
back to a cancelled context and return without ever reaching its
generator. Same hole, same manifest, weaker proof - a file that never
started is not a file cut off half way.

Measured with tools/probes/stoprace -held before changing anything:
never entered 0 times in 50 idle runs and 0 in 25 starved ones. So the
second road is one the construction allows and the machine does not
take, and that number decided the shape of this change.

The cancellation condition is therefore NOT rebuilt. Requiring the
generator to have started before cancelling would be a change with no
measured effect that carries its own risk, since a generator that never
started would end the run in success. What is added instead is a net:
the generator records that it was reached and the guard asserts it, as a
fourth assertion beside the three it already makes about its own reach.

This turns "measured once, did not happen" into "cannot happen
unnoticed", which matters because the sizes and the cancellation
condition above it are both things a later change can move.

Measured after: 50 runs including 30 under CPU starvation, zero
failures, the prefix mutation still reddens it, race detector clean.

The assertion has no mutation of its own and that is deliberate - no
mutation of product code reddens it alone.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@donislawdev
donislawdev merged commit c6f275d into main Sep 8, 2026
18 checks passed
@donislawdev
donislawdev deleted the guard/held-open-asserted branch September 8, 2026 18:34
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