github/copilot-sdk · error

failed to write runtime assets

Error message

failed to write runtime assets: %w

What it means

This error wraps a failure from createRuntimeAssetsArchive, which repacks the downloaded CLI tarball into the runtime assets archive (gzipped tar). The bundler throws it during buildBundle when the runtime package could not be produced (e.g. tar/gzip stream errors, no retained assets, or I/O failure). It aborts bundle creation since the assets artifact is required.

Solutions

  1. Delete the cached/intermediate tarball and re-run the bundler so a fresh, complete release package is downloaded
  2. Check available disk space on the output/temp filesystem
  3. Verify the release version and baseURL point to a package with the expected asset layout; update filter logic if assets are being filtered out
  4. Inspect the wrapped error (%w chain) for the underlying tar/gzip/I/O cause

Example fix

// before
if err := createRuntimeAssetsArchive(tarballPath, assetsArtifactPath, info); err != nil {
	return bundleArtifacts{}, fmt.Errorf("failed to write runtime assets: %w", err)
}
// after
if err := createRuntimeAssetsArchive(tarballPath, assetsArtifactPath, info); err != nil {
	if errors.Is(err, errNoRetainedAssets) {
		os.Remove(tarballPath) // drop corrupt/partial tarball so next run re-downloads
	}
	return bundleArtifacts{}, fmt.Errorf("failed to write runtime assets: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

if fi, err := os.Stat(tarballPath); err != nil || fi.Size() == 0 {
	return fmt.Errorf("source tarball %s missing or empty; re-download before bundling", tarballPath)
}

Type guard

func tarballLooksValid(path string) bool {
	f, err := os.Open(path)
	if err != nil { return false }
	defer f.Close()
	magic := make([]byte, 2)
	if _, err := io.ReadFull(f, magic); err != nil { return false }
	return magic[0] == 0x1f && magic[1] == 0x8b
}

Try / catch

if err := buildBundle(...); err != nil {
	var wrapped *os.PathError
	if errors.As(err, &wrapped) && errors.Is(wrapped, syscall.ENOSPC) {
		// free disk space and retry
	}
	return fmt.Errorf("bundle build failed: %w", err)
}

Prevention

When it happens

Trigger: createRuntimeAssetsArchive returns any error while writing the gzipped tar of retained assets in buildBundle: source tar read failure, gzip/tar writer close failure, or the archive containing zero retained entries.

Common situations: Downloaded/cached CLI tarball is corrupt or empty so no assets are retained; destination disk full preventing gzip writes; running against a release whose package layout changed and the filter retains nothing; premature EOF from an interrupted tarball download.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/616db188f06e7363. Report an issue: GitHub.

Appendix: source

Thrown at go/cmd/bundler/main.go:499

	wrapperName := runtimeWrapperName(info.binaryName)
	rawWrapperPath := filepath.Join(tempDir, wrapperName)
	if err := extractFileFromTarball(
		tarballPath,
		tempDir,
		"package/prebuilds/"+info.runtimePlatform+"/"+wrapperName,
		wrapperName,
	); err != nil {
		return bundleArtifacts{}, fmt.Errorf("runtime package is missing prebuilds/%s/%s: %w", info.runtimePlatform, wrapperName, err)
	}
	wrapperHash, err := sha256File(rawWrapperPath)
	if err != nil {
		return bundleArtifacts{}, fmt.Errorf("failed to hash runtime wrapper: %w", err)
	}
	if err := compressZstdFile(rawWrapperPath, wrapperArtifactPath); err != nil {
		return bundleArtifacts{}, fmt.Errorf("failed to write runtime wrapper: %w", err)
	}
	if err := createRuntimeAssetsArchive(tarballPath, assetsArtifactPath, info); err != nil {
		return bundleArtifacts{}, fmt.Errorf("failed to write runtime assets: %w", err)
	}
	assetsHash, err := sha256File(assetsArtifactPath)
	if err != nil {
		return bundleArtifacts{}, fmt.Errorf("failed to hash runtime assets: %w", err)
	}

	fmt.Printf("Successfully created %s\n", outputPath)
	fmt.Printf("Successfully created %s\n", runtimeArtifactPath)
	fmt.Printf("Successfully created %s\n", wrapperArtifactPath)
	fmt.Printf("Successfully created %s\n", assetsArtifactPath)
	return bundleArtifacts{outputPath, binaryHash, runtimeArtifactPath, runtimeHash, wrapperArtifactPath, wrapperHash, assetsArtifactPath, assetsHash}, nil
}

func filesExist(paths ...string) bool {
	for _, path := range paths {
		if _, err := os.Stat(path); err != nil {
			return false
		}

View on GitHub (pinned to cd8cf15dc3)