FAILURE MAP
← Case archive

FA-1386 / Concurrency / Open access

Grant permits from a distributed semaphore: A retried grant allocates the same request twice · case 01

The semaphore grant operation is admitted even though a retried grant allocates the same request twice.

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

ROOT CAUSE

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

VERIFIED REPAIR

Require r['request_not_granted'][0] not in r['request_not_granted'][1] together with every other stated precondition before accepting the operation.

Unsuccessful approach: Adding the request not granted check repairs the reported defect, but replacing the adjacent weighted fifo 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['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

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['request_not_granted'][0] not in r['request_not_granted'][1]) 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 headTrueFalseFailed
A session destroyed while waiting receives permitsFalseFalsePassed
unrelated tracing metadataTrueTruePassed
repeat validation is pureTrueTruePassed
two independent violations in variantFalseFalsePassed

SHA-256 / 63e47c28a578f188a99371c649df7d952a6e0a78fa25a99f849422b62ea66363

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.712133+00:00.

Case digest / 8a422d6b4a4d58ffa86cc1c505ef0366b3ae49431f36b0b1c1648031ed502431