vxcontrol/pentagi · error

tar archive content serialization failed: %w

Error message

tar archive content serialization failed: %w

What it means

After writing the tar header, writeFileToContainer writes the file bytes into the in-memory tar archive via archiveWriter.Write. This error wraps that Write failing. Because the underlying writer is a bytes.Buffer, the only realistic cause is memory exhaustion while buffering the content — the error is effectively an out-of-memory signal, not a disk or network problem.

Source

Thrown at backend/pkg/tools/terminal.go:479

	// Docker SDK requires TAR format for file transfer
	tarBuffer := &bytes.Buffer{}
	archiveWriter := tar.NewWriter(tarBuffer)
	defer archiveWriter.Close()

	filename := filepath.Base(path)
	fileDescriptor := &tar.Header{
		Name: filename,
		Mode: 0600,
		Size: int64(len(content)),
	}
	err = archiveWriter.WriteHeader(fileDescriptor)
	if err != nil {
		return fmt.Errorf("tar archive header generation failed: %w", err)
	}

	_, err = archiveWriter.Write([]byte(content))
	if err != nil {
		return fmt.Errorf("tar archive content serialization failed: %w", err)
	}

	err = archiveWriter.Close()
	if err != nil {
		return fmt.Errorf("failed to close tar writer: %w", err)
	}

	dir := filepath.Dir(path)
	err = t.dockerClient.CopyToContainer(ctx, containerName, dir, tarBuffer, client.CopyToContainerOptions{
		AllowOverwriteDirWithFile: true,
	})
	if err != nil {
		return fmt.Errorf("container file transfer failed: %w", err)
	}

	return nil
}

View on GitHub (pinned to ea665308ba)

Solutions

  1. Reduce the size of the content being written; split into multiple smaller WriteFile calls
  2. Increase memory available to the backend container/host
  3. Check the wrapped error for an out-of-memory/alloc message and confirm with runtime metrics
  4. Pre-check content size before calling writeFileToContainer and reject implausibly large writes early

Example fix

// before
_, err = archiveWriter.Write([]byte(content))
if err != nil {
    return fmt.Errorf("tar archive content serialization failed: %w", err)
}
// after
const maxWriteSize = 64 << 20 // 64MB
if int64(len(content)) > maxWriteSize {
    return fmt.Errorf("content of %d bytes exceeds max write size %d", len(content), maxWriteSize)
}
_, err = archiveWriter.Write([]byte(content))
if err != nil {
    return fmt.Errorf("tar archive content serialization failed: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

if int64(len(content)) >= 1<<30 {
    return fmt.Errorf("content too large for in-memory tar: %d bytes", len(content))
}

Try / catch

if _, err := term.WriteFile(ctx, flowID, content, path); err != nil {
    var wrapped error = err
    for errors.Unwrap(wrapped) != nil { wrapped = errors.Unwrap(wrapped) }
    if strings.Contains(wrapped.Error(), "cannot allocate") { /* OOM: reduce size and retry */ }
}

Prevention

When it happens

Trigger: WriteFile or EditFile invoked with content so large that appending []byte(content) to the tar buffer exceeds available memory (allocation failure inside bytes.Buffer grow).

Common situations: Agents attempting to write very large files (huge logs, binary blobs, base64 payloads) into the sandbox container on memory-limited hosts; OOM-killer pressure inside the backend process.

Related errors


AI-assisted analysis of vxcontrol/pentagi@ea665308ba (2026-09-01). Data as JSON: /api/errors/7900b311d7afa174. Report an issue: GitHub.