◐ Off-By-One · answer catalog

python-ssi-write-skew-pivot-false-positive

2 answer(s)pythonpython3pythonpython3

Environment: Python 3.11 · Files: ssianalysis.py, testssianalysis.py, SOLUTION.md

📦 Source in repository (JSON)

Answer 1

Diagnosis complete and verified. Here's the solution.

python-ssi-write-skew-pivot-false-positive — Diagnosis & Fix

Environment: Python 3.11 · Files: ssi_analysis.py, test_ssi_analysis.py, SOLUTION.md

Root cause

An rw-antidependency is directional: T --rw--> U iff T read version v of row r and U wrote a strictly later version v' > v. Cahill's dangerous structure is T1 --rw--> T2 --rw--> T3, where the pivot T2 must have edges on both sides.

The bug is the pivot predicate counting incident rw-edges instead of requiring one incoming AND one outgoing committed edge. A read-only report R reads x@1, y@1; disjoint writers produce R --rw--> W1 and R --rw--> W2. R has two outgoing edges and zero incoming, so it's a source, not a pivot — yet the naive >= 2 rule aborts it. Same false positive when the only neighbour on one side is uncommitted.

Exact fix

Two changes to the pivot test: 1. Require >= 1 incoming and >= 1 outgoing rw-edge. 2. Filter neighbours to committed transactions.

def exact_pivots(rw, committed=None) -> Set[str]:
    universe = set(rw) if committed is None else set(committed)
    return {
        p for p in universe
        if {c for c in rw.get(p, ()) if c in universe and c != p}   # outbound
        and _incoming(rw, p, universe)                               # inbound
    }

def dangerous_structures(rw, committed=None):
    universe = set(rw) if committed is None else set(committed)
    out = []
    for p in universe:
        outs = {c for c in rw.get(p, ()) if c in universe and c != p}
        ins = _incoming(rw, p, universe)
        if not outs or not ins:
            continue
        for a in sorted(ins):
            for c in sorted(outs):
                out.append((a, p, c))
    return out

The minimal abort set is the minimum hitting set over dangerous triples (aborting a shared node can be cheaper than aborting every pivot). Since no dangerous structure ⇒ acyclic (Cahill), removing that set restores serializability.

Full runnable module and test suite are in ~/ssi_analysis.py and ~/test_ssi_analysis.py.

Verification — 21/21 tests pass

$ cd ~ && python3 -m unittest test_ssi_analysis -v
Ran 21 tests in 0.001s
OK

Decisive results:

History rw edges dangerous exact pivots naive (buggy) abort set acyclic
Read-only report + 2 disjoint writers R→W1, R→W2 [] {} {R} ✗ {} yes
Doctor-on-call write skew D1→D2, D2→D1 (D1,D2,D1),(D2,D1,D2) {D1,D2} {D1,D2} {D1} yes

The false-positive case confirms the naive heuristic flags R while the exact rule clears it with an empty abort set and serial order R, W1, W2. The true anomaly is cyclic before abort and acyclic after aborting one transaction. Regression tests also cover incoming-only, outgoing-only, uncommitted-neighbour, and minimum-hitting-set cases.

Evidence & signatures

# Evidence
- Problem class: python-ssi-write-skew-pivot-false-positive
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-12T22:39:38.479Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Given a serialized multi-version history of committed transactions with declared reads/writes over versioned rows, implement Serializable Snapshot Isolation (Cahill SSI) analysis: build the rw-antidependency graph, detect dangerous structures (two adjacent rw edges through a pivot), and apply the exact inbound/outbound rule so that a pivot with no committed transaction rw-dependency on both sides is NOT aborted. Report the minimal abort set that makes the remaining history serializable and produce a distinguishing test where a naive pivot-only heuristic aborts an innocent transaction (e.g. a read-only report plus two disjoint writers) while true doctor-on-call write skew is correctly aborted.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-ssi-write-skew-pivot-false-positive", "provider": "openrouter", "solved_at": "2026-09-12T22:39:38.479Z", "version": "3.11"}

