Tencent/WeKnora · error
failed to delete Redis key: %w
Error message
failed to delete Redis key: %w
What it means
DeleteWebSearchTempKBState cleans up a temporary knowledge base and its Redis state key. If s.redisClient.Del fails, the function logs a warning and wraps the Redis error as 'failed to delete Redis key: %w'. This signals that cleanup only partially succeeded: the temp KB may be gone but the Redis state entry persists.
Source
Thrown at internal/application/service/web_search_state.go:137
logger.Infof(ctx, "Cleaning temporary KB for session %s: %s", sessionID, state.KBID)
// Delete all knowledge items
for _, kid := range state.KnowledgeIDs {
if delErr := s.knowledgeService.DeleteKnowledge(ctx, kid); delErr != nil {
logger.Warnf(ctx, "Failed to delete temp knowledge %s: %v", kid, delErr)
}
}
// Delete the knowledge base
if delErr := s.knowledgeBaseService.DeleteKnowledgeBase(ctx, state.KBID); delErr != nil {
logger.Warnf(ctx, "Failed to delete temp knowledge base %s: %v", state.KBID, delErr)
}
// Delete the Redis key
if delErr := s.redisClient.Del(ctx, stateKey).Err(); delErr != nil {
logger.Warnf(ctx, "Failed to delete Redis key %s: %v", stateKey, delErr)
return fmt.Errorf("failed to delete Redis key: %w", delErr)
}
logger.Infof(ctx, "Successfully cleaned up temporary KB for session %s", sessionID)
return nil
}
View on GitHub (pinned to 988cbb0330)
Solutions
- Check Redis connectivity (redis-cli ping) and the app's Redis logs for the underlying delErr.
- Retry the delete; Del failures here are usually transient connection issues.
- Verify the Redis user's ACL permits DELETE on the stateKey pattern.
- If the key may already be gone, treat redis.Nil/'key not found' as success and only fail on real errors.
- As a fallback, rely on TTL expiry for orphaned state keys and alert on repeated cleanup failures.
Example fix
// before
if delErr := s.redisClient.Del(ctx, stateKey).Err(); delErr != nil {
return fmt.Errorf("failed to delete Redis key: %w", delErr)
}
// after
if delErr := s.redisClient.Del(ctx, stateKey).Err(); delErr != nil && delErr != redis.Nil {
return fmt.Errorf("failed to delete Redis key: %w", delErr)
} Defensive patterns
Strategy: try-catch
Validate before calling
if err := s.redisClient.Ping(ctx).Err(); err != nil {
// degrade: skip Redis cleanup and rely on TTL expiry
} Try / catch
if err := svc.DeleteWebSearchTempKBState(ctx, sessionID); err != nil {
if strings.Contains(err.Error(), "failed to delete Redis key") {
logger.Warnf(ctx, "state cleanup deferred; TTL will expire key: %v", err)
return nil // or queue a retry
}
return err
} Prevention
- Set a TTL on state keys at write time so failed deletes self-heal.
- Monitor Redis health and alerts so cleanup windows don't coincide with outages.
- Treat redis.Nil as success in delete paths.
- Grant the app's Redis user DELETE permission via ACL.
- Retry transient Del failures with backoff before surfacing an error.
When it happens
Trigger: Calling DeleteWebSearchTempKBState when Redis is down, connection dropped, the key is on a read-only replica, or the client lacks DELETE permission on the key (e.g. ACL restrictions or a protected prefix).
Common situations: Redis restarted or evicted connections mid-cleanup; network partition between app and Redis; wrong Redis database/ACL in staging vs production; key expired between read and delete causing unexpected client errors.
Related errors
- get sandbox binding: %w
- create sandbox binding: %w
- delete sandbox binding: %w
- scan sandbox bindings: %w
- WEKNORA_REDIS_NAMESPACE must not contain braces
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/e42cd0917f14848c.
Report an issue: GitHub.