Skip to content

fix: deal with injectMetadataSave properly#286

Merged
Syspretor merged 1 commit intosgl-project:mainfrom
diw-zw:0422-injectm
Apr 22, 2026
Merged

fix: deal with injectMetadataSave properly#286
Syspretor merged 1 commit intosgl-project:mainfrom
diw-zw:0422-injectm

Conversation

@diw-zw
Copy link
Copy Markdown
Collaborator

@diw-zw diw-zw commented Apr 22, 2026

Summary

Fixes two issues in the injectMetadataSave helper within rbgctl llm pull:

  1. Incomplete /bin/sh -c detection — the previous code only recognized Command: ["/bin/sh", "-c"], Args: [...]. It now also handles the variant Command: ["/bin/sh"], Args: ["-c", ...] and normalizes it to the standard form so downstream logic stays uniform.
  2. Inconsistent metadata save command between Case 1 and Case 2 — Case 2 (wrap a direct binary) was using a simplified printf '%s\n' without generating the downloadedAt timestamp via date and sed. It now reuses the same metadataCmd as Case 1, ensuring the .rbg-metadata.json file always contains the correct downloadedAt value.

Changes

  • cmd/cli/cmd/llm/pull.go
    • Expands isShellC detection to cover /bin/sh with -c in Args
    • Normalizes the split form into Command: ["/bin/sh", "-c"] before appending the metadata command
    • Handles the edge case where container.Args is empty
    • Unifies Case 2 to use the same metadataCmd (with date + sed) instead of a shorter variant
  • cmd/cli/cmd/llm/pull_test.go
    • Updates test comments to reflect that both cases now use printf '%s\n' with date and sed

Copy link
Copy Markdown
Collaborator

@Syspretor Syspretor left a comment

Choose a reason for hiding this comment

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

/lgtm

@Syspretor Syspretor merged commit c1dd985 into sgl-project:main Apr 22, 2026
8 of 9 checks passed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the injectMetadataSave function to more robustly handle various ways /bin/sh -c can be defined in container specifications, including normalization of command and argument slices. It also refactors the command wrapping logic to reuse a centralized metadata command. The review feedback identifies a missing case where the shell script might reside in the third element of the Command slice rather than Args, and points out a potential shell syntax error if the original command is empty, which would result in a leading '&&'.

I am having trouble creating individual review comments. Click here to see my feedback.

cmd/cli/cmd/llm/pull.go (394-400)

high

The current logic assumes the shell script is always in container.Args[0]. However, if the container is defined with the script directly in the Command slice (e.g., Command: ["/bin/sh", "-c", "my-script"]), container.Args will be empty. In this case, the code incorrectly appends metadataCmd to container.Args, where it will be treated as a positional parameter ($0) rather than being executed as part of the command. The logic should check if the script is in container.Command[2] first.

		if len(container.Command) > 2 {
			container.Command[2] = container.Command[2] + " && " + metadataCmd
		} else if len(container.Args) == 0 {
			container.Args = []string{metadataCmd}
		} else {
			// Args should typically have exactly one element for /bin/sh -c;
			// additional elements become $0, $1... and are not executed as commands.
			container.Args[0] = container.Args[0] + " && " + metadataCmd
		}

cmd/cli/cmd/llm/pull.go (421)

medium

If both container.Command and container.Args are empty, fullCmd.String() will be empty, resulting in a wrappedCmd starting with &&, which is a shell syntax error. While plugins should typically provide a command, handling this case gracefully by omitting the leading && ensures the Job doesn't fail with a syntax error if the plugin relies on the image's default entrypoint.

	wrappedCmd := metadataCmd
	if fullCmd.Len() > 0 {
		wrappedCmd = fmt.Sprintf("%s && %s", fullCmd.String(), metadataCmd)
	}

@diw-zw diw-zw deleted the 0422-injectm branch April 30, 2026 08:44
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