plandex-ai/plandex · error

error marshalling model pack: %v

Error message

error marshalling model pack: %v

What it means

WriteModelSettingsFile serializes the plan's model pack roles with json.MarshalIndent before writing model-settings.json. This error wraps a json.Marshal failure. Because ClientModelPackSchemaRoles consists of plain JSON-friendly structs, this rarely fails unless the struct contents are corrupt or a custom MarshalJSON implementation errors.

Source

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

	return ModelSettingsCheckLocalChangesResult{
		HasLocalChanges:           currentHash != string(lastSavedHash),
		LocalModelPackSchemaRoles: &modelPackSchemaRoles,
	}, nil
}

func WriteModelSettingsFile(path string, originalSettings *shared.PlanSettings) error {
	err := os.MkdirAll(filepath.Dir(path), 0755)
	if err != nil {
		return fmt.Errorf("error creating directory: %v", err)
	}

	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"

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped %v message for the exact field and type that failed to marshal
  2. Ensure the CLI and server/plandex-shared versions match so GetModelPack() returns schema-conformant roles
  3. Re-fetch settings from the server (GetSettings) instead of using a locally mutated PlanSettings
  4. Report/fix any custom MarshalJSON implementation that errors on valid data
Defensive patterns

Strategy: validation

Validate before calling

// ensure the model pack round-trips through JSON before writing
if _, err := json.Marshal(settings.GetModelPack().ToModelPackSchema().ModelPackSchemaRoles); err != nil {
    return fmt.Errorf("settings not serializable: %w", err)
}

Try / catch

if err := lib.WriteModelSettingsFile(path, settings); err != nil {
    if strings.Contains(err.Error(), "error marshalling model pack") {
        // re-fetch settings from server and retry with fresh data
    }
    return err
}

Prevention

When it happens

Trigger: json.MarshalIndent(clientModelPackRoles) returns an error — e.g. an unsupported type or a custom MarshalJSON on a role field failing due to invalid model role data in originalSettings.GetModelPack().

Common situations: A server-supplied settings payload with unexpected role values after a plandex-shared version change; programmatically constructed PlanSettings with fields that cannot be marshaled.

Related errors


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