FAILURE MAP
← Case archive

FA-74131 / Feature flag rollout bucketing / Open access

Multi-context canonical key: Colons are escaped before percent signs · case 01

Keys containing ":" become "%253A", so multi-context keys disagree with other SDKs.

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

ROOT CAUSE

The ":" -> "%3A" replacement runs first and its "%" is then escaped again.

VERIFIED REPAIR

Escape "%" first, then ":".

Unsuccessful approach: Escaping only colons leaves literal "%3A" in keys indistinguishable from escaped colons.

Case contract

contexts maps kind -> key. Empty input or any empty key -> None. A context containing only the kind "user" is keyed by the bare user key. Otherwise join, over kinds in sorted order, kind + ":" + escaped key with ":", where escaping replaces "%" by "%25" and then ":" by "%3A".

Why this case matters

Canonical context keys feed bucketing and caches; two spellings of one context split its traffic.

1 / The failure

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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace(':', '%3A').replace('%', '%25')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if list(contexts) == ['user']:
        return contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z'),
  ('context sample 3',
   [{'app': 'k:1%', 'user': 'acme', 'device': 'bob'}],
   'app:k%3A1%25:device:bob:user:acme')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 13', [{'app': 'x%3Ay'}], 'app:x%253Ay')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay'),
  ('context sample 54',
   [{'user': 'x%3Ay', 'app': 'k:1%', 'org': 'acme'}],
   'app:k%3A1%25:org:acme:user:x%253Ay')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 39', [{'device': 'acme', 'org': 'k:1%'}], 'device:acme:org:k%3A1%25')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 39', [{'device': 'acme', 'org': 'k:1%'}], 'device:acme:org:k%3A1%25'),
  ('context sample 51', [{'org': 'x%3Ay', 'app': 'z', 'user': 'z'}], 'app:z:org:x%253Ay:user:z')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
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
percent is escaped before colonorg:a%253Ab:user:50%25org:a%3Ab:user:50%25Failed
already escaped text is escaped againorg:x%253Ay:user:boborg:x%253Ay:user:bobPassed
kinds are sorted regardless of insertionorg:acme:user:boborg:acme:user:bobPassed
single non-user kind is prefixedorg:acmeorg:acmePassed
single user kind stays bare with colona:ba:bPassed
context sample 1app:a%253Ab:device:50%25:user:zapp:a%3Ab:device:50%25:user:zFailed
context sample 2device:acme:org:z:user:zdevice:acme:org:z:user:zPassed
context sample 3app:k%253A1%25:device:bob:user:acmeapp:k%3A1%25:device:bob:user:acmeFailed

SHA-256 / cc7a5452d6d1247a70c20f1eca6748bcefe445cd8b4d223476dbee96dd058cb3

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace(':', '%3A')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if list(contexts) == ['user']:
        return contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z'),
  ('context sample 3',
   [{'app': 'k:1%', 'user': 'acme', 'device': 'bob'}],
   'app:k%3A1%25:device:bob:user:acme')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 13', [{'app': 'x%3Ay'}], 'app:x%253Ay')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay'),
  ('context sample 54',
   [{'user': 'x%3Ay', 'app': 'k:1%', 'org': 'acme'}],
   'app:k%3A1%25:org:acme:user:x%253Ay')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 39', [{'device': 'acme', 'org': 'k:1%'}], 'device:acme:org:k%3A1%25')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 39', [{'device': 'acme', 'org': 'k:1%'}], 'device:acme:org:k%3A1%25'),
  ('context sample 51', [{'org': 'x%3Ay', 'app': 'z', 'user': 'z'}], 'app:z:org:x%253Ay:user:z')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
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
percent is escaped before colonorg:a%3Ab:user:50%org:a%3Ab:user:50%25Failed
already escaped text is escaped againorg:x%3Ay:user:boborg:x%253Ay:user:bobFailed
kinds are sorted regardless of insertionorg:acme:user:boborg:acme:user:bobPassed
single non-user kind is prefixedorg:acmeorg:acmePassed
single user kind stays bare with colona:ba:bPassed
context sample 1app:a%3Ab:device:50%:user:zapp:a%3Ab:device:50%25:user:zFailed
context sample 2device:acme:org:z:user:zdevice:acme:org:z:user:zPassed
context sample 3app:k%3A1%:device:bob:user:acmeapp:k%3A1%25:device:bob:user:acmeFailed

