Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .claude/board/ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ path while **leaving a second, independent verdict standing beside it**:
| #55 (8th) | — | the entry declared its own run void, then acted on it one paragraph later |
| #57 (9th) | `abi.md`'s "**every** operation returns `PARENT_CLOSED`" | "every **handle-mediated** operation returns `PARENT_CLOSED`" — still false |
| #58 (10th) | Q4's *conclusion*, made conditional | the *adjacent* sentence, still claiming close-after-cache is out of contract |
| #60 (11th) | fence 1b, built to catch a missing W1 block | a whole-file scan the block's own deletion could not turn red |

**The tenth arrived inside the fix for the eighth's cousin, one hop sideways.**
Two reviewers made Q4's conclusion conditional; the qualification landed, and
Expand All @@ -317,6 +318,26 @@ implied `requireOpen()` guards nothing in contract — an invitation to delete
the guard that makes the ordinary case safe. The ninth instance cost a
quantifier; this one could have cost a check.

**The eleventh is the one I had the evidence to catch and did not.** Fence 1b
was written to fail when the W1 class block is deleted; it scanned the whole
FILE, and `Mask.materializeRows()` independently names *happens-before* — so
the very regression it targets left it green. Codex found it on #60.

**The disproof was inside my own disable run.** Turning 1b red required
stripping **two** occurrences. I noticed the second, removed it to finish the
disable, and never asked why two were needed. **A disable that removes more
than the regression does not demonstrate the regression is caught** — it
demonstrates that removing everything works, which was never in doubt. The rule
this adds to the falsifier discipline: *the disable must be exactly the
regression; if it has to be widened to go red, the widening IS the finding.*

**A second, smaller lesson from the repair.** Scoping the scan to the class
javadoc immediately failed four arms on prose that plainly said the right
thing — because javadoc WRAPS, and "no guard detects it" split across two
lines matches no literal. A doc fence must normalize the region (strip the
`*` furniture, collapse whitespace, fold case) or it enforces where an author
pressed return.

**What generalizes past instance nine:** nine was the same *sentence* narrowed
and still wrong. Ten is a *neighbouring* sentence left asserting the stronger
claim after its neighbour was weakened. So the sweep after any qualification is
Expand Down
13 changes: 12 additions & 1 deletion .claude/board/PR_ARC_INVENTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,21 @@
observable distinguishes a leaked slot from a live one, so
`orphanCloseActuallyReleases` asserts a **second** close is REJECTED — which
can only happen if the first one ran. Red-then-green verified; 337 → **338**.
- **Arm (ii)'s written contract, finally landed.** `docs/abi.md` "Concurrency"
- **Arm (ii)'s written contract, PARTLY landed.** `docs/abi.md` "Concurrency"
gains *The sole-closer contract (normative for callers; NOT enforced)*,
carried at all three `close()` sites, stated **with the three facts that make
it unenforceable** rather than as a bare rule.
- ⊘ **Corrected on #60 (Codex P2, raised on #59 after it merged).** This line
read *"finally landed"*, which **hid two ratified obligations**: W1 (a
thread-safety block on `RowStore` and `Mask` naming the caller's
*happens-before* duty, plus a `DoctrineFenceTest` leg asserting the literal)
and W2 (root `CLAUDE.md`'s wording matching the mechanism, plus a fence leg
that actually READS the doctrine file — W2's own words: *"this precedent
must be built, not merely cited"*). Neither existed. Worse, `CLAUDE.md` had
gone **stale the day W1.1 shipped**: it still said the cached path takes
"NO further registry call" and that `epoch` "is unconsulted anywhere in
`src/main`" — both false for `Mask` since #53, in the file every session
reads first. All four landed in #60 with two disable-runs red-then-green.
- **Three doc overclaims corrected, each verified in source first.** (1) *"every
operation on an orphaned child returns `PARENT_CLOSED`"* — this PR's own first
correction narrowed it to *"every **handle-mediated** operation"* and that was
Expand Down
12 changes: 12 additions & 0 deletions .claude/plans/epoch-recheck-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ raw-segment read.

### What arm (ii) obliges — six, and W1/W2 are mechanically checkable

> **STATUS 2026-08-28 (#60): W1 and W2 are BUILT.** Both were recorded as
> discharged on #57's arc entry — by the two words *"finally landed"* — while
> neither existed; Codex caught it on #59, after that PR had merged. What now
> exists: the thread-safety block on `RowStore` and `Mask` (the literal
> `happens-before`, absent from `java/src` entirely until then) plus the
> once-per-scan note on `materializeRows()`; the corrected `CLAUDE.md` wording;
> and **two new `DoctrineFenceTest` legs** — 1b (W1) and 1c (W2). **W2's
> "this precedent must be built, not merely cited" is discharged by 1c**, the
> first leg in that class to open the doctrine file rather than cite it.
> Both legs are disable-verified red-then-green. **W3-W6 are unaffected by this
> note** and are not claimed here.

- **W1 — Javadoc scope, on both classes.** A thread-safety block on
`RowStore` and `Mask`: the facade is not thread-safe; the caller must
establish happens-before between `close()` and every access; a concurrent
Expand Down
32 changes: 22 additions & 10 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,28 @@ build):
`use_after_close_is_a_status_not_a_crash`, the falsifier that holds
unconditionally). Generation is `u32` and wraps after 2³² closes of one
slot (documented in-source at the wrap site; not reachable in practice).
**Scope note, not covered by the registry check:** `lgj_lane_describe`/
`lgj_mask_describe` hand Java a raw `addr` once, which Java then caches
(`RowStore.java`'s `lanes[]`, `Mask.java`'s `words`) and reads directly
on every subsequent access with NO further registry call — that repeat
path is guarded only by a Java-side `closed` boolean, a strictly weaker,
non-generation-checked mechanism. `LgjLaneDesc` carries an `epoch` field
designed for exactly this re-check and it is currently unconsulted
anywhere in `src/main` (tracked: `.claude/board/ISSUES.md`
`ISS-LGJ-EPOCH-UNCHECKED`). Do not read "fails closed before dereference"
as covering the cached-descriptor path until that epoch check is wired.
**Scope note — the cached-descriptor path, corrected 2026-08-28 (plan W2;
the earlier text was written before W1.1 shipped and went stale the day
it did).** `lgj_lane_describe`/`lgj_mask_describe` hand Java a raw `addr`,
which Java caches (`RowStore.java`'s `lanes[]`, `Mask.java`'s `words`).
The two halves now differ and must not be described together:
- **`Mask`** re-validates the cached window against the generation-checked
registry **at each top-level facade call** (`Mask.words()` re-describes
through `lgj_mask_describe`, which resolves the mask WITH its parent, and
compares the returned `epoch` against the stamp it holds). This is
**not atomic with respect to a concurrent `close`** — it narrows the
window, it does not close it.
- **`RowStore`** does **not**: its `lanes[]` reads consult only the
Java-side `closed` boolean, a strictly weaker, non-generation-checked
mechanism. `ISS-LGJ-EPOCH-UNCHECKED` stays OPEN, scoped to `RowStore`.

