babalae/better-genshin-impact · error · InvalidOperationException

状态 {CurrentState} 等待中间态转换超时

Error message

状态 {CurrentState} 等待中间态转换超时

What it means

Thrown inside RunStateMachineUntil after a handler returns Success but WaitStateTransitionTo / WaitNextStateTransition returns StateTransitionWaitStatus.IntermediateTimeout. This means the handler reported success and the state machine waited for the UI to leave the current state toward a neighbor, but no transition was detected within GetTransitionTimeoutForState (default DefaultTransitionTimeout). The game UI stayed in an unexpected/intermediate state.

Source

Thrown at BetterGenshinImpact/GameTask/Common/StateMachine/StateMachineBase.cs:745

                    case StateHandlerStatus.Success:
                        // 成功:等待指定的目标状态,或当前状态的全部邻接状态。
                        var transitionResult = result.TargetStates.Count > 0
                            ? await WaitStateTransitionTo(result.TargetStates, transitionTimeout)
                            : await WaitNextStateTransition(transitionTimeout);
                        switch (transitionResult.Status)
                        {
                            case StateTransitionWaitStatus.ReachedTarget:
                                CurrentStateRetryCount = 0; // 成功转换后重置重试计数
                                stateRetryStopwatch.Restart();
                                break;

                            case StateTransitionWaitStatus.RetryCurrentState:
                                RecordStateRetry("源状态持续可见,触发当前状态重试", retryPolicy, stateRetryStopwatch);
                                nextLoopInterval = retryInterval;
                                break;

                            case StateTransitionWaitStatus.IntermediateTimeout:
                                throw new InvalidOperationException($"状态 {CurrentState} 等待中间态转换超时");
                        }
                        break;

                    case StateHandlerStatus.Wait:
                        // 可预期的等待:状态机继续循环,重新检测状态。
                        Logger.LogDebug("Handler 返回 Wait,状态机继续等待");
                        break;

                    case StateHandlerStatus.Retry:
                        // 意外失败重试:检查重试次数。
                        RecordStateRetry("Handler 返回 Retry", retryPolicy, stateRetryStopwatch);
                        nextLoopInterval = retryInterval;
                        break;

                    case StateHandlerStatus.Fail:
                        // 失败:抛出异常。
                        throw new InvalidOperationException($"状态 {CurrentState} 的 Handler 返回失败");
                }

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Increase the transition timeout for the state via RegisterStateTransitionTimeout.
  2. Register a state detector for the intermediate screen so the transition is recognized rather than timing out.
  3. Verify captures succeed during the wait (no '截图失败' warnings).
  4. Confirm the handler's declared TargetStates match the real possible next states.
Defensive patterns

Strategy: retry

Try / catch

try { await RunStateMachineUntil(context, targets); }
catch (InvalidOperationException ex) when (ex.Message.Contains("等待中间态转换超时"))
{ Logger.LogError(ex, "中间态转换超时"); throw; }

Prevention

When it happens

Trigger: A handler acted (e.g. clicked a button) and returned Success, then the transition waiter polled for a neighboring state but the game never entered any registered state within the transition timeout — e.g. a loading screen or unregistered intermediate UI appeared and persisted.

Common situations: Game shows an intermediate screen (loading, dialog, confirmation) that has no registered state detector; transition timeout too short for slow loads; game update introduced a new intermediate screen; capture failing during the wait so detection never succeeds.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/daf0c13253ef9c41. Report an issue: GitHub.