FAILURE MAP
← Case archive

FA-1381 / Concurrency / Open access

Grant permits from a distributed semaphore: A zero or negative grant corrupts permit accounting · case 01

The semaphore grant operation is admitted even though a zero or negative grant corrupts permit accounting.

Verified by executionVariant 1 · 9 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The admission path omits the positive request invariant while validating the other operation preconditions.

VERIFIED REPAIR

Require r['positive_request'] > 0 together with every other stated precondition before accepting the operation.

Unsuccessful approach: Adding the positive request check repairs the reported defect, but replacing the adjacent request not granted check loses that independent invariant.

Case contract

Return a Boolean admission decision for grant permits from a distributed semaphore. The record r must satisfy all of: r['permit_capacity'][0]+r['permit_capacity'][1] <= r['permit_capacity'][2]; r['positive_request'] > 0; r['request_not_granted'][0] not in r['request_not_granted'][1]; r['weighted_fifo'][0] == r['weighted_fifo'][1][0]; r['grant_session'] in ['active']. Extra tracing fields are ignored; validation does not mutate the record.

Why this case matters

A deterministic local contract for concurrency. Each negative fixture violates exactly one invariant. No transport timing, persistence, cryptographic verification, or full protocol implementation is claimed.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(r):
    return (r['permit_capacity'][0]+r['permit_capacity'][1] <= r['permit_capacity'][2]) and (r['request_not_granted'][0] not in r['request_not_granted'][1]) and (r['weighted_fifo'][0] == r['weighted_fifo'][1][0]) and (r['grant_session'] in ['active'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
r = {'permit_capacity': [3, 2, 5], 'positive_request': 1, 'request_not_granted': ['r2', ['r1']], 'weighted_fifo': ['big', ['big', 'small']], 'grant_session': 'active'}
check('valid operation', solve(r), True)
check('The grant exceeds the configured total permit count', solve(dict(r, **{'permit_capacity': [4, 2, 5]})), False)
check('A zero or negative grant corrupts permit accounting', solve(dict(r, **{'positive_request': 0})), False)
check('A retried grant allocates the same request twice', solve(dict(r, **{'request_not_granted': ['r1', ['r1']]})), False)
check('A later small request overtakes the queued weighted head', solve(dict(r, **{'weighted_fifo': ['small', ['big', 'small']]})), False)
check('A session destroyed while waiting receives permits', solve(dict(r, **{'grant_session': 'closed'})), False)
check('unrelated tracing metadata', solve(dict(r, trace='run-'+str(N))), True)
check('repeat validation is pure', solve(r), True)
invalid = {'permit_capacity': [4, 2, 5], 'positive_request': 0, 'request_not_granted': ['r1', ['r1']], 'weighted_fifo': ['small', ['big', 'small']], 'grant_session': 'closed'}
keys = list(invalid)
pair = {keys[N % len(keys)]: invalid[keys[N % len(keys)]], keys[(N+1) % len(keys)]: invalid[keys[(N+1) % len(keys)]]}
check('two independent violations in variant', solve(dict(r, **pair)), False)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
valid operationTrueTruePassed
The grant exceeds the configured total permit countFalseFalsePassed
A zero or negative grant corrupts permit accountingTrueFalseFailed
A retried grant allocates the same request twiceFalseFalsePassed
A later small request overtakes the queued weighted headFalseFalsePassed
A session destroyed while waiting receives permitsFalseFalsePassed
unrelated tracing metadataTrueTruePassed
repeat validation is pureTrueTruePassed
two independent violations in variantFalseFalsePassed

SHA-256 / 2438cb4b2fa93168131114187e195f410b37c3964c5c22c26e9a829f0f38b6e3

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(r):
    return (r['permit_capacity'][0]+r['permit_capacity'][1] <= r['permit_capacity'][2]) and (r['positive_request'] > 0) and (r['weighted_fifo'][0] == r['weighted_fifo'][1][0]) and (r['grant_session'] in ['active'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
r = {'permit_capacity': [3, 2, 5], 'positive_request': 1, 'request_not_granted': ['r2', ['r1']], 'weighted_fifo': ['big', ['big', 'small']], 'grant_session': 'active'}
check('valid operation', solve(r), True)
check('The grant exceeds the configured total permit count', solve(dict(r, **{'permit_capacity': [4, 2, 5]})), False)
check('A zero or negative grant corrupts permit accounting', solve(dict(r, **{'positive_request': 0})), False)
check('A retried grant allocates the same request twice', solve(dict(r, **{'request_not_granted': ['r1', ['r1']]})), False)
check('A later small request overtakes the queued weighted head', solve(dict(r, **{'weighted_fifo': ['small', ['big', 'small']]})), False)
check('A session destroyed while waiting receives permits', solve(dict(r, **{'grant_session': 'closed'})), False)
check('unrelated tracing metadata', solve(dict(r, trace='run-'+str(N))), True)
check('repeat validation is pure', solve(r), True)
invalid = {'permit_capacity': [4, 2, 5], 'positive_request': 0, 'request_not_granted': ['r1', ['r1']], 'weighted_fifo': ['small', ['big', 'small']], 'grant_session': 'closed'}
keys = list(invalid)
pair = {keys[N % len(keys)]: invalid[keys[N % len(keys)]], keys[(N+1) % len(keys)]: invalid[keys[(N+1) % len(keys)]]}
check('two independent violations in variant', solve(dict(r, **pair)), False)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
valid operationTrueTruePassed
The grant exceeds the configured total permit countFalseFalsePassed
A zero or negative grant corrupts permit accountingFalseFalsePassed
A retried grant allocates the same request twiceTrueFalseFailed
A later small request overtakes the queued weighted headFalseFalsePassed
A session destroyed while waiting receives permitsFalseFalsePassed
unrelated tracing metadataTrueTruePassed
repeat validation is pureTrueTruePassed
two independent violations in variantFalseFalsePassed

SHA-256 / 541d9a20a0fcecb2f734d8e9739389d5b10b72a728882be33466b87c04126924

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(r):
    return (r['permit_capacity'][0]+r['permit_capacity'][1] <= r['permit_capacity'][2]) and (r['positive_request'] > 0) and (r['request_not_granted'][0] not in r['request_not_granted'][1]) and (r['weighted_fifo'][0] == r['weighted_fifo'][1][0]) and (r['grant_session'] in ['active'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
r = {'permit_capacity': [3, 2, 5], 'positive_request': 1, 'request_not_granted': ['r2', ['r1']], 'weighted_fifo': ['big', ['big', 'small']], 'grant_session': 'active'}
check('valid operation', solve(r), True)
check('The grant exceeds the configured total permit count', solve(dict(r, **{'permit_capacity': [4, 2, 5]})), False)
check('A zero or negative grant corrupts permit accounting', solve(dict(r, **{'positive_request': 0})), False)
check('A retried grant allocates the same request twice', solve(dict(r, **{'request_not_granted': ['r1', ['r1']]})), False)
check('A later small request overtakes the queued weighted head', solve(dict(r, **{'weighted_fifo': ['small', ['big', 'small']]})), False)
check('A session destroyed while waiting receives permits', solve(dict(r, **{'grant_session': 'closed'})), False)
check('unrelated tracing metadata', solve(dict(r, trace='run-'+str(N))), True)
check('repeat validation is pure', solve(r), True)
invalid = {'permit_capacity': [4, 2, 5], 'positive_request': 0, 'request_not_granted': ['r1', ['r1']], 'weighted_fifo': ['small', ['big', 'small']], 'grant_session': 'closed'}
keys = list(invalid)
pair = {keys[N % len(keys)]: invalid[keys[N % len(keys)]], keys[(N+1) % len(keys)]: invalid[keys[(N+1) % len(keys)]]}
check('two independent violations in variant', solve(dict(r, **pair)), False)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
valid operationTrueTruePassed
The grant exceeds the configured total permit countFalseFalsePassed
A zero or negative grant corrupts permit accountingFalseFalsePassed
A retried grant allocates the same request twiceFalseFalsePassed
A later small request overtakes the queued weighted headFalseFalsePassed
A session destroyed while waiting receives permitsFalseFalsePassed
unrelated tracing metadataTrueTruePassed
repeat validation is pureTrueTruePassed
two independent violations in variantFalseFalsePassed

SHA-256 / a11e2ba6a0891119d35921dbf86a983fbccb1841608df63888f86a6c46b994a6

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:37:01.677436+00:00.

Case digest / 800242eb39ac8992188ffb12a86e1608e20949709db843b11b1d61bea0d81b0c