fix(skills): handle bytes content in bundle_content_hash - #19157
Closed
venyon2k wants to merge 1 commit into
Closed
Conversation
SkillBundle.files can contain bytes (e.g. from LocalSource.fetch()
which reads files via f.read_bytes()), not just strings.
Calling .encode('utf-8') on a bytes value raises AttributeError.
Co-authored-by: Hermes Agent <jason@yechiu.com.cn>
Collaborator
1 similar comment
Collaborator
Contributor
|
The same bytes fix landed via #19575 (salvage of @teknium1's #19328, which was itself the canonical consolidation of five concurrent PRs — including yours). The logic you proposed is identical; thanks for catching and fixing this bug. Both contributors who implemented the same fix get credit via the commit's AUTHOR_MAP and this acknowledgement. Closing as duplicate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
bundle_content_hash()calls.encode("utf-8")on every file entry inSkillBundle.files, but the type annotation explicitly declaresfiles: Dict[str, Union[str, bytes]].When a
SkillBundleis constructed byLocalSource.fetch()— which reads skill files from disk viaf.read_bytes()— thefilesdict containsbytesvalues. Calling.encode()on abytesobject raisesAttributeError.Fix
Check
isinstance(content, bytes)before encoding. Bytes content is fed directly into the SHA-256 hasher; string content is UTF-8 encoded as before.Evidence
SkillBundleannotation:files: Dict[str, Union[str, bytes]](line 81)LocalSource.fetch()reads files as bytes:files[rel_path] = f.read_bytes()(line 2396 in current main)content_hash()intools/skills_guard.pyalready handles both paths — it callsf.read_bytes()directly, the in-memory equivalent should matchVerification
test_bundle_content_hash_matches_installed_content_hashpasses (it uses string-only bundles)Co-authored-by: Jason Kuo jason@yechiu.com.cn