babalae/better-genshin-impact · error · InvalidOperationException
状态 {CurrentState} 重试超时达到上限 {retryPolicy.value} ms
Error message
状态 {CurrentState} 重试超时达到上限 {retryPolicy.value} ms What it means
Thrown by StateMachineBase.RecordStateRetry when a state registered with a time-based retry policy (RegisterStateRetryTimeout) has retried longer than the configured timeout. Each retry increments CurrentStateRetryCount and, when retryPolicy.useTimeout is true, compares stateRetryStopwatch.ElapsedMilliseconds against retryPolicy.value; if elapsed >= timeout, it logs an error and throws InvalidOperationException, aborting RunStateMachineUntil.
Source
Thrown at BetterGenshinImpact/GameTask/Common/StateMachine/StateMachineBase.cs:634
}
private int GetTransitionTimeoutForState(TState state)
{
return _stateTransitionTimeouts.TryGetValue(state, out var timeoutMs) ? timeoutMs : DefaultTransitionTimeout;
}
private void RecordStateRetry(string reason, (bool useTimeout, int value) retryPolicy, Stopwatch stateRetryStopwatch)
{
CurrentStateRetryCount++;
if (retryPolicy.useTimeout)
{
var elapsedMilliseconds = stateRetryStopwatch.ElapsedMilliseconds;
if (elapsedMilliseconds >= retryPolicy.value)
{
Logger.LogError("状态 {State} {Reason},重试超时达到上限 {Max} ms,转为失败",
CurrentState, reason, retryPolicy.value);
throw new InvalidOperationException($"状态 {CurrentState} 重试超时达到上限 {retryPolicy.value} ms");
}
Logger.LogWarning("状态 {State} {Reason},将在重试超时窗口内继续重试(第 {Count} 次,已用 {Elapsed}/{Max} ms)",
CurrentState, reason, CurrentStateRetryCount, elapsedMilliseconds, retryPolicy.value);
return;
}
if (CurrentStateRetryCount >= retryPolicy.value)
{
Logger.LogError("状态 {State} {Reason},重试次数达到上限 {Max},转为失败",
CurrentState, reason, retryPolicy.value);
throw new InvalidOperationException($"状态 {CurrentState} 重试次数达到上限 {retryPolicy.value}");
}
Logger.LogWarning("状态 {State} {Reason},将重试当前状态(第 {Count}/{Max} 次)",
CurrentState, reason, CurrentStateRetryCount, retryPolicy.value);
}
View on GitHub (pinned to a7cb36712d)
Solutions
- Increase the per-state timeout registered via RegisterStateRetryTimeout for the failing state.
- Inspect the preceding warning logs ('将在重试超时窗口内继续重试') to see how many retries occurred and whether detection improved.
- Verify the state's detector and handler logic against the current game UI (re-capture templates).
- If the game is genuinely stuck, the throw is correct — fix the upstream cause (game state) rather than suppressing it.
Defensive patterns
Strategy: retry
Validate before calling
// Before running the state machine, sanity-check the game is responsive
using var r = CaptureToRectArea();
if (r.Width == 0) throw new InvalidOperationException("截图不可用,状态机无法运行"); Try / catch
try { await RunStateMachineUntil(context, targets); }
catch (InvalidOperationException ex) when (ex.Message.Contains("重试超时达到上限"))
{ Logger.LogError(ex, "状态机重试超时"); await RecoverToKnownState(ct); throw; } Prevention
- Size per-state timeouts to the slowest expected transition.
- Keep detector templates current with the game version.
- Log each retry to distinguish persistent failure from slow recovery.
When it happens
Trigger: A state handler returns Retry (or the transition keeps reporting RetryCurrentState) repeatedly. Because the state is registered with a timeout policy (not a count policy), retries continue until the stopwatch exceeds the configured ms. Persistent UI nondetection, a stuck game state, or a handler that always returns Retry will exhaust the time budget.
Common situations: Game UI not transitioning as expected (e.g. loading screen stuck); state detector templates outdated after a game update; the configured timeout is too short for slow machines; network lag in the game; the handler's success condition is never met due to a logic bug.
Related errors
- 状态 {CurrentState} 重试次数达到上限 {retryPolicy.value}
- 选择队伍失败,等待队伍切换超时!
- 状态 {CurrentState} 等待中间态转换超时
- 状态 {CurrentState} 的 Handler 返回失败
- 状态机达到最大迭代次数 {maxIterations},未到达目标状态:{string.Join(", ", targe
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/228db5928fc51bb0.
Report an issue: GitHub.