{"record":{"id":"0c5c9ffb81f6288d","repo":"iflytek/astron-agent","slug":"model-api-key-not-found","errorCode":"MODEL_API_KEY_NOT_FOUND","errorMessage":"ResponseEnum.MODEL_API_KEY_NOT_FOUND","messagePattern":"ResponseEnum\\.MODEL_API_KEY_NOT_FOUND","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"critical","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/runtime/AgentMemorySecretService.java","lineNumber":65,"sourceCode":"            privateKey = cachedPrivateKey;\n            if (privateKey != null && now < privateKeyCacheExpiresAt) {\n                return privateKey;\n            }\n            privateKey = loadPrivateKey();\n            cachedPrivateKey = privateKey;\n            privateKeyCacheExpiresAt = System.currentTimeMillis() + PRIVATE_KEY_CACHE_TTL_MS;\n            return privateKey;\n        }\n    }\n\n    private RSAPrivateKey loadPrivateKey() {\n        ConfigInfo modelSecretKey = configInfoMapper.selectOne(Wrappers.<ConfigInfo>lambdaQuery()\n                .eq(ConfigInfo::getCategory, CAT_MODEL_SECRET_KEY)\n                .eq(ConfigInfo::getCode, CODE_PRIVATE_KEY)\n                .eq(ConfigInfo::getIsValid, 1)\n                .last(\"LIMIT 1\"));\n        if (modelSecretKey == null) {\n            throw new BusinessException(ResponseEnum.MODEL_API_KEY_NOT_FOUND);\n        }\n\n        try {\n            RSAPrivateKey privateKey = RSAUtil.loadPrivateKey(modelSecretKey.getValue());\n            if (privateKey == null) {\n                throw new IllegalStateException(\"Private key is null\");\n            }\n            return privateKey;\n        } catch (Exception e) {\n            log.error(\"Load agent memory private key failed\", e);\n            throw new BusinessException(ResponseEnum.MODEL_APIKEY_LOAD_ERROR);\n        }\n    }\n}\n","sourceCodeStart":47,"sourceCodeEnd":80,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentmemory/runtime/AgentMemorySecretService.java#L47-L80","documentation":"loadPrivateKey throws MODEL_API_KEY_NOT_FOUND when no valid config_info row exists with category=model secret key and code=private key (is_valid=1). The service cannot even attempt decryption because the RSA private key is missing from configuration.","triggerScenarios":"Any decrypt attempt when the private-key row is absent from config_info, is invalid (is_valid=0), or the category/code strings don't match the constants CAT_MODEL_SECRET_KEY / CODE_PRIVATE_KEY.","commonSituations":"Fresh environment where the config table was never seeded; key row soft-invalidated during rotation without inserting the new one; wrong environment database (key only exists in prod).","solutions":["Insert a config_info row with the correct category, code='private key', is_valid=1, and value=PEM private key.","Verify the environment's config_info table is seeded (check deploy/init SQL or config management).","If the key was rotated, insert the new private key row rather than only invalidating the old one."],"exampleFix":"-- before: no row\n-- after\nINSERT INTO config_info (category, code, value, is_valid)\nVALUES ('model_secret_key', 'private_key', '-----BEGIN PRIVATE KEY-----\\n...\\n-----END PRIVATE KEY-----', 1);","handlingStrategy":"try-catch","validationCode":"SELECT COUNT(*) FROM config_info WHERE category='model_secret_key' AND code='private_key' AND is_valid=1; // must be >= 1","typeGuard":null,"tryCatchPattern":"try { svc.decryptApiKey(ct); } catch (BusinessException e) { if (e.getCode() == ResponseEnum.MODEL_API_KEY_NOT_FOUND) { alertOpsToSeedPrivateKeyConfig(); } }","preventionTips":["Seed the private-key config row in every environment's init/迁移 SQL.","Never invalidate the old key row until the new one is inserted.","Add a health check that the private key config resolves at startup."],"tags":["configuration","missing-config","rsa"],"backgroundTag":"missing-config-key","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"}