SHA-256 / 070993e1e36da1400b72d5874aa155acdb883fb69eed4d2f1a6c0daac88f4182

3 / The verified repair

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

N = 1
observations = []
def solve(contexts):
    def esc(s):
        return s.replace('%', '%25').replace(':', '%3A')
    if not contexts or any(k == '' for k in contexts.values()):
        return None
    if list(contexts) == ['user']:
        return contexts['user']
    return ':'.join(kind + ':' + esc(contexts[kind]) for kind in sorted(contexts))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('context sample 1', [{'device': '50%', 'user': 'z', 'app': 'a:b'}], 'app:a%3Ab:device:50%25:user:z'),
  ('context sample 2', [{'device': 'acme', 'user': 'z', 'org': 'z'}], 'device:acme:org:z:user:z'),
  ('context sample 3',
   [{'app': 'k:1%', 'user': 'acme', 'device': 'bob'}],
   'app:k%3A1%25:device:bob:user:acme')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('already escaped text is escaped again', [{'org': 'x%3Ay', 'user': 'bob'}], 'org:x%253Ay:user:bob'),
  ('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 13', [{'app': 'x%3Ay'}], 'app:x%253Ay')],
 [('kinds are sorted regardless of insertion', [{'user': 'bob', 'org': 'acme'}], 'org:acme:user:bob'),
  ('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('context sample 11', [{'org': 'x%3Ay', 'app': 'a:b', 'device': 'z'}], 'app:a%3Ab:device:z:org:x%253Ay'),
  ('context sample 22', [{'org': 'x%3Ay'}], 'org:x%253Ay'),
  ('context sample 54',
   [{'user': 'x%3Ay', 'app': 'k:1%', 'org': 'acme'}],
   'app:k%3A1%25:org:acme:user:x%253Ay')],
 [('single non-user kind is prefixed', [{'org': 'acme'}], 'org:acme'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 6', [{'device': 'bob', 'org': 'a:b'}], 'device:bob:org:a%3Ab'),
  ('context sample 16', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 39', [{'device': 'acme', 'org': 'k:1%'}], 'device:acme:org:k%3A1%25')],
 [('percent is escaped before colon', [{'org': 'a:b', 'user': '50%'}], 'org:a%3Ab:user:50%25'),
  ('single user kind stays bare with colon', [{'user': 'a:b'}], 'a:b'),
  ('empty key is invalid', [{'org': 'acme', 'user': ''}], None),
  ('empty mapping is invalid', [{}], None),
  ('three kinds', [{'device': 'd1', 'app': 'z', 'user': 'bob'}], 'app:z:device:d1:user:bob'),
  ('context sample 21', [{'org': 'x%3Ay', 'app': 'z'}], 'app:z:org:x%253Ay'),
  ('context sample 39', [{'device': 'acme', 'org': 'k:1%'}], 'device:acme:org:k%3A1%25'),
  ('context sample 51', [{'org': 'x%3Ay', 'app': 'z', 'user': 'z'}], 'app:z:org:x%253Ay:user:z')]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), expected)
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
percent is escaped before colonorg:a%3Ab:user:50%25org:a%3Ab:user:50%25Passed
already escaped text is escaped againorg:x%253Ay:user:boborg:x%253Ay:user:bobPassed
kinds are sorted regardless of insertionorg:acme:user:boborg:acme:user:bobPassed
single non-user kind is prefixedorg:acmeorg:acmePassed
single user kind stays bare with colona:ba:bPassed
context sample 1app:a%3Ab:device:50%25:user:zapp:a%3Ab:device:50%25:user:zPassed
context sample 2device:acme:org:z:user:zdevice:acme:org:z:user:zPassed
context sample 3app:k%3A1%25:device:bob:user:acmeapp:k%3A1%25:device:bob:user:acmePassed

SHA-256 / 54a53859a404cf850ccb4bb026ee7f73820eeaa2a453e0fc15419fb91a262b8a

Verification & scope

A deterministic toy flag-evaluation model with a stipulated contract; it does not reproduce any vendor SDK byte for byte. 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:48:53.867226+00:00.

Case digest / f2e26d7e3586702e17fca60e87905a70e0863bf86748b99a22dc9fe311c63f1e