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
2 changes: 2 additions & 0 deletions .claude/board/entries/2026-10-25-drf-w3-ordered-apply.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
over 4 rows in a scrambled staging order match a scalar oracle (highest position per row).
- **W3 PASS (refusal arm):** different values at one declared position, or an unordered
`stage` next to a positioned one, refuse with `Conflict`. Equal values coalesce in both.
An unordered write is checked against every positioned value of its facet, not only its
sorted neighbour (`stage 1`, `stage_at 1@5`, `stage_at 2@6` refuses; codex P2 on #1766).
- **Mechanism:** patches sort by `(ord, offset, pos)` and apply in that order, so the
sort is the order of application; no second pass.
- **Disables, each red on its own test:** sort without `pos` (staging order wins); treat
Expand Down
11 changes: 11 additions & 0 deletions crates/drf-focus-probe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,17 @@ impl Writeback<'_> {
});
}
self.patches.sort_by_key(|p| (p.ord, p.offset, p.pos));
// Value of the current facet group's unordered writes. `None` sorts
// first, so they all precede the group's positioned writes; an
// unordered write has no order against ANY of them, not just the
// first, so every positioned value must equal it.
let mut unordered: Option<i32> = None;
for w in self.patches.windows(2) {
if (w[0].ord, w[0].offset) != (w[1].ord, w[1].offset) {
unordered = None;
} else if w[0].pos.is_none() {
unordered = Some(w[0].value);
}
if w[0].ord != w[1].ord {
continue;
}
Expand All @@ -396,6 +406,7 @@ impl Writeback<'_> {
let same = w[0].offset == w[1].offset;
let ordered = matches!((w[0].pos, w[1].pos), (Some(a), Some(b)) if a != b);
if (same && w[0].value != w[1].value && !ordered)
|| (same && unordered.is_some_and(|u| u != w[1].value))
|| (!same && w[1].offset < w[0].offset + Facet::WIDTH)
{
return Err(Refusal::Conflict {
Expand Down
33 changes: 33 additions & 0 deletions crates/drf-focus-probe/tests/integration/focus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,36 @@ fn w3_equal_positions_or_mixed_ordering_with_different_values_refuse() {
4i32.to_le_bytes()
);
}

#[test]
fn w3_an_unordered_write_conflicts_with_every_different_positioned_value_in_its_group() {
// Codex P2 on #1766: after the sort the unordered write sits next to the
// equal-valued position-5 write only, so a neighbour check never compares
// it with the value-2 write at position 6. Nothing orders 1 against 2.
let r = rows();
let soa = Soa {
rows: &r,
id: sid(1, 1, 1, 9),
};
let m = map_from(307, 9, |s| if s < 3 { 500 } else { (s % NROWS) as u16 });
let mgr = FocusManager::new();
let f = mgr.load(&soa, &m, Scope(1), facet()).unwrap();
let mut wb = f.writeback();
wb.stage(0, facet(), 1).unwrap();
wb.stage_at(1, facet(), 1, 5).unwrap();
wb.stage_at(2, facet(), 2, 6).unwrap();
assert_eq!(
wb.flush(&soa).err(),
Some(Refusal::Conflict {
ord: 500,
offset: OFF
})
);
// Silence twin: every positioned value equals the unordered one.
let mut wb = f.writeback();
wb.stage(0, facet(), 1).unwrap();
wb.stage_at(1, facet(), 1, 5).unwrap();
wb.stage_at(2, facet(), 1, 6).unwrap();
let imgs = wb.flush(&soa).unwrap();
assert_eq!(imgs[0].row[OFF..OFF + 4], 1i32.to_le_bytes());
}
Loading