Skip to content

Conversation

@lifeizhou-ap
Copy link
Collaborator

@lifeizhou-ap lifeizhou-ap commented Oct 31, 2025

Summary

This fix is for a recipe with backtick and {{if}} block

Issue

serde_yaml serialization uses internal heuristics to decide between | and quoted text with escaped\n and \", and the quoted form breaks MiniJinja parsing. It seems that if the texts contains backtick, it tends to use the quoted texts without "|"

Example before:

prompt: "Hello \\\"World\\\"\\n{% if user == \\\"admin\\\" %}Welcome{% endif %}"

After fix:

prompt: |
   Hello "World"
  {% if user == "admin" %}Welcome{% endif %}

Changes

Apply extra format after the yaml serialization to convert the quoted multiline texts to the texts with "|"

Type of Change

  • Feature
  • Bug fix
  • Refactor / Code quality
  • Performance improvement
  • Documentation
  • Tests
  • Security fix
  • Build / Release
  • Other (specify below)

Testing

Unit testing and manual testing

@lifeizhou-ap
Copy link
Collaborator Author

.bundle

1 similar comment
@lifeizhou-ap
Copy link
Collaborator Author

.bundle

@angiejones angiejones requested a review from Copilot November 2, 2025 18:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a utility module to normalize multi-line YAML string formatting to fix issues with MiniJinja template parsing. The changes address a problem where serde_yaml sometimes uses quoted strings with escaped newlines and quotes, which breaks MiniJinja parsing.

