Found while writing the M3 slice 6 wall-removal restart test (#21): that test moves its wall's
endpoints off the exact 64-gon rays to step around this (tools/persistence.test.mjs, "Endpoints stay
off the exact 64-gon rays: a ray through a wall endpoint is the documented boundary ambiguity of 5.4").
Not fixed. Security-relevant: player-view leak, the core fog-of-war promise.
Summary
visibilityPolygon (DESIGN 5.1) casts one ray per vertex of the inscribed 64-gon range limit and three
rays (ang, ang ± RayEps) per blocking wall endpoint. The 64-gon directions get no± RayEps
companions, and rayHit returns no hit for a segment collinear with the ray (|den| < 1e-12). A wall
that lies exactly along a 64-gon ray - i.e. a wall whose endpoint is on that ray and whose body runs
along it - is therefore hit by no ray at all. The polygon gets no vertex for it, it casts no shadow, and
a token standing behind it on the same line is inside the visibility polygon: it is sent to the player
although the wall is between them (DESIGN 3.1).
Where
server/geometry.nim:
visibilityPolygon (lines 41-69): the 64-gon rays (46-51, one angle per vertex, no nudges) and the
per-endpoint fan (58-63, ang - RayEps, ang, ang + RayEps).
rayHit (31-39): if abs(den) < 1e-12: return Inf # parallel/collinear: grazing, other rays cover it (line 35) and if t > Eps and u >= -Eps and u <= 1 + Eps: t else: Inf (39).
DESIGN 5.1 (algorithm), 5.4 "Boundary epsilon ambiguity (RayEps 1e-4, inclusive tolerances)",
3.1 (a player receives another token only if its centre is inside its own LOS polygon).
Read from the code, then confirmed with a throwaway harness against a copy of server/geometry.nim at 1ad9f72 (/tmp only; the repo tree was read, never written):
Wall a = (300,200), b = (500,200); viewer o = (200,200). atan2(b.y-o.y, b.x-o.x) == 0, and the
k = 0 64-gon ray is arctan2(sin 0, cos 0) == 0: the endpoint angle is a duplicate of a range-limit
direction, so the fan has no ray of its own to spend on it.
The one ray that could hit it is the collinear one, and rayHit rejects collinear segments
(den == 0 -> Inf).
The ± RayEps companions cannot rescue it either: for a wall lying along a sight line, the ray line
meets the wall's line at the token itself, so t ≈ 0 and t > Eps rejects it (measured: t = 0, u = -0.027 for dphi = ±1e-4, so u is out of [0,1] too).
The neighbouring range-limit rays are 2π/64 = 5.625° away and, being off the wall's line, never cross
the segment at all.
Net effect: no vertex is emitted for the wall at all (visibilityPolygon returns 70 vertices instead
of 76), the polygon closes over it, and inside - even-odd - counts a point on the line beyond the
wall as seen. Note the wall is not merely "grazed": it contributes no coverage, so the region it should
shade is entirely inside the polygon (a zero-width slit in exact arithmetic, but exactly the slit a
token on that line sits in).
Note [INFERRED, measured]: the 64-gon alignment is the reported instance, not the general condition - a
wall radial to the viewer at an arbitrary angle behaves identically (checked at 10°), because its own ± RayEps rays also land on t ≈ 0. What a 64-gon direction adds is that the fan holds a ray exactly
there while holding none at ± RayEps, which is what makes the leak look like "a wall endpoint on a
64-gon ray". Grid-snapped, axis-aligned scenes are where this arises in practice: a wall on a grid row
and a token on the same row.
Side observation (separate finding, low confidence, not claimed as this bug): random degenerate wall
fields produced self-intersecting polygons - 1074 of 20000 scenes with an on-ray wall, 528 of 20000
without - where even-odd inside resolves the overlapping sliver arbitrarily. Worth its own look if it
ever shows up in a real scene.
Repro sketch
[MEASURED, harness against a copy of server/geometry.nim at 1ad9f72; the repo was not modified and no
test was run against the working tree, which another agent is editing]
Scene: vision origin o = (200,200), range R = 600, no other walls or doors.
case
wall a -> b
point p
segsCross(o,p,a,b)
inside(poly, p)
expected
leak (k = 0 64-gon ray)
(300,200) -> (500,200)
(560,200)
true
true
false
control, wall not radial
(500,200) -> (500,4000)
(560,300)
true
false
false
control, wall 0.5 px off the row
(300,200.5) -> (500,200.5)
(560,200)
false
true
true (genuinely visible)
The same by pure translation for a vertical wall on a grid column with the token on that column (the
k = 16 ray, (200,300)-(200,4000) from a token at (200,200): same result), and for any row/column the
map snaps to.
Unverified part: a non-radial wall whose endpoint sits exactly on a 64-gon ray did not leak in a sweep
of 600 random such scenes compared against a 4096-direction radial ray cast (max over-approximation
3e-14 px). If the wall that failed in slice 6 was not radial, its exact coordinates are needed to pin it
down; the per-endpoint ± RayEps fan does handle that shape (verified with the control above).
Impact
Player view leak, the fog-of-war promise: a token behind the wall is visibleTo -> it is fanned out to
the player in playerView with its position and radius, and it enters the player's encountered list,
which only the GM can prune.
The leaked region is a zero-width line, so the hidden token's centre must be exactly on it; grid-snapped
maps and axis-aligned walls make exact collinearity routine rather than exotic. This is the degenerate
wall the slice-6 test walks around rather than fixing.
Not affected: a gm_only token is refused before the LOS test in visibleTo, so this does not expose
GM-only tokens. Explored cells: a radial wall leaves the polygon covering both sides, so the explored
set shows no shadow line; cells off the line are marked, but for a zero-thickness wall that is
geometrically correct, so no separate explored defect is claimed here.
Acceptance
tests/tgeometry.nim, suite "visibility": a wall lying along a 64-gon ray with the viewer on its
line; the point behind the wall must not be inside, and the polygon must carry a vertex for the
wall. Same case translated to an axis row/column (grid snapping), both ray directions.
keep the negative controls: a non-radial wall with an endpoint exactly on a ray must still block
(the table above), and the existing "rays nudged past a corner" / shared-endpoint / T-junction cases
plus the /tools/mutation.sh a/b/c mutations must stay green - the fix must not trade this leak for
the under-approximation those guard.
leak harness: a tools/leak.mjs scenario with a plain token hidden behind such a wall, asserted
absent from the subject's view via the HIDDEN_TOKEN class. The checker's GEOMETRY class
(tools/leakcheck.nim, ~line 636) only tests missing vision (clearLine(o,p) and not inside(poly,p)), so it structurally cannot see this leak; either add an over-approximation check
(a sampled point inside the polygon with no clear LOS and not within the 5.4 boundary tolerance) or
rely on the token-level assertion and say so in the checker's header comment.
no visibility regression elsewhere: the existing tgeometry suite (visibility, cells, corpus,
differential and explored-oracle cases), the leak harness on its current scenarios, and the polygon
cost in results/bench.log (same order of magnitude).
Related
Found during #21 (M3 slice 6, explored persistence); the test's wall coordinates and its comment are
the workaround.
#20 (M3 slice 5) built the leak harness and its independent oracles; this is the first known leak the GEOMETRY class cannot express.
Found while writing the M3 slice 6 wall-removal restart test (#21): that test moves its wall's
endpoints off the exact 64-gon rays to step around this (`tools/persistence.test.mjs`, "Endpoints stay
off the exact 64-gon rays: a ray through a wall endpoint is the documented boundary ambiguity of 5.4").
Not fixed. Security-relevant: player-view leak, the core fog-of-war promise.
## Summary
`visibilityPolygon` (DESIGN 5.1) casts one ray per vertex of the inscribed 64-gon range limit and three
rays (`ang`, `ang ± RayEps`) per blocking wall endpoint. The 64-gon directions get **no** `± RayEps`
companions, and `rayHit` returns no hit for a segment collinear with the ray (`|den| < 1e-12`). A wall
that lies exactly along a 64-gon ray - i.e. a wall whose endpoint is on that ray *and* whose body runs
along it - is therefore hit by no ray at all. The polygon gets no vertex for it, it casts no shadow, and
a token standing behind it on the same line is `inside` the visibility polygon: it is sent to the player
although the wall is between them (DESIGN 3.1).
## Where
- `server/geometry.nim`:
- `visibilityPolygon` (lines 41-69): the 64-gon rays (46-51, one angle per vertex, no nudges) and the
per-endpoint fan (58-63, `ang - RayEps`, `ang`, `ang + RayEps`).
- `rayHit` (31-39): `if abs(den) < 1e-12: return Inf # parallel/collinear: grazing, other rays
cover it` (line 35) and `if t > Eps and u >= -Eps and u <= 1 + Eps: t else: Inf` (39).
- DESIGN 5.1 (algorithm), 5.4 "Boundary epsilon ambiguity (`RayEps` 1e-4, inclusive tolerances)",
3.1 (a player receives another token only if its centre is inside its own LOS polygon).
- Downstream: `inside` (token visibility), `cellsTouched` (explored), `server/vision.nim`
`insideAny`/`visibleTo`, `server/views.nim` `playerView`.
## Mechanism
Read from the code, then confirmed with a throwaway harness against a copy of `server/geometry.nim` at
1ad9f72 (`/tmp` only; the repo tree was read, never written):
1. Wall `a = (300,200)`, `b = (500,200)`; viewer `o = (200,200)`. `atan2(b.y-o.y, b.x-o.x) == 0`, and the
k = 0 64-gon ray is `arctan2(sin 0, cos 0) == 0`: the endpoint angle is a *duplicate* of a range-limit
direction, so the fan has no ray of its own to spend on it.
2. The one ray that could hit it is the collinear one, and `rayHit` rejects collinear segments
(`den == 0 -> Inf`).
3. The `± RayEps` companions cannot rescue it either: for a wall lying *along* a sight line, the ray line
meets the wall's line at the token itself, so `t ≈ 0` and `t > Eps` rejects it (measured: `t = 0`,
`u = -0.027` for `dphi = ±1e-4`, so `u` is out of `[0,1]` too).
4. The neighbouring range-limit rays are `2π/64 = 5.625°` away and, being off the wall's line, never cross
the segment at all.
5. Net effect: no vertex is emitted for the wall at all (`visibilityPolygon` returns 70 vertices instead
of 76), the polygon closes over it, and `inside` - even-odd - counts a point on the line beyond the
wall as seen. Note the wall is not merely "grazed": it contributes no coverage, so the region it should
shade is entirely inside the polygon (a zero-width slit in exact arithmetic, but exactly the slit a
token on that line sits in).
Note [INFERRED, measured]: the 64-gon alignment is the reported instance, not the general condition - a
wall radial to the viewer at an *arbitrary* angle behaves identically (checked at 10°), because its own
`± RayEps` rays also land on `t ≈ 0`. What a 64-gon direction adds is that the fan holds a ray exactly
there while holding none at `± RayEps`, which is what makes the leak look like "a wall endpoint on a
64-gon ray". Grid-snapped, axis-aligned scenes are where this arises in practice: a wall on a grid row
and a token on the same row.
Side observation (separate finding, low confidence, not claimed as this bug): random degenerate wall
fields produced self-intersecting polygons - 1074 of 20000 scenes with an on-ray wall, 528 of 20000
without - where even-odd `inside` resolves the overlapping sliver arbitrarily. Worth its own look if it
ever shows up in a real scene.
## Repro sketch
[MEASURED, harness against a copy of `server/geometry.nim` at 1ad9f72; the repo was not modified and no
test was run against the working tree, which another agent is editing]
Scene: vision origin `o = (200,200)`, range `R = 600`, no other walls or doors.
| case | wall a -> b | point p | `segsCross(o,p,a,b)` | `inside(poly, p)` | expected |
|---|---|---|---|---|---|
| leak (k = 0 64-gon ray) | (300,200) -> (500,200) | (560,200) | true | **true** | false |
| control, wall not radial | (500,200) -> (500,4000) | (560,300) | true | false | false |
| control, wall 0.5 px off the row | (300,200.5) -> (500,200.5) | (560,200) | false | true | true (genuinely visible) |
The same by pure translation for a vertical wall on a grid column with the token on that column (the
k = 16 ray, `(200,300)-(200,4000)` from a token at `(200,200)`: same result), and for any row/column the
map snaps to.
Unverified part: a *non-radial* wall whose endpoint sits exactly on a 64-gon ray did not leak in a sweep
of 600 random such scenes compared against a 4096-direction radial ray cast (max over-approximation
3e-14 px). If the wall that failed in slice 6 was not radial, its exact coordinates are needed to pin it
down; the per-endpoint `± RayEps` fan does handle that shape (verified with the control above).
## Impact
- Player view leak, the fog-of-war promise: a token behind the wall is `visibleTo` -> it is fanned out to
the player in `playerView` with its position and radius, and it enters the player's encountered list,
which only the GM can prune.
- The leaked region is a zero-width line, so the hidden token's centre must be exactly on it; grid-snapped
maps and axis-aligned walls make exact collinearity routine rather than exotic. This is the degenerate
wall the slice-6 test walks around rather than fixing.
- Not affected: a `gm_only` token is refused before the LOS test in `visibleTo`, so this does not expose
GM-only tokens. Explored cells: a radial wall leaves the polygon covering both sides, so the explored
set shows no shadow line; cells off the line are marked, but for a zero-thickness wall that is
geometrically correct, so no separate explored defect is claimed here.
## Acceptance
- [ ] `tests/tgeometry.nim`, suite "visibility": a wall lying along a 64-gon ray with the viewer on its
line; the point behind the wall must not be `inside`, and the polygon must carry a vertex for the
wall. Same case translated to an axis row/column (grid snapping), both ray directions.
- [ ] keep the negative controls: a non-radial wall with an endpoint exactly on a ray must still block
(the table above), and the existing "rays nudged past a corner" / shared-endpoint / T-junction cases
plus the `/tools/mutation.sh` a/b/c mutations must stay green - the fix must not trade this leak for
the under-approximation those guard.
- [ ] leak harness: a `tools/leak.mjs` scenario with a plain token hidden behind such a wall, asserted
absent from the subject's view via the `HIDDEN_TOKEN` class. The checker's `GEOMETRY` class
(`tools/leakcheck.nim`, ~line 636) only tests *missing* vision (`clearLine(o,p) and not
inside(poly,p)`), so it structurally cannot see this leak; either add an over-approximation check
(a sampled point inside the polygon with no clear LOS and not within the 5.4 boundary tolerance) or
rely on the token-level assertion and say so in the checker's header comment.
- [ ] no visibility regression elsewhere: the existing `tgeometry` suite (visibility, cells, corpus,
differential and explored-oracle cases), the leak harness on its current scenarios, and the polygon
cost in `results/bench.log` (same order of magnitude).
## Related
- Found during #21 (M3 slice 6, explored persistence); the test's wall coordinates and its comment are
the workaround.
- #20 (M3 slice 5) built the leak harness and its independent oracles; this is the first known leak the
`GEOMETRY` class cannot express.
- Map #2.
Category: bug Summary: A wall lying along the viewer's line of sight casts no shadow: points behind it on that line are reported visible.
Domain rule (owner decision)
A wall hides whatever its physical dimensions hide. In v1 walls are zero-width and full height, so a wall seen edge-on (collinear with the viewer) hides exactly the points behind it on that line - nothing more (no invented wedge), nothing less. For those points the sight polygon must agree with the straight-line "does the segment from the viewer to the point cross a wall" truth.
Verification on current main (2026-11-15, e13fa90)
Confirmed, on a scratch copy of the vision module, devbox nim; the repo tree was not modified.
scene (o, R, wall, p)
segsCross(o,p,wall)
inside(poly,p)
verdict
(200,200), 600, (300,200)-(500,200), (560,200)
true
true
leak
same, endpoints reversed (500,200)-(300,200)
true
true
leak
reverse direction: viewer at (560,200), p = (200,200)
true
true
leak
vertical translated: o (200,200), wall (200,300)-(200,500), p (200,560)
true
true
leak
translated: o (1000,1000), wall (1100,1000)-(1300,1000), p (1360,1000)
true
true
leak
diagonal 45 deg: o (0,0), wall (100,100)-(300,300), p (400,400)
true
true
leak
diagonal arbitrary slope 71.6 deg: o (0,0), wall (100,300)-(200,600), p (250,750), R 900
true
true
leak
control: point off the wall's line (560,240)
false
true
correct
control: point between viewer and wall on the line (250,200)
false
true
correct
Code path, measured:
The fan casts, per blocking wall endpoint, the endpoint angle with its RayEps (1e-4 rad) companions, plus one ray per range-limit direction.
The ray/segment helper rejects a segment parallel to the ray (|cross| < 1e-12) and reports "no hit".
A wall radial to the viewer lies on the ray leaving the viewer, so the nudge rays meet the wall's line only at the viewer: measured hit parameter t ~ 0 (rejected as degenerate) and segment parameter u = -0.5 (or 1.5 with the endpoints reversed) - outside the segment. So no nudge ray hits it either.
Net: a radial wall is hit by no ray at all. It emits no vertex and no notch, the polygon closes over it, and even-odd inside counts points on the line beyond the wall as inside. Polygon vertex count is the same with and without the wall.
64-gon alignment is incidental, not the condition: arbitrary slopes leak identically (45 deg is a range-limit direction, 71.6 deg is not, both reproduce). Alignment only means the range-limit ray coincides with the endpoint ray, so not even a near-miss ray exists.
The design document's edge-case note ("Collinear rays skipped (neighbouring +-eps rays cover them)") is false for radial walls: the nudges diverge from the wall's line after leaving the viewer, so they cover the non-radial case only.
Baseline tgeometry suite passes on current main, so this is a live defect in a green tree, not a broken test.
Current behavior
A blocking wall collinear with the viewer is treated as absent by the polygon: no shadow, no vertex, no notch. Points on that line beyond the wall are inside the polygon, so a token standing exactly there is sent to the player (visibleTo / playerView), enters the encountered list, and its cells are explored. A token behind a visually opaque wall is exposed.
Desired behavior
For every blocking wall, the sight polygon agrees with the straight-line "does the viewer-to-point segment cross a wall" truth, within the documented boundary tolerance:
point beyond a radial wall on its line, within range, nothing else intervening: not visible;
point on that line between the viewer and the wall: visible;
point on that line behind the viewer: visible;
point beyond the wall but off the line by more than the documented boundary tolerance (0.5 px): visible - the wall is zero-width, so it must not invent a wedge;
both endpoint orderings and both viewer sides behave identically;
a viewer standing on a wall (on its endpoint or inside its body) is not a special case for this rule: the straight-line truth is the contract, and the tests covering a viewer on a wall state the resulting behaviour explicitly;
everything non-radial is unchanged: endpoints, the +-nudge fan, T-junctions, shared vertices, corners, free-standing walls, open doors.
Key interfaces
The ray/segment intersection helper the polygon fan uses (an rayHit-like function returning the nearest hit distance or infinity): today it returns "no hit" for a segment parallel/collinear with the ray. It must report the wall's nearest intersection when the wall lies ahead of the viewer within the segment's span, while keeping the existing degeneracy guards (viewer on the wall or on an endpoint, hits at ~0).
visibilityPolygon(o, walls, radius): output must carry a vertex or coincident-vertex notch for a radial blocking wall, and stay ordered by angle and CCW.
inside(poly, p) and segsCross(p, q, a, b): contract surfaces; no signature change expected, but inside must report a point on the line beyond a radial wall as outside.
The leak checker's geometry oracle: gains the over-approximation direction described below.
The design document's edge-case note about skipped collinear rays: rewrite it to what actually holds.
Acceptance criteria
Regression tests in the visibility suite: a radial wall with the viewer on its line and a point behind it must not be visible; both endpoint orders; a translated horizontal wall (grid row) and a vertical wall (grid column); at least one diagonal wall of an arbitrary slope that is not a range-limit direction.
No invented wedge, same scenes: a point beyond the wall 0.5 px or more off the line is visible; a point on the line between viewer and wall is visible; a point on the line behind the viewer is visible.
The polygon for each radial-wall scene is still simple and angularly ordered (no bow-tie) and carries a vertex (or coincident pair) at the wall's near intersection on that line.
At least one test pins the viewer-on-a-wall case (viewer at the wall's endpoint and viewer on its body).
The whole geometry test suite stays green, including the existing negative controls: a non-radial wall whose endpoint sits exactly on a range-limit direction still blocks; the nudged-corner, shared-endpoint, T-junction, box-corner, long-thin-corridor and "collinear walls act as one" cases; the random-polygon differential and explored-oracle cases.
The leak harness gains a scenario with a plain token hidden behind a radial wall; the checker flags it as a hidden token reaching the subject.
The leak checker's geometry oracle gains an over-approximation check: a sampled point that the recomputed polygon calls visible while a blocking wall crosses the viewer-to-point segment is a failure, with the existing boundary tolerance (0.5 px) excluding samples that sit within it of a wall or of the polygon boundary. The check must fail against the unfixed polygon code (demonstrate this on the radial-wall scenario before landing the fix) and pass afterwards.
The mutation suite is green, including a new mutation that pins the fix: restoring "collinear means no hit" must fail the new tests.
No measurable regression against the existing sight-polygon benchmark (prototype scene and the sparse 5k scene): same order, within noise of the recorded numbers.
The design document's claim that neighbouring nudged rays cover collinear walls is corrected, and the boundary-epsilon known-limitation entry still describes the residual hairline shadow accurately.
Out of scope
Wall thickness and height. v1 walls are zero-width and full height; per-wall thickness and a real height (low walls one can see over) are a separate enhancement opened from this triage: #37 (walls: per-wall thickness and height (low walls)).
Client/rendering changes.
The self-intersecting-polygon side observation in the issue body: unverified. A 20 000-scene sweep on current main (six random walls each, proper crossings only, shared endpoints excluded) found none. Not claimed here; it would be its own follow-up if it ever reproduces.
Wall/vision performance work (spatial index), the explored rasterizer, and door semantics.
Changing segsCross inclusivity or open-door blocking rules.
> *This was generated by AI during triage.*
## Agent Brief
**Category:** bug
**Summary:** A wall lying along the viewer's line of sight casts no shadow: points behind it on that line are reported visible.
### Domain rule (owner decision)
A wall hides whatever its physical dimensions hide. In v1 walls are zero-width and full height, so a wall seen edge-on (collinear with the viewer) hides exactly the points behind it on that line - nothing more (no invented wedge), nothing less. For those points the sight polygon must agree with the straight-line "does the segment from the viewer to the point cross a wall" truth.
### Verification on current main (2026-11-15, e13fa90)
**Confirmed**, on a scratch copy of the vision module, devbox nim; the repo tree was not modified.
| scene (o, R, wall, p) | `segsCross(o,p,wall)` | `inside(poly,p)` | verdict |
|---|---|---|---|
| (200,200), 600, (300,200)-(500,200), (560,200) | true | **true** | leak |
| same, endpoints reversed (500,200)-(300,200) | true | **true** | leak |
| reverse direction: viewer at (560,200), p = (200,200) | true | **true** | leak |
| vertical translated: o (200,200), wall (200,300)-(200,500), p (200,560) | true | **true** | leak |
| translated: o (1000,1000), wall (1100,1000)-(1300,1000), p (1360,1000) | true | **true** | leak |
| diagonal 45 deg: o (0,0), wall (100,100)-(300,300), p (400,400) | true | **true** | leak |
| diagonal arbitrary slope 71.6 deg: o (0,0), wall (100,300)-(200,600), p (250,750), R 900 | true | **true** | leak |
| control: point off the wall's line (560,240) | false | true | correct |
| control: point between viewer and wall on the line (250,200) | false | true | correct |
Code path, measured:
1. The fan casts, per blocking wall endpoint, the endpoint angle with its `RayEps` (1e-4 rad) companions, plus one ray per range-limit direction.
2. The ray/segment helper rejects a segment parallel to the ray (`|cross| < 1e-12`) and reports "no hit".
3. A wall radial to the viewer lies on the ray leaving the viewer, so the nudge rays meet the wall's line only at the viewer: measured hit parameter `t ~ 0` (rejected as degenerate) and segment parameter `u = -0.5` (or `1.5` with the endpoints reversed) - outside the segment. So no nudge ray hits it either.
4. Net: a radial wall is hit by no ray at all. It emits no vertex and no notch, the polygon closes over it, and even-odd `inside` counts points on the line beyond the wall as inside. Polygon vertex count is the same with and without the wall.
5. 64-gon alignment is incidental, not the condition: arbitrary slopes leak identically (45 deg is a range-limit direction, 71.6 deg is not, both reproduce). Alignment only means the range-limit ray coincides with the endpoint ray, so not even a near-miss ray exists.
6. The design document's edge-case note ("Collinear rays skipped (neighbouring +-eps rays cover them)") is false for radial walls: the nudges diverge from the wall's line after leaving the viewer, so they cover the non-radial case only.
7. Baseline `tgeometry` suite passes on current main, so this is a live defect in a green tree, not a broken test.
### Current behavior
A blocking wall collinear with the viewer is treated as absent by the polygon: no shadow, no vertex, no notch. Points on that line beyond the wall are inside the polygon, so a token standing exactly there is sent to the player (`visibleTo` / `playerView`), enters the encountered list, and its cells are explored. A token behind a visually opaque wall is exposed.
### Desired behavior
For every blocking wall, the sight polygon agrees with the straight-line "does the viewer-to-point segment cross a wall" truth, within the documented boundary tolerance:
- point beyond a radial wall on its line, within range, nothing else intervening: **not visible**;
- point on that line between the viewer and the wall: **visible**;
- point on that line behind the viewer: **visible**;
- point beyond the wall but off the line by more than the documented boundary tolerance (0.5 px): **visible** - the wall is zero-width, so it must not invent a wedge;
- both endpoint orderings and both viewer sides behave identically;
- a viewer standing on a wall (on its endpoint or inside its body) is not a special case for this rule: the straight-line truth is the contract, and the tests covering a viewer on a wall state the resulting behaviour explicitly;
- everything non-radial is unchanged: endpoints, the +-nudge fan, T-junctions, shared vertices, corners, free-standing walls, open doors.
### Key interfaces
- The ray/segment intersection helper the polygon fan uses (an `rayHit`-like function returning the nearest hit distance or infinity): today it returns "no hit" for a segment parallel/collinear with the ray. It must report the wall's nearest intersection when the wall lies ahead of the viewer within the segment's span, while keeping the existing degeneracy guards (viewer on the wall or on an endpoint, hits at ~0).
- `visibilityPolygon(o, walls, radius)`: output must carry a vertex or coincident-vertex notch for a radial blocking wall, and stay ordered by angle and CCW.
- `inside(poly, p)` and `segsCross(p, q, a, b)`: contract surfaces; no signature change expected, but `inside` must report a point on the line beyond a radial wall as outside.
- The leak checker's geometry oracle: gains the over-approximation direction described below.
- The design document's edge-case note about skipped collinear rays: rewrite it to what actually holds.
### Acceptance criteria
- [ ] Regression tests in the visibility suite: a radial wall with the viewer on its line and a point behind it must not be visible; both endpoint orders; a translated horizontal wall (grid row) and a vertical wall (grid column); at least one diagonal wall of an arbitrary slope that is not a range-limit direction.
- [ ] No invented wedge, same scenes: a point beyond the wall 0.5 px or more off the line is visible; a point on the line between viewer and wall is visible; a point on the line behind the viewer is visible.
- [ ] The polygon for each radial-wall scene is still simple and angularly ordered (no bow-tie) and carries a vertex (or coincident pair) at the wall's near intersection on that line.
- [ ] At least one test pins the viewer-on-a-wall case (viewer at the wall's endpoint and viewer on its body).
- [ ] The whole geometry test suite stays green, including the existing negative controls: a non-radial wall whose endpoint sits exactly on a range-limit direction still blocks; the nudged-corner, shared-endpoint, T-junction, box-corner, long-thin-corridor and "collinear walls act as one" cases; the random-polygon differential and explored-oracle cases.
- [ ] The leak harness gains a scenario with a plain token hidden behind a radial wall; the checker flags it as a hidden token reaching the subject.
- [ ] The leak checker's geometry oracle gains an over-approximation check: a sampled point that the recomputed polygon calls visible while a blocking wall crosses the viewer-to-point segment is a failure, with the existing boundary tolerance (0.5 px) excluding samples that sit within it of a wall or of the polygon boundary. The check must fail against the unfixed polygon code (demonstrate this on the radial-wall scenario before landing the fix) and pass afterwards.
- [ ] The mutation suite is green, including a new mutation that pins the fix: restoring "collinear means no hit" must fail the new tests.
- [ ] No measurable regression against the existing sight-polygon benchmark (prototype scene and the sparse 5k scene): same order, within noise of the recorded numbers.
- [ ] The design document's claim that neighbouring nudged rays cover collinear walls is corrected, and the boundary-epsilon known-limitation entry still describes the residual hairline shadow accurately.
### Out of scope
- Wall thickness and height. v1 walls are zero-width and full height; per-wall thickness and a real height (low walls one can see over) are a separate enhancement opened from this triage: #37 (walls: per-wall thickness and height (low walls)).
- Client/rendering changes.
- The self-intersecting-polygon side observation in the issue body: **unverified**. A 20 000-scene sweep on current main (six random walls each, proper crossings only, shared endpoints excluded) found none. Not claimed here; it would be its own follow-up if it ever reproduces.
- Wall/vision performance work (spatial index), the explored rasterizer, and door semantics.
- Changing `segsCross` inclusivity or open-door blocking rules.
Root cause. Exactly as reported: rayHit returned Inf for |den| < 1e-12, so the one ray that could hit a wall radial to the viewer (the collinear one) never did, and the endpoint fan's own ±RayEps rays meet the wall's line at the viewer (t = 0, rejected by t > Eps). Fixed after the Walls r1 tree too: reproduced on origin/main at 38941da before touching anything (70-vertex polygon, no wall vertex, inside = true at (560,200)) — so Walls r1 did not retire it.
Repro at the highest seam first. Added the fixture to the one leak world: a wall on the subject's own column (600,700 -> 600,850, the k = 16 ray from (600,640)) with token H1 beyond it at (600,950). With the unfixed geometry the leak checker fails with exactly HIDDEN_TOKEN (token ... is inside the subject's polygon only through a wall), 1 failure; after the fix 0 failures, A and B.
Fix.server/geometry.nimrayHit: when the segment is parallel, Inf only if it is on another line; if it lies on the ray's line, return the nearest point of the overlap (t0 > Eps), so the wall contributes its near end as a vertex and the line's continuation is outside the polygon. A zero-width wall hides exactly that line, so the polygon is right. {.inline.} keeps the fan's inner loop at its old cost (it is called per ray x wall). DESIGN §5.2's collinear bullet and the module header are updated. No algorithm change beyond that; the ANALYSIS-review build item 2 (circle-segment-per-sector ray test) is a perf item and was not touched.
Proof.
tests/tgeometry.nim, suite visibility: 4 new tests — k = 0 horizontal and k = 16 vertical, both wall directions, a 32 px grid translation, 10 degrees (the general radial case, not the 64-gon alignment), plus the negative controls from the report (non-radial wall with an endpoint exactly on a ray still blocks, 0.5 px-off wall still shows the point). All 4 red before the fix, green after.
Leak harness: the new onRayHidden coverage (read off the GM's wall frames + the subject's own positions, asserted in tools/leak.test.mjs) keeps the fixture honest. HIDDEN_TOKEN in tools/leakcheck.nim now also asserts the token-level over-approximation (token centre + viewer -> token segment vs the walls, both shrunk by the 5.4 0.5 px tolerance), which the GEOMETRY class structurally cannot see; header + TESTING §10.3 say so.
Mutations a/b/c still apply and still fail their expected tests (control passes); one-way, window and secretgap groups stay green (full node suite 149/149, nimble test all pass).
Bench (tools/bench.nim, best of 3, same machine; before = 38941da build):
item
before
after
prototype scene poly+cells (target 0.451)
0.049 ms
0.048 ms
5k sparse polygon (target 1.0)
0.085 ms
0.081 ms
5k dense polygon
1.292 ms
1.256 ms
CPU-time cross-check (20k dense polygons, wall-clock unusable under the parallel lanes' load): 25.76 s before, 32.47 s without {.inline.}, 24.89 s with it — that is why the pragma is there. No budget moved.
Fixed in 414bb03.
**Root cause.** Exactly as reported: `rayHit` returned `Inf` for `|den| < 1e-12`, so the one ray that could hit a wall radial to the viewer (the collinear one) never did, and the endpoint fan's own `±RayEps` rays meet the wall's line at the viewer (`t = 0`, rejected by `t > Eps`). Fixed after the Walls r1 tree too: reproduced on `origin/main` at 38941da before touching anything (70-vertex polygon, no wall vertex, `inside` = true at (560,200)) — so Walls r1 did not retire it.
**Repro at the highest seam first.** Added the fixture to the one leak world: a wall on the subject's own column (`600,700 -> 600,850`, the k = 16 ray from (600,640)) with token H1 beyond it at `(600,950)`. With the unfixed geometry the leak checker fails with exactly `HIDDEN_TOKEN` (`token ... is inside the subject's polygon only through a wall`), 1 failure; after the fix 0 failures, A and B.
**Fix.** `server/geometry.nim` `rayHit`: when the segment is parallel, `Inf` only if it is on another line; if it lies on the ray's line, return the nearest point of the overlap (`t0 > Eps`), so the wall contributes its near end as a vertex and the line's continuation is outside the polygon. A zero-width wall hides exactly that line, so the polygon is right. `{.inline.}` keeps the fan's inner loop at its old cost (it is called per ray x wall). DESIGN §5.2's collinear bullet and the module header are updated. No algorithm change beyond that; the ANALYSIS-review build item 2 (circle-segment-per-sector ray test) is a perf item and was not touched.
**Proof.**
- `tests/tgeometry.nim`, suite visibility: 4 new tests — k = 0 horizontal and k = 16 vertical, both wall directions, a 32 px grid translation, 10 degrees (the general radial case, not the 64-gon alignment), plus the negative controls from the report (non-radial wall with an endpoint exactly on a ray still blocks, 0.5 px-off wall still shows the point). All 4 red before the fix, green after.
- Leak harness: the new `onRayHidden` coverage (read off the GM's wall frames + the subject's own positions, asserted in `tools/leak.test.mjs`) keeps the fixture honest. `HIDDEN_TOKEN` in `tools/leakcheck.nim` now also asserts the token-level over-approximation (token centre + viewer -> token segment vs the walls, both shrunk by the 5.4 0.5 px tolerance), which the `GEOMETRY` class structurally cannot see; header + TESTING §10.3 say so.
- Mutations a/b/c still apply and still fail their expected tests (control passes); one-way, window and secretgap groups stay green (full node suite 149/149, nimble test all pass).
**Bench** (`tools/bench.nim`, best of 3, same machine; before = 38941da build):
| item | before | after |
|---|---|---|
| prototype scene poly+cells (target 0.451) | 0.049 ms | 0.048 ms |
| 5k sparse polygon (target 1.0) | 0.085 ms | 0.081 ms |
| 5k dense polygon | 1.292 ms | 1.256 ms |
CPU-time cross-check (20k dense polygons, wall-clock unusable under the parallel lanes' load): 25.76 s before, 32.47 s without `{.inline.}`, 24.89 s with it — that is why the pragma is there. No budget moved.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Found while writing the M3 slice 6 wall-removal restart test (#21): that test moves its wall's
endpoints off the exact 64-gon rays to step around this (
tools/persistence.test.mjs, "Endpoints stayoff the exact 64-gon rays: a ray through a wall endpoint is the documented boundary ambiguity of 5.4").
Not fixed. Security-relevant: player-view leak, the core fog-of-war promise.
Summary
visibilityPolygon(DESIGN 5.1) casts one ray per vertex of the inscribed 64-gon range limit and threerays (
ang,ang ± RayEps) per blocking wall endpoint. The 64-gon directions get no± RayEpscompanions, and
rayHitreturns no hit for a segment collinear with the ray (|den| < 1e-12). A wallthat lies exactly along a 64-gon ray - i.e. a wall whose endpoint is on that ray and whose body runs
along it - is therefore hit by no ray at all. The polygon gets no vertex for it, it casts no shadow, and
a token standing behind it on the same line is
insidethe visibility polygon: it is sent to the playeralthough the wall is between them (DESIGN 3.1).
Where
server/geometry.nim:visibilityPolygon(lines 41-69): the 64-gon rays (46-51, one angle per vertex, no nudges) and theper-endpoint fan (58-63,
ang - RayEps,ang,ang + RayEps).rayHit(31-39):if abs(den) < 1e-12: return Inf # parallel/collinear: grazing, other rays cover it(line 35) andif t > Eps and u >= -Eps and u <= 1 + Eps: t else: Inf(39).RayEps1e-4, inclusive tolerances)",3.1 (a player receives another token only if its centre is inside its own LOS polygon).
inside(token visibility),cellsTouched(explored),server/vision.niminsideAny/visibleTo,server/views.nimplayerView.Mechanism
Read from the code, then confirmed with a throwaway harness against a copy of
server/geometry.nimat1ad9f72(/tmponly; the repo tree was read, never written):a = (300,200),b = (500,200); viewero = (200,200).atan2(b.y-o.y, b.x-o.x) == 0, and thek = 0 64-gon ray is
arctan2(sin 0, cos 0) == 0: the endpoint angle is a duplicate of a range-limitdirection, so the fan has no ray of its own to spend on it.
rayHitrejects collinear segments(
den == 0 -> Inf).± RayEpscompanions cannot rescue it either: for a wall lying along a sight line, the ray linemeets the wall's line at the token itself, so
t ≈ 0andt > Epsrejects it (measured:t = 0,u = -0.027fordphi = ±1e-4, souis out of[0,1]too).2π/64 = 5.625°away and, being off the wall's line, never crossthe segment at all.
visibilityPolygonreturns 70 vertices insteadof 76), the polygon closes over it, and
inside- even-odd - counts a point on the line beyond thewall as seen. Note the wall is not merely "grazed": it contributes no coverage, so the region it should
shade is entirely inside the polygon (a zero-width slit in exact arithmetic, but exactly the slit a
token on that line sits in).
Note [INFERRED, measured]: the 64-gon alignment is the reported instance, not the general condition - a
wall radial to the viewer at an arbitrary angle behaves identically (checked at 10°), because its own
± RayEpsrays also land ont ≈ 0. What a 64-gon direction adds is that the fan holds a ray exactlythere while holding none at
± RayEps, which is what makes the leak look like "a wall endpoint on a64-gon ray". Grid-snapped, axis-aligned scenes are where this arises in practice: a wall on a grid row
and a token on the same row.
Side observation (separate finding, low confidence, not claimed as this bug): random degenerate wall
fields produced self-intersecting polygons - 1074 of 20000 scenes with an on-ray wall, 528 of 20000
without - where even-odd
insideresolves the overlapping sliver arbitrarily. Worth its own look if itever shows up in a real scene.
Repro sketch
[MEASURED, harness against a copy of
server/geometry.nimat 1ad9f72; the repo was not modified and notest was run against the working tree, which another agent is editing]
Scene: vision origin
o = (200,200), rangeR = 600, no other walls or doors.segsCross(o,p,a,b)inside(poly, p)The same by pure translation for a vertical wall on a grid column with the token on that column (the
k = 16 ray,
(200,300)-(200,4000)from a token at(200,200): same result), and for any row/column themap snaps to.
Unverified part: a non-radial wall whose endpoint sits exactly on a 64-gon ray did not leak in a sweep
of 600 random such scenes compared against a 4096-direction radial ray cast (max over-approximation
3e-14 px). If the wall that failed in slice 6 was not radial, its exact coordinates are needed to pin it
down; the per-endpoint
± RayEpsfan does handle that shape (verified with the control above).Impact
visibleTo-> it is fanned out tothe player in
playerViewwith its position and radius, and it enters the player's encountered list,which only the GM can prune.
maps and axis-aligned walls make exact collinearity routine rather than exotic. This is the degenerate
wall the slice-6 test walks around rather than fixing.
gm_onlytoken is refused before the LOS test invisibleTo, so this does not exposeGM-only tokens. Explored cells: a radial wall leaves the polygon covering both sides, so the explored
set shows no shadow line; cells off the line are marked, but for a zero-thickness wall that is
geometrically correct, so no separate explored defect is claimed here.
Acceptance
tests/tgeometry.nim, suite "visibility": a wall lying along a 64-gon ray with the viewer on itsline; the point behind the wall must not be
inside, and the polygon must carry a vertex for thewall. Same case translated to an axis row/column (grid snapping), both ray directions.
(the table above), and the existing "rays nudged past a corner" / shared-endpoint / T-junction cases
plus the
/tools/mutation.sha/b/c mutations must stay green - the fix must not trade this leak forthe under-approximation those guard.
tools/leak.mjsscenario with a plain token hidden behind such a wall, assertedabsent from the subject's view via the
HIDDEN_TOKENclass. The checker'sGEOMETRYclass(
tools/leakcheck.nim, ~line 636) only tests missing vision (clearLine(o,p) and not inside(poly,p)), so it structurally cannot see this leak; either add an over-approximation check(a sampled point inside the polygon with no clear LOS and not within the 5.4 boundary tolerance) or
rely on the token-level assertion and say so in the checker's header comment.
tgeometrysuite (visibility, cells, corpus,differential and explored-oracle cases), the leak harness on its current scenarios, and the polygon
cost in
results/bench.log(same order of magnitude).Related
the workaround.
GEOMETRYclass cannot express.Agent Brief
Category: bug
Summary: A wall lying along the viewer's line of sight casts no shadow: points behind it on that line are reported visible.
Domain rule (owner decision)
A wall hides whatever its physical dimensions hide. In v1 walls are zero-width and full height, so a wall seen edge-on (collinear with the viewer) hides exactly the points behind it on that line - nothing more (no invented wedge), nothing less. For those points the sight polygon must agree with the straight-line "does the segment from the viewer to the point cross a wall" truth.
Verification on current main (2026-11-15,
e13fa90)Confirmed, on a scratch copy of the vision module, devbox nim; the repo tree was not modified.
segsCross(o,p,wall)inside(poly,p)Code path, measured:
RayEps(1e-4 rad) companions, plus one ray per range-limit direction.|cross| < 1e-12) and reports "no hit".t ~ 0(rejected as degenerate) and segment parameteru = -0.5(or1.5with the endpoints reversed) - outside the segment. So no nudge ray hits it either.insidecounts points on the line beyond the wall as inside. Polygon vertex count is the same with and without the wall.tgeometrysuite passes on current main, so this is a live defect in a green tree, not a broken test.Current behavior
A blocking wall collinear with the viewer is treated as absent by the polygon: no shadow, no vertex, no notch. Points on that line beyond the wall are inside the polygon, so a token standing exactly there is sent to the player (
visibleTo/playerView), enters the encountered list, and its cells are explored. A token behind a visually opaque wall is exposed.Desired behavior
For every blocking wall, the sight polygon agrees with the straight-line "does the viewer-to-point segment cross a wall" truth, within the documented boundary tolerance:
Key interfaces
rayHit-like function returning the nearest hit distance or infinity): today it returns "no hit" for a segment parallel/collinear with the ray. It must report the wall's nearest intersection when the wall lies ahead of the viewer within the segment's span, while keeping the existing degeneracy guards (viewer on the wall or on an endpoint, hits at ~0).visibilityPolygon(o, walls, radius): output must carry a vertex or coincident-vertex notch for a radial blocking wall, and stay ordered by angle and CCW.inside(poly, p)andsegsCross(p, q, a, b): contract surfaces; no signature change expected, butinsidemust report a point on the line beyond a radial wall as outside.Acceptance criteria
Out of scope
segsCrossinclusivity or open-door blocking rules.Fixed in
414bb03.Root cause. Exactly as reported:
rayHitreturnedInffor|den| < 1e-12, so the one ray that could hit a wall radial to the viewer (the collinear one) never did, and the endpoint fan's own±RayEpsrays meet the wall's line at the viewer (t = 0, rejected byt > Eps). Fixed after the Walls r1 tree too: reproduced onorigin/mainat38941dabefore touching anything (70-vertex polygon, no wall vertex,inside= true at (560,200)) — so Walls r1 did not retire it.Repro at the highest seam first. Added the fixture to the one leak world: a wall on the subject's own column (
600,700 -> 600,850, the k = 16 ray from (600,640)) with token H1 beyond it at(600,950). With the unfixed geometry the leak checker fails with exactlyHIDDEN_TOKEN(token ... is inside the subject's polygon only through a wall), 1 failure; after the fix 0 failures, A and B.Fix.
server/geometry.nimrayHit: when the segment is parallel,Infonly if it is on another line; if it lies on the ray's line, return the nearest point of the overlap (t0 > Eps), so the wall contributes its near end as a vertex and the line's continuation is outside the polygon. A zero-width wall hides exactly that line, so the polygon is right.{.inline.}keeps the fan's inner loop at its old cost (it is called per ray x wall). DESIGN §5.2's collinear bullet and the module header are updated. No algorithm change beyond that; the ANALYSIS-review build item 2 (circle-segment-per-sector ray test) is a perf item and was not touched.Proof.
tests/tgeometry.nim, suite visibility: 4 new tests — k = 0 horizontal and k = 16 vertical, both wall directions, a 32 px grid translation, 10 degrees (the general radial case, not the 64-gon alignment), plus the negative controls from the report (non-radial wall with an endpoint exactly on a ray still blocks, 0.5 px-off wall still shows the point). All 4 red before the fix, green after.onRayHiddencoverage (read off the GM's wall frames + the subject's own positions, asserted intools/leak.test.mjs) keeps the fixture honest.HIDDEN_TOKENintools/leakcheck.nimnow also asserts the token-level over-approximation (token centre + viewer -> token segment vs the walls, both shrunk by the 5.4 0.5 px tolerance), which theGEOMETRYclass structurally cannot see; header + TESTING §10.3 say so.Bench (
tools/bench.nim, best of 3, same machine; before =38941dabuild):CPU-time cross-check (20k dense polygons, wall-clock unusable under the parallel lanes' load): 25.76 s before, 32.47 s without
{.inline.}, 24.89 s with it — that is why the pragma is there. No budget moved.