Repository navigation
fix(skills): treat YAML and UTF-8 skill resources as text - #1915
100lalitahegde-eng wants to merge 1 commit into
Conversation
|
Hi @100lalitahegde-eng, Thank you for your contribution and for taking the time to submit this pull request. Our team is currently reviewing your changes, and we will reach out if we need any further information. |
kvmilos
left a comment
There was a problem hiding this comment.
Could you change Fixes #1893 to Part of #1893 (or Refs #1893) if we keep this PR scoped to .yml/.yaml? Issue #1893 asks for valid UTF-8 text regardless of extension, so we don't want the remaining extensions lost when the issue closes.
| String contentType; | ||
| if (resourcePath.endsWith(".sh") || resourcePath.endsWith(".bash")) { | ||
| // guessContentTypeFromName would return application/x-shar | ||
| contentType = "application/x-sh"; | ||
| } else if (resourcePath.endsWith(".yml") || resourcePath.endsWith(".yaml")) { | ||
| // The JVM does not map these extensions, so the name-based guess is null | ||
| // and we would otherwise fall back to application/octet-stream. | ||
| contentType = "application/yaml"; | ||
| } else { | ||
| contentType = guessContentTypeFromName(resourcePath); | ||
| } |
There was a problem hiding this comment.
Could we fall back to strict UTF-8 decoding before application/octet-stream when both guesses return null?
Handling only .yml and .yaml still leaves other text formats missing from the JDK's MIME table (.toml, .ini, .properties, .sql, .ts, .kt, etc.) falling back to application/octet-stream and hitting the same Vertex AI 400. ADK Python and ADK Kotlin instead try a strict UTF-8 decode and treat valid UTF-8 as text.
Note that references/binary.dat in the test uses {0, 1, 2, 3}, which is valid UTF-8, so it would need non-UTF-8 bytes (or a NUL check) if we go that route. If you prefer to keep this PR scoped to YAML, that's fine too; we can leave #1893 open for the rest.
| if (resourcePath.endsWith(".sh") || resourcePath.endsWith(".bash")) { | ||
| // guessContentTypeFromName would return application/x-shar | ||
| contentType = "application/x-sh"; | ||
| } else if (resourcePath.endsWith(".yml") || resourcePath.endsWith(".yaml")) { |
There was a problem hiding this comment.
If we keep the extension check, could you match on a lowercased extension (such as Ascii.toLowerCase(Files.getFileExtension(resourcePath)) with a small map, or Ascii.toLowerCase(resourcePath)) and add an uppercase test case in LoadSkillResourceToolTest?
endsWith(".yml") || endsWith(".yaml") is case-sensitive, so uppercase extensions like assets/CONFIG.YAML or assets/config.YML still fall through to application/octet-stream (the JDK lowercases extensions internally, but has no YAML entry).
|
@kvmilos Thanks for the review. I went with the strict UTF-8 fallback: when both MIME guesses are null, valid UTF-8 is now returned as text/plain. That covers unmapped extensions such as .toml, .ini, .properties, .sql, .ts, and .kt, so I kept Fixes #1893. Also in the follow-up commit:
|
kvmilos
left a comment
There was a problem hiding this comment.
Thanks for the update. The UTF-8 fallback, case-insensitive extension check, and comment cleanup look good. A few small things before we merge:
- Update the PR title (which becomes the changelog headline) to cover the general UTF-8 fallback, e.g.,
fix(skills): treat YAML and UTF-8 skill resources as text. - Qualify "This matches ADK Python and ADK Kotlin" in the PR description to note that Java uses the UTF-8 fallback only when JDK MIME guessing returns null, so JDK-mapped non-
text/types like.svgand.texstay binary. - Squash the two commits into one so the single-commit check passes once CI runs.
| @Test | ||
| public void call_loadSkillResourceTool_unknownTextExtension_success() { | ||
| LoadSkillResourceTool loadSkillResourceTool = | ||
| new LoadSkillResourceTool(createTestSkillSource()); | ||
| Map<String, Object> response = | ||
| loadSkillResourceTool | ||
| .runAsync( | ||
| ImmutableMap.of("skill_name", "test-skill", "file_path", "assets/config.toml"), | ||
| createToolContext()) | ||
| .blockingGet(); | ||
|
|
||
| assertThat(response) | ||
| .containsExactly( | ||
| "skill_name", "test-skill", | ||
| "file_path", "assets/config.toml", | ||
| "mime_type", "text/plain", | ||
| "content", "id = \"a\"\nname = \"b\"\n"); | ||
| } |
There was a problem hiding this comment.
assets/config.toml is plain 7-bit ASCII and references/binary.dat fails on byte 0, so swapping UTF_8 for US_ASCII would still pass every test. Could you include multi-byte UTF-8 characters (for example, "name = \"café\"\n") in the .toml test, and add a binary case with a valid UTF-8 prefix followed by a truncated sequence (for example, {'a', (byte) 0xC3})?
Fixes google#1893. LoadSkillResourceTool.createResult left many text formats untyped (.yml, .yaml, .toml, .ini, and others), so they fell back to application/octet-stream and were sent as binary parts, which Vertex AI rejects. Map .yml and .yaml to application/yaml (case-insensitive, like .sh). When both MIME guesses are null, strictly decode as UTF-8 and treat valid UTF-8 as text/plain.
5b4260e to
4157f4a
Compare
|
@kvmilos Thanks. I updated the title, qualified the Python/Kotlin note (UTF-8 fallback only when both JDK guesses are null, so .svg and .tex stay binary), added multi-byte UTF-8 in the .toml test and a truncated-sequence binary case ( |
Fixes #1893.
LoadSkillResourceTool.createResultdecided whether a resource was text from its guessed MIME type. The JDK has no mapping for many text formats (.yml,.yaml,.toml,.ini,.properties,.sql,.ts,.kt, ...), so those files fell through toapplication/octet-streamand were sent as a binaryPart, which Vertex AI rejects.This change:
.ymland.yamltoapplication/yaml, the same way.sh/.bashare already special-cased. Extension checks are case-insensitive.text/plain, anything else staysapplication/octet-stream. This matches ADK Python and ADK Kotlin in treating valid UTF-8 as text, except that Java applies that fallback only when JDK MIME guessing returns null, so JDK-mapped non-text/types like.svgand.texstay binary.Testing:
./mvnw -pl core test -Dtest=LoadSkillResourceToolTest,LoadSkillResourceMixedPartsRegressionTest: all pass, including new cases for.yml,.yaml,assets/CONFIG.YAML,assets/config.toml(with multi-byte UTF-8,name = "café"), a non-UTF-8references/binary.dat(0xFF 0xFE 0x80), and a truncated UTF-8 sequence inreferences/truncated.dat({'a', 0xC3}). Formatted with google-java-format 1.28.0.