This commit is contained in:
commit
8f085a28d3
3220 files changed
+985495
No files matched your search
@@ -0,0 +1 @@
|
||||
{"body": "[Claude #4] Stage 3 code-edit IMP-46 \u2014 u4 structural cache key + fingerprints\n\nExecuting unit: u4\n\n\u25a0 unit_executed\n- id: u4\n- summary: Replace the sample-identity cache_key (`template_id::sorted(source_section_ids)`) in `src/phase_z2_ai_fallback/step12.py` with a structural signature key `\"{frame_id}::{signature_hash}\"` derived from the 8 IMP-46 axes via `build_signature` (u1). Extend Step 12 helper inputs (unit attributes) for `layout_preset`, `zone_position`, `source_shape`, `h3_count`, `char_count`, and `cardinality`; project `char_count` through `bucket_char_count` (u1). Compute the three invalidation fingerprints (`contract_sha`, `partial_sha`, `catalog_sha`) and attach them \u2014 with the new `cache_key` \u2014 to each AI-eligible record for downstream `save_proposal` use. Exact-match lookup only (no fuzzy fallback added). v4_result.cardinality now mirrors the unit's cardinality (was hardcoded `None`).\n\n\u25a0 files_changed\n- src/phase_z2_ai_fallback/step12.py (modified, +82 / -2 \u2014 adds `_sha256_of` helper, `catalog_sha_loader` kwarg, structural signature + fingerprint block, record fields `cache_key` + `fingerprints`)\n- tests/phase_z2_ai_fallback/test_step12.py (modified, +247 / -16 \u2014 replaces the legacy `test_cache_key_includes_template_and_section_ids` test with 14 new u4 cases; FakeUnit extended with 6 new signature-input fields)\n\n\u25a0 diff_summary\n- `src/phase_z2_ai_fallback/step12.py`\n - Module docstring expanded with an `IMP-46 u4 \u2014 structural cache key + fingerprints` section that names every signature axis read from unit attributes and explains why fingerprint *computation* lives here (cache.py is a comparator per u3 \u2014 keeps the cache module schema-agnostic).\n - New stdlib imports: `hashlib`, `json` (both already in the AST isolation whitelist \u2014 `test_ast_isolation.py:39-42`).\n - New intra-package import: `bucket_char_count`, `build_signature` from `src.phase_z2_ai_fallback.signature` (u1).\n - New module-level helper `_sha256_of(payload: Any) -> str`: deterministic SHA256 over `json.dumps(payload, sort_keys=True, ensure_ascii=False)`. Used only for `contract_sha` and `partial_sha`.\n - `gather_step12_ai_repair_proposals` signature gains one new keyword-only argument:\n - `catalog_sha_loader: Callable[[], str] | None = None` \u2014 called once per gather invocation (verified by `test_catalog_sha_loader_called_once_per_gather`). When `None`, `catalog_sha` defaults to `\"\"` (sentinel \u2014 always present, so `fingerprints` is always a 3-key dict).\n - Record schema gains two fields, both initialised to `None`:\n - `\"cache_key\": str | None` \u2014 populated only on the AI-eligible code path; the structural axes are not guaranteed for skipped units, so the field is left `None` for `not_provisional` / `design_reference_only_no_ai` / `route_not_ai_adaptation:*` records.\n - `\"fingerprints\": dict | None` \u2014 same population rule.\n - Inside the AI-eligible branch (after route gates pass):\n - Read signature inputs from unit attributes via `getattr` with safe defaults (so existing test fixtures and pre-IMP-46 units survive): `frame_id_value`, `cardinality`, `layout_preset` (default `\"\"`), `zone_position` (default `\"\"`), `source_shape` (default `\"paragraph\"` \u2014 valid `SourceShape` enum member), `h3_count` (default `0`), `char_count` (default `0`).\n - `char_count_bucket = bucket_char_count(char_count)` \u2014 u1 fixed-bin projection.\n - `signature_hash = build_signature(frame_id=..., v4_label=label or \"\", cardinality=..., source_shape=..., h3_count=..., char_count_bucket=..., layout_preset=..., zone_position=...)` \u2014 8-axis SHA256.\n - `cache_key = f\"{frame_id_value}::{signature_hash}\"` \u2014 matches cache.py `_parse_key` format (`KEY_DELIMITER = \"::\"`); validated by `test_cache_key_is_compatible_with_cache_parse_key`.\n - `fingerprints = {\"contract_sha\": _sha256_of(frame_contract), \"partial_sha\": _sha256_of(figma_partial_json), \"catalog_sha\": catalog_sha}`.\n - `v4_result[\"cardinality\"]` now reads the unit's `cardinality` attribute instead of the hardcoded `None` from IMP-33 u8.\n - `route_ai_fallback(cache_key=cache_key, ...)` now receives the structural key (the router's existing read-side path is unchanged \u2014 `read_proposal(cache_key)` continues to perform exact-match lookup only, as required by the u4 contract).\n\n- `tests/phase_z2_ai_fallback/test_step12.py`\n - Module docstring updated to declare the IMP-46 u4 coverage axis alongside the IMP-33 gates.\n - `FakeUnit` dataclass extended with 6 new fields (all with safe defaults): `cardinality: int | None = None`, `layout_preset: str = \"\"`, `zone_position: str = \"\"`, `source_shape: str = \"paragraph\"`, `h3_count: int = 0`, `char_count: int = 0`. All pre-existing tests continue to construct `FakeUnit(label=..., provisional=...)` without modification.\n - New helper `_ai_unit(**overrides)`: builds anLine truncated
|
||||
Reference in new issue
Block a user