plandex-ai/plandex · error

error saving model pack roles hash: %v

Error message

error saving model pack roles hash: %v

What it means

After writing model-settings.json, WriteModelSettingsFile calls SaveModelPackRolesHash to persist a hash sidecar (<path>.hash) used later to detect local edits. Any error from that helper is re-wrapped as 'error saving model pack roles hash: %v'. The JSON file may already have been written successfully when this fires, leaving the pair inconsistent.

Source

Thrown at app/cli/lib/model_settings.go:95

	}

	modelPackSchemaRoles := originalSettings.GetModelPack().ToModelPackSchema().ModelPackSchemaRoles

	clientModelPackRoles := modelPackSchemaRoles.ToClientModelPackSchemaRoles()

	bytes, err := json.MarshalIndent(clientModelPackRoles, "", "  ")
	if err != nil {
		return fmt.Errorf("error marshalling model pack: %v", err)
	}

	err = os.WriteFile(path, bytes, 0644)
	if err != nil {
		return fmt.Errorf("error writing JSON file: %v", err)
	}

	err = SaveModelPackRolesHash(path, &modelPackSchemaRoles)
	if err != nil {
		return fmt.Errorf("error saving model pack roles hash: %v", err)
	}

	return nil
}

func SaveModelPackRolesHash(basePath string, serverModelPack *shared.ModelPackSchemaRoles) error {
	hashPath := basePath + ".hash"

	hash, err := serverModelPack.Hash()
	if err != nil {
		return fmt.Errorf("error hashing model pack: %v", err)
	}

	err = os.WriteFile(hashPath, []byte(hash), 0644)
	if err != nil {
		return fmt.Errorf("error writing hash file: %v", err)
	}

View on GitHub (pinned to e2d772072e)

Solutions

  1. Read the wrapped cause: if it's a hash-write OS error, fix ~/.plandex directory permissions
  2. If the hash is inconsistent, delete both model-settings.json and model-settings.json.hash and re-save model settings
  3. Free disk space if the write failed with ENOSPC
  4. Match CLI and plandex-shared versions if the underlying Hash() call failed

Example fix

// before
error saving model pack roles hash: open .../model-settings.json.hash: permission denied
// after
chmod u+w ~/.plandex/<planId> && plandex update-model-settings
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure both the settings file and hash sidecar path are writable beforehand
for _, p := range []string{path, path + ".hash"} {
    if f, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE, 0o644); err != nil {
        return fmt.Errorf("%s not writable: %w", p, err)
    } else { f.Close() }
}

Try / catch

if err := lib.WriteModelSettingsFile(path, settings); err != nil {
    if strings.Contains(err.Error(), "error saving model pack roles hash") {
        // JSON may be written but hash stale: remove both files and re-save
    }
    return err
}

Prevention

When it happens

Trigger: SaveModelPackRolesHash fails because ModelPackSchemaRoles.Hash() errors or because writing the <path>.hash file fails (read-only directory, permissions, disk full).

Common situations: Hash file locked or owned by another user; plan directory made read-only after the JSON write succeeded; plandex-shared hashing failure after a version upgrade.

Understand the failure class

Background: "Permission denied" / "Failed to write" file errors: why a library can't write its files to disk (EACCES, EPERM, ENOSPC) and how to fix them — this error's family across 43 libraries.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/a568dd769c55577b. Report an issue: GitHub.