Skip to content

Collision: the broad phase hands over each pair once, and never more than every pair - #59

Merged
omardev29 merged 3 commits into
mainfrom
ccr-0e58095e-jh8d23
Nov 20, 2026
Merged

omardev29 merged 3 commits into
mainfrom
ccr-0e58095e-jh8d23

Conversation

@omardev29

@omardev29 omardev29 commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

What changed, and why

The nightly deep.yml runs of 17, 18 and 19 November ended cancelled. In each one, the properties (1) shard reached its 60-minute timeout-minutes.

I replayed shard 1 (cases 1-40) here with the nightly's settings (seed=12345 max_success=5000) and --duration:

  • The other 30 cases: about 28 minutes together.
  • "every new behavior with any fields keeps the world finite" (tests/property/behavior_more_prop.cpp:448): still running after 3731 s.

gdb shows the property inside candidate_pairs() (src/rmp/scene/collision.cpp), sorting a vector of 20 608 486 pairs. That came from 164 objects, which have only 13 366 pairs between them. The cause is in the framework, not the test: when many objects share many cells (a volley of bullets whose sweeps cross the grid), each cell handed over every pair it held. The total was the pairs times the cells they share, and it was sorted and de-duplicated every frame.

The fix, in candidate_pairs():

  • Each pair once: a pair comes only from the first cell its two spans share, the corner (max x0, max y0) of their overlap. This is the same set as before, without duplicates.
  • The fallback: when the cells would hand over more pairs than there are (Σ k(k-1)/2 > n(n-1)/2, counted from the counting sort's starts), the pass takes the all-pairs loop. The grid is an optimisation of that loop, and the code already treats the loop as correct.
  • Order unchanged: both paths give the pairs sorted by (a, b), as before, so no callback changes order and no golden moves.

After the fix, that property takes 16.6 s at the nightly's seed and 5000 cases.

objects::detail::candidates_for_tests() (in src/rmp/scene/object_internal.h, which is internal, not include/) tells the test how many pairs one pass gathered.

The timeout is unchanged and no gate is touched.

Second commit (d45dd34): the next finding of the same nightly. Fixes #60.

The nightly dispatched on this branch (run 44602911780) went on to fail its hypothesis job in MainIsTotalTest.test_rmp_update, with UnicodeEncodeError: ... '\ud800' ... surrogates not allowed from Path.resolve() in cmd_update. The program output that made it was git rev-parse --show-toplevel answering '\ud800', and no real git can answer that:

  • subprocess.run(text=True) decodes strictly, so a byte that is not UTF-8 raises UnicodeDecodeError there and never comes back as a lone surrogate. printf '\355\240\200' (U+D800's own bytes) raises too.
  • So the generator SHORT in tests/rmp_property_test.py now leaves out category Cs, as TYPED already does for argv.

Third commit (a84d640): Omar's decision on what the second leaves out. A git that prints bytes that are not UTF-8 (a framework cloned into a folder whose name is not UTF-8) makes rmp die with UnicodeDecodeError as a traceback. Omar decided on 2026-11-20 to leave it so, as the one exception to R7 ("a sentence, never a traceback"). It is written in CLAUDE.md's standing rules, with his name and the date, and in tests/rmp_property_test.py's docstring.

The ladder

Stage Where Result
rmp fmt check laptop (clang-format 22.1.8) clean on the three files
rmp lint laptop (clang-tidy 22.1.8, --experimental-custom-checks) nothing new: collision.cpp 27 and collision_test.cpp 9 custom-rmp-raw-pointer, exactly tools/lint_debt.txt
unit_test (sanitized Debug) laptop 1144 cases, 301 365 assertions passed
property_test (collision, grid and pair cases) laptop 6 passed
The property that hung laptop, seed=12345 max_success=5000 >3731 s before → 16.6 s
rmp test (xvfb-run -a ./rmp test) laptop PASS, every stage, 10 min 15 s
Hypothesis, rmp_property_test laptop profile ci: 38 tests OK; profile nightly, MainIsTotalTest: 21 tests OK (325 s)
Nightly dispatched on this branch (run 44602911780, a random seed) GitHub's runner properties (1) success in 37 min 52 s (it was cancelled at 60 min on 17, 18 and 19 Nov); shards 2-4: 22, 18, 19 min; every fuzz target success; hypothesis red on #60, fixed by d45dd34
Shard 1 at the nightly's settings (cases 1-40, seed=12345 max_success=5000) laptop 40 cases, all pass, 44 min 19 s of tests; before, the run never got past case 31

Seen red first

  • The generator fix: the nightly's counterexample (@reproduce_failure('6.168.5', b'AXicY3BkYAAjTAgiGJvfLmgAAE4VBiA=')) was replayed on the old generator and printed UnicodeEncodeError: 'utf-8' codec can't encode character '\ud800'. On the new one, the class passes at nightly strength.

  • "the broad phase never hands over more pairs than there are" (tests/collision_test.cpp). The world is 300 small objects and 100 objects of 2000 by 2000 over the same cells. I put the old behaviour back on a copy (no bound, no first-cell rule) and the test printed CHECK( 111570 <= 79800 ) is NOT correct!. With the fix it passes.

  • "they agree where many big objects share many cells": the existing grid-against-loop differential, on the same world. It now goes through the fallback path and must give the same touching set. It is a differential, so it was not planted red.

Not verified

  • rmp test coverage and the collision mutation module: these are measured in the pinned image, so CI's coverage job and the weekly run will say.

Checklist

  • rmp fmt check is clean.
  • rmp lint is clean: no new warning, and a NOLINT only with its reason.
  • rmp test passes.
  • rmp test examples passes: not applicable (no public API, example, scene, input or UI change).
  • rmp test sanitize passes: not applicable (nothing that parses, casts or frees).
  • rmp test fuzz passes: not applicable (no parser).
  • rmp test coverage passes in the pinned image (CI).
  • The docs say what the code now does: no page describes the broad phase's internals.
  • An API change is labelled: none here.
  • No gate was weakened to get green.
  • No secret anywhere.
  • Commits are plain, in Omar's name.

Generated by Claude Code

…than every pair -- many objects sharing many cells made it the pairs times the cells they share: 164 objects gave 20 million candidates a frame, for 13 366 pairs, and the nightly's behaviors property sat an hour in that sort until the shard's 60-minute limit cancelled the run (17, 18 and 19 November). A pair comes from the first cell its two spans share; past every pair, the loop the grid is an optimisation of. The order is the sorted one it was, so no callback moves. The property: over an hour, then 16.6 s at the nightly's seed and 5000 cases
…ess.run(text=True) decodes strictly, so a byte that is not UTF-8 raises there and never comes back as one. Drawn with them, git rev-parse 'printed' '\ud800' and Path.resolve() could not encode a folder name no git can have answered (Hypothesis, the nightly run on this branch, test_rmp_update; replayed red on the old generator)
…bytes that are not UTF-8 -- the one exception to R7, by Omar's decision (2026-11-20); the rmp properties' docstring says so
@omardev29
omardev29 merged commit 62c2036 into main Nov 20, 2026
31 checks passed
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.

nightly-finding: hypothesis hypothesis: hypothesis: test_rmp_update (rmp_property_test.MainIsTotalTest.test_rmp_update) [4f1e2528808e]

1 participant