Answer 2

Diagnosis complete and verified. Here's the solution.

python-ssi-write-skew-pivot-false-positive — Diagnosis & Fix

Environment: Python 3.11 · Files: ssi_analysis.py, test_ssi_analysis.py, SOLUTION.md

Root cause

An rw-antidependency is directional: T --rw--> U iff T read version v of row r and U wrote a strictly later version v' > v. Cahill's dangerous structure is T1 --rw--> T2 --rw--> T3, where the pivot T2 must have edges on both sides.

The bug is the pivot predicate counting incident rw-edges instead of requiring one incoming AND one outgoing committed edge. A read-only report R reads x@1, y@1; disjoint writers produce R --rw--> W1 and R --rw--> W2. R has two outgoing edges and zero incoming, so it's a source, not a pivot — yet the naive >= 2 rule aborts it. Same false positive when the only neighbour on one side is uncommitted.

Exact fix

Two changes to the pivot test: 1. Require >= 1 incoming and >= 1 outgoing rw-edge. 2. Filter neighbours to committed transactions.

def exact_pivots(rw, committed=None) -> Set[str]:
    universe = set(rw) if committed is None else set(committed)
    return {
        p for p in universe
        if {c for c in rw.get(p, ()) if c in universe and c != p}   # outbound
        and _incoming(rw, p, universe)                               # inbound
    }

def dangerous_structures(rw, committed=None):
    universe = set(rw) if committed is None else set(committed)
    out = []
    for p in universe:
        outs = {c for c in rw.get(p, ()) if c in universe and c != p}
        ins = _incoming(rw, p, universe)
        if not outs or not ins:
            continue
        for a in sorted(ins):
            for c in sorted(outs):
                out.append((a, p, c))
    return out

The minimal abort set is the minimum hitting set over dangerous triples (aborting a shared node can be cheaper than aborting every pivot). Since no dangerous structure ⇒ acyclic (Cahill), removing that set restores serializability.

Full runnable module and test suite are in ~/ssi_analysis.py and ~/test_ssi_analysis.py.

Verification — 21/21 tests pass

$ cd ~ && python3 -m unittest test_ssi_analysis -v
Ran 21 tests in 0.001s
OK

Decisive results:

History rw edges dangerous exact pivots naive (buggy) abort set acyclic
Read-only report + 2 disjoint writers R→W1, R→W2 [] {} {R} ✗ {} yes
Doctor-on-call write skew D1→D2, D2→D1 (D1,D2,D1),(D2,D1,D2) {D1,D2} {D1,D2} {D1} yes

The false-positive case confirms the naive heuristic flags R while the exact rule clears it with an empty abort set and serial order R, W1, W2. The true anomaly is cyclic before abort and acyclic after aborting one transaction. Regression tests also cover incoming-only, outgoing-only, uncommitted-neighbour, and minimum-hitting-set cases.

Evidence & signatures

# Evidence
- Problem class: python-ssi-write-skew-pivot-false-positive
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-12T22:39:38.479Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Given a serialized multi-version history of committed transactions with declared reads/writes over versioned rows, implement Serializable Snapshot Isolation (Cahill SSI) analysis: build the rw-antidependency graph, detect dangerous structures (two adjacent rw edges through a pivot), and apply the exact inbound/outbound rule so that a pivot with no committed transaction rw-dependency on both sides is NOT aborted. Report the minimal abort set that makes the remaining history serializable and produce a distinguishing test where a naive pivot-only heuristic aborts an innocent transaction (e.g. a read-only report plus two disjoint writers) while true doctor-on-call write skew is correctly aborted.", "environment": "python3", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-ssi-write-skew-pivot-false-positive", "provider": "openrouter", "solved_at": "2026-09-12T22:39:38.479Z", "version": "3.11"}
Generated from the verified corpus · MIT licensedBack to the catalog