{"record":{"id":"b8438cd9659ee6d2","repo":"iflytek/astron-agent","slug":"unauthorized-b8438c","errorCode":"UNAUTHORIZED","errorMessage":"UNAUTHORIZED","messagePattern":"UNAUTHORIZED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"error","filePath":"console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentdebug/impl/AgentDebugServiceImpl.java","lineNumber":149,"sourceCode":"\n    @Override\n    public void clearSessions(String uid, Long spaceId, Integer botId) {\n        validateUser(uid);\n        checkBotPermission(uid, spaceId, botId);\n        AgentDebugSession update = new AgentDebugSession();\n        update.setIsDelete(1);\n        update.setUpdateTime(LocalDateTime.now());\n        LambdaUpdateWrapper<AgentDebugSession> updateWrapper = Wrappers.lambdaUpdate(AgentDebugSession.class)\n                .eq(AgentDebugSession::getBotId, botId)\n                .eq(AgentDebugSession::getUid, uid)\n                .eq(AgentDebugSession::getIsDelete, 0);\n        addSpaceCondition(updateWrapper, spaceId);\n        sessionMapper.update(update, updateWrapper);\n    }\n\n    private void validateUser(String uid) {\n        if (StringUtils.isBlank(uid)) {\n            throw new BusinessException(ResponseEnum.UNAUTHORIZED);\n        }\n    }\n\n    private void checkBotPermission(String uid, Long spaceId, Integer botId) {\n        if (botId == null || chatBotBaseMapper.checkBotPermission(botId, uid, spaceId) <= 0) {\n            throw new BusinessException(ResponseEnum.INSUFFICIENT_PERMISSIONS);\n        }\n    }\n\n    private AgentDebugSession findAccessibleSession(String uid, Long spaceId, String sessionId) {\n        AgentDebugSession session = findSession(uid, sessionId);\n        if (!isSameSpace(session.getSpaceId(), spaceId)) {\n            throw new BusinessException(ResponseEnum.DATA_NOT_FOUND);\n        }\n        checkBotPermission(uid, spaceId, session.getBotId());\n        return session;\n    }\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/agentdebug/impl/AgentDebugServiceImpl.java#L131-L167","documentation":"UNAUTHORIZED thrown by AgentDebugService.validateUser when the uid is blank. All agent-debug operations (list/create/get/save/delete/clear sessions) call it first; an empty user id means authentication context was missing.","triggerScenarios":"Calling any agent-debug endpoint without a valid authenticated session, so the UID lookup yields null/blank.","commonSituations":"Expired or missing login token; auth header stripped by a proxy; calling the internal service directly bypassing the auth filter.","solutions":["Re-authenticate and retry with a valid session/token","Ensure the auth filter populates uid for this route","Check gateway/proxy forwards the Authorization header","Verify the UID is resolved after the auth context is set"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!getUID()) redirectToLogin();","typeGuard":null,"tryCatchPattern":"try { await debugApi.list(); } catch (e) { if (e.code === 'UNAUTHORIZED') redirectToLogin(); }","preventionTips":["Refresh tokens before expiry","Forward auth headers through proxies/gateways","Check auth context is set before service calls"],"tags":["auth","unauthorized","session"],"backgroundTag":"authentication-required","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"}