Skip to content

Conversation

doringeman
Copy link

Fixes 3 related issues preventing models from working with the include directive:

  • Missing merge logic for models in override package.
  • Short syntax validation failed (models: [llama]{llama: null} violates schema).
  • Models weren't being imported from included files (missing from importResources).

E.g.,
Fixes running docker-compose up with the root docker-compose.yml in docker/hello-genai#15.

Before this PR:

$ docker compose up
validating /Users/doringeman/workspace/hello-genai/docker-compose.yml: services.go-genai.models.llama must be a mapping

After the second commit (run go mod edit -replace=github.com/compose-spec/compose-go/v2=github.com/doringeman/compose-go/v2@80d4df69626c3c3ab08f5c3af0870de5900aecde && go mod tidy && make install in https://github.com/docker/compose):

$ docker compose up
service "rust-genai" refers to undefined model llama: invalid compose project

After the third commit (run go mod edit -replace=github.com/compose-spec/compose-go/v2=github.com/doringeman/compose-go/v2@95abc2eef4c7b7d1278a34c2e548ec47a216acc9 && go mod tidy && make install in https://github.com/docker/compose):

$ docker compose up
[+] Running 4/5
 ⠙ llama Configuring                                                                                                0.1s
 ✔ Container hello-genai-rust-genai-1    Created                                                                    0.1s
 ✔ Container hello-genai-node-genai-1    Created                                                                    0.1s
 ✔ Container hello-genai-python-genai-1  Created                                                                    0.1s
 ✔ Container hello-genai-go-genai-1      Created                                                                    0.1s
Attaching to go-genai-1, node-genai-1, python-genai-1, rust-genai-1

Networks schema allows null but models schema requires objects. Fixes validation error when using models short syntax with includes.

Signed-off-by: Dorin Geman <[email protected]>
Copy link
Collaborator

@ndeloof ndeloof left a comment

Choose a reason for hiding this comment

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

Changes to transformStringSliceToMap are not required, this same mechanism is used in many other places without any issue.

var mergeSpecials = map[tree.Path]merger{}

func init() {
mergeSpecials["models.*.runtime_flags"] = override
Copy link
Collaborator

Choose a reason for hiding this comment

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

This requires an update on the compose-spec documentation to make it clear runtime_flags won't be appended
see https://github.com/compose-spec/compose-spec/blob/main/13-merge.md#exceptions

Comment on lines +164 to +173
// Check if both sides are string arrays for short syntax only
if rightArr, ok := c.([]any); ok {
if leftArr, ok := o.([]any); ok {
if isStringArray(rightArr) && isStringArray(leftArr) {
return mergeStringArrays(rightArr, leftArr), nil
}
}
}

// Otherwise, use map merge for long syntax or mixed syntax
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should not be necessary, as next lines merge equivalent mapping syntax

Copy link
Author

Choose a reason for hiding this comment

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

You mean to remove the comment only?

Copy link
Collaborator

Choose a reason for hiding this comment

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

no, I mean this all block. Mutating into mapping format then merge is the right way, and should not require any extra processing - we do the same for the many other comparable structs

@doringeman
Copy link
Author

Changes to transformStringSliceToMap are not required, this same mechanism is used in many other places without any issue.

In this case I'd need to add {"type": "null"} for models in compose-spec.json, right? This is why I changed transformStringSliceToMap.

diff --git a/schema/compose-spec.json b/schema/compose-spec.json
index 5db97d0..047a6b4 100644
--- a/schema/compose-spec.json
+++ b/schema/compose-spec.json
@@ -546,7 +546,8 @@
                   "patternProperties": {"^x-": {}}
                 }
               }
-            }
+            },
+            {"type": "null"}
           ],
           "description": "AI Models to use, referencing entries under the top-level models key."
         },

@ndeloof
Copy link
Collaborator

ndeloof commented Oct 10, 2025

In this case I'd need to add {"type": "null"} for models in compose-spec.json, right?

I don't think so. See networks for a comparable struct. Can be set either as a string array or a mapping

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.

2 participants