Skip to content

fix(skills): preserve binary skill assets as Buffer - #644

Merged
kalenkevich merged 3 commits into
google:mainfrom
nothariharan:fix/skill-loader-binary-utf8
Aug 13, 2026
Merged

kalenkevich merged 3 commits into
google:mainfrom
nothariharan:fix/skill-loader-binary-utf8

Conversation

@nothariharan

Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:
loadDir / loadZipDir tried to keep binary skill resources as Buffer via try { data.toString('utf-8') } catch { data }. In Node.js, Buffer.prototype.toString('utf-8') never throws on invalid sequences — it substitutes U+FFFD — so the catch path was dead and binary assets were stored as corrupted strings. That breaks LoadSkillResourceTool's Buffer.isBuffer path, which is what injects binary content as inlineData.

Solution:
Decode with isUtf8 from node:buffer: valid UTF-8 becomes a string; everything else stays a Buffer. Shared helper used by both directory and zip loaders. Text skill resources are unchanged.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Summary: npx vitest run --project unit:core core/test/skills/loader_test.ts — 49 passed (includes new coverage for PNG-signature bytes via loadSkillFromDir and loadSkillFromZipBuffer).

Also ran npx eslint / npx prettier --check on the touched files.

Manual End-to-End (E2E) Tests:

  1. Create a skill with assets/logo.png containing real PNG bytes.
  2. loadSkillFromDir / loadSkillFromZipBuffer — resources.assets['logo.png'] is a Buffer.
  3. load_skill_resource for that path returns the binary-detected status (not mangled UTF-8 text).

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Scoped to the skill loader decode path only. No packaging / CLI / unrelated changes.

Buffer.toString('utf-8') never throws on invalid sequences, so the previous try/catch always stored mangled strings. Use node:buffer isUtf8 so non-UTF-8 assets stay as Buffer for LoadSkillResourceTool.
@google-cla

google-cla Bot commented Aug 10, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@nothariharan

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@Varun-S10 Varun-S10 self-assigned this Aug 12, 2026
@Varun-S10

Copy link
Copy Markdown
Contributor

Hi @nothariharan, We noticed that a few of the pre-checks are failing on this PR. Could you please resolve them?

@Varun-S10 Varun-S10 added the request clarification [Status] The maintainer need clarification or more information from the author label Aug 12, 2026
@nothariharan

Copy link
Copy Markdown
Contributor Author

Hi @Varun-S10 — thanks for flagging this.

I looked into the failing validation / run-tests jobs. They never reached the test suite: actions/checkout@v6 failed while fetching the PR merge ref with:

fatal: unable to access 'https://github.com/google/adk-js/': server certificate verification failed. CAfile: none CRLfile: none

So this looks like a transient GitHub Actions / TLS checkout issue on the runner, not a failure in the skill-loader change. CLA, license-header, and cross-language checks on the same PR were already green, and core/test/skills/loader_test.ts still passes locally (49/49).

I pushed an empty commit to re-trigger CI. Happy to re-run again if anything is still red after this pass.

@nothariharan

Copy link
Copy Markdown
Contributor Author

Follow-up: the empty commit re-queued the workflows, but validation / License Header Check / Cross-Language Tests are currently sitting in action_required (GitHub’s fork-PR approval gate). I don’t have permission to approve them from this side.

@Varun-S10 if you could hit Approve and run workflows on the latest commit (2d75b52), that should clear the red checks assuming checkout TLS is healthy again. No code changes are pending on my end for this.

@kalenkevich
kalenkevich merged commit 94cbe4a into google:main Aug 13, 2026
12 checks passed
@kalenkevich kalenkevich mentioned this pull request Aug 13, 2026
prasanna8585 pushed a commit to prasanna8585/adk-js that referenced this pull request Aug 21, 2026
* fix(skills): preserve binary skill assets as Buffer

Buffer.toString('utf-8') never throws on invalid sequences, so the previous try/catch always stored mangled strings. Use node:buffer isUtf8 so non-UTF-8 assets stay as Buffer for LoadSkillResourceTool.

* chore: re-trigger Google CLA check

* chore: re-run CI after transient checkout SSL failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Skill loader corrupts binary assets: Buffer.toString('utf-8') never throws

3 participants