Repository navigation
abi: the sole-closer contract — and a real leak found behind two reviewers disagreeing #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,12 +252,12 @@ plan falsifies it directly rather than assuming it. | |
| | Question | Answer | | ||
| |---|---| | ||
| | Who owns this memory? | Rust. Always. Java never allocates a lane. | | ||
| | How long does a `MemorySegment` remain valid? | Until `lgj_close` on the owning handle. Java models this with an `Arena` whose lifetime is *nested inside* the resource's, so closing the resource is what ends the segment's usefulness — and the `epoch` field lets Java detect a stale segment it still holds. | | ||
| | How long does a `MemorySegment` remain valid? | Until `lgj_close` on the owning handle. ⚠ **Java does not model this with a scope.** A lane/mask window is `MemorySegment.ofAddress(addr).reinterpret(len)` (`Engine.windowOf`) — an **unbounded-lifetime** segment that cannot observe its resource closing. (The `Arena`s in the facade back *output scratch*, e.g. `RowStore`'s result buffer; they never back a lane window, so an earlier claim that segment lifetime is "nested inside" a resource's arena was wrong.) What actually detects staleness is **re-asking the substrate**: `Mask.words()` re-describes through `lgj_mask_describe` on every use of its cache and compares the returned `epoch` with the stamp it holds. `RowStore`'s cached lanes do **not** do this — see `ISS-LGJ-EPOCH-UNCHECKED`, and *The sole-closer contract* below. | | ||
| | What invalidates a view? | Closing the owner, or closing the owner's parent. | | ||
| | Can native storage relocate? | **No.** Lanes are allocated once at `lgj_pattern_open` and never reallocated, resized, or moved while the resource is alive. This is a hard ABI guarantee; any future growable lane requires a `major` bump. | | ||
| | Can Java mutate it? | Only where `LGJ_FLAG_WRITABLE` is set on the descriptor. Pattern lanes are **read-only**; mask words are writable. | | ||
| | What happens when the resource closes? | Its lanes are freed, its generation is bumped, its children fail with `PARENT_CLOSED`. | | ||
| | Can a child view outlive the parent? | It can *exist* but not *work* — every operation on it returns `PARENT_CLOSED`. | | ||
| | Can a child view outlive the parent? | It can *exist* but not *work* — every operation that **resolves the child with its parent** (`resolve_mask_with_parent`: `mask_count`, `mask_describe`, `mask_and`, …) returns `PARENT_CLOSED`. Two exclusions, both deliberate and both covered by tests: `lgj_resource_info` resolves the child's **own** slot, which is still live, and returns `OK`; and `lgj_close(child)` on an orphan also returns `OK`, since the child is still a real resource to release. ⚠ Nor does any of this cover a descriptor address Java has already cached and reads directly — that read resolves nothing, so no status is returned at all. See *The sole-closer contract* below. | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win Align the earlier ABI table rows with the narrowed lifetime contract. The table still contains two stale guarantees: the child-operation row says all child operations return 📍 Affects 1 file
🤖 Prompt for AI Agents |
||
| | How are errors represented? | Negative `i32` status. Never a panic across the boundary (§9). | | ||
|
|
||
| ### Concurrency | ||
|
|
@@ -269,6 +269,44 @@ So bulk ops on distinct resources run concurrently, and only | |
| open/close serialize globally. Stated honestly: this has not been benchmarked | ||
| under contention, and the POC's Java layer is single-threaded. | ||
|
|
||
| #### The sole-closer contract (normative for callers; NOT enforced) | ||
|
|
||
| **A resource handle has exactly one closer: the facade object that owns it.** | ||
| Closing a handle by any other route, or from any other thread, is outside this | ||
| ABI version's contract, and the result is undefined behaviour rather than an | ||
| error status. | ||
|
|
||
| This is a **documented contract, not an enforced one**, and the distinction is | ||
| load-bearing — three facts make it unenforceable from the Java side, so a | ||
| caller who violates it gets no diagnostic: | ||
|
|
||
| 1. `Engine.close(long)` is reachable outside the owning facade object, so | ||
| nothing structurally prevents a second closer. | ||
| 2. `Engine.windowOf` builds an **unbounded-lifetime** `MemorySegment` from a | ||
| descriptor address. The segment cannot observe its resource closing; it has | ||
| no FFM scope tied to the resource's lifetime. | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| 3. The facade's own `closed` flags are plain non-volatile booleans, so they | ||
| carry both a check-then-act race and a *visibility* race across threads. | ||
|
|
||
| **Why the generation-checked registry does not close this.** It fails closed on | ||
| every *handle resolve*, which is why every operation that resolves a child **with | ||
| its parent** returns `PARENT_CLOSED` once that parent is gone (the exclusions are | ||
| in the resource table above: `lgj_resource_info` and `lgj_close` resolve the | ||
| child's own slot and return `OK`). But a cached descriptor read resolves nothing: | ||
| Java holds the address, reads through it, and the registry is never consulted. | ||
| Re-authorising the cached address before each use (as `Mask.words()` does, via | ||
| `lgj_mask_describe`) **narrows** the window — the probe's read is a native | ||
| acquire through the registry `RwLock` — and does not close it, because a close | ||
| landing between the probe's return and the segment read is still unguarded. | ||
|
|
||
| So the contract's scope is precisely the residue: single-closer, and no | ||
| concurrent close against a live reader. A concurrent Java writer would need a | ||
| documented protocol, which this ABI version does not define. | ||
|
|
||
| Tracked as `ISS-LGJ-CACHED-DESCRIPTOR-CROSS-THREAD-WINDOW`. It closes when the | ||
| ABI defines a concurrent access protocol that makes this enforceable rather than | ||
| merely stated. | ||
|
|
||
| ## 5. Descriptors describe lanes, not pointers | ||
|
|
||
| Java's *public* API never sees an address. Internally, `LgjLaneDesc` is the | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the issue-number formatting at Line 230.
The leading
#57triggers markdownlint MD018 (no-missing-space-atx). Format the issue number as inline code or bold text so the ledger remains prose and the Markdown check passes.Proposed fix
This finding is based on the supplied markdownlint warning.
📝 Committable suggestion
🧰 Tools
🪛 markdownlint-cli2 (0.23.2)
[warning] 230-230: No space after hash on atx style heading
(MD018, no-missing-space-atx)
🤖 Prompt for AI Agents
Source: Linters/SAST tools