Key changes:

  • Added new yaml_format_utils.rs module with a function to reformat multi-line string fields in YAML
  • Added to_yaml() method to the Recipe struct that applies this reformatting
  • Updated recipe serialization calls in recipe_utils.rs to use the new to_yaml() method

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
crates/goose/src/recipe/yaml_format_utils.rs New utility module that transforms quoted multi-line strings to YAML literal block format and handles unescaping
crates/goose/src/recipe/mod.rs Added to_yaml() method to Recipe struct and module declaration for yaml_format_utils
crates/goose-server/src/routes/recipe_utils.rs Updated two functions to use Recipe's new to_yaml() method instead of direct serde_yaml::to_string()

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if let Some(field) = matched_field {
if let Some((_, raw_val)) = trimmed.split_once(": ") {
if raw_val.contains("\\n") {
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The detection logic checks for literal \\n in the string, but this may not correctly identify all multi-line strings. Consider checking for both \\n (single backslash) and \\\\n (double backslash) patterns, or using a more robust method to detect escaped newlines in serialized YAML strings.

Suggested change
if raw_val.contains("\\n") {
if raw_val.contains("\\n") || raw_val.contains("\\\\n") {

Copilot uses AI. Check for mistakes.
Comment on lines +243 to +246
reformat_fields_with_multiline_values(&recipe_yaml, &["prompt", "instructions"]);
Ok(formatted_recipe_yaml)
}

Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The list of fields to reformat is hardcoded here. Consider making this configurable or deriving it from the Recipe struct to ensure all relevant string fields are handled consistently as the struct evolves.

Suggested change
reformat_fields_with_multiline_values(&recipe_yaml, &["prompt", "instructions"]);
Ok(formatted_recipe_yaml)
}
reformat_fields_with_multiline_values(&recipe_yaml, Self::multiline_fields());
Ok(formatted_recipe_yaml)
}
/// Returns the list of Recipe fields that should be reformatted for multiline YAML output.
fn multiline_fields() -> &'static [&'static str] {
&["prompt", "instructions"]
}

Copilot uses AI. Check for mistakes.
@lifeizhou-ap lifeizhou-ap requested a review from DOsinga November 2, 2025 23:03
@lifeizhou-ap lifeizhou-ap merged commit bdd04d6 into main Nov 6, 2025
21 checks passed
lifeizhou-ap added a commit that referenced this pull request Nov 6, 2025
* main:
  fix: customised recipe to yaml string to avoid minininjia parsing error (#5494)
  Add pending extension indicator to extension panel (#5493)
  Add environment subsition for auth blocks (#5439)
  acp: ToolCallLocations and working cancellation (#5588)
  feat(providers): add Mistral AI provider (#5009)
  Listen for ctrl-c during provider request (#5585)
  Also accept null as description, not just missing (#5589)
  Document missing recipe param types (#5584)
  docs: description required for "Add Extension" in cli (#5573)
  fix: Add schema-aware numeric coercion for MCP tool arguments (#5478)
  Add uv for uvx in Justfile (#5581)
  Keep llm logs in place (#5577)
  bump to 1.12.0 (#5580)
  automate more of the release process (#5409)
aharvard added a commit that referenced this pull request Nov 6, 2025
* origin/main: (75 commits)
  fix: customised recipe to yaml string to avoid minininjia parsing error (#5494)
  Add pending extension indicator to extension panel (#5493)
  Add environment subsition for auth blocks (#5439)
  acp: ToolCallLocations and working cancellation (#5588)
  feat(providers): add Mistral AI provider (#5009)
  Listen for ctrl-c during provider request (#5585)
  Also accept null as description, not just missing (#5589)
  Document missing recipe param types (#5584)
  docs: description required for "Add Extension" in cli (#5573)
  fix: Add schema-aware numeric coercion for MCP tool arguments (#5478)
  Add uv for uvx in Justfile (#5581)
  Keep llm logs in place (#5577)
  bump to 1.12.0 (#5580)
  automate more of the release process (#5409)
  add clippy warning for string_slice (#5422)
  improve linux tray icon support (#5425)
  feat: log rotation (#5561)
  use app.isPackaged instead of checking for node env development (#5465)
  disable RPM build-ID generation to prevent package conflicts (#5563)
  Add Diagnostics Info to Q&A and Bug Report Templates (#5565)
  ...
wpfleger96 added a commit that referenced this pull request Nov 6, 2025
* main: (60 commits)
  fix: add standard context menu items to prevent empty right-click menu (#5616)
  Bump openapi in prepare-release (#5611)
  docs: add access control section to Developer tutorial (#5615)
  Token state not showing on load, or after message is finished. (#5606)
  Change the other location too (#5608)
  feat(ui): bring back quick launcher (#5144)
  Support platform tools through CLI (#5570)
  Avoid web double write (#5601)
  fix: gemini flash -> pro for mcp smoke tests (#5574)
  Manual compaction test and fix (#5568)
  fix: tidy up claude cli handling (#5594)
  Remove jetbrains (#5602)
  feat(githubcopilot): add support for newer Copilot AI Models (#5603)
  fix: customised recipe to yaml string to avoid minininjia parsing error (#5494)
  Add pending extension indicator to extension panel (#5493)
  Add environment subsition for auth blocks (#5439)
  acp: ToolCallLocations and working cancellation (#5588)
  feat(providers): add Mistral AI provider (#5009)
  Listen for ctrl-c during provider request (#5585)
  Also accept null as description, not just missing (#5589)
  ...
wpfleger96 added a commit that referenced this pull request Nov 6, 2025
* main: (31 commits)
  Standardize CLI argument flags and update documentation (#5516)
  Release 1.13.0
  fix: move goosehints/AGENTS.md handling to goose, and out of developer extension (#5575)
  fix: add standard context menu items to prevent empty right-click menu (#5616)
  Bump openapi in prepare-release (#5611)
  docs: add access control section to Developer tutorial (#5615)
  Token state not showing on load, or after message is finished. (#5606)
  Change the other location too (#5608)
  feat(ui): bring back quick launcher (#5144)
  Support platform tools through CLI (#5570)
  Avoid web double write (#5601)
  fix: gemini flash -> pro for mcp smoke tests (#5574)
  Manual compaction test and fix (#5568)
  fix: tidy up claude cli handling (#5594)
  Remove jetbrains (#5602)
  feat(githubcopilot): add support for newer Copilot AI Models (#5603)
  fix: customised recipe to yaml string to avoid minininjia parsing error (#5494)
  Add pending extension indicator to extension panel (#5493)
  Add environment subsition for auth blocks (#5439)
  acp: ToolCallLocations and working cancellation (#5588)
  ...
michaelneale added a commit that referenced this pull request Nov 7, 2025
* main: (21 commits)
  differentiate debug/release in cache key (#5613)
  Unify subrecipe and subagent execution through shared recipe pipeline (#5082)
  Standardize CLI argument flags and update documentation (#5516)
  Release 1.13.0
  fix: move goosehints/AGENTS.md handling to goose, and out of developer extension (#5575)
  fix: add standard context menu items to prevent empty right-click menu (#5616)
  Bump openapi in prepare-release (#5611)
  docs: add access control section to Developer tutorial (#5615)
  Token state not showing on load, or after message is finished. (#5606)
  Change the other location too (#5608)
  feat(ui): bring back quick launcher (#5144)
  Support platform tools through CLI (#5570)
  Avoid web double write (#5601)
  fix: gemini flash -> pro for mcp smoke tests (#5574)
  Manual compaction test and fix (#5568)
  fix: tidy up claude cli handling (#5594)
  Remove jetbrains (#5602)
  feat(githubcopilot): add support for newer Copilot AI Models (#5603)
  fix: customised recipe to yaml string to avoid minininjia parsing error (#5494)
  Add pending extension indicator to extension panel (#5493)
  ...
fbalicchia pushed a commit to fbalicchia/goose that referenced this pull request Nov 7, 2025
Surendhar-N-D pushed a commit to Surendhar-N-D/goose that referenced this pull request Nov 17, 2025
arul-cc pushed a commit to arul-cc/goose that referenced this pull request Nov 17, 2025
BlairAllan pushed a commit to BlairAllan/goose that referenced this pull request Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants