github/copilot-sdk · error
invalid AskUserVariant
Error message
invalid AskUserVariant %q: expected %q, %q, or unset
What it means
validateAskUserVariant enforces that SessionConfig.AskUserVariant is either unset, AskUserVariantLegacy, or AskUserVariantElicitation. Any other string is rejected with this error before a session is created.
Solutions
- Set AskUserVariant to one of the exported constants: AskUserVariantLegacy or AskUserVariantElicitation.
- Leave AskUserVariant as the zero value ("") for default behavior.
- Check the SDK version for the set of valid variants and update your value accordingly.
Example fix
// before cfg.AskUserVariant = "elicitation-mode" // after cfg.AskUserVariant = AskUserVariantElicitation
Defensive patterns
Strategy: validation
Validate before calling
if v := cfg.AskUserVariant; v != "" && v != AskUserVariantLegacy && v != AskUserVariantElicitation { return fmt.Errorf("invalid AskUserVariant %q", v) } Type guard
func validAskUserVariant(v AskUserVariant) bool { return v == "" || v == AskUserVariantLegacy || v == AskUserVariantElicitation } Try / catch
if err := validateAskUserVariant(cfg.AskUserVariant); err != nil { return err } Prevention
- Always use exported constants, never raw strings
- Leave AskUserVariant unset for default
- Re-validate after SDK upgrades
When it happens
Trigger: Passing an arbitrary/typo'd string in config.AskUserVariant to Client.CreateSession or ResumeSessionWithOptions.
Common situations: Typo like "elicitaton" or "legacy-mode"; constructing the value dynamically from user input; SDK version change adding new variants not yet known to the caller.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- SessionFS.Conventions must be either 'posix' or 'windows'
- sessionFs.conventions must be either 'windows' or 'posix'
- Unknown AgentMode value: + value
- Unknown AskUserVariant value: + value
- Unknown AutoTier value: + value
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/cf039c8770cfb2cc.
Report an issue: GitHub.
Appendix: source
Thrown at go/client.go:829
if len(callbacks) == 0 {
return config, nil
}
wireConfig := &SystemMessageConfig{
Mode: config.Mode,
Content: config.Content,
Sections: wireSections,
}
return wireConfig, callbacks
}
func hasManagedSettings(enableManagedSettings *bool, managedSettings *ManagedSettings) bool {
return (enableManagedSettings != nil && *enableManagedSettings) || managedSettings != nil
}
func validateAskUserVariant(variant AskUserVariant) error {
if variant != "" && variant != AskUserVariantLegacy && variant != AskUserVariantElicitation {
return fmt.Errorf("invalid AskUserVariant %q: expected %q, %q, or unset", variant, AskUserVariantLegacy, AskUserVariantElicitation)
}
return nil
}
func (c *Client) CreateSession(ctx context.Context, config *SessionConfig) (*Session, error) {
if config == nil {
config = &SessionConfig{}
}
if config.GitHubToken != "" && config.GitHubTokenProvider != nil {
return nil, fmt.Errorf("GitHubToken and GitHubTokenProvider cannot be used together")
}
if err := validateAskUserVariant(config.AskUserVariant); err != nil {
return nil, err
}
if err := c.ensureConnected(ctx); err != nil {
return nil, err
}View on GitHub (pinned to cd8cf15dc3)