iflytek/astron-agent · info
Failed to get current user ID, using system as creator
Error message
Failed to get current user ID, using system as creator
What it means
NotificationServiceImpl.createNotificationEntity tries to obtain the current operator's UID via RequestContextUtil.getUID() to set creatorUid. If that call throws (no request context, unauthenticated, or context cleared), the code catches Exception, logs "Failed to get current user ID, using system as creator", and falls back to leaving creatorUid unset (system). This is a logged warning fallback, not a thrown error.
Solutions
- If a user context should exist, verify auth middleware/interceptor ran and propagated the UID.
- For async processing, propagate the request context (or UID explicitly) to the worker thread before calling notification().
- Accept the fallback only for genuinely system-initiated notifications; otherwise pass the creator UID as an explicit parameter.
- Consider upgrading the log to include the notification type/reason to aid tracing.
Example fix
// before String currentUid = RequestContextUtil.getUID(); notification.setCreatorUid(currentUid); // after String currentUid = RequestContextUtil.getUIDSafe(); // returns null if absent notification.setCreatorUid(currentUid != null ? currentUid : SYSTEM_UID);
Defensive patterns
Strategy: fallback
Validate before calling
// caller-side: pass the UID explicitly when available notificationService.notification(req, currentUser != null ? currentUser.getUid() : null);
Type guard
boolean hasUserContext = RequestContextUtil.getUIDOrNull() != null;
Try / catch
try {
String uid = RequestContextUtil.getUID();
notification.setCreatorUid(uid);
} catch (Exception e) {
log.warn("Failed to get current user ID, using system as creator, source={}", trigger);
} Prevention
- Propagate request context ThreadLocals to async/consumer threads.
- For system-initiated notifications, pass an explicit SYSTEM creator instead of relying on the fallback.
- Only call getUID() where an authenticated request is guaranteed.
- Tag these warnings with the notification type to trace missing-context paths.
When it happens
Trigger: notification() called from a path without an HTTP request context (Kafka consumer, scheduled job, async thread) or before authentication is established, so RequestContextUtil.getUID() throws.
Common situations: System-generated notifications (billing events, background tasks) with no logged-in user; async executor thread lacking the request-context ThreadLocal propagated; internal API call without auth headers.
Related errors
- LOGIN_INFO_ERROR
- SPARK_API_IMAGE_PARAM_ERROR
- Failed to build authentication URL
- RESPONSE_FAILED
- RESPONSE_FAILED
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/e296057a67634d99.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/service/notification/impl/NotificationServiceImpl.java:234
Notification notification = new Notification();
// Manually copy properties, excluding type field
notification.setTitle(request.getTitle());
notification.setBody(request.getBody());
notification.setTemplateCode(request.getTemplateCode());
notification.setPayload(request.getPayload());
notification.setExpireAt(request.getExpireAt());
notification.setMeta(request.getMeta());
// Set type as String type code
notification.setType(type.getCode());
// Get current operating user
try {
String currentUid = RequestContextUtil.getUID();
notification.setCreatorUid(currentUid);
} catch (Exception e) {
log.warn("Failed to get current user ID, using system as creator");
}
return notification;
}
private NotificationPageResponse getUserNotificationsByUid(String receiverUid, NotificationQueryRequest queryRequest) {
if (receiverUid == null) {
throw new BusinessException(ResponseEnum.PARAMETER_ERROR);
}
List<NotificationDto> notifications;
long unreadCount = notificationDataService.countUserUnreadNotifications(receiverUid);
long totalCount;
if (Boolean.TRUE.equals(queryRequest.getUnreadOnly())) {
// Query unread messages only
notifications = notificationDataService.getUserUnreadNotifications(
receiverUid, queryRequest);View on GitHub (pinned to 5e758547a8)