Repository navigation
Fix/restore ref said resolution 1.2.14 - #16
Conversation
A schema can reference another schema by putting its SAID in a $ref value (e.g. one schema extending another via allOf). CacheResolver. resolver() only resolved "did:"-scheme $ref URIs; a $ref that was just the SAID by itself, with no "did:" prefix, always came back Unresolvable, even when the referenced schema was already cached in db.schema. Build the jsonschema resolver's store from db.schema so these SAID-only refs resolve locally too. Separately, Credentialer.validate() and Verifier.processCredential() never passed a resolver into Schemer at all, so no $ref-based schema could validate through either the issuance or the verification path. Schemer.__init__ now accepts an optional resolver argument and passes it through _inhale/_sniff (raw-based construction always re-detects typ, which was silently discarding any resolver passed in before), and both call sites now pass their existing CacheResolver in. Signed-off-by: arshdeep singh <arsh.binny@gmail.com> (cherry picked from commit 0bcc197)
CacheResolver.resolver() rebuilt its jsonschema store from every schema in db.schema on every single call. Since JSONSchema.verify_json calls this once per credential schema check, that meant re-reading and re-parsing the entire local schema cache on every credential validation, growing with however many schemas a Habery has ever cached. Cache the built store and only rebuild it when db.schema.cntAll() changes. db.schema entries are keyed by their own content SAID and are never removed, so that count can only change when a schema is added, making it an exact signal for when the store actually needs rebuilding. Signed-off-by: arshdeep singh <arsh.binny@gmail.com> (cherry picked from commit e08853d)
rodolfomiranda
left a comment
There was a problem hiding this comment.
Thanks Charles — the $ref-by-SAID fix looks good to me. I checked out the branch and ran the affected tests locally: all 18 pass, and the 5 new ref-resolution tests fail against the pre-fix src, so they really exercise the change. I also confirmed v0.6.14-fix1 in our hio fork is a single commit on top of v0.6.14 (the parseLeader malformed-header fix). A few things I'd like to settle before merging, mostly around dependencies:
1. hio as a git direct reference
'hio @ git+https://github.com/provenant-dev/hio@v0.6.14-fix1'
- A direct URL dependency means this package can't be uploaded to PyPI, and anything installing it (e.g. the origin-keria image build) needs
gitavailable. - Tags are mutable. Pinning the commit (
@078290ff5f16603776dc84c74a594ac7cad8416c) would make the build reproducible and avoid a moved tag silently changing what we ship. - The fork still reports version
0.6.14, the same as upstream. It's worth double-checking that origin-keria's ownhiorequirement is compatible, otherwise pip will fail to resolve.
2. lmdb==1.8.1
This went from >=1.4.1 to an exact pin, which isn't mentioned in the PR description. An exact pin in a library's install_requires is quite restrictive for downstream consumers. If the intent is to stay off lmdb 2.x, something like lmdb>=1.4.1,<2 expresses that more directly. Either way, could we note the reason in the commit or PR description?
3. Resolver referrer (pre-existing, but now easier to hit)
JSONSchema.verify_json calls self.resolver.resolver(scer=raw), where raw is the credential, not the schema, so RefResolver gets the credential as its referrer. When Schemer(raw=..., resolver=cache) is used with a schema that is not in db.schema and that has internal refs ("$ref": "#/definitions/..."), validation fails with unknown url type: 'E...', while the same schema validates fine without a resolver. Repro:
sed = {"$id": "", "$schema": "http://json-schema.org/draft-07/schema#",
"type": "object", "definitions": {"s": {"type": "string"}},
"properties": {"a": {"$ref": "#/definitions/s"}}, "required": ["a"]}
with habbing.openHby(name="t", temp=True) as hby:
tmp = scheming.Schemer(sed=sed)
s = scheming.Schemer(raw=tmp.raw, resolver=scheming.CacheResolver(db=hby.db))
s.verify(b'{"a":"x"}') # ValidationError: unknown url typeThe two call sites changed here always load the schema from db.schema, so they aren't affected today. The new public resolver= argument on Schemer does expose it, though. Passing the schema as the referrer with its $id as base_uri (e.g. verify_json passes scer=schema, and resolver() builds RefResolver(scer.get("$id", ""), scer, ...)) would close it. I'm fine with that as a follow-up.
Nits
- The new docstrings on
CacheResolver.resolver()andSchemer.__init__are much longer than the surrounding code's. Could they be trimmed to the essentials? __version__stays1.2.14for the-pr2tag. That's consistent with-pr1, so it's fine, just flagging it.
🤖 Generated with Claude Code on behalf of Rodolfo Miranda
|
1 is okay because this is for internal use and we don't have plans to push to pypi, tags are fine because we control them so I'm going to leave that one as is. The origin-keria build will be next based on this build so I will make it conform.
|
…resolution to fail for a given credential per PR review comment. Added referencing to the setup.py in order to get the correct fix.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the schema reference resolution changes.
No open issues 🎉
What changed in this PR
Restores SAID-based schema reference resolution on the 1.2.14 branch for the planned v1.2.14-pr2 release used by origin-keria.
Changes:
- Replaces deprecated reference resolution with a lazy, local-cache-backed registry and passes resolvers through credential issuance and verification.
- Adds regression tests for chained schemas, internal fragments, missing references, and cache behavior.
- Pins LMDB to
1.8.1, switches hio to the patched Git tag, and declares thereferencingdependency.
| File | Description |
|---|---|
| tests/vdr/test_verifying.py | Tests verification of chained schemas and rejection of missing inherited fields. |
| tests/vdr/test_credentialing.py | Tests issuance with chained schemas, missing required fields, and unresolved references. |
| tests/core/test_scheming.py | Adds reference-resolution and cache-behavior regression tests. |
| src/keri/vdr/verifying.py | Passes the cache resolver into credential schema verification. |
| src/keri/vdr/credentialing.py | Passes the verifier’s resolver into issuance validation. |
| src/keri/core/scheming.py | Introduces registry-backed resolution and preserves resolvers when loading raw schemas. |
| setup.py | Updates dependencies for the resolver changes and maintenance release. |
Review effort: Balanced
Pulls in the fixes we needed from pr-main into 1.2.14 branch with a target to release the v1.2.14-pr2 tag release in this repo for use in origin-keria.
Related to https://eipi.atlassian.net/browse/VC-1942
Pinning LMDB to 1.8.1 so I don't have to fix the use after free bug in the tests on this branch.