Skip to content

nav: per-plane raster_version; gate nav-stats raster publishing on it - #581

Merged
transfix merged 1 commit into
masterfrom
fix/nav-plane-write-version
Oct 7, 2026
Merged

transfix merged 1 commit into
masterfrom
fix/nav-plane-write-version

Conversation

@transfix

@transfix transfix commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Problem

sim_world::plane_version(m) only counts log-odds sign flips: it bumps once per sensing agent whose update flips a cell's sign. A plane's published rasters can change without it bumping:

  • (a) belief_occ(m) changes on a planning-threshold crossing that isn't a sign flip.
  • (b) add_obstacle() marks appear in the composited occupancy and later expire by TTL.
  • (c) ever_seen(m) grows and last_visible(m) moves whenever a field of view moves over open ground.

The reverse also happens: a flip on the occupied side of the threshold bumps plane_version while no raster changes. #503 corrected the header comment, but publish_nav_rasters still documented its per-plane versions[] gate as plane_version(m). So the fog and belief layers went stale in cases (a)–(c).

Change

  • sense_batch: belief_planes gains an optional fov_changed[K] output. When set, each plane gets 1 iff the call changed any byte of its ever_seen or last_visible. When the result would be byte-identical, the last_visible blank-and-restamp is skipped. Callers that don't pass it, including pycvc, run the old code path unchanged.
  • sim_world::raster_version(m) is new. It bumps exactly once per sense tick on which any byte of plane m's belief_occ / ever_seen / last_visible changed, and never otherwise. belief_occ is the composited occupancy, so threshold crossings and obstacle marks/expiry count. The occupancy half reuses the per-plane change detection the rebuild trigger already does, so it adds no extra pass.
  • plane_version(m) keeps its belief-flip meaning for existing callers. Both are documented, and each points to the other.
  • cvcGL: publish_nav_rasters(app, pub, prefix, const sim_world&, st) is a new overload. It reads dims, bounds and rasters from the world and gates each plane on raster_version(m). The array overload's doc now says to pass raster_version(m), not plane_version(m).
  • sim_world outputs are bit-identical; only bookkeeping changes.

Tests

src/cvc/tests/nav_test.cpp:

  • NavSense.FovChangedIsExactAndContentNeutral senses into twin stacks, one with fov_changed and one without. The stacks must stay byte-identical, and fov_changed[p] must equal "plane p's FoV bytes differ". It runs in the private, clustered and shared layouts, plus an empty plane. The rounds are: first sense, identical re-sense (0 changes), 20 half-cell translations, an agent going off the grid, and stray non-canonical bytes. The translations move a plane's last-agent FoV to a different cell set of the same size, which is the case the skip shortcut must not mistake for "unchanged".
  • NavSimWorld.RasterVersionBumpsOncePerRasterChange uses the stationary one-ray phantom scenario from the existing flip test, so every event lands on a known tick. Each case causes exactly one bump: an ever_seen-only growth (tick 0, no flip), a threshold crossing without a sign flip (tick 6), an add_obstacle mark appearing (first sense after the call), and its TTL expiry (5 ticks later). Unchanged ticks, and the flip that changes no raster (tick 5), bump nothing.
  • NavSimWorld.RasterVersionEverSeenOnlyGrowth: two agents share a plane. The first drives into new ground while the plane's last agent, whose FoV is last_visible, stays parked. ever_seen grows with last_visible and occupancy unchanged, and each such tick bumps exactly once.
  • NavSimWorld.RasterVersionStillUnderFreezeSense: under freeze_sense, including after an add_obstacle, nothing changes and nothing bumps.
  • NavSimWorld.RasterVersionMatchesRasterDiffOracle runs live fog-of-war in the private (pooled), clustered and shared layouts, sensing every other tick, with obstacle marks mid-run. Every tick and every plane, the raster_version delta must equal "did a raster byte change". Non-sense ticks must change nothing. The run must include occupancy changes without a flip, FoV-only changes and quiet sense ticks.
  • PooledRebuildMatchesSerialBitExact now also checks that raster_version matches between serial and pooled runs.

src/cvcGL/test/cvcgl_nav_stats_publish.cpp runs the same phantom scenario through the new overload every tick. It detects a republish by the stored belief volume's buffer identity, while holding the previous handle. It checks that exactly the 4 expected ticks republish, that the published belief/ever_seen/last_visible volumes always equal the world's current rasters, and that .version tracks raster_version.

What ran locally

This box can't configure libcvc (no Boost/VTK/CGAL). The nav core is stdlib-only, though, so I built nav_test.cpp against the real nav sources. I used a minimal gtest stand-in and a brute-force stand-in for the CGAL neighbour search (neighbors_within_radius).

  • All 56 nav_test tests pass (51 existing + 5 new).
  • Bit-identity: I hashed every sim_world output over 150 ticks in 4 layouts (private/pooled, clustered, shared, optimistic; sense_every 1 and 2; obstacle marks). The hash covers poses, headings, speeds, modes, reached flags, clearances, all belief_occ/ever_seen/last_visible planes, the SDF field, field_version and every plane_version. It is identical between origin/master and this branch.
  • Mutation check: 9 mutations of the new logic are each caught by at least one new test. They are: drop the FoV term, drop the occupancy term, alias raster_version to the flip count, always bump, drop the ever_seen growth flag, ignore last_visible changes, skip the nonzero count, skip the per-cell FoV check, and treat a non-canonical ever_seen byte as already seen.
  • Review: a multi-agent review (sense_batch, sim_world semantics, a compiler-style read of the cvcGL code, test robustness), with each finding independently verified. It turned up two test-coverage gaps, both fixed here. The first was a no-op "turn" round that left the last_visible skip shortcut untested; a mutant that breaks bit-identity survived the original tests. The second was a non-canonical ever_seen byte that was only exercised in 2 of 6 runs.
  • clang-format is clean on the changed lines (CI's ranges, via libclang-cpp 14).

The cvcGL code and its test were not compiled locally. CI is their only build gate.

Downstream

cvcdbg's demo3 sim worker (demos/demo3_sim_worker.cpp) gates its belief-buffer copy on plane_version and passes plane_version to publish_nav_rasters. Once it builds against a libcvc with this change, it should switch both to raster_version. That's a separate cvcdbg change.

@transfix
transfix merged commit 2434dbb into master Oct 7, 2026
14 checks passed
@transfix
transfix deleted the fix/nav-plane-write-version branch October 7, 2026 23:09
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