fix(hashing): route Schema through SchemaHandler, not _expand_mapping (ITL-639) - #263
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes the dispatch order in hash_object so SchemaHandler is reached for Schema objects (previously intercepted by _is_structure as a Mapping). Implements SchemaHandler with Arrow-translatability validation and wires type_converter at registration. Adds SchemaHandler to v0.1.json context spec so it is registered when loading from JSON. Adds four regression tests. No hash values change — all golden assertions continue to pass. Closes ITL-639. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… for SchemaHandler type_converter is now forwarded to SchemaHandler as well; reflect this in the Args docstring. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
🟢 Approval recommended
The changes are narrowly scoped, align with the PR’s stated intent, and are backed by targeted regression tests plus context-registry wiring to ensure the handler is actually used in the default configuration.
Pull request overview
This PR fixes schema hashing dispatch so Schema objects are hashed via the explicit SchemaHandler (rather than being intercepted as a generic Mapping and expanded via _expand_mapping). It also implements the canonical SchemaHandler behavior (stable field hashing + optional Arrow-translatability validation), registers it in the v0.1 context spec, and adds regression tests to prevent the original routing bug and module-rename instability from recurring.
Changes:
- Reorders
SemanticAwarePythonHasher.hash_objectdispatch so registered handlers run before the generic “structure expansion” path. - Implements
SchemaHandlerand wirestype_converterinto its registration (code + v0.1 JSON context registry). - Adds regression tests covering SchemaHandler routing, module-rename stability, unregistered-type rejection, and
optional_fieldsexclusion; adds supporting design/plan artifacts undersuperpowers/.
File summaries
| File | Description |
|---|---|
src/orcapod/hashing/semantic_hashing/semantic_hasher.py |
Moves handler dispatch ahead of _is_structure to ensure SchemaHandler is reachable for Schema instances. |
src/orcapod/hashing/semantic_hashing/builtin_handlers.py |
Implements SchemaHandler with deterministic field hashing and optional Arrow-translatability validation; registers it with type_converter. |
src/orcapod/contexts/data/v0.1.json |
Registers SchemaHandler (with type_converter reference) in the default context’s Python handler registry. |
tests/test_hashing/test_type_annotation_golden.py |
Adds TestSchemaHashBehavior regression tests for dispatch routing and stability/validation rules. |
superpowers/specs/2026-09-03-itl-639-schema-hashing-arrow-representation-design.md |
Design write-up documenting the motivation and intended hashing/validation behavior for ITL-639. |
superpowers/plans/2026-09-03-itl-639-schema-hashing.md |
Implementation plan artifact capturing the step-by-step work and verification checklist for ITL-639. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
SemanticAwarePythonHasher.hash_objectso registered handlers run before the_is_structurecheck. This makesSchemaHandlerreachable forSchemaobjects (previously intercepted as a plainMappingby_expand_mapping).NotImplementedErrorstub inSchemaHandlerwith the canonical implementation: iterates fields in sorted order, hashes each Python type viaTypeObjectHandler, validates Arrow-translatability when atype_converteris available.type_converterintoSchemaHandlerat registration (both inregister_builtin_python_type_handlersand inv0.1.json) so unregistered types are caught at hash time with a clear diagnostic error.SchemaHandlerto thev0.1.jsoncontext registry — it was previously absent, meaning the handler was never registered when loading from the JSON spec.TestSchemaHashBehavior): dispatch routing, module-rename stability, Arrow-translatability guard, andoptional_fieldsexclusion.schema_hash_golden.jsonremain byte-identical.Fixes ITL-639
Test plan
uv run pytest tests/test_hashing/ -v— all 10 tests pass, includingTestSchemaHashStabilitywith unchanged golden hashesuv run pytest tests/ -x -q— full suite (4823 passed, 93 skipped, 2 xfailed)🤖 Generated with Claude Code