⊘ Struck: the earlier claim that this path reads "with NO further registry
call" and that `epoch` "is currently unconsulted anywhere in `src/main`".
Both were true when written and both became false with W1.1 (#53) —
`Mask.words()` is the counter-example to each. Do not read "fails closed
before dereference" as covering `RowStore`'s cached lanes; for `Mask`,
read it as re-validated per facade call and racy against a concurrent
close, never as a guarantee that holds through a scan.
- **Bounds/overflow are checked, never wrapped, at the point n_rows is
first derived.** `rowstore.rs` uses `checked_mul` at its two allocation
sites (`generate_in`/`generate_with_edges_in`); overflow there fails
Expand Down
22 changes: 22 additions & 0 deletions java/src/main/java/com/adaworldapi/lancegraph/Mask.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
* object, but it can never work after the parent closes: every operation then throws
* {@link ClosedResourceException}, which is the Java face of the ABI's {@code PARENT_CLOSED}. There
* is no arrangement of closes that lets a selection read freed memory.
*
* <h2>Thread safety — this class is NOT thread-safe (arm (ii), plan W1)</h2>
*
* <p><strong>The caller must establish <em>happens-before</em> between {@link #close()} and every
* other access.</strong> A concurrent close-vs-access is <strong>undefined, and no guard detects
* it</strong> — not the {@code closed} flag (a plain non-volatile field, so it carries both a
* check-then-act and a visibility race) and not the substrate, because a cached descriptor read
* resolves no handle and so returns no status.
*
* <p>This is the Java-side half of {@code docs/abi.md}'s <em>sole-closer contract</em>: one
* handle, one closer, no concurrent close against a live reader. Documented, not enforced —
* {@code Engine.close(long)} is reachable outside this object and nothing here can stop it.
* Tracked as {@code ISS-LGJ-CACHED-DESCRIPTOR-CROSS-THREAD-WINDOW}.
*/
public final class Mask implements AutoCloseable {

Expand Down Expand Up @@ -96,6 +109,15 @@ public Mask minus(Mask other) {
*
* <p>Prefer {@link #count()} when only a number is needed — it never reads a word.
*
* <p><strong>Guard scope (plan W1): the liveness check runs ONCE for the whole scan, not
* per bit.</strong> {@link #words} re-authorises the cached window with the substrate when
* this method resolves it, and the bit walk that follows is entirely in-process. So a close
* landing <em>after</em> that check and <em>during</em> the walk is not detected — see the
* class-level thread-safety note, which requires the caller to establish
* <em>happens-before</em> between {@link #close()} and this call. That one-check-per-scan
* shape is exactly what makes the check affordable here, and is why the same guard was never
* a foregone conclusion for {@code RowStore}'s per-accessor-call reads.
*
* @throws ClosedResourceException if this selection, or its resource, is closed
*/
public long[] materializeRows() {
Expand Down
13 changes: 13 additions & 0 deletions java/src/main/java/com/adaworldapi/lancegraph/RowStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
* <p>Ordinary try-with-resources, mirroring {@link NativePattern}. After {@link #close()} every
* operation on this resource, and on any {@link Mask} or {@link FacetMatchView} derived from it,
* throws {@link ClosedResourceException}. Closing twice is an error, not a silent no-op.
*
* <h2>Thread safety — this class is NOT thread-safe (arm (ii), plan W1)</h2>
*
* <p><strong>The caller must establish <em>happens-before</em> between {@link #close()} and every
* other access.</strong> A concurrent close-vs-access is <strong>undefined, and no guard detects
* it</strong> — not the {@code closed} flag (a plain non-volatile field, so it carries both a
* check-then-act and a visibility race) and not the substrate, because a cached descriptor read
* resolves no handle and so returns no status.
*
* <p>This is the Java-side half of {@code docs/abi.md}'s <em>sole-closer contract</em>: one
* handle, one closer, no concurrent close against a live reader. Documented, not enforced —
* {@code Engine.close(long)} is reachable outside this object and nothing here can stop it.
* Tracked as {@code ISS-LGJ-CACHED-DESCRIPTOR-CROSS-THREAD-WINDOW}.
*/
public final class RowStore implements NativeResource, AutoCloseable {

Expand Down
Loading