{"record":{"id":"228db5928fc51bb0","repo":"babalae/better-genshin-impact","slug":"currentstate-retrypolicy-value-ms","errorCode":null,"errorMessage":"状态 {CurrentState} 重试超时达到上限 {retryPolicy.value} ms","messagePattern":"状态 (.+?) 重试超时达到上限 (.+?) ms","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/GameTask/Common/StateMachine/StateMachineBase.cs","lineNumber":634,"sourceCode":"    }\n\n    private int GetTransitionTimeoutForState(TState state)\n    {\n        return _stateTransitionTimeouts.TryGetValue(state, out var timeoutMs) ? timeoutMs : DefaultTransitionTimeout;\n    }\n\n    private void RecordStateRetry(string reason, (bool useTimeout, int value) retryPolicy, Stopwatch stateRetryStopwatch)\n    {\n        CurrentStateRetryCount++;\n\n        if (retryPolicy.useTimeout)\n        {\n            var elapsedMilliseconds = stateRetryStopwatch.ElapsedMilliseconds;\n            if (elapsedMilliseconds >= retryPolicy.value)\n            {\n                Logger.LogError(\"状态 {State} {Reason}，重试超时达到上限 {Max} ms，转为失败\",\n                    CurrentState, reason, retryPolicy.value);\n                throw new InvalidOperationException($\"状态 {CurrentState} 重试超时达到上限 {retryPolicy.value} ms\");\n            }\n\n            Logger.LogWarning(\"状态 {State} {Reason}，将在重试超时窗口内继续重试（第 {Count} 次，已用 {Elapsed}/{Max} ms）\",\n                CurrentState, reason, CurrentStateRetryCount, elapsedMilliseconds, retryPolicy.value);\n            return;\n        }\n\n        if (CurrentStateRetryCount >= retryPolicy.value)\n        {\n            Logger.LogError(\"状态 {State} {Reason}，重试次数达到上限 {Max}，转为失败\",\n                CurrentState, reason, retryPolicy.value);\n            throw new InvalidOperationException($\"状态 {CurrentState} 重试次数达到上限 {retryPolicy.value}\");\n        }\n\n        Logger.LogWarning(\"状态 {State} {Reason}，将重试当前状态（第 {Count}/{Max} 次）\",\n            CurrentState, reason, CurrentStateRetryCount, retryPolicy.value);\n    }\n","sourceCodeStart":616,"sourceCodeEnd":652,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/GameTask/Common/StateMachine/StateMachineBase.cs#L616-L652","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Before running the state machine, sanity-check the game is responsive\nusing var r = CaptureToRectArea();\nif (r.Width == 0) throw new InvalidOperationException(\"截图不可用，状态机无法运行\");","typeGuard":null,"tryCatchPattern":"try { await RunStateMachineUntil(context, targets); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"重试超时达到上限\"))\n{ Logger.LogError(ex, \"状态机重试超时\"); await RecoverToKnownState(ct); throw; }","preventionTips":["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."],"tags":["state-machine","retry-timeout","game-automation","config"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}