{"record":{"id":"c78c3e0463c62b75","repo":"xai-org/x-algorithm","slug":"sink-policy-resolved-unknown-keys-sorted-unkno","errorCode":null,"errorMessage":"sink policy {resolved}: unknown keys {sorted(unknown)}","messagePattern":"sink policy (.+?): unknown keys (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"bdsm/runtime/score_results_sink_focal.py","lineNumber":290,"sourceCode":"        or os.environ.get(\"BDSM_SINK_POLICY\", \"\")\n        or os.path.join(os.path.dirname(os.path.abspath(__file__)), \"sink_policy.yaml\")\n    )\n    if not os.path.exists(resolved):\n        log.info(f\"sink policy: baked-in defaults (no policy file at {resolved})\")\n        return DEFAULT_POLICY\n    try:\n        import yaml\n    except ImportError:\n        log.warning(\n            f\"sink policy: pyyaml unavailable, IGNORING {resolved}; using baked-in defaults\"\n        )\n        return DEFAULT_POLICY\n    with open(resolved) as f:\n        raw = yaml.safe_load(f) or {}\n    known = {f_.name for f_ in dataclasses.fields(SinkPolicy)} - {\"source\"}\n    unknown = set(raw) - known - {\"notes\"}\n    if unknown:\n        raise ValueError(f\"sink policy {resolved}: unknown keys {sorted(unknown)}\")\n    kw = {}\n    for k, v in raw.items():\n        if k == \"notes\":\n            continue\n        if k in _POLICY_2TUPLE_TABLES:\n            kw[k] = {h: (float(t[0]), float(t[1])) for h, t in v.items()}\n        elif k == \"official_client_app_ids\":\n            kw[k] = frozenset(int(x) for x in v)\n        elif k == \"spam_bounce_action_key\":\n            kw[k] = {str(h): str(a) for h, a in v.items()}\n        elif k == \"min_actions_for_enforcement\":\n            kw[k] = int(v)\n        elif k in (\"cusp_delta\", \"reply_spam_hard_suspend_tau\"):\n            kw[k] = float(v)\n        else:\n            kw[k] = str(v)\n    pol = SinkPolicy(source=resolved, **kw)\n    log.info(f\"sink policy: LOADED {resolved} (version={pol.version})\")","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/bdsm/runtime/score_results_sink_focal.py#L272-L308","documentation":"_load_policy parses the optional YAML sink-policy file into the SinkPolicy dataclass. Any top-level key that is not a SinkPolicy field (minus 'source') or the free-form 'notes' key makes it raise, so typo'd or forward-incompatible policy options fail loudly instead of being silently ignored.","triggerScenarios":"Pointing the policy-file setting at a YAML containing a key like 'sampling_ratio' when SinkPolicy has no such field; misspelling a field ('throttle_ms' vs 'throttling_ms'); using a policy file written for a newer version of the sink.","commonSituations":"Hand-edited policy YAML with typos; version skew between policy file format and deployed sink; copy-pasted keys from a different config schema.","solutions":["Diff the YAML keys against dataclasses.fields(SinkPolicy) (the error lists the offenders)","Fix typos or remove the unknown keys from the policy file","If the key is from a newer sink version, upgrade the sink or drop the key until you upgrade","Rely on test_shipped_policy_matches_baked_in_defaults-style checks to keep policy files valid"],"exampleFix":"# before (policy.yaml)\nunknown_key: 1\nchallenge_fraction: 0.05\n# after\nchallenge_fraction: 0.05","handlingStrategy":"validation","validationCode":"import dataclasses, yaml\nknown = {f.name for f in dataclasses.fields(SinkPolicy)} - {'source'} | {'notes'}\nraw = yaml.safe_load(open(path)) or {}\nassert set(raw) <= known, f\"bad keys: {set(raw) - known}\"","typeGuard":"def policy_keys_valid(path: str) -> bool:\n    raw = yaml.safe_load(open(path)) or {}\n    known = {f.name for f in dataclasses.fields(SinkPolicy)} - {'source'} | {'notes'}\n    return set(raw) <= known","tryCatchPattern":"try:\n    policy = _load_policy(path)\nexcept ValueError as e:\n    if 'unknown keys' in str(e):\n        policy = DEFAULT_POLICY  # or fix the file and reload\n    else:\n        raise","preventionTips":["Validate policy YAML in CI with the shipped defaults test","Generate policy files from typed code instead of hand-editing","Version policy schemas alongside the sink"],"tags":["python","yaml","config-validation","policy"],"backgroundTag":"config-schema-validation-failed","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}