LykosAI/StabilityMatrix · error · InvalidOperationException
Lykos account must be connected in to manage OAuth…
Error message
Lykos account must be connected in to manage OAuth connections
What it means
AccountsService throws this InvalidOperationException when a Patreon OAuth logout is requested for the Lykos account but no Lykos account (secrets.LykosAccountV2) is stored. Managing OAuth connections (connect/disconnect Patreon) only makes sense when the user is already signed in to Lykos, so the service fails fast instead of silently doing nothing.
Solutions
- Ensure the user is logged in to Lykos (call LykosLoginAsync / complete the OAuth login) before attempting Patreon OAuth management
- Check secrets.LykosAccountV2 for null before calling LykosPatreonOAuthLogoutAsync and route the user to login instead
- Catch InvalidOperationException and surface a 'Sign in to Lykos first' message to the user
Example fix
// before
await accountsService.LykosPatreonOAuthLogoutAsync();
// after
var secrets = await secretsManager.SafeLoadAsync();
if (secrets.LykosAccountV2 is not null)
{
await accountsService.LykosPatreonOAuthLogoutAsync();
}
else
{
// prompt user to connect their Lykos account first
} Defensive patterns
Strategy: try-catch
Validate before calling
var secrets = await secretsManager.SafeLoadAsync(); bool canManage = secrets.LykosAccountV2 is not null;
Type guard
bool HasLykosAccount(SecretsManager m) => m.SafeLoadAsync().GetAwaiter().GetResult().LykosAccountV2 is not null;
Try / catch
try
{
await accountsService.LykosPatreonOAuthLogoutAsync();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Lykos account"))
{
// navigate user to Lykos login flow
} Prevention
- Gate Patreon OAuth UI actions on the Lykos login state
- Check secrets.LykosAccountV2 before any OAuth management call
- After logout, disable OAuth management controls until re-login
When it happens
Trigger: Calling AccountsService.LykosPatreonOAuthLogoutAsync() while secrets.LykosAccountV2 is null — i.e. the user never logged in to Lykos, logged out previously (which removes the secret), or the secrets store was cleared/corrupted.
Common situations: User clicks 'Disconnect Patreon' after having signed out of the Lykos account; a fresh install with no Lykos login; secrets vault reset or a failed Lykos login left LykosAccountV2 unset; app state restored from a backup without account secrets.
Related errors
- BatchSize card is null
- GetUserAccount did not contain an id
- Client is not connected
- API key is required
- Token is required
AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12).
Data as JSON: /api/errors/4c5129e3467a2484.
Report an issue: GitHub.
Appendix: source
Thrown at StabilityMatrix.Avalonia/Services/AccountsService.cs:157
await RefreshLykosAsync(secrets);
}
public async Task LykosAccountV2LogoutAsync()
{
var secrets = await secretsManager.SafeLoadAsync();
await secretsManager.SaveAsync(secrets with { LykosAccountV2 = null });
OnLykosAccountStatusUpdate(LykosAccountStatusUpdateEventArgs.Disconnected);
}
/// <inheritdoc />
public async Task LykosPatreonOAuthLogoutAsync()
{
var secrets = await secretsManager.SafeLoadAsync();
if (secrets.LykosAccountV2 is null)
{
throw new InvalidOperationException(
"Lykos account must be connected in to manage OAuth connections"
);
}
await lykosAuthApiV2.ApiV2OauthPatreon();
await RefreshLykosAsync(secrets);
}
public async Task CivitLoginAsync(string apiToken)
{
var secrets = await secretsManager.SafeLoadAsync();
// Get id first using the api token
var userAccount = await civitTRPCApi.GetUserAccount(bearerToken: apiToken);
var id =
userAccount.InnerJson?.Id
?? throw new InvalidOperationException("GetUserAccount did not contain an id");View on GitHub (pinned to af93d6ef57)