grafana/k6 · error
serialising archive
Error message
serialising archive: %w
What it means
ProvisionLocalExecution could not serialize the test archive: params.Archive.Write(&buf) failed while producing the tar bytes whose length is needed for the start_local_execution request and whose bytes are later uploaded to S3. The wrapped error comes from lib.Archive's writer and usually indicates a problem with the archive contents (script sources, embedded files), not with the network or cloud API.
Solutions
- Validate the archive independently first: run `k6 archive script.js` and confirm it succeeds
- If constructing the Archive in code, prefer lib.ReadArchive(bytes.NewReader(archiveBytes)) over assembling fields manually
- Check that all files referenced by the script (open() calls, data files) exist and are readable
- Update both producer and consumer to the same k6 version if the archive came from another binary
Example fix
// before
res, err := client.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{Archive: handBuiltArchive})
// after
arc, err := lib.ReadArchive(bytes.NewReader(archiveBytes))
if err != nil { return fmt.Errorf("reading archive: %w", err) }
res, err := client.ProvisionLocalExecution(ctx, provisioning.ProvisionParams{Archive: arc}) Defensive patterns
Strategy: try-catch
Validate before calling
// validate the archive round-trips before provisioning
var buf bytes.Buffer
if err := arc.Write(&buf); err != nil {
return fmt.Errorf("archive is not serializable: %w", err)
}
if buf.Len() == 0 {
return fmt.Errorf("archive serialized to 0 bytes; refusing to provision")
} Try / catch
if err := params.Archive.Write(&buf); err != nil {
return nil, fmt.Errorf("serialising archive: %w", err)
}
// fall back to re-reading from disk if the in-memory archive is broken
if params.ArchivePath != "" {
if f, ferr := os.Open(params.ArchivePath); ferr == nil {
defer f.Close()
buf.Reset()
_ = params.Archive.Write(&buf) // try again from the on-disk copy
}
} Prevention
- Run `k6 archive script.js` in CI as a pre-flight check before any cloud provisioning
- Construct archives via lib.ReadArchive instead of manual struct assembly
- Keep k6 versions aligned between archive producer and the binary that uploads it
When it happens
Trigger: Passing a hand-constructed or corrupted *lib.Archive, a script whose source references unreadable/missing files, filesystem errors while reading referenced assets during Write, or an archive built by a mismatched k6 version with an incompatible internal layout.
Common situations: Programmatically building an Archive (xk6/extensions) instead of loading it from disk, moving an archive between machines where referenced file paths no longer resolve, or a partially-written archive from a previous failed `k6 archive` run.
Related errors
- archive_size
- archive upload failed
- archive upload failed
- create or find load test
- creating temporary directory for downloads
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/21a35f2a59f913e3.
Report an issue: GitHub.
Appendix: source
Thrown at internal/cloudapi/provisioning/provision.go:72
// provisioning flow: CreateOrFindLoadTest → StartLocalExecution →
// optional UploadArchive → WaitForTestRunReady.
func (c *Client) ProvisionLocalExecution(ctx context.Context, params ProvisionParams) (*ProvisionResult, error) {
loadTestID, err := c.v6Client.CreateOrFindLoadTest(ctx, params.ProjectID, params.Name)
if err != nil {
return nil, fmt.Errorf("create or find load test: %w", err)
}
// Serialise archive once to get its byte-length for the
// start_local_execution body. The same buffer is reused for
// the S3 upload to avoid a second serialisation.
var (
archiveSize int64
archiveBytes []byte
)
if params.Archive != nil {
var buf bytes.Buffer
if err := params.Archive.Write(&buf); err != nil {
return nil, fmt.Errorf("serialising archive: %w", err)
}
archiveSize = int64(buf.Len())
archiveBytes = buf.Bytes()
}
sleReq := StartLocalExecutionRequest{
Options: params.Options,
MaxVUs: params.MaxVUs,
TotalDuration: params.TotalDuration,
ArchiveSize: archiveSize,
}
sleResp, err := c.StartLocalExecution(ctx, loadTestID, sleReq)
if err != nil {
return nil, fmt.Errorf("start local execution: %w", err)
}
switch {View on GitHub (pinned to 01ffac6f24)