{"record":{"id":"bed250afff8c1981","repo":"iflytek/astron-agent","slug":"timeout-must-be-between-1-300-seconds","errorCode":null,"errorMessage":"Timeout must be between 1-300 seconds","messagePattern":"Timeout must be between 1-300 seconds","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java","lineNumber":248,"sourceCode":"            if (e instanceof BusinessException) {\n                throw e;\n            }\n            throw new BusinessException(ResponseEnum.SYSTEM_ERROR);\n        }\n    }\n\n    /**\n     * Validate text generation parameters\n     */\n    private void validateTextGenerationParams(String question, String domain, int seconds) {\n        if (question == null || question.trim().isEmpty()) {\n            throw new IllegalArgumentException(\"Generation prompt cannot be empty\");\n        }\n        if (domain == null || domain.trim().isEmpty()) {\n            throw new IllegalArgumentException(\"Model domain cannot be empty\");\n        }\n        if (seconds <= 0 || seconds > 300) {\n            throw new IllegalArgumentException(\"Timeout must be between 1-300 seconds\");\n        }\n    }\n\n    /**\n     * Convert AI service error code to corresponding ResponseEnum\n     *\n     * @param errorCode Error code returned by AI service\n     * @return Corresponding ResponseEnum\n     */\n    private ResponseEnum convertTextErrorCodeToResponseEnum(Integer errorCode) {\n        if (errorCode == null) {\n            return ResponseEnum.SYSTEM_ERROR;\n        }\n\n        ResponseEnum responseEnum = TEXT_ERROR_CODE_MAP.get(errorCode);\n        if (responseEnum == null) {\n            log.warn(\"Unknown AI text service error code: {}\", errorCode);\n            return ResponseEnum.SYSTEM_ERROR;","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/BotAIServiceClient.java#L230-L266","documentation":"validateTextGenerationParams requires the timeout 'seconds' to be strictly between 1 and 300 inclusive; otherwise it throws IllegalArgumentException('Timeout must be between 1-300 seconds'). This bounds how long generateText will block on latch.await for the WebSocket response.","triggerScenarios":"generateText(question, domain, 0), negative seconds, or seconds > 300 — a caller computing the timeout from a bad config value or passing a millisecond value where seconds is expected.","commonSituations":"Configuration storing timeout in milliseconds (e.g. 30000) passed directly as seconds, a default of 0 meaning 'unset', or an attempt to allow very long generations beyond the 300s cap.","solutions":["Clamp the timeout at the call site: Math.max(1, Math.min(300, configuredSeconds))","Fix unit confusion if the config value is in milliseconds (divide by 1000)","Provide a sane default (e.g. 60s) when the timeout config is missing or zero"],"exampleFix":"// before\nint seconds = (int) timeoutConfig.getValue(); // 30000 (ms)\nbotAIServiceClient.generateText(prompt, domain, seconds);\n// after\nint seconds = Math.max(1, Math.min(300, (int) (timeoutConfig.getValue() / 1000)));\nbotAIServiceClient.generateText(prompt, domain, seconds);","handlingStrategy":"validation","validationCode":"if (seconds <= 0 || seconds > 300) { seconds = Math.max(1, Math.min(300, seconds)); }","typeGuard":null,"tryCatchPattern":"try { return client.generateText(q, domain, seconds); } catch (IllegalArgumentException e) { log.warn(\"Bad timeout: {}\", e.getMessage()); return client.generateText(q, domain, 60); }","preventionTips":["Clamp configured timeouts into the 1-300 range before calling","Watch for ms-vs-s unit confusion in config values","Use a sane default (60s) when timeout config is absent"],"tags":["java","validation","argument-validation","timeout"],"backgroundTag":"value-out-of-range","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}