plandex-ai/plandex · error

error copying settings: %v

Error message

error copying settings: %v

What it means

ApplyModelSettings deep-copies the original PlanSettings so it can attach a custom model pack without mutating the caller's copy. A DeepCopy failure is wrapped as 'error copying settings: %v'. DeepCopy in plandex-shared goes through JSON round-trip marshaling, so failures mean the settings struct could not be serialized/cloned.

Source

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

	}

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

	return nil
}

func ApplyModelSettings(path string, originalSettings *shared.PlanSettings) (*shared.PlanSettings, error) {
	jsonData, err := os.ReadFile(path)
	if err != nil {
		return nil, fmt.Errorf("error reading JSON file: %v", err)
	}

	settings, err := originalSettings.DeepCopy()
	if err != nil {
		return nil, fmt.Errorf("error copying settings: %v", err)
	}

	clientModelPackRoles, err := schema.ValidateModelPackInlineJSON(jsonData)
	if err != nil {
		term.StopSpinner()
		color.New(color.Bold, term.ColorHiRed).Println("🚨 Error validating JSON file")
		fmt.Println(err.Error())
		os.Exit(1)
	}
	modelPackRoles := clientModelPackRoles.ToModelPackSchemaRoles()

	modelPackSchema := shared.ModelPackSchema{
		Name:                 "custom",
		Description:          "Model pack with custom settings",
		ModelPackSchemaRoles: modelPackRoles,
	}
	modelPack := modelPackSchema.ToModelPack()
	settings.SetCustomModelPack(&modelPack)

View on GitHub (pinned to e2d772072e)

Solutions

  1. Inspect the wrapped %v message to find the field that failed to copy
  2. Align CLI and server versions so PlanSettings round-trips cleanly
  3. Re-fetch settings via GetSettings/GetOrgDefaultSettings instead of reusing a possibly stale object
  4. If DeepCopy is failing on benign data, clone manually or update plandex-shared to fix the round-trip
Defensive patterns

Strategy: validation

Validate before calling

// smoke-test that DeepCopy will work: the copy is JSON round-trip based
if _, err := json.Marshal(originalSettings); err != nil {
    return fmt.Errorf("settings not copyable: %w", err)
}

Try / catch

updated, err := lib.ApplyModelSettings(path, current)
if err != nil {
    if strings.Contains(err.Error(), "error copying settings") {
        // re-fetch settings from server and retry
    }
    return err
}

Prevention

When it happens

Trigger: originalSettings.DeepCopy() errors — i.e. the PlanSettings (including its model pack) contains data that cannot be JSON-marshaled/unmarshaled, typically after version mismatch or corrupt server payload.

Common situations: Settings fetched from a server on a different plandex-shared version with role fields of unexpected shape; a custom model pack assembled programmatically with unsupported values.

Related errors


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